每日运势小程序
This commit is contained in:
77
DailyFortuneGuide/pages/history-detail/index.js
Normal file
77
DailyFortuneGuide/pages/history-detail/index.js
Normal file
@@ -0,0 +1,77 @@
|
||||
const fortuneStore = require("../../store/fortuneStore");
|
||||
const { normalizeFortunePayload } = require("../../utils/fortuneFormatter");
|
||||
const { formatDisplayDateTime } = require("../../utils/date");
|
||||
const messages = require("../../constants/messages");
|
||||
const { getPageSafeTop } = require("../../utils/safeArea");
|
||||
const { formatRegionDisplay, normalizeRegionArray } = require("../../utils/region");
|
||||
|
||||
function showToast(title) {
|
||||
if (typeof tt === "undefined" || !tt.showToast) {
|
||||
console.warn("Toast:", title);
|
||||
return;
|
||||
}
|
||||
tt.showToast({
|
||||
title,
|
||||
icon: "none",
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
safeAreaTop: 64,
|
||||
recordTime: "",
|
||||
fortuneDate: "",
|
||||
summary: "",
|
||||
narrative: "",
|
||||
dimensions: [],
|
||||
luckyGuide: null,
|
||||
profile: null,
|
||||
overallScore: 0,
|
||||
city: ""
|
||||
},
|
||||
onLoad(options) {
|
||||
this.updateSafeAreaPadding();
|
||||
fortuneStore.loadHistory();
|
||||
const id = options && options.id ? options.id : "";
|
||||
if (!id) {
|
||||
showToast(messages.HISTORY_NOT_FOUND);
|
||||
this.safeBack();
|
||||
return;
|
||||
}
|
||||
const record = fortuneStore.getHistoryById(id);
|
||||
if (!record) {
|
||||
showToast(messages.HISTORY_NOT_FOUND);
|
||||
this.safeBack();
|
||||
return;
|
||||
}
|
||||
const normalized = normalizeFortunePayload(record.fortune);
|
||||
if (!normalized) {
|
||||
showToast(messages.HISTORY_NOT_FOUND);
|
||||
this.safeBack();
|
||||
return;
|
||||
}
|
||||
const snapshot = record.formSnapshot || {};
|
||||
const regionValue = normalizeRegionArray(snapshot.birthRegion);
|
||||
const fallbackSegments = [snapshot.birthProvince, snapshot.birthCity, snapshot.birthDistrict].filter(Boolean);
|
||||
const cityLabel = formatRegionDisplay(regionValue, fallbackSegments);
|
||||
this.setData(
|
||||
Object.assign({}, normalized, {
|
||||
recordTime: formatDisplayDateTime(record.createdAt),
|
||||
city: cityLabel || snapshot.birthCity || ""
|
||||
})
|
||||
);
|
||||
},
|
||||
handleBack() {
|
||||
this.safeBack();
|
||||
},
|
||||
updateSafeAreaPadding() {
|
||||
const padding = getPageSafeTop();
|
||||
this.setData({ safeAreaTop: padding });
|
||||
},
|
||||
safeBack() {
|
||||
if (typeof tt !== "undefined" && tt.navigateBack) {
|
||||
tt.navigateBack();
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user