Files
lunar-mini/mini/pages/day-detail/day-detail.js
T

64 lines
1.7 KiB
JavaScript

const { getDayInfo, getAlmanacInfo } = require('../../utils/core/index.js');
Page({
data: {
date: '',
dayInfo: {},
almanac: {}
},
onLoad(options) {
const date = options.date || new Date().toISOString().split('T')[0];
this.setData({ date });
this.loadData(date);
},
loadData(dateStr) {
const [year, month, day] = dateStr.split('-').map(Number);
const dayInfo = getDayInfo(year, month, day);
const almanac = getAlmanacInfo(year, month, day);
this.setData({ dayInfo, almanac });
},
addBookmark() {
const bookmarks = wx.getStorageSync('lunar-bookmarks') || [];
const { dayInfo } = this.data;
const exists = bookmarks.some(b => b.date === dayInfo.solarDate);
if (!exists) {
bookmarks.push({
date: dayInfo.solarDate,
lunarDate: `${dayInfo.lunarMonthName}${dayInfo.lunarDayName}`,
note: ''
});
wx.setStorageSync('lunar-bookmarks', bookmarks);
wx.showToast({ title: '已收藏', icon: 'success' });
} else {
wx.showToast({ title: '已收藏过', icon: 'none' });
}
},
goBazi() {
wx.navigateTo({ url: '/pages/bazi/bazi' });
},
onShareAppMessage() {
const { dayInfo } = this.data;
const title = dayInfo.lunarMonthName
? `${dayInfo.lunarMonthName}${dayInfo.lunarDayName} 黄历详情`
: '每日黄历详情';
return {
title,
path: `/pages/day-detail/day-detail?date=${this.data.date}`
};
},
onShareTimeline() {
const { dayInfo } = this.data;
return {
title: dayInfo.lunarMonthName
? `${dayInfo.lunarMonthName}${dayInfo.lunarDayName} 黄历详情`
: '每日黄历详情'
};
}
});