fix: daily page

This commit is contained in:
zzc
2026-03-02 15:32:37 +08:00
parent f11b48e50a
commit b9bec457a7
2 changed files with 31 additions and 13 deletions

View File

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

View File

@@ -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) => {