QRCode.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <view class="container">
  3. <!-- 二维码区域 -->
  4. <view class="code">
  5. <view class="code_top">
  6. <view class="top_title">◆ 请使用微信扫码 ◆</view>
  7. <view class="top_code">
  8. <uv-qrcode ref="qrcode" size="300rpx" :value="QRCodeUrl" @complete="over"></uv-qrcode>
  9. <view class="code_info">
  10. <img class="code_log" src="../../static/images/school-logo.png" />
  11. 万载三中
  12. </view>
  13. </view>
  14. </view>
  15. <view class="code_bottom">填写访客信息</view>
  16. </view>
  17. <!-- 提示区域 -->
  18. <view class="tips">提示:微信扫码即可快速进入小程序进行预约</view>
  19. <!-- 按钮区域 -->
  20. <view class="btn" @click="handleSave">保存二维码到本地</view>
  21. </view>
  22. </template>
  23. <script setup>
  24. import { ref } from 'vue'
  25. // 二维码元素标记
  26. const qrcode = ref(null)
  27. // 二维码是否加载完毕标识
  28. const flag = ref(null)
  29. // 二维码信息
  30. const QRCodeUrl = ref('https://chtech.ncjti.edu.cn/testingServer/repairManage/test')
  31. // 二维码加载完成时触发的回调
  32. const over = (e) => {
  33. flag.value = e.success
  34. }
  35. // 点击保存按钮的回调
  36. const handleSave = () => {
  37. if (flag.value) {
  38. qrcode.value.save({
  39. success: (e) => {
  40. // console.log(e)
  41. uni.showToast({
  42. title: '保存成功',
  43. icon: 'success'
  44. })
  45. },
  46. fail: (err) => {
  47. uni.showToast({
  48. title: '保存失败',
  49. icon: 'fail'
  50. })
  51. }
  52. })
  53. } else {
  54. uni.showToast({
  55. title: '二维码加载失败,无法保存',
  56. icon: 'none'
  57. })
  58. }
  59. }
  60. </script>
  61. <style lang="scss" scoped>
  62. .container {
  63. display: flex;
  64. flex-direction: column;
  65. padding: 0 40rpx;
  66. min-height: 100vh;
  67. background-color: #f1f6fe;
  68. .code {
  69. margin-top: 42rpx;
  70. width: 670rpx;
  71. height: 795rpx;
  72. .code_top {
  73. display: flex;
  74. flex-direction: column;
  75. align-items: center;
  76. height: 679rpx;
  77. border-radius: 18rpx 18rpx 0 0;
  78. background-color: rgba(0, 97, 255, 0.8);
  79. .top_title {
  80. margin: 50rpx 0 40rpx 0;
  81. color: #fff;
  82. font-size: 44rpx;
  83. }
  84. .top_code {
  85. display: flex;
  86. flex-direction: column;
  87. justify-content: space-evenly;
  88. align-items: center;
  89. width: 406rpx;
  90. height: 456rpx;
  91. border-radius: 0 30rpx 0 30rpx;
  92. background-color: #fff;
  93. .code_info {
  94. display: flex;
  95. align-items: center;
  96. font-size: 28rpx;
  97. .code_log {
  98. margin-right: 18rpx;
  99. width: 40rpx;
  100. height: 40rpx;
  101. }
  102. }
  103. }
  104. }
  105. .code_bottom {
  106. display: flex;
  107. justify-content: center;
  108. align-items: center;
  109. height: 116rpx;
  110. font-size: 38rpx;
  111. border-radius: 0 0 18rpx 18rpx;
  112. background-color: #fff;
  113. }
  114. }
  115. .tips {
  116. margin-top: 70rpx;
  117. text-align: center;
  118. color: #a6a6a6;
  119. }
  120. .btn {
  121. display: flex;
  122. justify-content: center;
  123. align-items: center;
  124. margin-top: 80rpx;
  125. width: 670rpx;
  126. height: 100rpx;
  127. font-size: 32rpx;
  128. color: #fff;
  129. border-radius: 8rpx;
  130. background-color: #0061ff;
  131. }
  132. }
  133. </style>