优化取名逻辑

This commit is contained in:
cjd
2025-11-05 17:26:52 +08:00
parent 1d312df7ca
commit 200c29ac09
5 changed files with 95 additions and 57 deletions

View File

@@ -1,4 +1,4 @@
const namingStore = require("../../store/namingStore");
const namingStore = require("../../store/namingStore");
function showToast(title) {
if (typeof tt === "undefined" || !tt.showToast) {
@@ -14,12 +14,13 @@ function showToast(title) {
Page({
data: {
results: []
results: [],
matchSummary: ""
},
onLoad() {
const { results } = namingStore.getState();
const { results, analysis } = namingStore.getState();
if (!results || !results.length) {
showToast("暂无结果,请先生成姓名");
showToast("暂无生成结果,请返回重新生成");
setTimeout(() => {
if (typeof tt !== "undefined" && tt.navigateBack) {
tt.navigateBack();
@@ -27,20 +28,21 @@ Page({
}, 1000);
return;
}
this.setData({ results });
const summary = analysis && (analysis.matchSummary || analysis.MatchSummary) ? analysis.matchSummary || analysis.MatchSummary : "";
const normalized = results.map((item) => ({
name: item.name,
meaning: item.meaning || "寓意待补充",
elementReason: item.elementReason || "五行流转相济"
}));
this.setData({
results: normalized,
matchSummary: summary
});
},
handleFavorite(event) {
const { name, meaning } = event.currentTarget.dataset;
const item = {
name,
meaning
};
const saved = namingStore.addFavorite(item);
if (saved) {
showToast("已收藏");
} else {
showToast("收藏失败");
}
const saved = namingStore.addFavorite({ name, meaning });
showToast(saved ? "已收藏" : "收藏失败");
},
handleBack() {
if (typeof tt !== "undefined" && tt.navigateBack) {