const namingStore = require("../../store/namingStore"); function showToast(title) { if (typeof tt === "undefined" || !tt.showToast) { console.warn("Toast:", title); return; } tt.showToast({ title, icon: "none", duration: 2000 }); } Page({ data: { results: [] }, onLoad() { const { results } = namingStore.getState(); if (!results || !results.length) { showToast("暂无结果,请先生成姓名"); setTimeout(() => { if (typeof tt !== "undefined" && tt.navigateBack) { tt.navigateBack(); } }, 1000); return; } this.setData({ results }); }, handleFavorite(event) { const { name, meaning } = event.currentTarget.dataset; const item = { name, meaning }; const saved = namingStore.addFavorite(item); if (saved) { showToast("已收藏"); } else { showToast("收藏失败"); } }, handleBack() { if (typeof tt !== "undefined" && tt.navigateBack) { tt.navigateBack(); return; } if (typeof tt !== "undefined" && tt.redirectTo) { tt.redirectTo({ url: "/pages/home/index" }); } } });