This commit is contained in:
dhr
2025-09-26 20:32:14 +08:00
parent 6b9bfb66b1
commit 3f07f7afe3
18 changed files with 1672 additions and 945 deletions

View File

@ -2,7 +2,7 @@
<div>
<div class="inspection-tasks">
<!-- 导航栏 -->
<div class="navigation-tabs">
<!-- <div class="navigation-tabs">
<div class="nav-tab" @click="handleInspection1">待办事项</div>
<div class="nav-tab" @click="handleInspection2">巡检管理</div>
<div class="nav-tab active" @click="handleInspection3">试验管理</div>
@ -10,7 +10,7 @@
<div class="nav-tab" @click="handleInspection5">抢修管理</div>
<div class="nav-tab" @click="handleInspection6">工单管理</div>
<div class="nav-tab" @click="handleInspection7">运维组织</div>
</div>
</div> -->
<!-- 选项卡 -->
<div class="tabs-wrapper">
@ -29,7 +29,7 @@
<el-option label="待执行" value="1"></el-option>
<el-option label="执行中" value="4"></el-option>
<el-option label="已延期" value="2"></el-option>
<!-- 接口暂停对应页面已延期 -->
<el-option label="已完成" value="5"></el-option>
<el-option label="失败" value="3"></el-option>
</el-select>
@ -137,7 +137,7 @@
</div>
<!-- 添加新任务弹窗 -->
<el-dialog v-model="createTaskDialogVisible" title="添加新任务" width="700px" :before-close="handleCancelCreateTask">
<el-dialog v-model="createTaskDialogVisible" title="添加新任务" width="750px" :before-close="handleCancelCreateTask">
<el-form ref="createTaskFormRef" :model="createTaskForm" :rules="createTaskRules" label-width="80px">
<el-form-item label="任务名称" prop="taskName">
<el-input v-model="createTaskForm.taskName" placeholder="输入任务名称" />
@ -338,7 +338,7 @@
<div v-if="node.remark" class="step-remark">备注{{ node.remark }}</div>
</div>
<div class="step-status" :class="getStatusClass(node.status)">
{{ getStepStatusText(node.status) }}
{{ node.status === '2' ? '未完成' : '已完成' }}
</div>
</div>
</div>
@ -377,7 +377,7 @@
</template>
<script setup>
import { ref, computed, onMounted, getCurrentInstance } from 'vue';
import { ref, computed, onMounted } from 'vue';
import router from '@/router';
// 引入已定义的接口函数
import { syrenwulist, syrenwuDetail, addsyrenwu, updatesyrenwu } from '@/api/zhinengxunjian/shiyan/renwu';
@ -386,7 +386,6 @@ import { xunjianUserlist } from '@/api/zhinengxunjian/xunjian/index';
import { addjiedian } from '@/api/zhinengxunjian/jiedian/index';
// 引入Element Plus组件提示/空状态/骨架屏/弹窗)
import { ElMessage, ElEmpty, ElSkeleton, ElForm, ElMessageBox } from 'element-plus';
import { Plus } from '@element-plus/icons-vue';
/**
* 根据任务ID获取完整的任务详情数据
@ -428,7 +427,6 @@ const groupNodesByModule = (nodes) => {
if (!nodes || !Array.isArray(nodes)) {
return [];
}
// 这里简单地将所有节点放在一个默认模块下实际应用中可以根据节点数据的module字段进行分组
const defaultGroup = {
module: '测试步骤',
@ -856,9 +854,18 @@ const handleAction = async (task) => {
id: task.id
};
// 声明resultType变量提升作用域
let resultType = null;
// 3. 根据任务状态只修改状态相关的字段
if (task.status === '4') {
// 执行中 → 完成:使用弹窗确认结果
try {
// 保持原有结构
} catch (error) {
console.error('捕获到异常:', error);
}
try {
const confirmResult = await ElMessageBox.confirm('请选择试验结果', '完成试验', {
confirmButtonText: '正常',
@ -870,12 +877,14 @@ const handleAction = async (task) => {
updateParams.status = '5';
updateParams.progress = 100;
updateParams.testFinal = '正常';
resultType = 'normal'; // 现在在外部作用域中定义
} catch (error) {
if (error === 'cancel') {
// 用户点击取消(异常)
updateParams.status = '5';
updateParams.progress = 100;
updateParams.testFinal = '异常';
resultType = 'abnormal'; // 现在在外部作用域中定义
} else {
// 关闭弹窗,不执行操作
return;
@ -887,6 +896,8 @@ const handleAction = async (task) => {
case '1': // 待执行 → 开始执行状态改为4
updateParams.status = '4';
updateParams.progress = 10; // 初始进度10%
// 设置开始时间为当前时间
updateParams.planBeginTime = new Date().toISOString().slice(0, 16).replace('T', ' ');
break;
case '2': // 已延期 → 重新安排状态改为1重置时间
updateParams.status = '1';
@ -904,6 +915,30 @@ const handleAction = async (task) => {
const response = await updatesyrenwu(updateParams);
if (response.code === 200) {
ElMessage.success(`任务${task.actionText}成功`);
// 只有在接口调用成功后才设置时间
if (task.status === '4') {
// 获取最新的任务详情,确保包含所有字段
const latestTaskDetails = await getTaskDetails(task.id);
if (latestTaskDetails) {
// 创建包含所有字段的新参数对象
const timeUpdateParams = {
...latestTaskDetails,
id: task.id
};
// 根据结果类型设置相应的时间现在resultType已在作用域内
if (resultType === 'normal') {
timeUpdateParams.planFinishTime = new Date().toISOString().slice(0, 16).replace('T', ' ');
} else if (resultType === 'abnormal') {
timeUpdateParams.failTime = new Date().toISOString().slice(0, 16).replace('T', ' ');
}
// 再次调用接口更新时间
await updatesyrenwu(timeUpdateParams);
}
}
getTaskList(); // 刷新任务列表
} else {
ElMessage.error(`任务${task.actionText}失败:` + response.msg);
@ -1010,10 +1045,10 @@ const handleSaveTask = async () => {
status: '1', // 初始状态:待执行(必需)
testPlanId: createTaskForm.value.relatedPlan, // 关联计划ID必需
testSetting: '', // 测试设置
planBeginTime: createTaskForm.value.timeRange[0], // 计划开始时间
planBeginTime: '', // 计划开始时间(新增时为空)
progress: 0, // 初始进度0%
failReason: '',
failTime: now.toISOString(),
failTime: '', // 失败时间(新增时为空)
failPhase: 0,
faileAnalyze: '',
faileTips: '',
@ -1021,8 +1056,8 @@ const handleSaveTask = async () => {
testFinal: '',
finalInfo: '',
pauseFor: '',
pauseTime: now.toISOString(),
planFinishTime: createTaskForm.value.timeRange[1], // 计划完成时间
pauseTime: '', // 暂停时间(新增时为空)
planFinishTime: '', // 计划完成时间(新增时为空)
nodeIds: nodeIds // 步骤节点ID数组
};
@ -1114,6 +1149,18 @@ onMounted(() => {
const pagedTasks = computed(() => {
return tasks.value;
});
// 获取任务状态对应的CSS类
const getTaskStatusClass = (status) => {
const statusStr = status?.toString() || '';
const statusMap = {
'1': 'status-pending',
'2': 'status-delayed',
'3': 'status-failed',
'4': 'status-running',
'5': 'status-completed'
};
return statusMap[statusStr] || 'status-pending';
};
</script>
<style scoped>
@ -1234,27 +1281,6 @@ const pagedTasks = computed(() => {
background-color: #52c41a;
}
/* 自定义步骤条样式覆盖 */
.custom-steps .el-step__description {
white-space: pre-wrap;
font-size: 12px;
color: #666;
line-height: 1.4;
}
.module-group {
margin-bottom: 20px;
}
.module-title {
font-size: 14px;
font-weight: 600;
color: #1d2129;
margin-bottom: 12px;
padding-bottom: 8px;
border-bottom: 1px solid #f0f2f5;
}
/* 卡片悬停效果 */
.task-card:hover {
transform: translateY(-3px);
@ -1393,22 +1419,6 @@ const pagedTasks = computed(() => {
color: #165dff;
}
.start-btn,
.report-btn {
background-color: #165dff;
border-color: #165dff;
}
.reschedule-btn {
background-color: #ff7d00;
border-color: #ff7d00;
}
.complete-btn {
background-color: #00b42a;
border-color: #00b42a;
}
/* 分页区域样式 */
.pagination-section {
display: flex;
@ -1536,10 +1546,6 @@ const pagedTasks = computed(() => {
color: #e6a23c;
}
.status-running {
color: #409eff;
}
.status-completed {
color: #67c23a;
}