ShareTemplate.vue 4.8 KB

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