优化日程管理功能

This commit is contained in:
2026-09-09 17:16:52 +08:00
parent 2f238875e1
commit c146dc2f2f
4 changed files with 126 additions and 72 deletions
+65 -63
View File
@@ -136,19 +136,14 @@
>查看全部</el-button
>
</div>
<el-tabs v-model="scheduleTab" class="schedule-tabs">
<el-tabs v-model="scheduleRange" class="schedule-tabs">
<el-tab-pane
v-for="tab in scheduleTabs"
v-for="tab in scheduleRanges"
:key="tab.value"
:name="tab.value"
>
<template #label>
<span class="tab-label">
{{ tab.label }}
<span class="tab-count">{{
scheduleCounts[tab.value] || 0
}}</span>
</span>
<span class="tab-label">{{ tab.label }}</span>
</template>
</el-tab-pane>
</el-tabs>
@@ -203,9 +198,9 @@
<el-empty
v-if="!filteredScheduleReminders.length && !scheduleLoading"
:description="
scheduleTab === 'all'
? '近期暂无日程安排'
: '该分类下暂无日程'
scheduleRange === 'today'
? '今日暂无日程安排'
: '该时间范围内暂无日程'
"
:image-size="60"
/>
@@ -263,7 +258,7 @@
</template>
<script setup>
import { computed, onBeforeUnmount, onMounted, reactive, ref } from "vue";
import { computed, onBeforeUnmount, onMounted, reactive, ref, watch } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import * as echarts from "echarts";
@@ -376,67 +371,74 @@ const router = useRouter();
const scheduleReminders = ref([]);
const scheduleLoading = ref(false);
// 待办分类:all-全部 today-今日 pending-未完成 done-已完成
// 注:matchScheduleCategory 仍保留 ongoing 分支(进行中 = 跨天延期中的任务),
// 当前不启用;以后要恢复,在下面数组里加一行 { value: "ongoing", label: "进行中" } 即可。
const scheduleTabs = [
{ value: "all", label: "全部" },
// 时间范围筛选:今日(默认)/ 本周 / 本月 / 本季度 / 本年
const scheduleRanges = [
{ value: "today", label: "今日" },
{ value: "pending", label: "未完成" },
{ value: "done", label: "已完成" },
{ value: "week", label: "本周" },
{ value: "month", label: "本月" },
{ value: "quarter", label: "本季度" },
{ value: "year", label: "本年" },
];
const scheduleTab = ref("all");
// 判断一条日程是否属于某个分类(与后端 category 语义保持一致)
const matchScheduleCategory = (item, category) => {
switch (category) {
case "today":
return item.schedule_date === fmtDate(new Date());
case "pending":
return item.status === 0;
// 进行中 = 跨天顺延中的任务:被顺延出去的源日程,或顺延出来的续做日程
case "ongoing":
return item.source_id > 0 || item.carry_over === 1;
case "done":
return item.status === 1;
default:
return true;
}
};
const filteredScheduleReminders = computed(() =>
scheduleReminders.value.filter((item) =>
matchScheduleCategory(item, scheduleTab.value),
),
);
// 各分类数量按当前面板范围(逾期 + 未来7天)统计
const scheduleCounts = computed(() => {
const result = {};
for (const tab of scheduleTabs) {
result[tab.value] = scheduleReminders.value.filter((item) =>
matchScheduleCategory(item, tab.value),
).length;
}
return result;
});
const scheduleRange = ref("today");
const pad2 = (n) => String(n).padStart(2, "0");
const fmtDate = (d) =>
`${d.getFullYear()}-${pad2(d.getMonth() + 1)}-${pad2(d.getDate())}`;
// 拉取逾期 + 未来7天日程(均含已完成,完成后灰显沉底而非从列表消失)
const loadScheduleReminders = async () => {
// 计算指定时间范围的起止日期(含本周一 ~ 周日、季度首末月等)
const rangeDates = (range) => {
const now = new Date();
const today = fmtDate(now);
if (range === "today") {
return { start: today, end: today };
}
if (range === "week") {
// 周一为一周起点
const weekday = now.getDay() || 7;
const start = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() - (weekday - 1),
);
const end = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + (7 - weekday),
);
return { start: fmtDate(start), end: fmtDate(end) };
}
if (range === "month") {
const start = new Date(now.getFullYear(), now.getMonth(), 1);
const end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
return { start: fmtDate(start), end: fmtDate(end) };
}
if (range === "quarter") {
const q = Math.floor(now.getMonth() / 3);
const start = new Date(now.getFullYear(), q * 3, 1);
const end = new Date(now.getFullYear(), q * 3 + 3, 0);
return { start: fmtDate(start), end: fmtDate(end) };
}
// year
const start = new Date(now.getFullYear(), 0, 1);
const end = new Date(now.getFullYear(), 11, 31);
return { start: fmtDate(start), end: fmtDate(end) };
};
// 列表直接展示按所选时间范围拉取的数据(已完成灰显沉底)
const filteredScheduleReminders = computed(() => scheduleReminders.value);
// 切换时间范围时重新拉取对应区间的日程
watch(scheduleRange, () => loadScheduleReminders());
// 按所选时间范围拉取日程(含已完成,完成后灰显沉底而非从列表消失)
const loadScheduleReminders = async (range) => {
const r = range || scheduleRange.value;
scheduleLoading.value = true;
try {
const today = new Date();
const weekLater = new Date(
today.getFullYear(),
today.getMonth(),
today.getDate() + 7,
);
const { start, end } = rangeDates(r);
const res = await getScheduleList({
end_date: fmtDate(weekLater),
start_date: start,
end_date: end,
page: 1,
pageSize: 500,
});