const fortuneStore = require("../../store/fortuneStore"); const { normalizeFortunePayload } = require("../../utils/fortuneFormatter"); const { getPageSafeTop } = require("../../utils/safeArea"); function showToast(title) { if (typeof tt === "undefined" || !tt.showToast) { console.warn("Toast:", title); return; } tt.showToast({ title, icon: "none", duration: 2000 }); } Page({ data: { safeAreaTop: 64, fortuneDate: "", summary: "", narrative: "", dimensions: [], luckyGuide: null, profile: null, overallScore: 0 }, onLoad() { this.updateSafeAreaPadding(); const { currentFortune } = fortuneStore.getState(); if (!currentFortune) { showToast("暂无结果,请返回重新生成"); setTimeout(() => { if (typeof tt !== "undefined" && tt.navigateBack) { tt.navigateBack(); } }, 1000); return; } const normalized = normalizeFortunePayload(currentFortune); if (normalized) { this.setData(normalized); } }, updateSafeAreaPadding() { const padding = getPageSafeTop(); this.setData({ safeAreaTop: padding }); }, handleBack() { if (typeof tt !== "undefined" && tt.navigateBack) { tt.navigateBack(); return; } if (typeof tt !== "undefined" && tt.redirectTo) { tt.redirectTo({ url: "/pages/home/index" }); } }, handleGoHistory() { if (typeof tt !== "undefined" && tt.navigateTo) { tt.navigateTo({ url: "/pages/history/index" }); } } });