From eb72b5556b505b5119e4ba861a4dd17d6e8512c6 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Tue, 27 Jan 2026 21:21:46 +0800 Subject: [PATCH] optimize: fortune page share reward --- pages/fortune/detail.vue | 2 + pages/fortune/index.vue | 173 +++++++++++++++++---------------------- utils/common.js | 34 +++++++- 3 files changed, 111 insertions(+), 98 deletions(-) diff --git a/pages/fortune/detail.vue b/pages/fortune/detail.vue index f3573c4..70260a4 100644 --- a/pages/fortune/detail.vue +++ b/pages/fortune/detail.vue @@ -93,6 +93,7 @@ import { ref } from "vue"; import { onLoad } from "@dcloudio/uni-app"; import { getPageDetail } from "@/api/system.js"; +import { saveViewRequest } from "@/utils/common.js"; const inviterName = ref(""); const inviterAvatar = ref(""); @@ -122,6 +123,7 @@ const loadPageDetail = async (shareToken) => { fortuneData.value = data; inviterName.value = data?.from?.nickname || ""; inviterAvatar.value = data?.from?.avatar || ""; + saveViewRequest(shareToken, "fortune_draw", data.fortuneId); }; const goHome = () => { diff --git a/pages/fortune/index.vue b/pages/fortune/index.vue index 28b61b0..2b250bc 100644 --- a/pages/fortune/index.vue +++ b/pages/fortune/index.vue @@ -38,7 +38,7 @@ {{ status === "shaking" ? "抽取中..." : "立即抽取" }} - + 今日还有 {{ remainingCount }} 次抽取机会,分享可增加次数 @@ -107,11 +107,11 @@ - + > --> @@ -126,6 +126,7 @@ import { drawFortune } from "@/api/fortune.js"; import { createShareToken, getShareReward } from "@/api/system.js"; import LoginPopup from "@/components/LoginPopup/LoginPopup.vue"; import { useUserStore } from "@/stores/user"; +import { saveRemoteImageToLocal, saveRecordRequest } from "@/utils/common.js"; const userStore = useUserStore(); const loginPopupRef = ref(null); @@ -190,11 +191,9 @@ const checkDrawStatus = async () => { if (!isLoggedIn.value) return; const res = await abilityCheck("fortune_draw"); - if (res.canUse) { - remainingCount.value = res.remain; - allowShareCount.value = res.allowShareCount || 0; - useShareCount.value = res.useShareCount || 0; - } + remainingCount.value = res.remain || 0; + allowShareCount.value = res.allowShareCount || 0; + useShareCount.value = res.useShareCount || 0; }; const currentFortune = ref({}); @@ -262,107 +261,89 @@ const reset = () => { const saveCard = () => { if (currentFortune.value.imageUrl) { uni.showLoading({ title: "保存中..." }); - uni.downloadFile({ - url: currentFortune.value.imageUrl, - success: (res) => { - if (res.statusCode === 200) { - uni.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: () => { - uni.hideLoading(); - uni.showToast({ title: "已保存到相册" }); - }, - fail: () => { - uni.hideLoading(); - uni.showToast({ title: "保存失败", icon: "none" }); - }, - }); - } else { - uni.hideLoading(); - uni.showToast({ title: "下载失败", icon: "none" }); - } - }, - fail: () => { - uni.hideLoading(); - uni.showToast({ title: "下载失败", icon: "none" }); - }, - }); + saveRemoteImageToLocal(currentFortune.value.imageUrl); + saveRecordRequest( + "", + cardId.value, + "fortune_draw", + currentFortune.value.imageUrl, + ); return; } - uni.showLoading({ title: "生成中..." }); + // uni.showLoading({ title: "生成中..." }); - const ctx = uni.createCanvasContext("shareCanvas"); + // const ctx = uni.createCanvasContext("shareCanvas"); - // 绘制背景 - ctx.setFillStyle("#FFFBF0"); - ctx.fillRect(0, 0, 300, 500); + // // 绘制背景 + // ctx.setFillStyle("#FFFBF0"); + // ctx.fillRect(0, 0, 300, 500); - // 绘制外边框 - ctx.setStrokeStyle("#E6CAA0"); - ctx.setLineWidth(1); - ctx.strokeRect(0, 0, 300, 500); + // // 绘制外边框 + // ctx.setStrokeStyle("#E6CAA0"); + // ctx.setLineWidth(1); + // ctx.strokeRect(0, 0, 300, 500); - // 绘制内装饰边框 - ctx.setStrokeStyle("#D4AF37"); - ctx.setLineWidth(2); - ctx.strokeRect(10, 10, 280, 480); + // // 绘制内装饰边框 + // ctx.setStrokeStyle("#D4AF37"); + // ctx.setLineWidth(2); + // ctx.strokeRect(10, 10, 280, 480); - // 绘制年份标签 - ctx.setFillStyle("#E63946"); - // 圆角矩形模拟(简化) - ctx.fillRect(100, 40, 100, 24); - ctx.setFillStyle("#FFFFFF"); - ctx.setFontSize(14); - ctx.setTextAlign("center"); - ctx.fillText("2026 乙巳年", 150, 57); + // // 绘制年份标签 + // ctx.setFillStyle("#E63946"); + // // 圆角矩形模拟(简化) + // ctx.fillRect(100, 40, 100, 24); + // ctx.setFillStyle("#FFFFFF"); + // ctx.setFontSize(14); + // ctx.setTextAlign("center"); + // ctx.fillText("2026 乙巳年", 150, 57); - // 绘制标题 - ctx.setFillStyle("#C0392B"); - ctx.setFontSize(32); - ctx.font = "bold 32px serif"; - ctx.fillText(currentFortune.value.title, 150, 120); + // // 绘制标题 + // ctx.setFillStyle("#C0392B"); + // ctx.setFontSize(32); + // ctx.font = "bold 32px serif"; + // ctx.fillText(currentFortune.value.title, 150, 120); - // 绘制分隔线 - ctx.setStrokeStyle("#D4AF37"); - ctx.beginPath(); - ctx.moveTo(130, 140); - ctx.lineTo(170, 140); - ctx.stroke(); + // // 绘制分隔线 + // ctx.setStrokeStyle("#D4AF37"); + // ctx.beginPath(); + // ctx.moveTo(130, 140); + // ctx.lineTo(170, 140); + // ctx.stroke(); - // 绘制描述 - ctx.setFillStyle("#333333"); - ctx.setFontSize(16); - // 简单换行处理(假设文字不长) - ctx.fillText(currentFortune.value.desc, 150, 180); + // // 绘制描述 + // ctx.setFillStyle("#333333"); + // ctx.setFontSize(16); + // // 简单换行处理(假设文字不长) + // ctx.fillText(currentFortune.value.desc, 150, 180); - // 绘制底部文字 - ctx.setFillStyle("#888888"); - ctx.setFontSize(12); - ctx.fillText("旧岁千般皆如意,新年万事定称心。", 150, 220); + // // 绘制底部文字 + // ctx.setFillStyle("#888888"); + // ctx.setFontSize(12); + // ctx.fillText("旧岁千般皆如意,新年万事定称心。", 150, 220); - ctx.draw(false, () => { - uni.canvasToTempFilePath({ - canvasId: "shareCanvas", - success: (res) => { - uni.saveImageToPhotosAlbum({ - filePath: res.tempFilePath, - success: () => { - uni.hideLoading(); - uni.showToast({ title: "已保存到相册" }); - }, - fail: () => { - uni.hideLoading(); - uni.showToast({ title: "保存失败", icon: "none" }); - }, - }); - }, - fail: (err) => { - uni.hideLoading(); - console.error(err); - }, - }); - }); + // ctx.draw(false, () => { + // uni.canvasToTempFilePath({ + // canvasId: "shareCanvas", + // success: (res) => { + // uni.saveImageToPhotosAlbum({ + // filePath: res.tempFilePath, + // success: () => { + // uni.hideLoading(); + // uni.showToast({ title: "已保存到相册" }); + // }, + // fail: () => { + // uni.hideLoading(); + // uni.showToast({ title: "保存失败", icon: "none" }); + // }, + // }); + // }, + // fail: (err) => { + // uni.hideLoading(); + // console.error(err); + // }, + // }); + // }); }; diff --git a/utils/common.js b/utils/common.js index bcd9f21..e2a0783 100644 --- a/utils/common.js +++ b/utils/common.js @@ -37,8 +37,10 @@ export const uploadImage = (filePath) => { }); }; -export const saveRecordRequest = async (path, targetId, scene) => { - const imageUrl = await uploadImage(path); +export const saveRecordRequest = async (path, targetId, scene, imageUrl) => { + if (!imageUrl) { + imageUrl = await uploadImage(path); + } const deviceInfo = getDeviceInfo(); saveRecord({ scene, @@ -57,3 +59,31 @@ export const saveViewRequest = async (shareToken, scene, targetId) => { deviceInfo, }); }; + +export const saveRemoteImageToLocal = (imageUrl) => { + uni.downloadFile({ + url: imageUrl, + success: (res) => { + if (res.statusCode === 200) { + uni.saveImageToPhotosAlbum({ + filePath: res.tempFilePath, + success: () => { + uni.hideLoading(); + uni.showToast({ title: "已保存到相册" }); + }, + fail: () => { + uni.hideLoading(); + uni.showToast({ title: "保存失败", icon: "none" }); + }, + }); + } else { + uni.hideLoading(); + uni.showToast({ title: "下载失败", icon: "none" }); + } + }, + fail: () => { + uni.hideLoading(); + uni.showToast({ title: "下载失败", icon: "none" }); + }, + }); +};