qrcode.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div id="qrcodes" style="width:100%;">
  3. <mt-header title="二维码">
  4. <mt-button class="bgnone" slot="left" @click="$router.go(-1)">返回</mt-button>
  5. </mt-header>
  6. <span v-if="user.role === 'user'">
  7. <li class="txtQr" style="padding-top:7vh;">学生姓名:{{ userInfo.xm || '' }}</li>
  8. <li class="txtQr">门票类型:{{ ticketType }}</li>
  9. </span>
  10. <div id="qrcode" style="display:flex;justify-content:center;align-items:center;" :style="newHeight" ref="qrcode">
  11. <canvas id="canvas" style="display:-webkit-inline-box;width: 4rem !important;height:4rem !important;margin-top: 200px;"></canvas>
  12. </div>
  13. </div>
  14. </template>
  15. <script>
  16. import { mapActions, mapState, mapMutations } from 'vuex';
  17. import QRCode from 'qrcode';
  18. export default {
  19. name: 'qrcodes',
  20. data() {
  21. return {
  22. id: this.$route.query.id || '',
  23. ticketType: this.$route.query.type && this.$route.query.type === '0' ? '普通票' : '受限票' || '',
  24. popupVisible: false,
  25. };
  26. },
  27. computed: {
  28. ...mapState({
  29. user: state => state.publics.user,
  30. userInfo: state => state.self.userInfo,
  31. }),
  32. newHeight: {
  33. get() {
  34. let height;
  35. if (this.user.role === 'user') {
  36. height = window.screen.availHeight * 0.3 + 'px';
  37. } else {
  38. height = window.screen.availHeight * 0.6 + 'px';
  39. }
  40. let style = { height: height };
  41. return style;
  42. },
  43. },
  44. },
  45. created() {
  46. this.$nextTick(() => {
  47. this.initQrcode();
  48. });
  49. },
  50. methods: {
  51. async initQrcode() {
  52. if (!this.booForQrcode) {
  53. await QRCode.toCanvas(document.getElementById('canvas'), this.id, {
  54. width: 300,
  55. margin: 0,
  56. color: { dark: this.$route.query.type === '0' ? '#00ff14' : '#FF9900' },
  57. });
  58. }
  59. },
  60. },
  61. };
  62. </script>
  63. <style lang="less" scoped>
  64. .txtQr {
  65. font-size: 14px;
  66. text-align: center;
  67. min-height: 30px;
  68. margin-bottom: 1px;
  69. white-space: nowrap;
  70. overflow: hidden;
  71. text-overflow: ellipsis;
  72. }
  73. .mint-header {
  74. -webkit-box-align: center;
  75. -ms-flex-align: center;
  76. align-items: center;
  77. background-color: #26a2ff;
  78. -webkit-box-sizing: border-box;
  79. box-sizing: border-box;
  80. color: #fff;
  81. display: -webkit-box;
  82. display: -ms-flexbox;
  83. display: flex;
  84. height: 50px;
  85. line-height: 50px;
  86. color: #fff;
  87. font-size: 16px;
  88. background: #2577e3;
  89. padding: 0;
  90. position: relative;
  91. text-align: center;
  92. white-space: nowrap;
  93. }
  94. </style>