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

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