share.vue 4.3 KB

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