You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.4 KiB

8 months ago
8 months ago
8 months ago
  1. <template>
  2. <view class="pageBgImg">
  3. <topNavbar title="个人二维码"></topNavbar>
  4. <view class="pad">
  5. <view class="card">
  6. <view class="refresh_row" @click="refresh">
  7. <view class="text">刷新二维码</view>
  8. <view class="icon">
  9. <image src="@/static/images/index/ic_shuaxin.png" mode=""></image>
  10. </view>
  11. </view>
  12. <view class="qcode">
  13. <canvas id="qrcode" canvas-id="qrcode" style="width: 200px;height: 200px;"></canvas>
  14. </view>
  15. </view>
  16. <view class="card">
  17. <user-info/>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import UQRCode from 'uqrcodejs';
  24. var qr = new UQRCode();
  25. export default {
  26. data() {
  27. return {
  28. timer: null
  29. }
  30. },
  31. onShow() {
  32. this.$nextTick(()=>{
  33. this.refresh()
  34. })
  35. },
  36. // onHide() {
  37. // console.log('清除了')
  38. // clearTimeout(this.timer)
  39. // this.timer = null
  40. // },
  41. beforeDestroy() {
  42. clearTimeout(this.timer)
  43. this.timer = null
  44. // this.refresh = null
  45. },
  46. methods: {
  47. refresh() {
  48. let {coachId, name, schoolId, tenantId, schoolName} = this.vuex_userInfo
  49. // 设置二维码内容
  50. qr.data = JSON.stringify({
  51. coachId,
  52. schoolId,
  53. nickname: encodeURIComponent(name),
  54. timer: Date.now(),
  55. schoolName: encodeURIComponent(schoolName),
  56. })
  57. // 设置二维码大小,必须与canvas设置的宽高一致
  58. qr.size = 200;
  59. qr.margin = 10;
  60. qr.errorCorrectLevel = UQRCode.errorCorrectLevel.L
  61. // 调用制作二维码方法
  62. qr.make()
  63. qr.foregroundImageSrc = require('./coach.png')
  64. // 获取canvas上下文
  65. var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件,this必须传入
  66. // 设置uQRCode实例的canvas上下文
  67. qr.canvasContext = canvasContext;
  68. // 调用绘制方法将二维码图案绘制到canvas上
  69. qr.drawCanvas();
  70. this.timer = setTimeout(()=>{
  71. console.log('刷新了')
  72. this.refresh()
  73. },1000*20)
  74. }
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .qcode {
  80. width: 100%;
  81. display: flex;
  82. align-items: center;
  83. justify-content: center;
  84. padding: 50rpx 0;
  85. }
  86. .card {
  87. padding: 28rpx;
  88. margin-bottom: 24rpx;
  89. }
  90. .refresh_row {
  91. display: flex;
  92. justify-content: flex-end;
  93. align-items: center;
  94. padding: 10rpx 0;
  95. .text {
  96. color: $themC;
  97. font-size: 28rpx;
  98. }
  99. .icon {
  100. width: 24rpx;
  101. height: 24rpx;
  102. margin-left: 6rpx;
  103. }
  104. }
  105. </style>