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.

92 lines
2.0 KiB

8 months ago
8 months ago
8 months ago
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. }
  29. },
  30. onShow() {
  31. this.$nextTick(()=>{
  32. this.refresh()
  33. })
  34. },
  35. methods: {
  36. refresh() {
  37. let { schoolId, schoolName} = this.vuex_userInfo
  38. // 设置二维码内容
  39. qr.data = JSON.stringify({
  40. schoolId,
  41. schoolName: encodeURIComponent(schoolName),
  42. QrType: 1
  43. })
  44. // 设置二维码大小,必须与canvas设置的宽高一致
  45. qr.size = 200;
  46. qr.margin = 10;
  47. qr.errorCorrectLevel = UQRCode.errorCorrectLevel.L
  48. // 调用制作二维码方法
  49. qr.make()
  50. qr.foregroundImageSrc = require('./coach.png')
  51. // 获取canvas上下文
  52. var canvasContext = uni.createCanvasContext('qrcode', this); // 如果是组件,this必须传入
  53. // 设置uQRCode实例的canvas上下文
  54. qr.canvasContext = canvasContext;
  55. // 调用绘制方法将二维码图案绘制到canvas上
  56. qr.drawCanvas();
  57. }
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .qcode {
  63. width: 100%;
  64. display: flex;
  65. align-items: center;
  66. justify-content: center;
  67. padding: 50rpx 0;
  68. }
  69. .card {
  70. padding: 28rpx;
  71. margin-bottom: 24rpx;
  72. }
  73. .refresh_row {
  74. display: flex;
  75. justify-content: flex-end;
  76. align-items: center;
  77. padding: 10rpx 0;
  78. .text {
  79. color: $themC;
  80. font-size: 28rpx;
  81. }
  82. .icon {
  83. width: 24rpx;
  84. height: 24rpx;
  85. margin-left: 6rpx;
  86. }
  87. }
  88. </style>