optimize: make page share reward
This commit is contained in:
@@ -507,7 +507,6 @@ const getRewardByShare = async () => {
|
|||||||
const res = await getShareReward({ scene: "avatar_download" });
|
const res = await getShareReward({ scene: "avatar_download" });
|
||||||
if (res.success) {
|
if (res.success) {
|
||||||
uni.showToast({ title: "分享成功,可下载头像" });
|
uni.showToast({ title: "分享成功,可下载头像" });
|
||||||
checkDrawStatus();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ import {
|
|||||||
getCardTemplateList,
|
getCardTemplateList,
|
||||||
getCardTemplateContentList,
|
getCardTemplateContentList,
|
||||||
} from "@/api/make";
|
} from "@/api/make";
|
||||||
import { createShareToken, saveRecord } from "@/api/system";
|
import { createShareToken, abilityCheck, getShareReward } from "@/api/system";
|
||||||
import {
|
import {
|
||||||
onShareAppMessage,
|
onShareAppMessage,
|
||||||
onLoad,
|
onLoad,
|
||||||
@@ -299,7 +299,7 @@ import {
|
|||||||
} from "@dcloudio/uni-app";
|
} from "@dcloudio/uni-app";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
import LoginPopup from "@/components/LoginPopup/LoginPopup.vue";
|
||||||
import { uploadImage } from "@/utils/common.js";
|
import { saveRecordRequest, uploadImage } from "@/utils/common.js";
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const loginPopupRef = ref(null);
|
const loginPopupRef = ref(null);
|
||||||
@@ -482,6 +482,7 @@ const loadMoreTemplates = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
onShareAppMessage(async () => {
|
onShareAppMessage(async () => {
|
||||||
|
getShareReward({ scene: "card_generate" });
|
||||||
if (!isLoggedIn.value) {
|
if (!isLoggedIn.value) {
|
||||||
return {
|
return {
|
||||||
title: "新春祝福",
|
title: "新春祝福",
|
||||||
@@ -503,6 +504,7 @@ onShareAppMessage(async () => {
|
|||||||
targetId: id,
|
targetId: id,
|
||||||
...deviceInfo,
|
...deviceInfo,
|
||||||
});
|
});
|
||||||
|
shareOrSave(id);
|
||||||
return {
|
return {
|
||||||
title: "新春祝福",
|
title: "新春祝福",
|
||||||
path: "/pages/detail/index?shareToken=" + shareTokenRes.shareToken,
|
path: "/pages/detail/index?shareToken=" + shareTokenRes.shareToken,
|
||||||
@@ -569,58 +571,43 @@ const preview = async () => {
|
|||||||
loginPopupRef.value.open();
|
loginPopupRef.value.open();
|
||||||
return;
|
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);
|
const tempPath = await saveByCanvas(true);
|
||||||
createSaveRecord(tempPath);
|
saveRecordRequest(tempPath, cardId.value || "", "card_generate");
|
||||||
|
|
||||||
// uni.showToast({ title: '已保存到相册', icon: 'checkmarkempty' })
|
// uni.showToast({ title: '已保存到相册', icon: 'checkmarkempty' })
|
||||||
};
|
};
|
||||||
|
|
||||||
const createSaveRecord = async (path) => {
|
const shareOrSave = async (id) => {
|
||||||
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 tempPath = await saveByCanvas(false);
|
const tempPath = await saveByCanvas(false);
|
||||||
const fileKeyRes = await uni.uploadFile({
|
const imageUrl = await uploadImage(tempPath);
|
||||||
url: "https://api.ai-meng.com/api/common/upload",
|
|
||||||
filePath: tempPath,
|
updateCard({
|
||||||
name: "file", // 和后端接收文件字段名一致
|
id,
|
||||||
header: {
|
imageUrl,
|
||||||
"x-app-id": "69665538a49b8ae3be50fe5d",
|
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 = () => {
|
const showMore = () => {
|
||||||
|
|||||||
@@ -1,3 +1,6 @@
|
|||||||
|
import { getDeviceInfo } from "@/utils/system";
|
||||||
|
import { saveRecord } from "@/api/system";
|
||||||
|
|
||||||
export const generateObjectId = (
|
export const generateObjectId = (
|
||||||
m = Math,
|
m = Math,
|
||||||
d = Date,
|
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