optimize: make page share reward
This commit is contained in:
@@ -507,7 +507,6 @@ const getRewardByShare = async () => {
|
||||
const res = await getShareReward({ scene: "avatar_download" });
|
||||
if (res.success) {
|
||||
uni.showToast({ title: "分享成功,可下载头像" });
|
||||
checkDrawStatus();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ import {
|
||||
getCardTemplateList,
|
||||
getCardTemplateContentList,
|
||||
} from "@/api/make";
|
||||
import { createShareToken, saveRecord } from "@/api/system";
|
||||
import { createShareToken, abilityCheck, getShareReward } from "@/api/system";
|
||||
import {
|
||||
onShareAppMessage,
|
||||
onLoad,
|
||||
@@ -299,7 +299,7 @@ import {
|
||||
} from "@dcloudio/uni-app";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
||||
import { uploadImage } from "@/utils/common.js";
|
||||
import { saveRecordRequest, uploadImage } from "@/utils/common.js";
|
||||
|
||||
const userStore = useUserStore();
|
||||
const loginPopupRef = ref(null);
|
||||
@@ -482,6 +482,7 @@ const loadMoreTemplates = () => {
|
||||
};
|
||||
|
||||
onShareAppMessage(async () => {
|
||||
getShareReward({ scene: "card_generate" });
|
||||
if (!isLoggedIn.value) {
|
||||
return {
|
||||
title: "新春祝福",
|
||||
@@ -503,6 +504,7 @@ onShareAppMessage(async () => {
|
||||
targetId: id,
|
||||
...deviceInfo,
|
||||
});
|
||||
shareOrSave(id);
|
||||
return {
|
||||
title: "新春祝福",
|
||||
path: "/pages/detail/index?shareToken=" + shareTokenRes.shareToken,
|
||||
@@ -569,58 +571,43 @@ const preview = async () => {
|
||||
loginPopupRef.value.open();
|
||||
return;
|
||||
}
|
||||
const abilityRes = await abilityCheck("card_generate");
|
||||
if (!abilityRes.canUse) {
|
||||
if (
|
||||
abilityRes?.blockType === "need_share" &&
|
||||
abilityRes?.message === "分享可继续"
|
||||
) {
|
||||
uni.showToast({
|
||||
title: "分享给好友可继续使用",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: "您今日祝福卡下载次数已用完,直接分享给好友或者明日再试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const tempPath = await saveByCanvas(true);
|
||||
createSaveRecord(tempPath);
|
||||
saveRecordRequest(tempPath, cardId.value || "", "card_generate");
|
||||
|
||||
// uni.showToast({ title: '已保存到相册', icon: 'checkmarkempty' })
|
||||
};
|
||||
|
||||
const createSaveRecord = async (path) => {
|
||||
const imageUrl = await uploadImage(path);
|
||||
const deviceInfo = getDeviceInfo();
|
||||
saveRecord({
|
||||
scene: "card_generate",
|
||||
targetId: cardId.value || "",
|
||||
imageUrl,
|
||||
deviceInfo,
|
||||
});
|
||||
};
|
||||
|
||||
const shareOrSave = async () => {
|
||||
if (!isLoggedIn.value) {
|
||||
loginPopupRef.value.open();
|
||||
return;
|
||||
}
|
||||
|
||||
const shareOrSave = async (id) => {
|
||||
const tempPath = await saveByCanvas(false);
|
||||
const fileKeyRes = await uni.uploadFile({
|
||||
url: "https://api.ai-meng.com/api/common/upload",
|
||||
filePath: tempPath,
|
||||
name: "file", // 和后端接收文件字段名一致
|
||||
header: {
|
||||
"x-app-id": "69665538a49b8ae3be50fe5d",
|
||||
},
|
||||
const imageUrl = await uploadImage(tempPath);
|
||||
|
||||
updateCard({
|
||||
id,
|
||||
imageUrl,
|
||||
status: 1,
|
||||
blessingId: blessingText.value?.id || "",
|
||||
blessingTo: targetName.value,
|
||||
blessingFrom: signatureName.value,
|
||||
templateId: currentTemplate.value?.id || "",
|
||||
});
|
||||
if (fileKeyRes.statusCode < 400) {
|
||||
const keyJson = JSON.parse(fileKeyRes.data);
|
||||
const url = `https://file.lihailezzc.com/${keyJson?.data.key}`;
|
||||
// const url =
|
||||
// "https://file.lihailezzc.com/resource/99c9f7e0086ed66d20bd1675b4ab22e9.png";
|
||||
// 1. 确保有 cardId
|
||||
if (!cardId.value) {
|
||||
createCard();
|
||||
}
|
||||
updateCard({
|
||||
id: cardId.value,
|
||||
imageUrl: url,
|
||||
status: 1,
|
||||
blessingId: blessingText.value?.id || "",
|
||||
blessingTo: targetName.value,
|
||||
blessingFrom: signatureName.value,
|
||||
templateId: currentTemplate.value?.id || "",
|
||||
});
|
||||
}
|
||||
// uni.showToast({ title: '已保存到相册并可分享', icon: 'none' })
|
||||
};
|
||||
|
||||
const showMore = () => {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import { getDeviceInfo } from "@/utils/system";
|
||||
import { saveRecord } from "@/api/system";
|
||||
|
||||
export const generateObjectId = (
|
||||
m = Math,
|
||||
d = Date,
|
||||
@@ -33,3 +36,14 @@ export const uploadImage = (filePath) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const saveRecordRequest = async (path, targetId, scene) => {
|
||||
const imageUrl = await uploadImage(path);
|
||||
const deviceInfo = getDeviceInfo();
|
||||
saveRecord({
|
||||
scene,
|
||||
targetId,
|
||||
imageUrl,
|
||||
deviceInfo,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user