ShareTemplateExam.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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: 410rpx;left: 120rpx;color: #e7a552; 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.rate.toFixed(1) + '%'"
  94. css="position: absolute;top: 550rpx;left: 100rpx;color: #e7a552;font-size: 30rpx; z-index: 2;"
  95. />
  96. <l-painter-image
  97. :src="qrCode"
  98. css="width: 146rpx; height: 146rpx;position: absolute;bottom: 18rpx;left: 18rpx;"
  99. >
  100. </l-painter-image>
  101. </l-painter-view>
  102. </l-painter>
  103. </view>
  104. <view class="footer">
  105. <div class="title">
  106. <view>分享更多好友</view>
  107. <uni-icons type="closeempty" class="closeempty" @click="onClose" />
  108. </div>
  109. <view class="items">
  110. <view class="save-img" @click="onSaveImage">
  111. <image
  112. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/zGBXaE27pgRjEA6NoMLC75CSdMs3BKjh1vnpGKAc.png"
  113. mode="scaleToFill"
  114. class="save"
  115. />
  116. <text>保存图片</text>
  117. </view>
  118. </view>
  119. </view>
  120. </view>
  121. </template>
  122. <style scoped lang="scss">
  123. .share-template {
  124. height: 100vh;
  125. width: 100%;
  126. background: #999999;
  127. position: relative;
  128. .share-img {
  129. position: absolute;
  130. top: 368rpx;
  131. left: 65rpx;
  132. }
  133. .footer {
  134. position: absolute;
  135. bottom: 0;
  136. left: 0;
  137. width: 100%;
  138. height: calc(68rpx + 80rpx + 140rpx);
  139. background-color: #fff;
  140. border-radius: 40rpx 40rpx 0rpx 0rpx;
  141. .title {
  142. display: flex;
  143. height: 80rpx;
  144. align-items: center;
  145. justify-content: center;
  146. position: relative;
  147. .closeempty {
  148. position: absolute;
  149. right: 32rpx;
  150. }
  151. }
  152. .items {
  153. display: flex;
  154. align-items: center;
  155. justify-content: center;
  156. height: 140rpx;
  157. .save-img {
  158. display: flex;
  159. align-items: center;
  160. gap: 12rpx;
  161. font-weight: 400;
  162. font-size: 28rpx;
  163. color: #000000;
  164. .save {
  165. width: 60rpx;
  166. height: 60rpx;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. </style>