ContentSharePoster.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <template>
  2. <view class="poster-overlay" v-if="show" @click.self="$emit('close')">
  3. <view class="poster-container">
  4. <canvas canvas-id="contentPosterCanvas" class="poster-canvas" id="contentPosterCanvas"></canvas>
  5. <view class="poster-actions">
  6. <button class="poster-btn save" @click="savePoster">保存到相册</button>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'ContentSharePoster',
  14. props: {
  15. show: { type: Boolean, default: false },
  16. title: { type: String, default: '' },
  17. coverImage: { type: String, default: '' },
  18. qrCodeBase64: { type: String, default: '' },
  19. typeLabel: { type: String, default: '好物推荐' },
  20. dimensionCode: { type: String, default: '' },
  21. summary: { type: String, default: '' },
  22. priceText: { type: String, default: '' },
  23. ctaText: { type: String, default: '长按识别二维码 · 查看详情' },
  24. inviteText: { type: String, default: '' },
  25. // 五维能量数据卡:{ label?: String, overall?: Number, dims: [{ key, label, score, color }] }
  26. // 传 null 时不画数据卡,按 coverImage -> brandFallback -> 占位图 顺序降级(原有行为不变)
  27. energyData: { type: Object, default: null },
  28. // 无 energyData 且 coverImage 为空时,是否用品牌渐变卡替代"暂无封面图"占位
  29. brandFallback: { type: Boolean, default: false }
  30. },
  31. watch: {
  32. show(val) {
  33. if (val) {
  34. this.$nextTick(function() {
  35. setTimeout(this.drawPoster.bind(this), 300)
  36. }.bind(this))
  37. }
  38. }
  39. },
  40. methods: {
  41. getColors() {
  42. var map = {
  43. body: { main: '#FF8C42', dark: '#EA580C', light: '#FFF7ED' },
  44. mind: { main: '#FF6B9D', dark: '#DB2777', light: '#FDF2F8' },
  45. wisdom: { main: '#6366F1', dark: '#4F46E5', light: '#EEF2FF' },
  46. action: { main: '#10B981', dark: '#059669', light: '#ECFDF5' },
  47. wealth: { main: '#F59E0B', dark: '#D97706', light: '#FFFBEB' }
  48. }
  49. return map[this.dimensionCode] || { main: '#F97316', dark: '#EA580C', light: '#FFF7ED' }
  50. },
  51. drawPoster() {
  52. var self = this
  53. uni.createSelectorQuery().in(this)
  54. .select('#contentPosterCanvas')
  55. .boundingClientRect(function(rect) {
  56. var scaleX = 1
  57. var scaleY = 1
  58. if (rect && rect.width && rect.height) {
  59. scaleX = rect.width / 500
  60. scaleY = rect.height / 800
  61. }
  62. self._renderPoster(scaleX, scaleY)
  63. })
  64. .exec()
  65. },
  66. _renderPoster(scaleX, scaleY) {
  67. var ctx = uni.createCanvasContext('contentPosterCanvas', this)
  68. var w = 500
  69. var h = 800
  70. var colors = this.getColors()
  71. // 画布 CSS 用 rpx,实际像素随设备变化(375px 屏约 310x496),而绘制按 500x800 设计坐标;
  72. // 不缩放坐标系时右侧/底部内容(含二维码 y≈552-702)会被裁剪出画布,导致海报显示不全。
  73. if (scaleX !== 1 || scaleY !== 1) {
  74. ctx.scale(scaleX, scaleY)
  75. }
  76. var gradient = ctx.createLinearGradient(0, 0, w * 0.3, h)
  77. gradient.addColorStop(0, colors.main)
  78. gradient.addColorStop(0.55, colors.dark)
  79. gradient.addColorStop(1, colors.dark)
  80. ctx.setFillStyle(gradient)
  81. ctx.fillRect(0, 0, w, h)
  82. this._drawTopDecoration(ctx, w, colors)
  83. var cardX = 28
  84. var cardY = 112
  85. var cardW = 444
  86. var cardH = 600
  87. this._drawContentCard(ctx, cardX, cardY, cardW, cardH, colors)
  88. var coverY = cardY + 20
  89. var coverW = cardW - 40
  90. var coverH = 220
  91. var self = this
  92. if (this.energyData) {
  93. // 方案C:五维能量数据卡,canvas 直接绘制(文字锐利、数据真实、无网络开销)
  94. this._drawEnergyCard(ctx, cardX + 20, coverY, coverW, coverH, colors)
  95. this._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  96. } else if (this.coverImage) {
  97. uni.downloadFile({
  98. url: this.coverImage,
  99. success: function(res) {
  100. if (res.statusCode === 200) {
  101. // 按原比例绘制封面图(contain 居中),避免拉伸变形
  102. uni.getImageInfo({
  103. src: res.tempFilePath,
  104. success: function(info) {
  105. var rect = self._fitCoverRect(info.width, info.height, cardX + 20, coverY, coverW, coverH)
  106. ctx.drawImage(res.tempFilePath, rect.x, rect.y, rect.w, rect.h)
  107. self._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  108. },
  109. fail: function() {
  110. ctx.drawImage(res.tempFilePath, cardX + 20, coverY, coverW, coverH)
  111. self._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  112. }
  113. })
  114. } else {
  115. self._drawCoverPlaceholder(ctx, cardX + 20, coverY, coverW, coverH)
  116. self._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  117. }
  118. },
  119. fail: function() {
  120. self._drawCoverPlaceholder(ctx, cardX + 20, coverY, coverW, coverH)
  121. self._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  122. }
  123. })
  124. } else if (this.brandFallback) {
  125. this._drawBrandCard(ctx, cardX + 20, coverY, coverW, coverH, colors)
  126. this._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  127. } else {
  128. this._drawCoverPlaceholder(ctx, cardX + 20, coverY, coverW, coverH)
  129. this._drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors)
  130. }
  131. },
  132. _fitCoverRect(imgW, imgH, boxX, boxY, boxW, boxH) {
  133. if (!imgW || !imgH) {
  134. return { x: boxX, y: boxY, w: boxW, h: boxH }
  135. }
  136. var scale = Math.min(boxW / imgW, boxH / imgH)
  137. var w = imgW * scale
  138. var h = imgH * scale
  139. return {
  140. x: boxX + (boxW - w) / 2,
  141. y: boxY + (boxH - h) / 2,
  142. w: w,
  143. h: h
  144. }
  145. },
  146. _drawTopDecoration(ctx, w, colors) {
  147. var centerX = w / 2
  148. var dotColors = ['#FF8C42', '#6366F1', '#F59E0B', '#10B981', '#FF6B9D']
  149. var dotY = 28
  150. var dotR = 5
  151. var dotSpacing = 26
  152. var i, offsetX, offsetY
  153. for (i = 0; i < 5; i++) {
  154. offsetX = (i - 2) * dotSpacing
  155. offsetY = Math.abs(i - 2) * 3
  156. ctx.setFillStyle(dotColors[i])
  157. ctx.beginPath()
  158. ctx.arc(centerX + offsetX, dotY + offsetY, dotR, 0, 2 * Math.PI)
  159. ctx.fill()
  160. }
  161. ctx.setFillStyle('#ffffff')
  162. ctx.setFontSize(20)
  163. ctx.setTextAlign('center')
  164. ctx.setTextBaseline('top')
  165. ctx.fillText('浠艾福', centerX, 52)
  166. ctx.setFontSize(14)
  167. ctx.setFillStyle('rgba(255,255,255,0.8)')
  168. ctx.fillText('给全家的一站式幸福提案', centerX, 76)
  169. ctx.setStrokeStyle('rgba(255,255,255,0.25)')
  170. ctx.setLineWidth(1)
  171. ctx.beginPath()
  172. ctx.moveTo(80, 100)
  173. ctx.lineTo(w - 80, 100)
  174. ctx.stroke()
  175. },
  176. _drawContentCard(ctx, x, y, w, h, colors) {
  177. ctx.setFillStyle('rgba(0,0,0,0.04)')
  178. this._roundRect(ctx, x + 2, y + 3, w, h, 16)
  179. ctx.fill()
  180. ctx.setFillStyle(colors.light)
  181. this._roundRect(ctx, x, y, w, h, 16)
  182. ctx.fill()
  183. },
  184. _drawCoverPlaceholder(ctx, x, y, w, h) {
  185. ctx.setFillStyle('#FEF3C7')
  186. this._roundRect(ctx, x, y, w, h, 8)
  187. ctx.fill()
  188. ctx.setFillStyle('#F97316')
  189. ctx.setFontSize(16)
  190. ctx.setTextAlign('center')
  191. ctx.setTextBaseline('middle')
  192. ctx.fillText('暂无封面图', x + w / 2, y + h / 2)
  193. },
  194. // 五维能量数据卡(方案C):综合分大字 + 五维彩色圆/分数/进度条
  195. _drawEnergyCard(ctx, x, y, w, h, colors) {
  196. var data = this.energyData || {}
  197. var dims = data.dims || []
  198. ctx.setFillStyle('#FFFFFF')
  199. this._roundRect(ctx, x, y, w, h, 8)
  200. ctx.fill()
  201. // 顶部:左侧标题,右侧综合分
  202. ctx.setFillStyle('#78716C')
  203. ctx.setFontSize(13)
  204. ctx.setTextAlign('left')
  205. ctx.setTextBaseline('top')
  206. ctx.fillText(data.label || '我们家的能量', x + 16, y + 16)
  207. var hasOverall = data.overall !== null && data.overall !== undefined && !isNaN(data.overall)
  208. if (hasOverall) {
  209. ctx.setFillStyle(colors.main)
  210. ctx.setFontSize(30)
  211. ctx.setTextAlign('right')
  212. ctx.fillText(String(data.overall), x + w - 28, y + 8)
  213. ctx.setFillStyle('#78716C')
  214. ctx.setFontSize(13)
  215. ctx.fillText('分', x + w - 16, y + 28)
  216. }
  217. ctx.setStrokeStyle('#F5F5F4')
  218. ctx.setLineWidth(1)
  219. ctx.beginPath()
  220. ctx.moveTo(x + 16, y + 54)
  221. ctx.lineTo(x + w - 16, y + 54)
  222. ctx.stroke()
  223. // 五维柱:彩色圆 + 单字 + 分数 + 进度条
  224. var count = dims.length
  225. for (var i = 0; i < count; i++) {
  226. var d = dims[i] || {}
  227. var cx = x + 16 + ((w - 32) / count) * i + (w - 32) / count / 2
  228. var color = d.color || colors.main
  229. var score = Number(d.score)
  230. if (isNaN(score) || score < 0) score = 0
  231. if (score > 100) score = 100
  232. ctx.setFillStyle(color)
  233. ctx.beginPath()
  234. ctx.arc(cx, y + 94, 17, 0, 2 * Math.PI)
  235. ctx.fill()
  236. ctx.setFillStyle('#FFFFFF')
  237. ctx.setFontSize(15)
  238. ctx.setTextAlign('center')
  239. ctx.setTextBaseline('middle')
  240. ctx.fillText(d.label || '', cx, y + 95)
  241. ctx.setFillStyle('#1C1917')
  242. ctx.setFontSize(18)
  243. ctx.setTextBaseline('top')
  244. ctx.fillText(String(score), cx, y + 120)
  245. var barW = 44
  246. var barH = 4
  247. var barX = cx - barW / 2
  248. var barY = y + 148
  249. ctx.setFillStyle('#F5F5F4')
  250. this._roundRect(ctx, barX, barY, barW, barH, 2)
  251. ctx.fill()
  252. if (score > 0) {
  253. ctx.setFillStyle(color)
  254. this._roundRect(ctx, barX, barY, barW * score / 100, barH, 2)
  255. ctx.fill()
  256. }
  257. }
  258. ctx.setFillStyle('#A8A29E')
  259. ctx.setFontSize(11)
  260. ctx.setTextAlign('center')
  261. ctx.setTextBaseline('top')
  262. ctx.fillText('五维能量 · 浠艾福家庭测评', x + w / 2, y + 172)
  263. },
  264. // 品牌渐变卡:用户未解锁全景(无五维数据)且无封面图时的降级方案
  265. _drawBrandCard(ctx, x, y, w, h, colors) {
  266. var g = ctx.createLinearGradient(x, y, x + w, y + h)
  267. g.addColorStop(0, colors.main)
  268. g.addColorStop(1, colors.dark)
  269. ctx.setFillStyle(g)
  270. this._roundRect(ctx, x, y, w, h, 8)
  271. ctx.fill()
  272. var dotColors = ['#FF8C42', '#6366F1', '#F59E0B', '#10B981', '#FF6B9D']
  273. var centerX = x + w / 2
  274. for (var i = 0; i < 5; i++) {
  275. ctx.setFillStyle(dotColors[i])
  276. ctx.beginPath()
  277. ctx.arc(centerX + (i - 2) * 26, y + 66, 5, 0, 2 * Math.PI)
  278. ctx.fill()
  279. }
  280. ctx.setFillStyle('#FFFFFF')
  281. ctx.setFontSize(24)
  282. ctx.setTextAlign('center')
  283. ctx.setTextBaseline('top')
  284. ctx.fillText('浠艾福', centerX, y + 86)
  285. ctx.setFillStyle('rgba(255,255,255,0.85)')
  286. ctx.setFontSize(13)
  287. ctx.fillText('给全家的一站式幸福提案', centerX, y + 124)
  288. ctx.setFillStyle('rgba(255,255,255,0.7)')
  289. ctx.setFontSize(12)
  290. ctx.fillText('测一测你家的五维能量', centerX, y + 152)
  291. },
  292. _drawContentAfterCover(ctx, w, h, cardX, cardW, coverY, coverH, colors) {
  293. var self = this
  294. var labelY = coverY + coverH + 16
  295. ctx.setFillStyle(colors.main)
  296. ctx.setFontSize(13)
  297. ctx.setTextAlign('left')
  298. ctx.setTextBaseline('top')
  299. ctx.fillText(this.typeLabel, cardX + 20, labelY)
  300. // 标题(2行截断)
  301. var titleY = labelY + 22
  302. ctx.setFillStyle('#1C1917')
  303. ctx.setFontSize(18)
  304. ctx.setTextAlign('left')
  305. ctx.setTextBaseline('top')
  306. this._drawWrappedText(ctx, this.title || '精彩内容', cardX + 20, titleY, cardW - 40, 24, 2)
  307. // 价格行(商品用;空则跳过)
  308. var priceY = titleY + 56
  309. if (this.priceText) {
  310. ctx.setFillStyle(colors.main)
  311. ctx.setFontSize(17)
  312. ctx.setTextAlign('left')
  313. ctx.setTextBaseline('top')
  314. ctx.fillText(this.priceText, cardX + 20, priceY)
  315. }
  316. // 简介(1-2行灰字;空则跳过)
  317. var summaryY = (this.priceText ? priceY + 34 : priceY)
  318. if (this.summary) {
  319. ctx.setFillStyle('#78716C')
  320. ctx.setFontSize(13)
  321. ctx.setTextAlign('left')
  322. ctx.setTextBaseline('top')
  323. this._drawWrappedText(ctx, this.summary, cardX + 20, summaryY, cardW - 40, 20, 2)
  324. }
  325. // 邀请语(二维码上方)
  326. var inviteY = (this.summary ? summaryY + 48 : summaryY)
  327. ctx.setFillStyle('#A8A29E')
  328. ctx.setFontSize(13)
  329. ctx.setTextAlign('center')
  330. ctx.setTextBaseline('top')
  331. ctx.fillText(this.inviteText || '长按识别二维码 · 查看详情', w / 2, inviteY)
  332. // 二维码
  333. var qrSize = 150
  334. var qrX = (w - qrSize) / 2
  335. var qrY = inviteY + 24
  336. if (this.qrCodeBase64) {
  337. var base64Data = this.qrCodeBase64
  338. if (base64Data.indexOf('data:image') === 0) {
  339. var commaIdx = base64Data.indexOf(',')
  340. if (commaIdx > -1) {
  341. base64Data = base64Data.substring(commaIdx + 1)
  342. }
  343. }
  344. var fs = uni.getFileSystemManager()
  345. var filePath = wx.env.USER_DATA_PATH + '/content_share_qr_tmp.png'
  346. fs.writeFile({
  347. filePath: filePath,
  348. data: base64Data,
  349. encoding: 'base64',
  350. success: function() {
  351. ctx.setFillStyle('#ffffff')
  352. self._roundRect(ctx, qrX - 10, qrY - 10, qrSize + 20, qrSize + 20, 8)
  353. ctx.fill()
  354. ctx.setStrokeStyle('#E7E5E4')
  355. ctx.setLineWidth(0.5)
  356. self._roundRect(ctx, qrX - 10, qrY - 10, qrSize + 20, qrSize + 20, 8)
  357. ctx.stroke()
  358. ctx.drawImage(filePath, qrX, qrY, qrSize, qrSize)
  359. self._drawBottomDecoration(ctx, w, h, qrY, qrSize, colors)
  360. },
  361. fail: function() {
  362. self._drawQrPlaceholder(ctx, qrX, qrY, qrSize)
  363. self._drawBottomDecoration(ctx, w, h, qrY, qrSize, colors)
  364. }
  365. })
  366. } else {
  367. this._drawQrPlaceholder(ctx, qrX, qrY, qrSize)
  368. this._drawBottomDecoration(ctx, w, h, qrY, qrSize, colors)
  369. }
  370. },
  371. _drawWrappedText(ctx, text, x, y, maxWidth, lineHeight, maxLines) {
  372. var chars = (text || '').split('')
  373. var line = ''
  374. var lineCount = 0
  375. for (var i = 0; i < chars.length; i++) {
  376. var testLine = line + chars[i]
  377. var testWidth = this._textWidth(ctx, testLine)
  378. if (testWidth > maxWidth && line.length > 0) {
  379. ctx.fillText(line, x, y + lineCount * lineHeight)
  380. line = chars[i]
  381. lineCount++
  382. if (lineCount >= maxLines - 1) {
  383. var remaining = chars.slice(i).join('')
  384. var remainingLine = line + remaining
  385. while (this._textWidth(ctx, remainingLine + '..') > maxWidth && remainingLine.length > 2) {
  386. remainingLine = remainingLine.substring(0, remainingLine.length - 1)
  387. }
  388. ctx.fillText(remainingLine + '..', x, y + lineCount * lineHeight)
  389. return
  390. }
  391. } else {
  392. line = testLine
  393. }
  394. }
  395. ctx.fillText(line, x, y + lineCount * lineHeight)
  396. },
  397. _textWidth(ctx, text) {
  398. if (ctx.measureText) {
  399. try { return ctx.measureText(text).width } catch (e) { return (text || '').length * 18 }
  400. }
  401. return (text || '').length * 18
  402. },
  403. _drawQrPlaceholder(ctx, x, y, size) {
  404. ctx.setFillStyle('#ffffff')
  405. this._roundRect(ctx, x - 10, y - 10, size + 20, size + 20, 8)
  406. ctx.fill()
  407. ctx.setStrokeStyle('#E7E5E4')
  408. ctx.setLineWidth(0.5)
  409. this._roundRect(ctx, x - 10, y - 10, size + 20, size + 20, 8)
  410. ctx.stroke()
  411. ctx.setFillStyle('#A8A29E')
  412. ctx.setFontSize(16)
  413. ctx.setTextAlign('center')
  414. ctx.setTextBaseline('middle')
  415. ctx.fillText('二维码加载中', x + size / 2, y + size / 2)
  416. },
  417. _drawBottomDecoration(ctx, w, h, qrY, qrSize, colors) {
  418. var centerX = w / 2
  419. var bottomY = qrY + qrSize + 16
  420. var diamondY = bottomY + 6
  421. ctx.setFillStyle('rgba(0,0,0,0.06)')
  422. ctx.beginPath()
  423. ctx.moveTo(centerX - 76, diamondY)
  424. ctx.lineTo(centerX - 72, diamondY - 4)
  425. ctx.lineTo(centerX - 68, diamondY)
  426. ctx.lineTo(centerX - 72, diamondY + 4)
  427. ctx.closePath()
  428. ctx.fill()
  429. ctx.beginPath()
  430. ctx.moveTo(centerX + 68, diamondY)
  431. ctx.lineTo(centerX + 72, diamondY - 4)
  432. ctx.lineTo(centerX + 76, diamondY)
  433. ctx.lineTo(centerX + 72, diamondY + 4)
  434. ctx.closePath()
  435. ctx.fill()
  436. ctx.setFillStyle(colors.main)
  437. ctx.setFontSize(18)
  438. ctx.setTextAlign('center')
  439. ctx.setTextBaseline('top')
  440. ctx.fillText(this.ctaText || '长按识别二维码 · 查看详情', centerX, bottomY)
  441. var dotColors = ['#FF8C42', '#6366F1', '#F59E0B', '#10B981', '#FF6B9D']
  442. var dotY = h - 22
  443. var dotR = 4
  444. var dotSpacing = 20
  445. var i_b, offsetX_b
  446. for (i_b = 0; i_b < 5; i_b++) {
  447. offsetX_b = (i_b - 2) * dotSpacing
  448. ctx.setFillStyle(dotColors[i_b])
  449. ctx.beginPath()
  450. ctx.arc(centerX + offsetX_b, dotY, dotR, 0, 2 * Math.PI)
  451. ctx.fill()
  452. }
  453. ctx.setFillStyle('rgba(255,255,255,0.45)')
  454. ctx.setFontSize(12)
  455. ctx.setTextAlign('center')
  456. ctx.setTextBaseline('top')
  457. ctx.fillText('浠艾福 · 家庭健康俱乐部', centerX, dotY + 7)
  458. ctx.draw()
  459. },
  460. _roundRect(ctx, x, y, w, h, r) {
  461. ctx.beginPath()
  462. ctx.moveTo(x + r, y)
  463. ctx.arcTo(x + w, y, x + w, y + r, r)
  464. ctx.arcTo(x + w, y + h, x + w - r, y + h, r)
  465. ctx.arcTo(x, y + h, x, y + h - r, r)
  466. ctx.arcTo(x, y, x + r, y, r)
  467. ctx.closePath()
  468. },
  469. savePoster() {
  470. var self = this
  471. uni.canvasToTempFilePath({
  472. canvasId: 'contentPosterCanvas',
  473. destWidth: 500,
  474. destHeight: 800,
  475. success: function(res) {
  476. uni.saveImageToPhotosAlbum({
  477. filePath: res.tempFilePath,
  478. success: function() {
  479. uni.showToast({ title: '已保存到相册', icon: 'success' })
  480. self.$emit('close')
  481. },
  482. fail: function(err) {
  483. if (err && err.errMsg && (err.errMsg.indexOf('deny') > -1 || err.errMsg.indexOf('auth denied') > -1 || err.errMsg.indexOf('authorize') > -1)) {
  484. uni.showModal({
  485. title: '提示',
  486. content: '需要相册权限才能保存图片',
  487. confirmText: '去设置',
  488. success: function(modalRes) {
  489. if (modalRes.confirm) {
  490. uni.openSetting()
  491. }
  492. }
  493. })
  494. } else {
  495. uni.showToast({ title: '保存失败,请重试', icon: 'none' })
  496. }
  497. }
  498. })
  499. },
  500. fail: function() {
  501. uni.showToast({ title: '生成图片失败', icon: 'none' })
  502. }
  503. }, this)
  504. }
  505. }
  506. }
  507. </script>
  508. <style scoped>
  509. .poster-overlay {
  510. position: fixed;
  511. top: 0;
  512. left: 0;
  513. right: 0;
  514. bottom: 0;
  515. background: rgba(0, 0, 0, 0.6);
  516. display: flex;
  517. align-items: center;
  518. justify-content: center;
  519. z-index: 999;
  520. }
  521. .poster-container {
  522. display: flex;
  523. flex-direction: column;
  524. align-items: center;
  525. }
  526. .poster-canvas {
  527. width: 620rpx;
  528. height: 992rpx;
  529. border-radius: 16rpx;
  530. }
  531. .poster-actions {
  532. display: flex;
  533. flex-direction: column;
  534. width: 620rpx;
  535. margin-top: 30rpx;
  536. }
  537. .poster-btn {
  538. height: 80rpx;
  539. line-height: 80rpx;
  540. font-size: 30rpx;
  541. border-radius: 40rpx;
  542. text-align: center;
  543. border: none;
  544. }
  545. .poster-btn::after { border: none; }
  546. .poster-btn.save {
  547. background: #ffffff;
  548. color: #F97316;
  549. font-weight: 600;
  550. }
  551. .poster-btn.save:active { opacity: 0.85; }
  552. </style>