optimize: fortune page share reward

This commit is contained in:
zzc
2026-01-27 21:21:46 +08:00
parent 115562de53
commit eb72b5556b
3 changed files with 111 additions and 98 deletions

View File

@@ -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 = () => {

View File

@@ -38,7 +38,7 @@
{{ status === "shaking" ? "抽取中..." : "立即抽取" }}
</button>
<view class="footer-info">
<view v-if="isLoggedIn" class="footer-info">
<text class="info-icon"></text>
<text v-if="allowShareCount - useShareCount > 0">
今日还有 {{ remainingCount }} 次抽取机会分享可增加次数
@@ -107,11 +107,11 @@
</view>
<!-- Canvas 用于生成图片 (隐藏) -->
<canvas
<!-- <canvas
canvas-id="shareCanvas"
class="share-canvas"
style="width: 300px; height: 500px; position: fixed; left: 9999px"
></canvas>
></canvas> -->
<LoginPopup ref="loginPopupRef" @logind="handleLogind" />
</view>
@@ -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);
// },
// });
// });
};
</script>