fix: daily page

This commit is contained in:
zzc
2026-03-02 15:23:00 +08:00
parent 033c70962c
commit f11b48e50a
2 changed files with 103 additions and 68 deletions

15
api/daily.js Normal file
View File

@@ -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",
});
};

View File

@@ -18,7 +18,18 @@
<!-- Main Card -->
<view class="main-card-container">
<view class="quote-card">
<view
class="quote-card"
:style="
currentQuote.backgroundUrl
? {
backgroundImage: `url(${currentQuote.backgroundUrl})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}
: {}
"
>
<view class="quote-icon"></view>
<view class="quote-content">
<text class="quote-text">{{ currentQuote.text }}</text>
@@ -53,7 +64,7 @@
<view class="category-section">
<view class="category-grid">
<view
v-for="(cat, index) in categories"
v-for="(cat, index) in scenes"
:key="index"
class="category-item"
@tap="selectCategory(cat.id)"
@@ -63,7 +74,7 @@
:class="{ active: currentCategory === cat.id }"
:style="{ background: cat.bg }"
>
<text class="cat-emoji">{{ cat.emoji }}</text>
<text class="cat-emoji">{{ cat.icon }}</text>
</view>
<text
class="cat-name"
@@ -146,10 +157,12 @@ import {
} from "@dcloudio/uni-app";
import { useUserStore } from "@/stores/user";
import { getDailyInfo } from "@/api/daily";
const userStore = useUserStore();
const navBarHeight = getBavBarHeight();
const streakDays = ref(5);
const streakDays = ref(0);
const dateStr = computed(() => {
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: "热榜推荐",