ShareTemplate.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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, objToUrlParams } 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. qrCode.value = url;
  37. }
  38. });
  39. });
  40. const onSaveImage = () => {
  41. painter.value?.canvasToTempFilePathSync({
  42. fileType: "jpg",
  43. pathType: "url",
  44. quality: 1,
  45. success: (res) => {
  46. // 非H5 保存到相册
  47. uni.saveImageToPhotosAlbum({
  48. filePath: res.tempFilePath,
  49. success: function () {
  50. uni.showToast({
  51. title: "保存成功",
  52. icon: "success",
  53. });
  54. prosp.onClose?.();
  55. },
  56. });
  57. },
  58. });
  59. };
  60. </script>
  61. <template>
  62. <view class="share-template">
  63. <view class="share-img">
  64. <l-painter ref="painter">
  65. <l-painter-view
  66. css="width: 620rpx; height: 889rpx; position: relative;"
  67. >
  68. <l-painter-image
  69. :src="bg"
  70. css="width: 620rpx; height: 889rpx; position: absolute;top: 0;z-index: 1;"
  71. />
  72. <l-painter-text
  73. :text="correct.right + '题'"
  74. css="position: absolute;top: 350rpx;left: 280rpx;color: #3e8647; z-index: 2;"
  75. />
  76. <l-painter-text
  77. :text="correct.total + '题'"
  78. css="position: absolute;top: 265rpx;color: #e7a552;left: 255rpx; z-index: 2;"
  79. />
  80. <l-painter-text
  81. :text="correct.error + '题'"
  82. css="position: absolute;top: 440rpx;left: 290rpx;color: red; z-index: 2;"
  83. />
  84. <l-painter-text
  85. :text="correct.rate.toFixed(1) + '%'"
  86. css="position: absolute;top: 550rpx;left: 100rpx;color: #e7a552;font-size: 30rpx; z-index: 2;"
  87. />
  88. <l-painter-image
  89. :src="qrCode"
  90. css="width: 146rpx; height: 146rpx;position: absolute;bottom: 18rpx;left: 18rpx;"
  91. >
  92. </l-painter-image>
  93. </l-painter-view>
  94. </l-painter>
  95. </view>
  96. <view class="footer">
  97. <div class="title">
  98. <view>分享更多好友</view>
  99. <uni-icons type="closeempty" class="closeempty" @click="onClose" />
  100. </div>
  101. <view class="items">
  102. <view class="save-img" @click="onSaveImage">
  103. <image
  104. src="https://openwork-oss.oss-cn-shenzhen.aliyuncs.com/uploads/question/2025/05/zGBXaE27pgRjEA6NoMLC75CSdMs3BKjh1vnpGKAc.png"
  105. mode="scaleToFill"
  106. class="save"
  107. />
  108. <text>保存图片</text>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. </template>
  114. <style scoped lang="scss">
  115. .share-template {
  116. height: 100vh;
  117. width: 100%;
  118. background: #999999;
  119. position: relative;
  120. .share-img {
  121. position: absolute;
  122. top: 368rpx;
  123. left: 65rpx;
  124. }
  125. .footer {
  126. position: absolute;
  127. bottom: 0;
  128. left: 0;
  129. width: 100%;
  130. height: calc(68rpx + 80rpx + 140rpx);
  131. background-color: #fff;
  132. border-radius: 40rpx 40rpx 0rpx 0rpx;
  133. .title {
  134. display: flex;
  135. height: 80rpx;
  136. align-items: center;
  137. justify-content: center;
  138. position: relative;
  139. .closeempty {
  140. position: absolute;
  141. right: 32rpx;
  142. }
  143. }
  144. .items {
  145. display: flex;
  146. align-items: center;
  147. justify-content: center;
  148. height: 140rpx;
  149. .save-img {
  150. display: flex;
  151. align-items: center;
  152. gap: 12rpx;
  153. font-weight: 400;
  154. font-size: 28rpx;
  155. color: #000000;
  156. .save {
  157. width: 60rpx;
  158. height: 60rpx;
  159. }
  160. }
  161. }
  162. }
  163. }
  164. </style>