From 642f8193e6c96424e3252e6c183948f9105efae3 Mon Sep 17 00:00:00 2001 From: kola-web Date: Wed, 11 Mar 2026 16:53:15 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=BB=9F=E8=AE=A1):=20=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8C=89=E6=9C=88=E7=BB=9F=E8=AE=A1=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在日期选择器中添加fields属性,根据统计类型显示日或月选择器 修改日期格式化函数,支持按月和按日两种格式 调整统计页面初始化逻辑,根据类型自动格式化日期 --- src/doctor/pages/home/index.ts | 9 +++++++-- src/doctor/pages/stat/index.ts | 19 +++++++++++++++---- src/doctor/pages/stat/index.wxml | 4 ++-- src/ground/pages/home/index.ts | 9 +++++++-- src/ground/pages/stat/index.ts | 34 ++++++++++++++++++++++++++++------ src/ground/pages/stat/index.wxml | 4 ++-- 6 files changed, 61 insertions(+), 18 deletions(-) diff --git a/src/doctor/pages/home/index.ts b/src/doctor/pages/home/index.ts index 173e7b9..104893a 100644 --- a/src/doctor/pages/home/index.ts +++ b/src/doctor/pages/home/index.ts @@ -646,9 +646,14 @@ Page({ handleStat() { trackClick('click_doctor_home_detail') - const { chartStartDate, chartEndDate, statType } = this.data + const { chartStartDate, chartEndDate, chartStartMonth, chartEndMonth, statType } = this.data + + // 根据统计类型决定传递的日期格式 + const startDate = statType === 'month' ? chartStartMonth : chartStartDate + const endDate = statType === 'month' ? chartEndMonth : chartEndDate + wx.navigateTo({ - url: `/doctor/pages/stat/index?startDate=${chartStartDate}&endDate=${chartEndDate}&type=${statType}`, + url: `/doctor/pages/stat/index?startDate=${startDate}&endDate=${endDate}&type=${statType}`, }) }, diff --git a/src/doctor/pages/stat/index.ts b/src/doctor/pages/stat/index.ts index 7e429a8..9092e68 100644 --- a/src/doctor/pages/stat/index.ts +++ b/src/doctor/pages/stat/index.ts @@ -49,12 +49,12 @@ Page({ // 初始化日期 initDate(options: any) { - const today = this.formatDate(new Date()) + const statType = options?.type || 'day' + const today = this.formatDate(new Date(), statType) // 从URL参数获取日期,如果没有则使用默认值 - const startDate = options?.startDate || this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000)) + const startDate = options?.startDate || this.formatDate(new Date(Date.now() - 30 * 24 * 60 * 60 * 1000), statType) const endDate = options?.endDate || today - const statType = options?.type || 'day' this.setData({ startDate, @@ -66,9 +66,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 month = String(date.getMonth() + 1).padStart(2, '0') + if (type === 'month') { + return `${year}-${month}` + } const day = String(date.getDate()).padStart(2, '0') return `${year}-${month}-${day}` }, @@ -130,8 +134,15 @@ Page({ trackClick('click_doctor_stat_type_month') } + // 切换类型时,重新格式化日期 + const today = new Date() + const startDate = this.formatDate(new Date(today.getTime() - 30 * 24 * 60 * 60 * 1000), type) + const endDate = this.formatDate(today, type) + this.setData({ statType: type, + startDate, + endDate, page: 1, hasMore: true, statList: [], diff --git a/src/doctor/pages/stat/index.wxml b/src/doctor/pages/stat/index.wxml index 4adfbc8..ac00132 100644 --- a/src/doctor/pages/stat/index.wxml +++ b/src/doctor/pages/stat/index.wxml @@ -8,14 +8,14 @@ - + {{startDate}} - + {{endDate}} diff --git a/src/ground/pages/home/index.ts b/src/ground/pages/home/index.ts index ccd8fc9..cea1798 100644 --- a/src/ground/pages/home/index.ts +++ b/src/ground/pages/home/index.ts @@ -927,9 +927,14 @@ Page({ handleInfo() { trackClick('click_ground_home_detail') - const { chart1StartDate, chart1EndDate, statType } = this.data + const { chart1StartDate, chart1EndDate, chart1StartMonth, chart1EndMonth, statType } = this.data + + // 根据统计类型决定传递的日期格式 + const startDate = statType === 'month' ? chart1StartMonth : chart1StartDate + const endDate = statType === 'month' ? chart1EndMonth : chart1EndDate + wx.navigateTo({ - url: `/ground/pages/stat/index?startDate=${chart1StartDate}&endDate=${chart1EndDate}&type=${statType}`, + url: `/ground/pages/stat/index?startDate=${startDate}&endDate=${endDate}&type=${statType}`, }) }, diff --git a/src/ground/pages/stat/index.ts b/src/ground/pages/stat/index.ts index bedf3d8..b915a4f 100644 --- a/src/ground/pages/stat/index.ts +++ b/src/ground/pages/stat/index.ts @@ -11,7 +11,7 @@ Page({ // 时间筛选 startDate: '', endDate: '', - today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器 + today: '', // 今天日期,用于限制时间选择器 type: 'day', // day-按日,month-按月 // 统计数据(从 summary 获取) @@ -45,12 +45,16 @@ Page({ // 设置页面参数 setOptions(options: any) { + const type = options?.type || this.data.type || 'day' + const today = this.formatDate(new Date(), type) + // 设置时间范围 if (options?.startDate && options?.endDate) { this.setData({ startDate: options.startDate, endDate: options.endDate, - type: options.type || 'day', + type, + today, }) } else { // 默认时间范围(2026年3月至今) @@ -58,8 +62,10 @@ Page({ const startDate = new Date('2026-03-01') this.setData({ - startDate: this.formatDate(startDate), - endDate: this.formatDate(endDate), + startDate: this.formatDate(startDate, type), + 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 month = String(date.getMonth() + 1).padStart(2, '0') + if (type === 'month') { + return `${year}-${month}` + } const day = String(date.getDate()).padStart(2, '0') return `${year}-${month}-${day}` }, @@ -266,7 +276,19 @@ Page({ // 切换统计类型 handleTypeChange(e: WechatMiniprogram.CustomEvent) { 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) }, handleBack() { diff --git a/src/ground/pages/stat/index.wxml b/src/ground/pages/stat/index.wxml index a518f73..8268f81 100644 --- a/src/ground/pages/stat/index.wxml +++ b/src/ground/pages/stat/index.wxml @@ -8,14 +8,14 @@ - + {{startDate}} - + {{endDate}}