From b293c3a57b569b8427afc79030b4e30746eb608a Mon Sep 17 00:00:00 2001 From: kola-web Date: Sat, 7 Mar 2026 17:26:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=E7=A1=AC=E7=BC=96?= =?UTF-8?q?=E7=A0=81=E9=A1=B9=E7=9B=AE=E5=90=8D=E7=A7=B0=E5=B9=B6=E9=99=90?= =?UTF-8?q?=E5=88=B6=E6=97=A5=E6=9C=9F=E9=80=89=E6=8B=A9=E4=B8=8D=E8=B6=85?= =?UTF-8?q?=E8=BF=87=E4=BB=8A=E5=A4=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refactor: 使用today变量限制日期选择器范围 feat: 添加requestId防止请求竞态条件 --- src/doctor/pages/articleList/index.ts | 18 ++++++++++++++++++ src/doctor/pages/home/index.ts | 4 ++-- src/doctor/pages/home/index.wxml | 4 ++-- src/doctor/pages/patientList/index.ts | 4 ++-- src/doctor/pages/stat/index.wxml | 4 ++-- src/ground/pages/home/index.ts | 4 ++-- src/ground/pages/home/index.wxml | 12 ++++++------ src/ground/pages/invite/index.wxml | 2 +- src/ground/pages/pharmacist/index.ts | 4 +++- src/ground/pages/pharmacist/index.wxml | 4 ++-- src/ground/pages/stat/index.ts | 2 ++ src/ground/pages/stat/index.wxml | 4 ++-- 12 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/doctor/pages/articleList/index.ts b/src/doctor/pages/articleList/index.ts index b3962a1..d7451fd 100644 --- a/src/doctor/pages/articleList/index.ts +++ b/src/doctor/pages/articleList/index.ts @@ -61,11 +61,17 @@ Page({ this.setData({ bannerList: [] }) } }, + // 请求ID,用于防止竞态条件 + requestId: 0, + // 获取文章列表 getArticleList() { if (this.data.loading || !this.data.hasMore) return if (!this.data.currentCategoryId) return + // 生成新的请求ID + this.requestId++ + const currentRequestId = this.requestId this.setData({ loading: true }) wx.ajax({ @@ -78,6 +84,11 @@ Page({ }, }) .then((res: any) => { + // 校验:如果请求ID已过期,则丢弃该响应 + if (currentRequestId !== this.requestId) { + return + } + const list = (res.list || []).map((item: any) => ({ ...item, isLiked: item.isLiked || false, @@ -98,17 +109,24 @@ Page({ }) }) .catch(() => { + // 校验:如果请求ID已过期,不重置loading状态 + if (currentRequestId !== this.requestId) { + return + } this.setData({ loading: false }) }) }, // 切换分类 handleTabChange(e: WechatMiniprogram.CustomEvent) { const categoryId = e.currentTarget.dataset.id + // 增加 requestId,使之前的请求失效 + this.requestId++ this.setData({ currentCategoryId: categoryId, articleList: [], page: 1, hasMore: true, + loading: false, }) this.getBannerList(categoryId) this.getArticleList() diff --git a/src/doctor/pages/home/index.ts b/src/doctor/pages/home/index.ts index 6b49940..2af5242 100644 --- a/src/doctor/pages/home/index.ts +++ b/src/doctor/pages/home/index.ts @@ -13,7 +13,7 @@ Page({ // 项目列表 projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, currentProjectId: 0, - currentProjectName: '特诺雅', + currentProjectName: '', projectIndex: 0, // 待处理患者数 @@ -146,7 +146,7 @@ Page({ this.setData({ projectList, currentProjectId, - currentProjectName: currentProject?.projectName || '特诺雅', + currentProjectName: currentProject?.projectName || '', projectIndex: projectIndex >= 0 ? projectIndex : 0, }) diff --git a/src/doctor/pages/home/index.wxml b/src/doctor/pages/home/index.wxml index 072f068..a886354 100644 --- a/src/doctor/pages/home/index.wxml +++ b/src/doctor/pages/home/index.wxml @@ -157,14 +157,14 @@ - + {{statType === 'month' ? chartStartMonth : chartStartDate}} - + {{statType === 'month' ? chartEndMonth : chartEndDate}} diff --git a/src/doctor/pages/patientList/index.ts b/src/doctor/pages/patientList/index.ts index eba41e2..8782d23 100644 --- a/src/doctor/pages/patientList/index.ts +++ b/src/doctor/pages/patientList/index.ts @@ -6,7 +6,7 @@ Page({ // 项目列表 projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, currentProjectId: 0, - currentProjectName: '特诺雅', + currentProjectName: '', projectIndex: 0, // 搜索关键词 @@ -76,7 +76,7 @@ Page({ this.setData({ projectList: list, currentProjectId, - currentProjectName: currentProject?.projectName || '特诺雅', + currentProjectName: currentProject?.projectName || '', projectIndex: list.findIndex((p: any) => p.projectId === currentProjectId), }) diff --git a/src/doctor/pages/stat/index.wxml b/src/doctor/pages/stat/index.wxml index cbd120f..4adfbc8 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 4b7e2c0..b58f693 100644 --- a/src/ground/pages/home/index.ts +++ b/src/ground/pages/home/index.ts @@ -74,7 +74,7 @@ Page({ // 项目列表 projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, currentProjectId: 0, - currentProjectName: '特诺雅', + currentProjectName: '', projectIndex: 0, }, @@ -158,7 +158,7 @@ Page({ this.setData({ projectList, currentProjectId, - currentProjectName: currentProject?.projectName || '特诺雅', + currentProjectName: currentProject?.projectName || '', projectIndex: projectIndex >= 0 ? projectIndex : 0, }) diff --git a/src/ground/pages/home/index.wxml b/src/ground/pages/home/index.wxml index 4a244a4..a4145a7 100644 --- a/src/ground/pages/home/index.wxml +++ b/src/ground/pages/home/index.wxml @@ -140,14 +140,14 @@ - + {{statType === 'month' ? chart1StartMonth : chart1StartDate}} - + {{statType === 'month' ? chart1EndMonth : chart1EndDate}} @@ -168,14 +168,14 @@ 邀约药师数统计 - + {{statType === 'month' ? chart2StartMonth : chart2StartDate}} - + {{statType === 'month' ? chart2EndMonth : chart2EndDate}} @@ -192,14 +192,14 @@ 邀约药店统计 - + {{statType === 'month' ? chart3StartMonth : chart3StartDate}} - + {{statType === 'month' ? chart3EndMonth : chart3EndDate}} diff --git a/src/ground/pages/invite/index.wxml b/src/ground/pages/invite/index.wxml index ecb73ff..76adb5b 100644 --- a/src/ground/pages/invite/index.wxml +++ b/src/ground/pages/invite/index.wxml @@ -27,7 +27,7 @@ 邀请您加入健康管理项目 - {{projectName || '特诺雅'}} + {{projectName || ''}} ® diff --git a/src/ground/pages/pharmacist/index.ts b/src/ground/pages/pharmacist/index.ts index 109b5f8..291e46a 100644 --- a/src/ground/pages/pharmacist/index.ts +++ b/src/ground/pages/pharmacist/index.ts @@ -1,3 +1,4 @@ +import dayjs from 'dayjs' const app = getApp() Page({ @@ -7,6 +8,7 @@ Page({ // 时间筛选 startDate: '', endDate: '', + today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器 // 项目列表 projectList: [] as Array<{ projectId: number; projectName: string; projectDescription: string }>, @@ -50,7 +52,7 @@ Page({ this.setData({ projectList, currentProjectId, - currentProjectName: currentProject?.projectName || '特诺雅', + currentProjectName: currentProject?.projectName || '', projectIndex: projectIndex >= 0 ? projectIndex : 0, }) diff --git a/src/ground/pages/pharmacist/index.wxml b/src/ground/pages/pharmacist/index.wxml index 42ffe4b..8ec79ee 100644 --- a/src/ground/pages/pharmacist/index.wxml +++ b/src/ground/pages/pharmacist/index.wxml @@ -22,11 +22,11 @@ 时间筛选: - + {{startDate || '开始时间'}} - + {{endDate || '结束时间'}} diff --git a/src/ground/pages/stat/index.ts b/src/ground/pages/stat/index.ts index 2ab5b0d..8688c68 100644 --- a/src/ground/pages/stat/index.ts +++ b/src/ground/pages/stat/index.ts @@ -1,3 +1,4 @@ +import dayjs from 'dayjs' const app = getApp() Page({ @@ -8,6 +9,7 @@ Page({ // 时间筛选 startDate: '', endDate: '', + today: dayjs().format('YYYY-MM-DD'), // 今天日期,用于限制时间选择器 type: 'day', // day-按日,month-按月 // 统计数据(从 summary 获取) diff --git a/src/ground/pages/stat/index.wxml b/src/ground/pages/stat/index.wxml index 7dbb3cc..a518f73 100644 --- a/src/ground/pages/stat/index.wxml +++ b/src/ground/pages/stat/index.wxml @@ -8,14 +8,14 @@ - + {{startDate}} - + {{endDate}}