s-follow-modal.vue 4.2 KB

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