share.vue 4.2 KB

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