取名小程序

This commit is contained in:
cjd
2025-11-06 19:23:37 +08:00
parent 200c29ac09
commit 1f9f8cd083
10 changed files with 253 additions and 38 deletions

View File

@@ -15,7 +15,8 @@ function showToast(title) {
Page({
data: {
results: [],
matchSummary: ""
matchSummary: "",
elementsChart: []
},
onLoad() {
const { results, analysis } = namingStore.getState();
@@ -28,15 +29,39 @@ Page({
}, 1000);
return;
}
const summary = analysis && (analysis.matchSummary || analysis.MatchSummary) ? analysis.matchSummary || analysis.MatchSummary : "";
const summary = analysis && (analysis.matchSummary || analysis.MatchSummary)
? analysis.matchSummary || analysis.MatchSummary
: "";
const elements = Array.isArray(analysis && (analysis.elementDistribution || analysis.ElementDistribution))
? analysis.elementDistribution || analysis.ElementDistribution
: [];
const total = elements.reduce((acc, current) => {
const value = Number(current.count ?? current.Count ?? 0);
return acc + (Number.isNaN(value) ? 0 : value);
}, 0);
const chart = elements.map((item) => {
const elementName = item.element || item.Element || "";
const countValue = Number(item.count ?? item.Count ?? 0);
const count = Number.isNaN(countValue) ? 0 : countValue;
const percent = total > 0 ? Math.round((count / total) * 100) : 0;
const widthPercent = percent > 0 ? Math.max(percent, 6) : 0;
return {
label: elementName || "未知",
count,
percent,
percentText: `${percent}%`,
percentWidth: `${widthPercent}%`
};
});
const normalized = results.map((item) => ({
name: item.name,
meaning: item.meaning || "寓意待补充",
elementReason: item.elementReason || "五行流转相济"
meaning: item.meaning || item.Meaning || "寓意待补充",
elementReason: item.elementReason || item.ElementReason || "五行流转相济"
}));
this.setData({
results: normalized,
matchSummary: summary
matchSummary: summary,
elementsChart: chart
});
},
handleFavorite(event) {