78 lines
2.1 KiB
JavaScript
78 lines
2.1 KiB
JavaScript
|
|
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();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|