Browse Source

fix: 移除硬编码项目名称并限制日期选择不超过今天

refactor: 使用today变量限制日期选择器范围
feat: 添加requestId防止请求竞态条件
master
kola-web 4 days ago
parent
commit
b293c3a57b
  1. 18
      src/doctor/pages/articleList/index.ts
  2. 4
      src/doctor/pages/home/index.ts
  3. 4
      src/doctor/pages/home/index.wxml
  4. 4
      src/doctor/pages/patientList/index.ts
  5. 4
      src/doctor/pages/stat/index.wxml
  6. 4
      src/ground/pages/home/index.ts
  7. 12
      src/ground/pages/home/index.wxml
  8. 2
      src/ground/pages/invite/index.wxml
  9. 4
      src/ground/pages/pharmacist/index.ts
  10. 4
      src/ground/pages/pharmacist/index.wxml
  11. 2
      src/ground/pages/stat/index.ts
  12. 4
      src/ground/pages/stat/index.wxml

18
src/doctor/pages/articleList/index.ts

@ -61,11 +61,17 @@ Page({
this.setData({ bannerList: [] }) this.setData({ bannerList: [] })
} }
}, },
// 请求ID,用于防止竞态条件
requestId: 0,
// 获取文章列表 // 获取文章列表
getArticleList() { getArticleList() {
if (this.data.loading || !this.data.hasMore) return if (this.data.loading || !this.data.hasMore) return
if (!this.data.currentCategoryId) return if (!this.data.currentCategoryId) return
// 生成新的请求ID
this.requestId++
const currentRequestId = this.requestId
this.setData({ loading: true }) this.setData({ loading: true })
wx.ajax({ wx.ajax({
@ -78,6 +84,11 @@ Page({
}, },
}) })
.then((res: any) => { .then((res: any) => {
// 校验:如果请求ID已过期,则丢弃该响应
if (currentRequestId !== this.requestId) {
return
}
const list = (res.list || []).map((item: any) => ({ const list = (res.list || []).map((item: any) => ({
...item, ...item,
isLiked: item.isLiked || false, isLiked: item.isLiked || false,
@ -98,17 +109,24 @@ Page({
}) })
}) })
.catch(() => { .catch(() => {
// 校验:如果请求ID已过期,不重置loading状态
if (currentRequestId !== this.requestId) {
return
}
this.setData({ loading: false }) this.setData({ loading: false })
}) })
}, },
// 切换分类 // 切换分类
handleTabChange(e: WechatMiniprogram.CustomEvent) { handleTabChange(e: WechatMiniprogram.CustomEvent) {
const categoryId = e.currentTarget.dataset.id const categoryId = e.currentTarget.dataset.id
// 增加 requestId,使之前的请求失效
this.requestId++
this.setData({ this.setData({
currentCategoryId: categoryId, currentCategoryId: categoryId,
articleList: [], articleList: [],
page: 1, page: 1,
hasMore: true, hasMore: true,
loading: false,
}) })
this.getBannerList(categoryId) this.getBannerList(categoryId)
this.getArticleList() this.getArticleList()

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

@ -13,7 +13,7 @@ Page({
// 项目列表 // 项目列表
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>,
currentProjectId: 0, currentProjectId: 0,
currentProjectName: '特诺雅', currentProjectName: '',
projectIndex: 0, projectIndex: 0,
// 待处理患者数 // 待处理患者数
@ -146,7 +146,7 @@ Page({
this.setData({ this.setData({
projectList, projectList,
currentProjectId, currentProjectId,
currentProjectName: currentProject?.projectName || '特诺雅', currentProjectName: currentProject?.projectName || '',
projectIndex: projectIndex >= 0 ? projectIndex : 0, projectIndex: projectIndex >= 0 ? projectIndex : 0,
}) })

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

@ -157,14 +157,14 @@
</view> </view>
</view> </view>
<view class="chart-range"> <view class="chart-range">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chartStartDate}}" end="{{chartEndDate}}" bindchange="onChartStartDateChange"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chartStartDate}}" end="{{today}}" bindchange="onChartStartDateChange">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chartStartMonth : chartStartDate}}</view> <view class="content">{{statType === 'month' ? chartStartMonth : chartStartDate}}</view>
<image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image>
</view> </view>
</picker> </picker>
<view class="line"></view> <view class="line"></view>
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chartEndDate}}" start="{{chartStartDate}}" bindchange="onChartEndDateChange"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chartEndDate}}" start="{{chartStartDate}}" end="{{today}}" bindchange="onChartEndDateChange">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chartEndMonth : chartEndDate}}</view> <view class="content">{{statType === 'month' ? chartEndMonth : chartEndDate}}</view>
<image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon13.png?t={{Timestamp}}"></image>

4
src/doctor/pages/patientList/index.ts

@ -6,7 +6,7 @@ Page({
// 项目列表 // 项目列表
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>,
currentProjectId: 0, currentProjectId: 0,
currentProjectName: '特诺雅', currentProjectName: '',
projectIndex: 0, projectIndex: 0,
// 搜索关键词 // 搜索关键词
@ -76,7 +76,7 @@ Page({
this.setData({ this.setData({
projectList: list, projectList: list,
currentProjectId, currentProjectId,
currentProjectName: currentProject?.projectName || '特诺雅', currentProjectName: currentProject?.projectName || '',
projectIndex: list.findIndex((p: any) => p.projectId === currentProjectId), projectIndex: list.findIndex((p: any) => p.projectId === currentProjectId),
}) })

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

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

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

@ -74,7 +74,7 @@ Page({
// 项目列表 // 项目列表
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>,
currentProjectId: 0, currentProjectId: 0,
currentProjectName: '特诺雅', currentProjectName: '',
projectIndex: 0, projectIndex: 0,
}, },
@ -158,7 +158,7 @@ Page({
this.setData({ this.setData({
projectList, projectList,
currentProjectId, currentProjectId,
currentProjectName: currentProject?.projectName || '特诺雅', currentProjectName: currentProject?.projectName || '',
projectIndex: projectIndex >= 0 ? projectIndex : 0, projectIndex: projectIndex >= 0 ? projectIndex : 0,
}) })

12
src/ground/pages/home/index.wxml

@ -140,14 +140,14 @@
</view> </view>
</view> </view>
<view class="chart-range"> <view class="chart-range">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart1StartDate}}" end="{{chart1EndDate}}" bindchange="onChart1DateChange" data-field="startDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart1StartDate}}" end="{{today}}" bindchange="onChart1DateChange" data-field="startDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart1StartMonth : chart1StartDate}}</view> <view class="content">{{statType === 'month' ? chart1StartMonth : chart1StartDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
</view> </view>
</picker> </picker>
<view class="line"></view> <view class="line"></view>
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart1EndDate}}" start="{{chart1StartDate}}" bindchange="onChart1DateChange" data-field="endDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart1EndDate}}" start="{{chart1StartDate}}" end="{{today}}" bindchange="onChart1DateChange" data-field="endDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart1EndMonth : chart1EndDate}}</view> <view class="content">{{statType === 'month' ? chart1EndMonth : chart1EndDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
@ -168,14 +168,14 @@
<view class="title">邀约药师数统计</view> <view class="title">邀约药师数统计</view>
</view> </view>
<view class="chart-range"> <view class="chart-range">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart2StartDate}}" end="{{chart2EndDate}}" bindchange="onChart2DateChange" data-field="startDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart2StartDate}}" end="{{today}}" bindchange="onChart2DateChange" data-field="startDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart2StartMonth : chart2StartDate}}</view> <view class="content">{{statType === 'month' ? chart2StartMonth : chart2StartDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
</view> </view>
</picker> </picker>
<view class="line"></view> <view class="line"></view>
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart2EndDate}}" start="{{chart2StartDate}}" bindchange="onChart2DateChange" data-field="endDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart2EndDate}}" start="{{chart2StartDate}}" end="{{today}}" bindchange="onChart2DateChange" data-field="endDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart2EndMonth : chart2EndDate}}</view> <view class="content">{{statType === 'month' ? chart2EndMonth : chart2EndDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
@ -192,14 +192,14 @@
<view class="title">邀约药店统计</view> <view class="title">邀约药店统计</view>
</view> </view>
<view class="chart-range"> <view class="chart-range">
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart3StartDate}}" end="{{chart3EndDate}}" bindchange="onChart3DateChange" data-field="startDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart3StartDate}}" end="{{today}}" bindchange="onChart3DateChange" data-field="startDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart3StartMonth : chart3StartDate}}</view> <view class="content">{{statType === 'month' ? chart3StartMonth : chart3StartDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>
</view> </view>
</picker> </picker>
<view class="line"></view> <view class="line"></view>
<picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart3EndDate}}" start="{{chart3StartDate}}" bindchange="onChart3DateChange" data-field="endDate"> <picker class="picker" mode="date" fields="{{statType === 'month' ? 'month' : 'day'}}" value="{{chart3EndDate}}" start="{{chart3StartDate}}" end="{{today}}" bindchange="onChart3DateChange" data-field="endDate">
<view class="p-content"> <view class="p-content">
<view class="content">{{statType === 'month' ? chart3EndMonth : chart3EndDate}}</view> <view class="content">{{statType === 'month' ? chart3EndMonth : chart3EndDate}}</view>
<image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon8.png?t={{Timestamp}}"></image>

2
src/ground/pages/invite/index.wxml

@ -27,7 +27,7 @@
<view class="title">邀请您加入健康管理项目</view> <view class="title">邀请您加入健康管理项目</view>
<view class="brand"> <view class="brand">
<view class="name"> <view class="name">
{{projectName || '特诺雅'}} {{projectName || ''}}
<text style="font-size: 0.5em; vertical-align: top">®</text> <text style="font-size: 0.5em; vertical-align: top">®</text>
</view> </view>
<view class="bg"></view> <view class="bg"></view>

4
src/ground/pages/pharmacist/index.ts

@ -1,3 +1,4 @@
import dayjs from 'dayjs'
const app = getApp<IAppOption>() const app = getApp<IAppOption>()
Page({ Page({
@ -7,6 +8,7 @@ Page({
// 时间筛选 // 时间筛选
startDate: '', startDate: '',
endDate: '', endDate: '',
today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器
// 项目列表 // 项目列表
projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>,
@ -50,7 +52,7 @@ Page({
this.setData({ this.setData({
projectList, projectList,
currentProjectId, currentProjectId,
currentProjectName: currentProject?.projectName || '特诺雅', currentProjectName: currentProject?.projectName || '',
projectIndex: projectIndex >= 0 ? projectIndex : 0, projectIndex: projectIndex >= 0 ? projectIndex : 0,
}) })

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

@ -22,11 +22,11 @@
<view class="range"> <view class="range">
<view class="label">时间筛选:</view> <view class="label">时间筛选:</view>
<view class="r-wrap"> <view class="r-wrap">
<picker class="picker" mode="date" value="{{startDate}}" bindchange="handleStartDateChange" end="{{endDate || ''}}"> <picker class="picker" mode="date" value="{{startDate}}" bindchange="handleStartDateChange" end="{{today}}">
<view class="date">{{startDate || '开始时间'}}</view> <view class="date">{{startDate || '开始时间'}}</view>
</picker> </picker>
<view class="line"></view> <view class="line"></view>
<picker class="picker" mode="date" value="{{endDate}}" bindchange="handleEndDateChange" start="{{startDate || ''}}"> <picker class="picker" mode="date" value="{{endDate}}" bindchange="handleEndDateChange" start="{{startDate || ''}}" end="{{today}}">
<view class="date">{{endDate || '结束时间'}}</view> <view class="date">{{endDate || '结束时间'}}</view>
</picker> </picker>
<image class="icon" src="{{imageUrl}}icon2.png?t={{Timestamp}}"></image> <image class="icon" src="{{imageUrl}}icon2.png?t={{Timestamp}}"></image>

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

@ -1,3 +1,4 @@
import dayjs from 'dayjs'
const app = getApp<IAppOption>() const app = getApp<IAppOption>()
Page({ Page({
@ -8,6 +9,7 @@ Page({
// 时间筛选 // 时间筛选
startDate: '', startDate: '',
endDate: '', endDate: '',
today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器
type: 'day', // day-按日,month-按月 type: 'day', // day-按日,month-按月
// 统计数据(从 summary 获取) // 统计数据(从 summary 获取)

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

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

Loading…
Cancel
Save