qrcode.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view class="public_dialog">
  3. <view class="code_inner">
  4. <image class="code_img_out" :src="iconUrl.icon_whiteClose" @click="codeHide"></image>
  5. <image class="code_img" :src="iconUrl.icon_codeBgTop"></image>
  6. <view class="code_tit">{{ codeInfo.codeInfo }}</view>
  7. <view class="code_con">
  8. <image class="qr_code" :src="qrCodeImage"></image>
  9. </view>
  10. <view class="code_tip">
  11. <text class="colorCustom">{{ seconds }}</text>秒后自动刷新二维码
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script lang="ts" setup>
  17. import { ref, watch, onUnmounted } from 'vue';
  18. import { REQUEST_CONFIG } from '@/config';
  19. import { common } from '@/utils';
  20. import icon from '@/utils/icon';
  21. const props = defineProps({
  22. /**二维码信息 */
  23. codeInfo: {
  24. type: Object,
  25. default: () => ({})
  26. }
  27. });
  28. const emit = defineEmits(['codeHide']);
  29. const iconUrl = ref(icon)
  30. const seconds = ref(59);
  31. const qrCodeImage = ref('');
  32. let timer: any = null;
  33. const setCode = (data: any) => {
  34. qrCodeImage.value = `${REQUEST_CONFIG.BASE_URL}api/340/340/createQrCode.do?content=${data}`;
  35. if (timer) {
  36. clearInterval(timer);
  37. timer = null;
  38. }
  39. timer = setInterval(() => {
  40. if (seconds.value <= 0) {
  41. seconds.value = 59;
  42. } else {
  43. seconds.value--;
  44. }
  45. }, 1000);
  46. };
  47. const codeHide = () => {
  48. emit('codeHide');
  49. };
  50. watch(
  51. () => props.codeInfo,
  52. (newVal) => {
  53. seconds.value = 59;
  54. if (timer) {
  55. clearInterval(timer);
  56. timer = null;
  57. }
  58. if (!common.isEmpty(newVal)) {
  59. uni.showLoading({
  60. title: '',
  61. mask: true
  62. });
  63. setCode(newVal.CardNo);
  64. uni.hideLoading();
  65. }
  66. },
  67. { deep: true, immediate: true }
  68. );
  69. onUnmounted(() => {
  70. if (timer) {
  71. clearInterval(timer);
  72. timer = null;
  73. }
  74. });
  75. </script>
  76. <style lang="scss" scoped>
  77. .public_dialog {
  78. background-color: rgba(1, 1, 1, 0.6);
  79. position: fixed;
  80. top: 0;
  81. left: 0;
  82. width: 100%;
  83. height: 100%;
  84. z-index: 2;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. }
  89. .code_inner {
  90. width: 600upx;
  91. border-radius: 24upx;
  92. position: relative;
  93. background-color: #fff;
  94. padding-bottom: 50upx;
  95. display: flex;
  96. flex-direction: column;
  97. align-items: center;
  98. justify-content: center;
  99. }
  100. .code_img_out {
  101. width: 24upx;
  102. height: 24upx;
  103. position: absolute;
  104. right: 30upx;
  105. top: 30upx;
  106. z-index: 1;
  107. }
  108. .code_img {
  109. width: 100%;
  110. height: 200upx;
  111. position: absolute;
  112. top: 0;
  113. left: 0;
  114. }
  115. .code_tit {
  116. font-size: 40upx;
  117. font-weight: 500;
  118. height: 200upx;
  119. line-height: 210upx;
  120. position: relative;
  121. color: #fff;
  122. }
  123. .code_card {
  124. font-size: 28upx;
  125. font-family: Arial;
  126. font-weight: 400;
  127. color: rgba(255, 255, 255, 1);
  128. margin: 23upx 0 107upx;
  129. position: relative;
  130. }
  131. .code_subtit {
  132. font-size: 28upx;
  133. }
  134. .code_con {
  135. margin: 37upx 0 30upx;
  136. width: 340upx;
  137. height: 340upx;
  138. }
  139. .code_tip {
  140. font-size: 26upx;
  141. color: #58AB56;
  142. }
  143. .qr_code {
  144. box-sizing: content-box;
  145. width: 340upx;
  146. height: 340upx;
  147. padding: 10upx 0;
  148. }
  149. </style>