s-follow-modal.vue 4.4 KB

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