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("\u6682\u65e0\u7ed3\u679c\uff0c\u8bf7\u5148\u751f\u6210\u59d3\u540d"); 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("\u5df2\u6536\u85cf"); } else { showToast("\u6536\u85cf\u5931\u8d25"); } }, handleBack() { if (typeof tt !== "undefined" && tt.navigateBack) { tt.navigateBack(); return; } if (typeof tt !== "undefined" && tt.redirectTo) { tt.redirectTo({ url: "/pages/home/index" }); } } });