s-follow-modal.vue 4.3 KB

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