Files
lunar-mini/mini/pages/fortune/fortune.js
T

61 lines
1.1 KiB
JavaScript

const { calculateDailyFortune } = require('../../utils/core/index.js');
Page({
data: {
hasBazi: false,
fortune: null,
scoreLevelText: ''
},
onShow() {
this.loadFortune();
},
onPullDownRefresh() {
this.loadFortune();
wx.stopPullDownRefresh();
},
loadFortune() {
const bazi = wx.getStorageSync('lunar-user-bazi');
if (!bazi) {
this.setData({ hasBazi: false, fortune: null });
return;
}
const today = new Date();
const fortune = calculateDailyFortune(bazi.eightChar, today);
const levelMap = {
great: '大吉',
good: '吉',
fair: '平',
poor: '凶',
bad: '大凶'
};
this.setData({
hasBazi: true,
fortune,
scoreLevelText: levelMap[fortune.scoreLevel] || '平'
});
},
goBazi() {
wx.switchTab({ url: '/pages/bazi/bazi' });
},
onShareAppMessage() {
return {
title: '每日运势 - 今日运势查询',
path: '/pages/fortune/fortune'
};
},
onShareTimeline() {
return {
title: '每日运势 - 今日运势查询'
};
}
});