|
|
|
@ -11,7 +11,7 @@ Page({ |
|
|
|
// 时间筛选
|
|
|
|
// 时间筛选
|
|
|
|
startDate: '', |
|
|
|
startDate: '', |
|
|
|
endDate: '', |
|
|
|
endDate: '', |
|
|
|
today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器
|
|
|
|
today: '', // 今天日期,用于限制时间选择器
|
|
|
|
type: 'day', // day-按日,month-按月
|
|
|
|
type: 'day', // day-按日,month-按月
|
|
|
|
|
|
|
|
|
|
|
|
// 统计数据(从 summary 获取)
|
|
|
|
// 统计数据(从 summary 获取)
|
|
|
|
@ -45,12 +45,16 @@ Page({ |
|
|
|
|
|
|
|
|
|
|
|
// 设置页面参数
|
|
|
|
// 设置页面参数
|
|
|
|
setOptions(options: any) { |
|
|
|
setOptions(options: any) { |
|
|
|
|
|
|
|
const type = options?.type || this.data.type || 'day' |
|
|
|
|
|
|
|
const today = this.formatDate(new Date(), type) |
|
|
|
|
|
|
|
|
|
|
|
// 设置时间范围
|
|
|
|
// 设置时间范围
|
|
|
|
if (options?.startDate && options?.endDate) { |
|
|
|
if (options?.startDate && options?.endDate) { |
|
|
|
this.setData({ |
|
|
|
this.setData({ |
|
|
|
startDate: options.startDate, |
|
|
|
startDate: options.startDate, |
|
|
|
endDate: options.endDate, |
|
|
|
endDate: options.endDate, |
|
|
|
type: options.type || 'day', |
|
|
|
type, |
|
|
|
|
|
|
|
today, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// 默认时间范围(2026年3月至今)
|
|
|
|
// 默认时间范围(2026年3月至今)
|
|
|
|
@ -58,8 +62,10 @@ Page({ |
|
|
|
const startDate = new Date('2026-03-01') |
|
|
|
const startDate = new Date('2026-03-01') |
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
this.setData({ |
|
|
|
startDate: this.formatDate(startDate), |
|
|
|
startDate: this.formatDate(startDate, type), |
|
|
|
endDate: this.formatDate(endDate), |
|
|
|
endDate: this.formatDate(endDate, type), |
|
|
|
|
|
|
|
type, |
|
|
|
|
|
|
|
today, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -72,9 +78,13 @@ Page({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// 格式化日期
|
|
|
|
// 格式化日期
|
|
|
|
formatDate(date: Date): string { |
|
|
|
// type: 'day' 返回 YYYY-MM-DD, 'month' 返回 YYYY-MM
|
|
|
|
|
|
|
|
formatDate(date: Date, type: string = 'day'): string { |
|
|
|
const year = date.getFullYear() |
|
|
|
const year = date.getFullYear() |
|
|
|
const month = String(date.getMonth() + 1).padStart(2, '0') |
|
|
|
const month = String(date.getMonth() + 1).padStart(2, '0') |
|
|
|
|
|
|
|
if (type === 'month') { |
|
|
|
|
|
|
|
return `${year}-${month}` |
|
|
|
|
|
|
|
} |
|
|
|
const day = String(date.getDate()).padStart(2, '0') |
|
|
|
const day = String(date.getDate()).padStart(2, '0') |
|
|
|
return `${year}-${month}-${day}` |
|
|
|
return `${year}-${month}-${day}` |
|
|
|
}, |
|
|
|
}, |
|
|
|
@ -266,7 +276,19 @@ Page({ |
|
|
|
// 切换统计类型
|
|
|
|
// 切换统计类型
|
|
|
|
handleTypeChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
handleTypeChange(e: WechatMiniprogram.CustomEvent) { |
|
|
|
const type = e.currentTarget.dataset.type |
|
|
|
const type = e.currentTarget.dataset.type |
|
|
|
this.setData({ type }) |
|
|
|
|
|
|
|
|
|
|
|
// 切换类型时,重新格式化日期
|
|
|
|
|
|
|
|
const today = new Date() |
|
|
|
|
|
|
|
const startDate = this.formatDate(new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000), type) |
|
|
|
|
|
|
|
const endDate = this.formatDate(today, type) |
|
|
|
|
|
|
|
const todayStr = this.formatDate(today, type) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
|
|
type, |
|
|
|
|
|
|
|
startDate, |
|
|
|
|
|
|
|
endDate, |
|
|
|
|
|
|
|
today: todayStr, |
|
|
|
|
|
|
|
}) |
|
|
|
this.getList(true) |
|
|
|
this.getList(true) |
|
|
|
}, |
|
|
|
}, |
|
|
|
handleBack() { |
|
|
|
handleBack() { |
|
|
|
|