优化取名逻辑
This commit is contained in:
@@ -146,6 +146,7 @@ Page({
|
|||||||
generateName(payload)
|
generateName(payload)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const results = response && Array.isArray(response.results) ? response.results : [];
|
const results = response && Array.isArray(response.results) ? response.results : [];
|
||||||
|
const analysis = response && response.analysis ? response.analysis : null;
|
||||||
if (!results.length) {
|
if (!results.length) {
|
||||||
showToast(messages.GENERATION_FAILED);
|
showToast(messages.GENERATION_FAILED);
|
||||||
return;
|
return;
|
||||||
@@ -157,7 +158,8 @@ Page({
|
|||||||
}
|
}
|
||||||
accumulator.push({
|
accumulator.push({
|
||||||
name,
|
name,
|
||||||
meaning: item.meaning || item.Meaning || ""
|
meaning: item.meaning || item.Meaning || "",
|
||||||
|
elementReason: item.elementReason || item.ElementReason || ""
|
||||||
});
|
});
|
||||||
return accumulator;
|
return accumulator;
|
||||||
}, []);
|
}, []);
|
||||||
@@ -165,7 +167,10 @@ Page({
|
|||||||
showToast(messages.GENERATION_FAILED);
|
showToast(messages.GENERATION_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
namingStore.setResults(normalizedResults);
|
namingStore.setResults({
|
||||||
|
results: normalizedResults,
|
||||||
|
analysis
|
||||||
|
});
|
||||||
namingStore.incrementQuota();
|
namingStore.incrementQuota();
|
||||||
this.updateQuotaState();
|
this.updateQuotaState();
|
||||||
if (typeof tt !== "undefined" && tt.navigateTo) {
|
if (typeof tt !== "undefined" && tt.navigateTo) {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
const namingStore = require("../../store/namingStore");
|
const namingStore = require("../../store/namingStore");
|
||||||
|
|
||||||
function showToast(title) {
|
function showToast(title) {
|
||||||
if (typeof tt === "undefined" || !tt.showToast) {
|
if (typeof tt === "undefined" || !tt.showToast) {
|
||||||
@@ -14,12 +14,13 @@ function showToast(title) {
|
|||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
results: []
|
results: [],
|
||||||
|
matchSummary: ""
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
const { results } = namingStore.getState();
|
const { results, analysis } = namingStore.getState();
|
||||||
if (!results || !results.length) {
|
if (!results || !results.length) {
|
||||||
showToast("暂无结果,请先生成姓名");
|
showToast("暂无生成结果,请返回重新生成");
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (typeof tt !== "undefined" && tt.navigateBack) {
|
if (typeof tt !== "undefined" && tt.navigateBack) {
|
||||||
tt.navigateBack();
|
tt.navigateBack();
|
||||||
@@ -27,20 +28,21 @@ Page({
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
return;
|
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) {
|
handleFavorite(event) {
|
||||||
const { name, meaning } = event.currentTarget.dataset;
|
const { name, meaning } = event.currentTarget.dataset;
|
||||||
const item = {
|
const saved = namingStore.addFavorite({ name, meaning });
|
||||||
name,
|
showToast(saved ? "已收藏" : "收藏失败");
|
||||||
meaning
|
|
||||||
};
|
|
||||||
const saved = namingStore.addFavorite(item);
|
|
||||||
if (saved) {
|
|
||||||
showToast("已收藏");
|
|
||||||
} else {
|
|
||||||
showToast("收藏失败");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
handleBack() {
|
handleBack() {
|
||||||
if (typeof tt !== "undefined" && tt.navigateBack) {
|
if (typeof tt !== "undefined" && tt.navigateBack) {
|
||||||
|
|||||||
@@ -6,21 +6,24 @@
|
|||||||
|
|
||||||
<scroll-view class="content" scroll-y="true">
|
<scroll-view class="content" scroll-y="true">
|
||||||
<view class="headline">
|
<view class="headline">
|
||||||
<text class="title">灵签揭示</text>
|
<text class="title">八字名鉴</text>
|
||||||
<text class="subtitle">从星宿生辰推演的五重吉名,择其心有所向</text>
|
<text class="subtitle">以生辰八字为准,优选五行调衡的候选姓名</text>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="summary" tt:if="{{matchSummary}}">
|
||||||
|
<text class="summary-text">{{matchSummary}}</text>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="empty" tt:if="{{!results.length}}">
|
<view class="empty" tt:if="{{!results.length}}">
|
||||||
<text>暂无生成结果,请返回主页重新召唤。</text>
|
<text>暂无生成结果,请返回主页重新生成。</text>
|
||||||
<button class="primary back-button" bindtap="handleBack">返回主页</button>
|
<button class="primary back-button" bindtap="handleBack">返回主页</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view tt:if="{{results.length}}">
|
<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">
|
<block tt:for="{{results}}" tt:for-index="index" tt:for-item="item" tt:key="name">
|
||||||
<view class="result-card">
|
<view class="result-card">
|
||||||
<view class="result-header">
|
<text class="result-line">{{item.name}}|{{item.meaning}}|{{item.elementReason}}</text>
|
||||||
<text class="name">{{item.name}}</text>
|
|
||||||
<button
|
<button
|
||||||
class="collect-button"
|
class="collect-button"
|
||||||
size="mini"
|
size="mini"
|
||||||
@@ -31,10 +34,8 @@
|
|||||||
收藏
|
收藏
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
<text class="meaning">{{item.meaning}}</text>
|
|
||||||
</view>
|
|
||||||
</block>
|
</block>
|
||||||
<button class="primary back-button" bindtap="handleBack">再占一卦</button>
|
<button class="primary back-button" bindtap="handleBack">再测一批</button>
|
||||||
</view>
|
</view>
|
||||||
</scroll-view>
|
</scroll-view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@@ -80,10 +80,24 @@
|
|||||||
line-height: 1.6;
|
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 {
|
.tip {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: rgba(255, 244, 227, 0.7);
|
color: rgba(255, 244, 227, 0.7);
|
||||||
letter-spacing: 4px;
|
letter-spacing: 2px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
@@ -91,7 +105,7 @@
|
|||||||
.result-card {
|
.result-card {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 10px;
|
gap: 12px;
|
||||||
background: linear-gradient(135deg, rgba(16, 22, 46, 0.86), rgba(36, 44, 80, 0.76));
|
background: linear-gradient(135deg, rgba(16, 22, 46, 0.86), rgba(36, 44, 80, 0.76));
|
||||||
border-radius: 18px;
|
border-radius: 18px;
|
||||||
padding: 18px 20px;
|
padding: 18px 20px;
|
||||||
@@ -101,18 +115,11 @@
|
|||||||
backdrop-filter: blur(16px);
|
backdrop-filter: blur(16px);
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-header {
|
.result-line {
|
||||||
display: flex;
|
font-size: 15px;
|
||||||
align-items: center;
|
color: rgba(255, 244, 227, 0.9);
|
||||||
justify-content: space-between;
|
line-height: 1.8;
|
||||||
gap: 12px;
|
word-break: break-all;
|
||||||
}
|
|
||||||
|
|
||||||
.name {
|
|
||||||
font-size: 20px;
|
|
||||||
font-weight: 600;
|
|
||||||
color: #fdf0da;
|
|
||||||
flex: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.collect-button {
|
.collect-button {
|
||||||
@@ -123,12 +130,7 @@
|
|||||||
background: rgba(255, 255, 255, 0.12);
|
background: rgba(255, 255, 255, 0.12);
|
||||||
color: #fbe6ce;
|
color: #fbe6ce;
|
||||||
border: 1px solid rgba(255, 255, 255, 0.18);
|
border: 1px solid rgba(255, 255, 255, 0.18);
|
||||||
}
|
align-self: flex-end;
|
||||||
|
|
||||||
.meaning {
|
|
||||||
font-size: 14px;
|
|
||||||
color: rgba(255, 244, 227, 0.78);
|
|
||||||
line-height: 1.8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-button {
|
.back-button {
|
||||||
|
|||||||
@@ -20,6 +20,11 @@ function createDefaultForm() {
|
|||||||
const state = {
|
const state = {
|
||||||
form: createDefaultForm(),
|
form: createDefaultForm(),
|
||||||
results: [],
|
results: [],
|
||||||
|
analysis: {
|
||||||
|
matchSummary: "",
|
||||||
|
pillars: [],
|
||||||
|
elementDistribution: []
|
||||||
|
},
|
||||||
favorites: [],
|
favorites: [],
|
||||||
quota: {
|
quota: {
|
||||||
date: "",
|
date: "",
|
||||||
@@ -97,12 +102,35 @@ function resetForm() {
|
|||||||
state.form = createDefaultForm();
|
state.form = createDefaultForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
function setResults(results) {
|
function setResults(payload) {
|
||||||
state.results = Array.isArray(results) ? results : [];
|
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() {
|
function clearResults() {
|
||||||
state.results = [];
|
state.results = [];
|
||||||
|
state.analysis = {
|
||||||
|
matchSummary: "",
|
||||||
|
pillars: [],
|
||||||
|
elementDistribution: []
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFavorites() {
|
function loadFavorites() {
|
||||||
|
|||||||
Reference in New Issue
Block a user