取名小程序
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
const namingStore = require("../../store/namingStore");
|
||||
const namingStore = require("../../store/namingStore");
|
||||
const messages = require("../../constants/messages");
|
||||
const { validateSurname, generateName } = require("../../services/namingService");
|
||||
const { showRewardedVideoAd } = require("../../utils/adService");
|
||||
const config = require("../../config/index");
|
||||
|
||||
const LOADING_MESSAGES = [
|
||||
"AI 正在推演八字,请稍候...",
|
||||
"结合天干地支,为您筛选契合佳名...",
|
||||
"耐心等待,吉名正在汇聚灵感..."
|
||||
];
|
||||
|
||||
function showToast(title) {
|
||||
if (typeof tt === "undefined" || !tt.showToast) {
|
||||
console.warn("Toast:", title);
|
||||
@@ -25,7 +31,9 @@ Page({
|
||||
birthTime: "",
|
||||
nameLength: "double",
|
||||
isSubmitting: false,
|
||||
quotaRemaining: null
|
||||
quotaRemaining: null,
|
||||
isLoading: false,
|
||||
loadingMessage: ""
|
||||
},
|
||||
onLoad() {
|
||||
const { form, quota } = namingStore.getState();
|
||||
@@ -53,11 +61,13 @@ Page({
|
||||
}
|
||||
validateSurname(surname)
|
||||
.then((response) => {
|
||||
if (!response || response.isValid === false) {
|
||||
showToast(messages.INVALID_SURNAME);
|
||||
const isValid = response ? response.isValid !== false : true;
|
||||
const message = response && response.message ? response.message : messages.INVALID_SURNAME;
|
||||
if (!isValid) {
|
||||
showToast(message);
|
||||
this.setData({
|
||||
surname: "",
|
||||
surnameError: messages.INVALID_SURNAME
|
||||
surnameError: message
|
||||
});
|
||||
namingStore.setForm({ surname: "" });
|
||||
} else {
|
||||
@@ -132,6 +142,7 @@ Page({
|
||||
} else {
|
||||
showToast("广告加载失败,请稍后重试");
|
||||
}
|
||||
this.hideLoadingOverlay();
|
||||
this.setData({ isSubmitting: false });
|
||||
});
|
||||
},
|
||||
@@ -143,7 +154,8 @@ Page({
|
||||
birthTime: this.data.birthTime || "",
|
||||
nameLength: this.data.nameLength
|
||||
};
|
||||
generateName(payload)
|
||||
this.showLoadingOverlay();
|
||||
return generateName(payload)
|
||||
.then((response) => {
|
||||
const results = response && Array.isArray(response.results) ? response.results : [];
|
||||
const analysis = response && response.analysis ? response.analysis : null;
|
||||
@@ -177,11 +189,35 @@ Page({
|
||||
tt.navigateTo({ url: "/pages/result/index" });
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
showToast(messages.GENERATION_FAILED);
|
||||
.catch((error) => {
|
||||
const message = error && error.data && error.data.message;
|
||||
if (message === "CONTENT_RISK") {
|
||||
showToast(messages.CONTENT_RISK);
|
||||
} else if (message === "INVALID_SURNAME") {
|
||||
showToast(messages.INVALID_SURNAME);
|
||||
} else {
|
||||
showToast(messages.GENERATION_FAILED);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
this.hideLoadingOverlay();
|
||||
this.setData({ isSubmitting: false });
|
||||
});
|
||||
},
|
||||
showLoadingOverlay() {
|
||||
const hint = LOADING_MESSAGES[Math.floor(Math.random() * LOADING_MESSAGES.length)];
|
||||
this.setData({
|
||||
isLoading: true,
|
||||
loadingMessage: hint
|
||||
});
|
||||
},
|
||||
hideLoadingOverlay() {
|
||||
if (!this.data.isLoading) {
|
||||
return;
|
||||
}
|
||||
this.setData({
|
||||
isLoading: false,
|
||||
loadingMessage: ""
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,14 @@
|
||||
<view class="glow glow-three"></view>
|
||||
</view>
|
||||
|
||||
<view class="loading-overlay" tt:if="{{isLoading}}">
|
||||
<view class="loading-dialog">
|
||||
<view class="loading-spinner"></view>
|
||||
<text class="loading-text">{{loadingMessage}}</text>
|
||||
<text class="loading-subtext">推演需片刻,感谢耐心等待</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<scroll-view class="content" scroll-y="true">
|
||||
<view class="title-block">
|
||||
<text class="title">玄名殿</text>
|
||||
|
||||
@@ -4,6 +4,54 @@
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.loading-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 20;
|
||||
background: rgba(6, 10, 22, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
backdrop-filter: blur(6px);
|
||||
}
|
||||
|
||||
.loading-dialog {
|
||||
width: 82%;
|
||||
max-width: 320px;
|
||||
padding: 26px 24px;
|
||||
border-radius: 22px;
|
||||
background: linear-gradient(180deg, rgba(22, 28, 52, 0.95), rgba(12, 18, 36, 0.88));
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
box-shadow: 0 24px 48px rgba(8, 10, 24, 0.4);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
align-items: center;
|
||||
color: rgba(255, 244, 227, 0.9);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.loading-spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
border-radius: 50%;
|
||||
border: 3px solid rgba(255, 244, 227, 0.25);
|
||||
border-top-color: #ffd8a0;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 15px;
|
||||
letter-spacing: 2px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.loading-subtext {
|
||||
font-size: 12px;
|
||||
color: rgba(255, 244, 227, 0.6);
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.glow-layer {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
@@ -56,6 +104,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
0% {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
|
||||
Reference in New Issue
Block a user