ShareTemplateExam.vue 4.3 KB

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