Browse Source

feat(统计): 支持按月统计功能

在日期选择器中添加fields属性,根据统计类型显示日或月选择器
修改日期格式化函数,支持按月和按日两种格式
调整统计页面初始化逻辑,根据类型自动格式化日期
master
kola-web 4 hours ago
parent
commit
642f8193e6
  1. 9
      src/doctor/pages/home/index.ts
  2. 19
      src/doctor/pages/stat/index.ts
  3. 4
      src/doctor/pages/stat/index.wxml
  4. 9
      src/ground/pages/home/index.ts
  5. 34
      src/ground/pages/stat/index.ts
  6. 4
      src/ground/pages/stat/index.wxml

9
src/doctor/pages/home/index.ts

@ -646,9 +646,14 @@ Page({ @@ -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}`,
})
},

19
src/doctor/pages/stat/index.ts

@ -49,12 +49,12 @@ Page({ @@ -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({ @@ -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({ @@ -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: [],

4
src/doctor/pages/stat/index.wxml

@ -8,14 +8,14 @@ @@ -8,14 +8,14 @@
<view class="page" style="padding-top: {{pageTop}}px;">
<view class="page-header" style="top:{{pageTop}}px">
<view class="chart-range">
<picker class="picker" mode="date" value="{{startDate}}" end="{{today}}" bindchange="handleStartDateChange">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{startDate}}" end="{{today}}" bindchange="handleStartDateChange">
<view class="p-content">
<view class="content">{{startDate}}</view>
<image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image>
</view>
</picker>
<view class="line"></view>
<picker class="picker" mode="date" value="{{endDate}}" start="{{startDate}}" end="{{today}}" bindchange="handleEndDateChange">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{endDate}}" start="{{startDate}}" end="{{today}}" bindchange="handleEndDateChange">
<view class="p-content">
<view class="content">{{endDate}}</view>
<image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image>

9
src/ground/pages/home/index.ts

@ -927,9 +927,14 @@ Page({ @@ -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}`,
})
},

34
src/ground/pages/stat/index.ts

@ -11,7 +11,7 @@ Page({ @@ -11,7 +11,7 @@ Page({
// 时间筛选
startDate: '',
endDate: '',
today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器
today: '', // 今天日期,用于限制时间选择器
type: 'day', // day-按日,month-按月
// 统计数据(从 summary 获取)
@ -45,12 +45,16 @@ Page({ @@ -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({ @@ -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({ @@ -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({ @@ -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() {

4
src/ground/pages/stat/index.wxml

@ -8,14 +8,14 @@ @@ -8,14 +8,14 @@
<view class="page" style="padding-top: {{pageTop}}px;">
<view class="page-header" style="top:{{pageTop}}px">
<view class="chart-range">
<picker class="picker" mode="date" value="{{startDate}}" end="{{today}}" bindchange="handleStartDateChange">
<picker class="picker" mode="date" fields="{{type === 'month' ? 'month' : 'day'}}" value="{{startDate}}" end="{{today}}" bindchange="handleStartDateChange">
<view class="p-content">
<view class="content">{{startDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
</view>
</picker>
<view class="line"></view>
<picker class="picker" mode="date" value="{{endDate}}" start="{{startDate}}" end="{{today}}" bindchange="handleEndDateChange">
<picker class="picker" mode="date" fields="{{type === 'month' ? 'month' : 'day'}}" value="{{endDate}}" start="{{startDate}}" end="{{today}}" bindchange="handleEndDateChange">
<view class="p-content">
<view class="content">{{endDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>

Loading…
Cancel
Save