From 1059a1f3b7942313046734b2c00cc1981da6226a Mon Sep 17 00:00:00 2001 From: yangzhe Date: Tue, 15 Apr 2025 09:59:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=A1=E5=88=92=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/planList.vue | 76 +++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 16 deletions(-) diff --git a/pages/index/planList.vue b/pages/index/planList.vue index 728bbd8..d4aaf46 100644 --- a/pages/index/planList.vue +++ b/pages/index/planList.vue @@ -30,7 +30,7 @@ @click="switchTab('completed')" > 已完成计划 - 12 + {{ completedPlanList.length }} 未完成计划 - 12 + {{ incompletePlanList.length }} @@ -63,7 +63,13 @@ --> - + + + @@ -102,27 +116,31 @@ import { getDateDiff } from "@/utils/utils"; export default { data() { + const todayStr = GetNowTime(new Date()); + return { activeTab: "completed", - maxDate: "2049-12-31", + // maxDate: "2049-12-31", // 默认最大日期为当天 showCalendar: false, // 请求参数 params: { - // '0 1 2' - "Item1.IsCompleted": 0, - dateBegin: GetNowTime(new Date()), - dateEnd: GetNowTime(new Date()), + // "Item1.IsCompleted": 1, // '0 1 2' 0未完成 1已完成 2不用管 + dateBegin: todayStr, + dateEnd: todayStr, }, // 计划列表 - planList: [], + completedPlanList: [], + incompletePlanList: [], + loading: false, // 添加加载状态 }; }, onShow() { - this.getPlanList(); + // 页面每次展示时都获取所有列表 + this.fetchAllPlanLists(); }, methods: { getDateDiff, @@ -137,15 +155,38 @@ export default { changeDate(e) { this.params.dateBegin = e.startDate; this.params.dateEnd = e.endDate; - this.getPlanList(); + // 日期更改后,重新获取所有列表 + this.fetchAllPlanLists(); }, - // 获取计划列表 - async getPlanList() { - const res = await GetPlanList(this.params); + // 统一获取所有列表数据 + async fetchAllPlanLists() { + if (this.loading) return; // 防止重复加载 + this.loading = true; + uni.showLoading({ title: "加载中..." }); // 显示加载提示 + try { + await Promise.all([this.fetchListData(1), this.fetchListData(0)]); + } catch (error) { + console.error("获取所有列表时出错:", error); + } finally { + this.loading = false; + uni.hideLoading(); // 隐藏加载提示 + } + }, + async fetchListData(status) { + const requestParams = { + ...this.params, + "Item1.IsCompleted": status, // 0未完成 1已完成 2不用管 + }; + + const res = await GetPlanList(requestParams); if (res.succeed) { - this.planList = res.data; + if (status === 1) { + this.completedPlanList = res.data || []; + } else { + this.incompletePlanList = res.data || []; + } } }, }, @@ -153,6 +194,9 @@ export default {