diff --git a/api/daily.js b/api/daily.js index a9d0170..661be4f 100644 --- a/api/daily.js +++ b/api/daily.js @@ -7,9 +7,9 @@ export const getDailyInfo = async () => { }); }; -export const getDailyRandomGreeting = async () => { +export const getDailyRandomGreeting = async (sceneId) => { return request({ - url: "/api/blessing/daily-greeting/random", + url: `/api/blessing/daily-greeting/random?sceneId=${sceneId}`, method: "GET", }); }; diff --git a/pages/greeting/daily.vue b/pages/greeting/daily.vue index 9079510..267f97f 100644 --- a/pages/greeting/daily.vue +++ b/pages/greeting/daily.vue @@ -157,7 +157,7 @@ import { } from "@dcloudio/uni-app"; import { useUserStore } from "@/stores/user"; -import { getDailyInfo } from "@/api/daily"; +import { getDailyInfo, getDailyRandomGreeting } from "@/api/daily"; const userStore = useUserStore(); @@ -250,19 +250,37 @@ const hotList = ref([ const selectCategory = (id) => { currentCategory.value = id; - // TODO: Call API to get quote for this category if API supports it - // For now, we just reload daily info which might not be category specific - // If the API supports category param, we should use it. - // Assuming getDailyInfo might accept params but user didn't specify. - // Or maybe we should just rely on refreshQuote? refreshQuote(); }; -const refreshQuote = () => { - // Since we don't have a specific refresh API in the prompt, re-call loadDailyInfo - // This might just reload the same "daily" greeting or a new one. - // Ideally there should be a refresh API. - loadDailyInfo(); +const refreshQuote = async () => { + try { + const res = await getDailyRandomGreeting(currentCategory.value); + if (res) { + const { greetingContent, backgroundUrl, greetingId } = res; + let text = ""; + let highlight = ""; + if (greetingContent) { + const parts = greetingContent.split(" "); + if (parts.length > 1) { + highlight = parts.pop(); + text = parts.join("\n"); + } else { + text = greetingContent; + } + } + + currentQuote.value = { + ...currentQuote.value, + text, + highlight, + backgroundUrl: backgroundUrl || "", + id: greetingId, + }; + } + } catch (e) { + console.error("Failed to refresh quote:", e); + } }; const useHotItem = (item) => {