优化取名逻辑

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

@@ -146,6 +146,7 @@ Page({
generateName(payload)
.then((response) => {
const results = response && Array.isArray(response.results) ? response.results : [];
const analysis = response && response.analysis ? response.analysis : null;
if (!results.length) {
showToast(messages.GENERATION_FAILED);
return;
@@ -157,7 +158,8 @@ Page({
}
accumulator.push({
name,
meaning: item.meaning || item.Meaning || ""
meaning: item.meaning || item.Meaning || "",
elementReason: item.elementReason || item.ElementReason || ""
});
return accumulator;
}, []);
@@ -165,7 +167,10 @@ Page({
showToast(messages.GENERATION_FAILED);
return;
}
namingStore.setResults(normalizedResults);
namingStore.setResults({
results: normalizedResults,
analysis
});
namingStore.incrementQuota();
this.updateQuotaState();
if (typeof tt !== "undefined" && tt.navigateTo) {

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) {

View File

@@ -6,35 +6,36 @@
<scroll-view class="content" scroll-y="true">
<view class="headline">
<text class="title">灵签揭示</text>
<text class="subtitle">从星宿生辰推演的五重吉名,择其心有所向</text>
<text class="title">八字名鉴</text>
<text class="subtitle">以生辰八字为准,优选五行调衡的候选姓名</text>
</view>
<view class="summary" tt:if="{{matchSummary}}">
<text class="summary-text">{{matchSummary}}</text>
</view>
<view class="empty" tt:if="{{!results.length}}">
<text>暂无生成结果,请返回主页重新召唤。</text>
<text>暂无生成结果,请返回主页重新生成。</text>
<button class="primary back-button" bindtap="handleBack">返回主页</button>
</view>
<view tt:if="{{results.length}}">
<view class="tip">轻触收藏,铭记心仪之名</view>
<view class="tip">轻触收藏按钮即可将心仪姓名收入星册</view>
<block tt:for="{{results}}" tt:for-index="index" tt:for-item="item" tt:key="name">
<view class="result-card">
<view class="result-header">
<text class="name">{{item.name}}</text>
<button
class="collect-button"
size="mini"
bindtap="handleFavorite"
data-name="{{item.name}}"
data-meaning="{{item.meaning}}"
>
收藏
</button>
</view>
<text class="meaning">{{item.meaning}}</text>
<text class="result-line">{{item.name}}{{item.meaning}}{{item.elementReason}}</text>
<button
class="collect-button"
size="mini"
bindtap="handleFavorite"
data-name="{{item.name}}"
data-meaning="{{item.meaning}}"
>
收藏
</button>
</view>
</block>
<button class="primary back-button" bindtap="handleBack">再占一卦</button>
<button class="primary back-button" bindtap="handleBack">再测一批</button>
</view>
</scroll-view>
</view>

View File

@@ -80,10 +80,24 @@
line-height: 1.6;
}
.summary {
background: rgba(18, 24, 46, 0.7);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 14px;
padding: 14px 16px;
color: rgba(255, 244, 227, 0.85);
line-height: 1.7;
font-size: 13px;
}
.summary-text {
white-space: pre-line;
}
.tip {
font-size: 14px;
color: rgba(255, 244, 227, 0.7);
letter-spacing: 4px;
letter-spacing: 2px;
text-align: center;
margin-bottom: 8px;
}
@@ -91,7 +105,7 @@
.result-card {
display: flex;
flex-direction: column;
gap: 10px;
gap: 12px;
background: linear-gradient(135deg, rgba(16, 22, 46, 0.86), rgba(36, 44, 80, 0.76));
border-radius: 18px;
padding: 18px 20px;
@@ -101,18 +115,11 @@
backdrop-filter: blur(16px);
}
.result-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
}
.name {
font-size: 20px;
font-weight: 600;
color: #fdf0da;
flex: 1;
.result-line {
font-size: 15px;
color: rgba(255, 244, 227, 0.9);
line-height: 1.8;
word-break: break-all;
}
.collect-button {
@@ -123,12 +130,7 @@
background: rgba(255, 255, 255, 0.12);
color: #fbe6ce;
border: 1px solid rgba(255, 255, 255, 0.18);
}
.meaning {
font-size: 14px;
color: rgba(255, 244, 227, 0.78);
line-height: 1.8;
align-self: flex-end;
}
.back-button {

View File

@@ -20,6 +20,11 @@ function createDefaultForm() {
const state = {
form: createDefaultForm(),
results: [],
analysis: {
matchSummary: "",
pillars: [],
elementDistribution: []
},
favorites: [],
quota: {
date: "",
@@ -97,12 +102,35 @@ function resetForm() {
state.form = createDefaultForm();
}
function setResults(results) {
state.results = Array.isArray(results) ? results : [];
function setResults(payload) {
if (Array.isArray(payload)) {
state.results = payload;
state.analysis = {
matchSummary: "",
pillars: [],
elementDistribution: []
};
return;
}
const safePayload = payload || {};
const nextResults = Array.isArray(safePayload.results) ? safePayload.results : [];
const analysis = safePayload.analysis || {};
state.results = nextResults;
state.analysis = {
matchSummary: analysis.matchSummary || analysis.MatchSummary || "",
pillars: analysis.pillars || analysis.Pillars || [],
elementDistribution: analysis.elementDistribution || analysis.ElementDistribution || []
};
}
function clearResults() {
state.results = [];
state.analysis = {
matchSummary: "",
pillars: [],
elementDistribution: []
};
}
function loadFavorites() {