share.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <script setup>
  2. import Container from "../../components/Container/Container.vue";
  3. import lPainter from "@/uni_modules/lime-painter/components/l-painter/l-painter.vue";
  4. import lPainterView from "@/uni_modules/lime-painter/components/l-painter-view/l-painter-view.vue";
  5. import lPainterImage from "@/uni_modules/lime-painter/components/l-painter-image/l-painter-image.vue";
  6. import { ref } from "vue";
  7. import { request } from "../../utils/request";
  8. import { onShow } from "@dcloudio/uni-app";
  9. const qrCode = ref("");
  10. const painter = ref(null);
  11. const showShare = ref(false);
  12. const onSaveImage = () => {
  13. painter.value?.canvasToTempFilePathSync({
  14. fileType: "jpg",
  15. pathType: "url",
  16. quality: 1,
  17. success: (res) => {
  18. // 非H5 保存到相册
  19. uni.saveImageToPhotosAlbum({
  20. filePath: res.tempFilePath,
  21. success: function () {
  22. uni.showToast({
  23. title: "保存成功",
  24. icon: "success",
  25. });
  26. showShare.value = false;
  27. },
  28. });
  29. },
  30. });
  31. };
  32. onShow(() => {
  33. const userInfo = uni.getStorageSync("userInfo");
  34. // 生成二维码
  35. request("api/question_bank/question_reception/user_share/get_invite_qrcode", {
  36. page_url: "pages/index/index",
  37. scene: `share_uid=${userInfo.uid}`
  38. }).then((res) => {
  39. let url = res.data?.image;
  40. if (url.startsWith("data:")) {
  41. var imgPath =
  42. uni.env.USER_DATA_PATH + "/e-invoice" + Date.parse(new Date()) + ".png";
  43. var imageData = url.replace(/^data:image\/\w+;base64,/, "");
  44. var fs = uni.getFileSystemManager();
  45. fs.writeFileSync(imgPath, imageData, "base64");
  46. fs.close();
  47. url = imgPath;
  48. }
  49. qrCode.value = url;
  50. });
  51. });
  52. </script>
  53. <template>
  54. <Container
  55. :scrollStyle="{
  56. padding: 0,
  57. }"
  58. title="分享有礼"
  59. v-if="!showShare"
  60. >
  61. <view>
  62. <view class="bg">
  63. <image class="qr-code" :src="qrCode" mode="scaleToFill" />
  64. </view>
  65. </view>
  66. <template #footer>
  67. <button @click="showShare = true">立即分享</button>
  68. </template>
  69. </Container>
  70. <view class="share-template" v-else>
  71. <view class="share-img">
  72. <l-painter ref="painter">
  73. <l-painter-view
  74. css="width: 686rpx; height: 888rpx; position: relative;"
  75. >
  76. <l-painter-image
  77. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/12nSpSIh19rrhQBm0q3jvmT6dgXeN77q4el6cdXX.png"
  78. css="width: 686rpx; height: 888rpx; position: absolute;top: 0;"
  79. />
  80. <l-painter-image
  81. :src="qrCode"
  82. css="width: 448rpx; height: 448rpx; position: absolute;top: 268rpx;left: 119rpx;"
  83. />
  84. </l-painter-view>
  85. </l-painter>
  86. </view>
  87. <view class="footer">
  88. <div class="title">
  89. <view>分享更多好友</view>
  90. <uni-icons
  91. type="closeempty"
  92. class="closeempty"
  93. @click="showShare = false"
  94. />
  95. </div>
  96. <view class="items">
  97. <view class="save-img" @click="onSaveImage">
  98. <image
  99. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/zGBXaE27pgRjEA6NoMLC75CSdMs3BKjh1vnpGKAc.png"
  100. mode="scaleToFill"
  101. class="save"
  102. />
  103. <text>保存图片</text>
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. </template>
  109. <style scoped lang="scss">
  110. @import "@/uni.scss";
  111. .bg {
  112. height: 1285rpx;
  113. width: 100%;
  114. background: url("https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/Ahdg7M3KIES9pNSnFB55Mlm9NNf6wrGq8oltvNUB.png");
  115. background-size: cover;
  116. position: relative;
  117. .qr-code {
  118. position: absolute;
  119. width: 322.14rpx;
  120. height: 322.14rpx;
  121. border-radius: 24rpx;
  122. border: 8rpx solid $primary;
  123. left: 50%;
  124. top: 36.5%;
  125. transform: translateX(-50%);
  126. }
  127. }
  128. .share-template {
  129. height: 100vh;
  130. width: 100%;
  131. background: #999999;
  132. position: relative;
  133. .share-img {
  134. position: absolute;
  135. top: 368rpx;
  136. left: 32rpx;
  137. }
  138. .footer {
  139. position: absolute;
  140. bottom: 0;
  141. left: 0;
  142. width: 100%;
  143. height: calc(68rpx + 80rpx + 140rpx);
  144. background-color: #fff;
  145. border-radius: 40rpx 40rpx 0rpx 0rpx;
  146. .title {
  147. display: flex;
  148. height: 80rpx;
  149. align-items: center;
  150. justify-content: center;
  151. position: relative;
  152. .closeempty {
  153. position: absolute;
  154. right: 32rpx;
  155. }
  156. }
  157. .items {
  158. display: flex;
  159. align-items: center;
  160. justify-content: center;
  161. height: 140rpx;
  162. .save-img {
  163. display: flex;
  164. align-items: center;
  165. gap: 12rpx;
  166. font-weight: 400;
  167. font-size: 28rpx;
  168. color: #000000;
  169. .save {
  170. width: 60rpx;
  171. height: 60rpx;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. </style>