diff --git a/api/avatar.js b/api/avatar.js index 8667a86..26121f1 100644 --- a/api/avatar.js +++ b/api/avatar.js @@ -36,3 +36,10 @@ export const avatarDownloadRecord = async (data) => { data, }); }; + +export const getAvatarRecommendList = async () => { + return request({ + url: `/api/blessing/avatar/recommend/list`, + method: "get", + }); +}; diff --git a/pages/avatar/detail.vue b/pages/avatar/detail.vue index 4a2198f..c96e2d7 100644 --- a/pages/avatar/detail.vue +++ b/pages/avatar/detail.vue @@ -65,7 +65,7 @@ - 热门新春头像框 + 热门新春头像 查看全部 @@ -77,9 +77,15 @@ @tap="goToMake" > - + - {{ item.name || "新春相框" }} + {{ + item.type === "decor" + ? "新春饰品" + : item.type === "avatar" + ? "新春头像" + : "新春相框" + }} @@ -133,8 +139,9 @@ import { ref, onMounted } from "vue"; import { onLoad } from "@dcloudio/uni-app"; import { getBavBarHeight } from "@/utils/system"; -import { getAvatarFrameList } from "@/api/avatar.js"; import { getPageDetail } from "@/api/system.js"; +import { getAvatarRecommendList } from "@/api/avatar.js"; +import { saveViewRequest } from "@/utils/common.js"; const defaultAvatar = "https://file.lihailezzc.com/resource/d9b329082b32f8305101f708593a4882.png"; @@ -173,6 +180,7 @@ const fetchDetail = async () => { try { // uni.showLoading({ title: "加载中..." }); const res = await getPageDetail(shareToken.value); + saveViewRequest(shareToken.value, "avatar_download", res.id); if (res) { detailData.value = res; } @@ -186,11 +194,8 @@ const fetchDetail = async () => { const fetchFrames = async () => { try { - const res = await getAvatarFrameList(1); - if (res) { - const list = Array.isArray(res) ? res : res.list || []; - frameList.value = list.slice(0, 3); // Take first 3 - } + const res = await getAvatarRecommendList(); + frameList.value = res; } catch (e) { console.error(e); } diff --git a/pages/avatar/index.vue b/pages/avatar/index.vue index 053e333..f9074d5 100644 --- a/pages/avatar/index.vue +++ b/pages/avatar/index.vue @@ -275,7 +275,7 @@ const initSystemAvatars = async () => { .slice(0, 3) .map((item) => ({ id: item.id, imageUrl: item.imageUrl })); // 默认选中第一个 - if (systemAvatars.value.length > 0) { + if (systemAvatars.value.length > 0 && !currentAvatar.value) { currentAvatar.value = systemAvatars.value[0]; } } @@ -299,19 +299,11 @@ onLoad((options) => { if (options.type === "frame") { activeTab.value = "frame"; selectedFrame.value = recommendItem; - // 如果 frames 列表中有这个 id,更新引用以保持选中状态(可选,但推荐) - const found = frames.value.find((f) => f.id === recommendItem.id); - if (found) selectedFrame.value = found; } else if (options.type === "decor") { activeTab.value = "decor"; selectedDecor.value = recommendItem; - const found = decors.value.find((d) => d.id === recommendItem.id); - if (found) selectedDecor.value = found; } else if (options.type === "avatar") { currentAvatar.value = recommendItem; - // 检查系统头像列表 - const found = systemAvatars.value.find((a) => a.id === recommendItem.id); - if (found) currentAvatar.value = found; } } }); @@ -679,11 +671,11 @@ onShareAppMessage(async () => { }; } const id = createAvatarId(); - // const shareTokenRes = { - // shareToken: "iFmK8WjRm6TK", - // }; - const shareTokenRes = await getShareToken("avatar_download", id); - completeCardInfo(id); + const shareTokenRes = { + shareToken: "iFmK8WjRm6TK", + }; + // const shareTokenRes = await getShareToken("avatar_download", id); + // completeCardInfo(id); return { title: "制作我的新春头像", path: `/pages/avatar/detail?shareToken=${shareTokenRes.shareToken}`,