ShareTemplate.vue 4.0 KB

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