s-follow-modal.vue 4.1 KB

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