52 lines
1.7 KiB
JavaScript
52 lines
1.7 KiB
JavaScript
const fortuneStore = require("../../store/fortuneStore");
|
|
const messages = require("../../constants/messages");
|
|
const { formatDisplayDateTime } = require("../../utils/date");
|
|
const { formatRegionDisplay, normalizeRegionArray } = require("../../utils/region");
|
|
const { getPageSafeTop } = require("../../utils/safeArea");
|
|
|
|
Page({
|
|
data: {
|
|
safeAreaTop: 64,
|
|
history: [],
|
|
emptyText: messages.HISTORY_EMPTY
|
|
},
|
|
onLoad() {
|
|
this.updateSafeAreaPadding();
|
|
},
|
|
onShow() {
|
|
fortuneStore.loadHistory();
|
|
const { history } = fortuneStore.getState();
|
|
const normalized = history.map((item) => {
|
|
const snapshot = item.formSnapshot || {};
|
|
const fortune = item.fortune || {};
|
|
const regionValue = normalizeRegionArray(snapshot.birthRegion);
|
|
const fallbackSegments = [snapshot.birthProvince, snapshot.birthCity, snapshot.birthDistrict].filter(Boolean);
|
|
const regionLabel = formatRegionDisplay(regionValue, fallbackSegments);
|
|
const fortuneDate = fortune.fortuneDate || fortune.FortuneDate || "";
|
|
const summary = fortune.summary || fortune.Summary || "";
|
|
return {
|
|
id: item.id,
|
|
createdAt: item.createdAt,
|
|
displayTime: formatDisplayDateTime(item.createdAt),
|
|
city: regionLabel || snapshot.birthCity || snapshot.birthProvince || "",
|
|
fortuneDate,
|
|
summary
|
|
};
|
|
});
|
|
this.setData({ history: normalized });
|
|
},
|
|
handleViewDetail(event) {
|
|
const { id } = event.currentTarget.dataset;
|
|
if (!id) {
|
|
return;
|
|
}
|
|
if (typeof tt !== "undefined" && tt.navigateTo) {
|
|
tt.navigateTo({ url: `/pages/history-detail/index?id=${id}` });
|
|
}
|
|
},
|
|
updateSafeAreaPadding() {
|
|
const padding = getPageSafeTop();
|
|
this.setData({ safeAreaTop: padding });
|
|
}
|
|
});
|