s-follow-modal.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <template>
  2. <!-- 关注 -->
  3. <su-popup :show="show" round="10" @close="closeSubscribeModal">
  4. <view class="login-wrap">
  5. <view class="head-box">
  6. <view class=" ss-m-b-20">
  7. <view class="head-title ss-m-r-40 head-title-animation">
  8. {{ t('pop.follow_public_account') }}
  9. </view>
  10. <view class="ss-flex ss-row-center">
  11. <canvas class="hideCanvas" canvas-id="myCanvas" style="width: 300px; height: 300px;"></canvas>
  12. <image :src="imagePath" mode="widthFix" />
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </su-popup>
  18. </template>
  19. <script setup>
  20. import {
  21. computed,
  22. onMounted,
  23. ref,
  24. watchEffect,
  25. nextTick
  26. } from 'vue';
  27. import sheep from '@/sheep';
  28. import QSCanvas from 'qs-canvas';
  29. import {
  30. onShow,
  31. } from '@dcloudio/uni-app';
  32. import {
  33. closeSubscribeModal,
  34. } from '@/sheep/hooks/useModal';
  35. import { t } from '@/locale'
  36. const show = computed(() => sheep.$store('modal').subscribe);
  37. // 创建一个响应式的图像路径变量
  38. const imagePath = ref('');
  39. // 绘制二维码的函数
  40. async function drawQrCode(url) {
  41. console.log(url)
  42. const qsc = new QSCanvas({
  43. canvasId: 'myCanvas',
  44. width: 300,
  45. height: 300,
  46. setCanvasWH: (canvas) => {
  47. // 动态设置画布宽高
  48. canvas.width = 300;
  49. canvas.height = 300;
  50. },
  51. });
  52. await qsc.drawQrCode({
  53. val: url, // 二维码内容
  54. x: 25,
  55. y: 15,
  56. size: 250, // 二维码大小
  57. background: '#ffffff', // 背景色
  58. foreground: '#000000', // 前景色
  59. pdground: '#000000', // 定位角点颜色
  60. correctLevel: 3, // 容错级别
  61. });
  62. // 计算二维码底部中心位置
  63. const qrY = 15;
  64. const qrHeight = 250;
  65. const textX = 300 / 2; // 文字的x位置,水平居中
  66. const textY = qrY + qrHeight + 15; // 文字的y位置,在二维码下方留出20px的空间
  67. // 绘制文字
  68. await qsc.drawText({
  69. val: t('pop.long_press_qrcode_follow'), // 文字内容
  70. x: textX,
  71. y: textY,
  72. maxWidth: 250, // 文字的最大宽度,确保文字不会超出画布
  73. paintbrushProps: {
  74. fillStyle: '#333', // 文字颜色
  75. textAlign: 'center', // 文字水平居中
  76. textBaseline: 'middle', // 文字垂直居中
  77. font: { // 字体属性以对象格式传递
  78. fontStyle: 'normal', // 字体样式
  79. fontVariant: 'normal', // 字体变体
  80. fontWeight: 'normal', // 字体粗细
  81. fontSize: 14, // 字体大小
  82. fontFamily: 'sans-serif' // 字体系列
  83. },
  84. },
  85. });
  86. await qsc.draw();
  87. // 确保使用 await 获取到图片路径
  88. const imagePathData = await qsc.toImage();
  89. if (imagePathData) {
  90. imagePath.value = imagePathData;
  91. }
  92. }
  93. function createQrcode() {
  94. let SHOPRO_DEV_BASE_URL = import.meta.env.SHOPRO_DEV_BASE_URL;
  95. console.log("当前接口Url",SHOPRO_DEV_BASE_URL)
  96. if (SHOPRO_DEV_BASE_URL.includes('letcgo.com')) {
  97. // 如果是常来此购的网址接口 就用常来此购的二维码
  98. drawQrCode(import.meta.env.SHOPRO_MP_HOME_PAGE_LETCGO);
  99. } else {
  100. // 如果不是常来此购的网址接口 就用非繁科技的二维码
  101. drawQrCode(import.meta.env.SHOPRO_MP_HOME_PAGE_FEIFAN);
  102. }
  103. }
  104. watchEffect(() => {
  105. if (show.value) {
  106. nextTick().then(() => {
  107. createQrcode()
  108. });
  109. }
  110. });
  111. </script>
  112. <style lang="scss" scoped>
  113. .hideCanvas {
  114. position: fixed;
  115. top: -99999rpx;
  116. left: -99999rpx;
  117. z-index: -99999;
  118. }
  119. .login-wrap {
  120. padding: 50rpx 34rpx;
  121. min-height: 500rpx;
  122. background-color: #fff;
  123. border-radius: 20rpx 20rpx 0 0;
  124. }
  125. .head-box {
  126. .head-title {
  127. min-width: 160rpx;
  128. font-size: 36rpx;
  129. font-weight: bold;
  130. color: #333333;
  131. line-height: 36rpx;
  132. }
  133. .head-title-active {
  134. width: 160rpx;
  135. font-size: 32rpx;
  136. font-weight: 600;
  137. color: #999;
  138. line-height: 36rpx;
  139. }
  140. .head-title-animation {
  141. animation-name: title-animation;
  142. animation-duration: 0.1s;
  143. animation-timing-function: ease-out;
  144. animation-fill-mode: forwards;
  145. }
  146. .head-title-line {
  147. position: relative;
  148. &::before {
  149. content: '';
  150. width: 1rpx;
  151. height: 34rpx;
  152. background-color: #e4e7ed;
  153. position: absolute;
  154. left: -30rpx;
  155. top: 50%;
  156. transform: translateY(-50%);
  157. }
  158. }
  159. .head-subtitle {
  160. font-size: 26rpx;
  161. font-weight: 400;
  162. color: #afb6c0;
  163. text-align: left;
  164. display: flex;
  165. }
  166. }
  167. </style>