s-follow-modal.vue 4.0 KB

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