From f11b48e50a3a2a3d2d155d8cfe00ed783ca716f2 Mon Sep 17 00:00:00 2001 From: zzc <1761997216@qq.com> Date: Mon, 2 Mar 2026 15:23:00 +0800 Subject: [PATCH] fix: daily page --- api/daily.js | 15 ++++ pages/greeting/daily.vue | 156 ++++++++++++++++++++++----------------- 2 files changed, 103 insertions(+), 68 deletions(-) create mode 100644 api/daily.js diff --git a/api/daily.js b/api/daily.js new file mode 100644 index 0000000..a9d0170 --- /dev/null +++ b/api/daily.js @@ -0,0 +1,15 @@ +import { request } from "@/utils/request.js"; + +export const getDailyInfo = async () => { + return request({ + url: "/api/blessing/daily-greeting/home", + method: "GET", + }); +}; + +export const getDailyRandomGreeting = async () => { + return request({ + url: "/api/blessing/daily-greeting/random", + method: "GET", + }); +}; diff --git a/pages/greeting/daily.vue b/pages/greeting/daily.vue index 2049341..9079510 100644 --- a/pages/greeting/daily.vue +++ b/pages/greeting/daily.vue @@ -18,7 +18,18 @@ - + {{ currentQuote.text }} @@ -53,7 +64,7 @@ - {{ cat.emoji }} + {{ cat.icon }} { const date = new Date(); @@ -165,70 +178,70 @@ const greetingTitle = computed(() => { return "晚安,好梦相伴"; }); -const categories = [ - { id: "vitality", name: "元气", emoji: "😊", bg: "#fff8e1" }, - { id: "luck", name: "好运", emoji: "🍀", bg: "#e8f5e9" }, - { id: "gentle", name: "温柔", emoji: "❤️", bg: "#ffebee" }, - { id: "work", name: "工作", emoji: "💼", bg: "#e3f2fd" }, - { id: "funny", name: "搞笑", emoji: "😂", bg: "#fff3e0" }, -]; +const scenes = ref([]); +const currentCategory = ref(""); -const currentCategory = ref("vitality"); - -const quotes = { - vitality: [ - { - text: "愿你眼中有星辰\n心中有山海\n每一步都走在", - highlight: "开满鲜花的路上", - author: "陈小明", - }, - { - text: "生活原本沉闷\n但跑起来就有风", - highlight: "做自己的小太阳", - author: "李华", - }, - ], - luck: [ - { - text: "好运正在派送中\n请保持心情舒畅", - highlight: "万事顺遂", - author: "锦鲤", - }, - ], - gentle: [ - { - text: "温柔是宝藏\n你也是", - highlight: "岁月静好", - author: "微风", - }, - ], - work: [ - { - text: "打工人的意志\n是钢铁铸成的", - highlight: "搞钱要紧", - author: "打工人", - }, - ], - funny: [ - { - text: "间歇性踌躇满志\n持续性混吃等死", - highlight: "这就是人生", - author: "咸鱼", - }, - ], -}; - -const currentQuote = ref(quotes.vitality[0]); +const currentQuote = ref({ + text: "", + highlight: "", + author: "", + backgroundUrl: "", + id: "", +}); const authorName = ref(""); -// Remove automatic sync with quote author to allow custom input to persist -// watch( -// currentQuote, -// (newVal) => { -// authorName.value = newVal.author; -// }, -// { deep: true } -// ); +const loadDailyInfo = async () => { + try { + const res = await getDailyInfo(); + if (res) { + streakDays.value = res.streakDays || 0; + if (res.lastSignature && !authorName.value) { + authorName.value = res.lastSignature; + } + + if (res.scenes && res.scenes.length > 0) { + scenes.value = res.scenes; + if (!currentCategory.value) { + currentCategory.value = res.scenes[0].id; + } + } + + if (res.mainHero) { + const { greetingContent, backgroundUrl, greetingId, greetingScene } = + res.mainHero; + 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 = { + text, + highlight, + author: authorName.value, // Will be reactive in template via authorName ref + backgroundUrl: backgroundUrl || "", + id: greetingId, + }; + + if (greetingScene) { + currentCategory.value = greetingScene; + } + } + } + } catch (e) { + console.error("Failed to load daily info:", e); + } +}; + +onMounted(() => { + loadDailyInfo(); +}); const hotList = ref([ { text: "新的一年,愿灵马带走烦恼...", count: "2.4" }, @@ -237,17 +250,24 @@ 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 = () => { - const list = quotes[currentCategory.value] || quotes.vitality; - const randomIndex = Math.floor(Math.random() * list.length); - currentQuote.value = list[randomIndex]; + // 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 useHotItem = (item) => { currentQuote.value = { + ...currentQuote.value, text: item.text, highlight: "", author: "热榜推荐",