share.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <view class="container" :style="{ '--font-scale': fontScale }">
  3. <!-- 任务模板信息卡片 -->
  4. <view class="package-card">
  5. <image class="cover" :src="getImageUrl(pkg.coverImage) || '/static/default-cover.png'" mode="aspectFill" />
  6. <view class="package-info">
  7. <text class="name">{{ pkg.name }}</text>
  8. <text class="desc">{{ pkg.description }}</text>
  9. <view class="meta">
  10. <text>{{ pkg.cycleDays }}天</text>
  11. <text class="price">{{ formatPriceWithSymbol(pkg.price) }}</text>
  12. </view>
  13. </view>
  14. </view>
  15. <!-- 分享选项 -->
  16. <view class="share-options">
  17. <text class="section-title">分享给家人</text>
  18. <view class="option-item" @click="copyShareCode">
  19. <text class="option-icon">📋</text>
  20. <text class="option-text">复制分享码</text>
  21. </view>
  22. <view class="option-item" @click="generatePoster">
  23. <image class="option-icon" src="/static/icons/poster.png" mode="aspectFit" />
  24. <text class="option-text">生成分享海报</text>
  25. </view>
  26. <view class="option-item" @click="shareToFriend">
  27. <text class="option-icon">📱</text>
  28. <text class="option-text">发送给朋友</text>
  29. </view>
  30. </view>
  31. <!-- 海报预览 -->
  32. <uni-popup ref="posterPopup" type="center">
  33. <view class="poster-popup">
  34. <text class="poster-title">分享海报</text>
  35. <canvas canvas-id="posterCanvas" class="poster-canvas"></canvas>
  36. <view class="poster-actions">
  37. <button class="btn-save" @click="savePoster">保存图片</button>
  38. <button class="btn-share" open-type="share">转发给朋友</button>
  39. </view>
  40. <text class="close-btn" @click="closePoster">关闭</text>
  41. </view>
  42. </uni-popup>
  43. </view>
  44. </template>
  45. <script>
  46. import { BrandColors } from '../../../utils/brand-colors.js'
  47. import { getPackage } from '@/utils/api.js'
  48. import config from '@/config.js'
  49. import fontScaleMixin from '@/mixins/font-scale.js'
  50. export default {
  51. mixins: [fontScaleMixin],
  52. data() {
  53. return {
  54. pkgId: null,
  55. pkg: {},
  56. shareCode: ''
  57. }
  58. },
  59. onLoad(options) {
  60. this.pkgId = options.id
  61. this.loadPackage()
  62. },
  63. methods: {
  64. async loadPackage() {
  65. try {
  66. const res = await getPackage(this.pkgId)
  67. this.pkg = res.data || {}
  68. this.shareCode = this.pkg.shareCode || ''
  69. } catch (e) {
  70. console.error(e)
  71. }
  72. },
  73. copyShareCode() {
  74. uni.setClipboardData({ data: this.shareCode })
  75. uni.showToast({ title: '已复制分享码' })
  76. },
  77. generatePoster() {
  78. const ctx = uni.createCanvasContext('posterCanvas')
  79. // 背景
  80. ctx.setFillStyle('#ffffff')
  81. ctx.fillRect(0, 0, 600, 900)
  82. // 封面图(简化处理,实际需要下载图片)
  83. ctx.setFillStyle(BrandColors.matGreen)
  84. ctx.fillRect(0, 0, 600, 300)
  85. // 标题
  86. ctx.setFillStyle('#333333')
  87. ctx.setFontSize(32)
  88. ctx.fillText(this.pkg.name || '任务模板名称', 30, 350)
  89. // 描述
  90. ctx.setFillStyle('#666666')
  91. ctx.setFontSize(24)
  92. const desc = this.pkg.description || '暂无描述'
  93. ctx.fillText(desc.substring(0, 30), 30, 400)
  94. if (desc.length > 30) {
  95. ctx.fillText(desc.substring(30, 60), 30, 430)
  96. }
  97. // 周期和价格
  98. ctx.setFillStyle('#333333')
  99. ctx.setFontSize(28)
  100. ctx.fillText(`${this.pkg.cycleDays}天`, 30, 480)
  101. ctx.setFillStyle('#f44336')
  102. ctx.setFontSize(36)
  103. ctx.fillText(this.formatPriceWithSymbol(this.pkg.price), 30, 520)
  104. // 分享码
  105. ctx.setFillStyle(BrandColors.matGreen)
  106. ctx.setFontSize(24)
  107. ctx.fillText('分享码: ' + this.shareCode, 30, 580)
  108. // 提示文字
  109. ctx.setFillStyle(BrandColors.textMuted)
  110. ctx.setFontSize(20)
  111. ctx.fillText('微信扫码或输入分享码查看任务模板', 30, 640)
  112. // 品牌标识
  113. ctx.setFillStyle('#cccccc')
  114. ctx.setFontSize(16)
  115. ctx.fillText('浠艾福', 480, 880)
  116. ctx.draw()
  117. this.$refs.posterPopup.open()
  118. },
  119. savePoster() {
  120. uni.canvasToTempFilePath({
  121. canvasId: 'posterCanvas',
  122. success: (res) => {
  123. uni.saveImageToPhotosAlbum({
  124. filePath: res.tempFilePath,
  125. success: () => {
  126. uni.showToast({ title: '已保存到相册' })
  127. },
  128. fail: () => {
  129. uni.showToast({ title: '保存失败', icon: 'none' })
  130. }
  131. })
  132. },
  133. fail: () => {
  134. uni.showToast({ title: '生成失败', icon: 'none' })
  135. }
  136. })
  137. },
  138. shareToFriend() {
  139. // 触发分享
  140. },
  141. closePoster() {
  142. this.$refs.posterPopup.close()
  143. },getImageUrl: function(path) {
  144. if (!path || path === 'null' || path === 'undefined' || path === '/null') return ''
  145. var s = String(path).trim()
  146. if (!s || s === 'null' || s === '/null') return ''
  147. if (s.indexOf('http://') === 0 || s.indexOf('https://') === 0) return s
  148. return config.API_BASE_URL + (s.charAt(0) === '/' ? s : '/' + s)
  149. }
  150. }
  151. }
  152. </script>
  153. <style scoped lang="scss">
  154. .container { min-height: 100vh; background: $facade-fill-2; padding: $uni-space-page; }
  155. .package-card { background: $app-surface; border-radius: 16rpx; overflow: hidden; margin-bottom: $uni-space-lg; }
  156. .cover { width: 100%; height: 300rpx; }
  157. .package-info { padding: $uni-space-page; }
  158. .name { font-size: calc(34rpx * var(--font-scale, 1)); font-weight: bold; color: $facade-text-strong; display: block; margin-bottom: 10rpx; }
  159. .desc { font-size: calc(26rpx * var(--font-scale, 1)); color: $facade-text-body; display: block; margin-bottom: 20rpx; }
  160. .meta { display: flex; align-items: center; gap: 20rpx; font-size: calc(26rpx * var(--font-scale, 1)); }
  161. .price { font-size: calc(34rpx * var(--font-scale, 1)); color: $mat-red; font-weight: bold; }
  162. .share-options { background: $app-surface; border-radius: 16rpx; padding: $uni-space-page; }
  163. .section-title { font-size: calc(30rpx * var(--font-scale, 1)); font-weight: bold; display: block; margin-bottom: 20rpx; }
  164. .option-item { display: flex; align-items: center; padding: $uni-space-lg 0; border-bottom: 1rpx solid $facade-fill; }
  165. .option-item:last-child { border-bottom: none; }
  166. .option-icon { width: calc(44rpx * var(--font-scale, 1)); height: calc(44rpx * var(--font-scale, 1)); margin-right: 20rpx; flex-shrink: 0; }
  167. .option-text { font-size: calc(28rpx * var(--font-scale, 1)); color: $facade-text-strong; }
  168. .poster-popup { background: $app-surface; border-radius: 16rpx; padding: $uni-space-page; width: 600rpx; }
  169. .poster-title { font-size: calc(32rpx * var(--font-scale, 1)); font-weight: bold; display: block; text-align: center; margin-bottom: 20rpx; }
  170. .poster-canvas { width: 600rpx; height: 900rpx; background: $facade-fill-2; margin: 0 auto; }
  171. .poster-actions { display: flex; gap: 20rpx; margin-top: 20rpx; }
  172. .btn-save, .btn-share { flex: 1; background: $mat-green; color: $app-surface; font-size: calc(28rpx * var(--font-scale, 1)); }
  173. .btn-share { background: $mat-blue-base; }
  174. .close-btn { display: block; text-align: center; margin-top: 20rpx; color: $facade-text-muted; font-size: calc(28rpx * var(--font-scale, 1)); }
  175. </style>