tabBar(5个,全部带图标): - 老黄历(首页) / 许愿 / 八字 / 百科(新) / 我的(原设置) - 移除日历tab,月历并入首页左上角切换 - 移除运势tab,改从'我的'页进入 首页重构: - custom 导航栏,标题'老黄历' - 老式万年历大日历卡片:大日期+农历+干支+宜忌 - 左右箭头切换日期,'回到今天' - 左上角'月历/日历'切换按钮,月历视图复用原日历网格 - 月历点选日期自动切回日视图 新增百科页: - 二十四节气/农历节日/公历节日/干支生肖/黄历术语 分类 - 搜索 + 展开详情 我的页(原设置): - 新增功能入口:每日运势/占卜/二十四节气/月历视图
This commit is contained in:
+98
-10
@@ -1,28 +1,116 @@
|
||||
const { getTodayInfo, getAlmanacInfo } = require('../../utils/core/index.js');
|
||||
const { getDayInfo, getAlmanacInfo, getMonthCalendar } = require('../../utils/core/index.js');
|
||||
|
||||
function pad(n) { return String(n).padStart(2, '0'); }
|
||||
function fmt(y, m, d) { return `${y}-${pad(m)}-${pad(d)}`; }
|
||||
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 20,
|
||||
navBarHeight: 44,
|
||||
viewMode: 'day', // day | month
|
||||
dayInfo: {},
|
||||
almanac: {}
|
||||
almanac: {},
|
||||
// 月历
|
||||
year: 0,
|
||||
month: 0,
|
||||
weekHeaders: ['日', '一', '二', '三', '四', '五', '六'],
|
||||
calendarDays: [],
|
||||
selectedDay: null
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.loadData();
|
||||
const sys = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync();
|
||||
const menu = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : null;
|
||||
const statusBarHeight = sys.statusBarHeight || 20;
|
||||
let navBarHeight = 44;
|
||||
if (menu && menu.top) {
|
||||
navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height;
|
||||
}
|
||||
this.setData({ statusBarHeight, navBarHeight });
|
||||
this.loadDay(new Date());
|
||||
},
|
||||
|
||||
onPullDownRefresh() {
|
||||
this.loadData();
|
||||
if (this.data.viewMode === 'day') {
|
||||
this.loadDay(new Date());
|
||||
} else {
|
||||
this.loadCalendar();
|
||||
}
|
||||
wx.stopPullDownRefresh();
|
||||
},
|
||||
|
||||
loadData() {
|
||||
const dayInfo = getTodayInfo();
|
||||
const almanac = getAlmanacInfo(dayInfo.solarYear, dayInfo.solarMonth, dayInfo.solarDay);
|
||||
this.setData({ dayInfo, almanac });
|
||||
/** 加载某日的老黄历 */
|
||||
loadDay(date) {
|
||||
const y = date.getFullYear();
|
||||
const m = date.getMonth() + 1;
|
||||
const d = date.getDate();
|
||||
const dayInfo = getDayInfo(y, m, d);
|
||||
const almanac = getAlmanacInfo(y, m, d);
|
||||
this.setData({ dayInfo, almanac, year: y, month: m });
|
||||
},
|
||||
|
||||
/** 前一天 / 后一天 */
|
||||
prevDay() { this.shiftDay(-1); },
|
||||
nextDay() { this.shiftDay(1); },
|
||||
shiftDay(delta) {
|
||||
const { dayInfo } = this.data;
|
||||
const date = new Date(dayInfo.solarYear, dayInfo.solarMonth - 1, dayInfo.solarDay + delta);
|
||||
this.loadDay(date);
|
||||
},
|
||||
|
||||
/** 回到今天 */
|
||||
backToday() {
|
||||
this.loadDay(new Date());
|
||||
},
|
||||
|
||||
/** 切换 日视图/月历视图 */
|
||||
toggleView() {
|
||||
const mode = this.data.viewMode === 'day' ? 'month' : 'day';
|
||||
this.setData({ viewMode: mode });
|
||||
if (mode === 'month') {
|
||||
const { dayInfo } = this.data;
|
||||
this.setData({ year: dayInfo.solarYear, month: dayInfo.solarMonth }, () => this.loadCalendar());
|
||||
}
|
||||
},
|
||||
|
||||
/** 月历 */
|
||||
loadCalendar() {
|
||||
const { year, month } = this.data;
|
||||
const weeks = getMonthCalendar(year, month);
|
||||
const calendarDays = [];
|
||||
weeks.forEach(w => w.forEach(d => calendarDays.push(d)));
|
||||
this.setData({ calendarDays });
|
||||
},
|
||||
|
||||
prevMonth() {
|
||||
let { year, month } = this.data;
|
||||
month--;
|
||||
if (month < 1) { month = 12; year--; }
|
||||
this.setData({ year, month }, () => this.loadCalendar());
|
||||
},
|
||||
|
||||
nextMonth() {
|
||||
let { year, month } = this.data;
|
||||
month++;
|
||||
if (month > 12) { month = 1; year++; }
|
||||
this.setData({ year, month }, () => this.loadCalendar());
|
||||
},
|
||||
|
||||
/** 月历中选中某天 → 切回日视图 */
|
||||
selectDay(e) {
|
||||
const date = e.currentTarget.dataset.date;
|
||||
const [y, m, d] = date.split('-').map(Number);
|
||||
this.loadDay(new Date(y, m - 1, d));
|
||||
this.setData({ viewMode: 'day' });
|
||||
},
|
||||
|
||||
/** 跳详情页 */
|
||||
goDetail() {
|
||||
const { dayInfo } = this.data;
|
||||
wx.navigateTo({ url: `/pages/day-detail/day-detail?date=${fmt(dayInfo.solarYear, dayInfo.solarMonth, dayInfo.solarDay)}` });
|
||||
},
|
||||
|
||||
navTo(e) {
|
||||
const url = e.currentTarget.dataset.url;
|
||||
wx.navigateTo({ url });
|
||||
wx.navigateTo({ url: e.currentTarget.dataset.url });
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user