This commit is contained in:
dhr
2025-09-22 15:42:13 +08:00
parent aa443c3d62
commit fc3abeb4c0
14 changed files with 4215 additions and 1572 deletions

View File

@ -11,12 +11,6 @@
<div class="nav-tab" @click="handleInspection6">工单管理</div>
<div class="nav-tab" @click="handleInspection7">运维组织</div>
</div>
<!-- 标题栏 -->
<div class="header">
<TitleComponent title="运维待办事项" subtitle="管理每日、每周等的运维工作任务"></TitleComponent>
</div>
<div class="main-content">
<!-- 左侧日历区域 -->
<div class="calendar-container">
@ -105,7 +99,13 @@
</div>
</div>
</div>
<el-dialog v-model="dialogVisible" title="新增任务" width="480px" class="custom-dialog" :before-close="closeDialog">
<el-dialog
v-model="dialogVisible"
:title="editingTaskId ? '编辑任务' : '新增任务'"
width="480px"
class="custom-dialog"
:before-close="closeDialog"
>
<el-form :model="taskForm" label-width="80px" class="task-form">
<el-form-item label="任务名称" prop="name">
<el-input v-model="taskForm.name" placeholder="输入任务名称" class="form-input"></el-input>
@ -119,6 +119,7 @@
type="datetimerange"
start-placeholder="开始时间"
end-placeholder="结束时间"
:disabled-date="() => false"
class="form-input"
style="width: 100%"
/>
@ -139,7 +140,7 @@
</el-select>
</el-form-item>
<!-- 新增:工作时间段选择器 -->
<el-form-item label="工作时间段1" prop="workTimeRange1">
<el-form-item label="开始时间" prop="workTimeRange1">
<el-time-picker
v-model="taskForm.workTimeRange1"
type="timerange"
@ -151,7 +152,7 @@
style="width: 100%"
/>
</el-form-item>
<el-form-item label="工作时间段2" prop="workTimeRange2">
<el-form-item label="结束时间" prop="workTimeRange2">
<el-time-picker
v-model="taskForm.workTimeRange2"
type="timerange"
@ -176,7 +177,6 @@
<script setup>
import { ref, computed, watch, onMounted } from 'vue';
import router from '@/router';
import TitleComponent from './TitleComponent.vue';
import { daibanlist, adddaiban, updatedaiban, deldaiban } from '@/api/zhinengxunjian/daiban/index';
// 默认显示当前月份
@ -442,93 +442,17 @@ const saveTask = async () => {
if (editingTaskId.value) {
// 编辑操作 - 修改参数传递方式将id合并到apiData中
response = await updatedaiban({ ...apiData, id: editingTaskId.value });
// 更新本地数据
const index = todoListData.value.findIndex((item) => item.id === editingTaskId.value);
if (index !== -1) {
todoListData.value[index] = {
...todoListData.value[index],
title: taskForm.value.name,
describeValue: taskForm.value.describeValue,
timeRange: formatTimeRange(taskForm.value.timeRange[0], taskForm.value.timeRange[1]),
originalTimeRange: taskForm.value.timeRange,
taskLevel: taskForm.value.taskLevel,
taskType: taskForm.value.taskType,
// 保留原有字段以便前端显示,添加类型检查
workTimeRange1: taskForm.value.workTimeRange1
? Array.isArray(taskForm.value.workTimeRange1)
? taskForm.value.workTimeRange1.join('-')
: taskForm.value.workTimeRange1
: '',
workTimeRange2: taskForm.value.workTimeRange2
? Array.isArray(taskForm.value.workTimeRange2)
? taskForm.value.workTimeRange2.join('-')
: taskForm.value.workTimeRange2
: ''
};
}
// 更新日历事件
const eventIndex = calendarEvents.value.findIndex((item) => item.id === editingTaskId.value);
if (eventIndex !== -1) {
calendarEvents.value[eventIndex] = {
...calendarEvents.value[eventIndex],
title: taskForm.value.name,
describeValue: taskForm.value.describeValue,
type: getEventType(taskForm.value.taskType)
};
}
ElMessage.success('任务更新成功');
} else {
// 新增操作
response = await adddaiban(apiData);
console.log('保存任务成功:', response);
// 获取当前日期
const currentDateStr = formatDate(new Date());
// 从接口响应中获取任务ID如果返回
const newId = response.data?.id || Date.now();
// 构建新任务对象添加到本地数据中
const newTask = {
id: newId,
title: taskForm.value.name,
describeValue: taskForm.value.describeValue,
timeRange: formatTimeRange(taskForm.value.timeRange[0], taskForm.value.timeRange[1]),
originalTimeRange: taskForm.value.timeRange,
taskLevel: taskForm.value.taskLevel,
taskType: taskForm.value.taskType,
// 保留原有字段以便前端显示,添加类型检查
workTimeRange1: taskForm.value.workTimeRange1
? Array.isArray(taskForm.value.workTimeRange1)
? taskForm.value.workTimeRange1.join('-')
: taskForm.value.workTimeRange1
: '',
workTimeRange2: taskForm.value.workTimeRange2
? Array.isArray(taskForm.value.workTimeRange2)
? taskForm.value.workTimeRange2.join('-')
: taskForm.value.workTimeRange2
: '',
date: currentDateStr
};
// 添加到待办列表
todoListData.value.unshift(newTask);
// 添加到日历事件
calendarEvents.value.push({
id: newId,
date: currentDateStr,
title: taskForm.value.name,
describeValue: taskForm.value.describeValue,
type: getEventType(taskForm.value.taskType)
});
ElMessage.success('任务添加成功');
}
// 重新从接口获取最新数据,确保列表数据与后端保持一致
await fetchData();
// 重置表单
taskForm.value = {
name: '',
@ -622,9 +546,8 @@ const handleDelete = (id) => {
// 接口要求格式: /ops/matter/{ids}这里ids是单个ID
await deldaiban(id);
// 前端删除同步
todoListData.value = todoListData.value.filter((item) => item.id !== id);
calendarEvents.value = calendarEvents.value.filter((item) => item.id !== id);
// 删除成功后重新获取最新数据
await fetchData();
ElMessage.success('任务已删除');
} catch (error) {
console.error('删除任务失败:', error);