Files
SPDM/src/components/taskDetail/taskPerformance.vue

492 lines
12 KiB
Vue
Raw Normal View History

2025-10-30 19:30:06 +08:00
<template>
2026-02-02 10:30:24 +08:00
<div class="task-performance-page" v-if="showSetting">
<BaseTable
tableName="TASK_RUN_PERFORMANCE"
ref="baseTableRef"
:export-file-name="'指标列表'"
:export-api="exportPerformanceApi"
showCheckbox
hidePagination
:data="performanceData"
:actionList="showLeftOptions ? actionList : []"
:export-params="excelParams"
:full-height="fullHeight"
>
<template v-if="showLeftOptions" #leftOptions>
2025-10-30 19:30:06 +08:00
<div class="operate-box">
2025-11-26 18:49:29 +08:00
<el-button type="primary" @click="openAddPerformanceWindFun">新增</el-button>
2025-10-30 19:30:06 +08:00
</div>
</template>
<template #completeStatus="{ row }">
<StatusDot
:status="getTaskAchieveStyleClass(row.completeStatus || '0')"
:title="RESULT_ACHIEVE_STATUS.O[row.completeStatus || '0']"
/>
</template>
2026-01-09 15:58:28 +08:00
<template #unit="{ row }">
{{ PERFORMANCE_UNIT.O[row.unit] }}
</template>
2025-10-30 19:30:06 +08:00
<template #operate="{ row }">
<el-button type="danger" link @click="delPerformance(row)">删除</el-button>
</template>
</BaseTable>
2026-02-02 10:30:24 +08:00
<addTaskPerformance
v-if="performanceVisible"
:tableName="'TASK_RUN_PERFORMANCE'"
@cancel="performanceVisible = false"
@submit="addPerformanceFun"
>
</addTaskPerformance>
<editPerformancePage
v-if="editPerformanceVisible"
@cancel="editPerformanceVisible = false"
:performance-info="currentPerformance"
@submit="updatePerformanceFun"
></editPerformancePage>
</div>
2026-02-03 19:56:33 +08:00
<div class="task-performance-page" v-else>
2026-02-02 10:30:24 +08:00
<div class="table-box">
<BaseTable
tableName="TASK_RUN_PERFORMANCE"
ref="baseTableRef"
:data="performanceData"
2026-02-02 10:30:24 +08:00
:export-file-name="'指标列表'"
:export-api="exportPerformanceApi"
showCheckbox
hidePagination
:actionList="showLeftOptions ? actionList : []"
:export-params="excelParams"
:full-height="fullHeight"
:show-setting="false"
>
<template v-if="showLeftOptions" #leftOptions>
<div class="operate-box">
<el-button type="primary" @click="ArchiveRunDataFun">归档</el-button>
<el-button type="primary" @click="openAddPerformanceWindFun">新增</el-button>
<el-button type="danger" @click="deleteFun">删除</el-button>
</div>
2026-02-02 10:30:24 +08:00
</template>
<template #completeStatus="{ row }">
<StatusDot
:status="getTaskAchieveStyleClass(row.completeStatus || '0')"
:title="RESULT_ACHIEVE_STATUS.O[row.completeStatus || '0']"
/>
</template>
<template #unit="{ row }">
{{ PERFORMANCE_UNIT.O[row.unit] }}
</template>
<template #operate="{ row }">
<el-button type="danger" link @click="delPerformance(row)">删除</el-button>
</template>
</BaseTable>
</div>
<!-- <div class="operate-box">
<el-button type="primary" @click="ArchiveRunDataFun">归档</el-button>
2026-02-02 10:30:24 +08:00
<el-button type="primary" @click="openAddPerformanceWindFun">新增</el-button>
<el-button type="danger" @click="deleteFun">删除</el-button>
</div> -->
2026-02-02 10:30:24 +08:00
2025-10-30 19:30:06 +08:00
<addTaskPerformance
v-if="performanceVisible"
:tableName="'TASK_RUN_PERFORMANCE'"
2025-10-30 19:30:06 +08:00
@cancel="performanceVisible = false"
2025-11-26 18:49:29 +08:00
@submit="addPerformanceFun"
2025-10-30 19:30:06 +08:00
>
</addTaskPerformance>
2025-12-08 14:54:38 +08:00
<editPerformancePage
v-if="editPerformanceVisible"
@cancel="editPerformanceVisible = false"
:performance-info="currentPerformance"
@submit="updatePerformanceFun"
></editPerformancePage>
2025-10-30 19:30:06 +08:00
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
2025-10-30 19:30:06 +08:00
import BaseTable from '@/components/common/table/baseTable.vue';
import { ElMessage } from 'element-plus';
import {
getTaskPerformanceApi,
batchAddTaskPerformanceApi,
batchDeleteTaskPerformanceApi,
getRunPerformanceApi,
} from '@/api/task/taskpool';
import addTaskPerformance from './addTaskPerformance.vue';
2025-12-08 14:54:38 +08:00
import { editPerformanceApi, exportPerformanceApi } from '@/api/task/taskPerformance';
import { getFormConfigureApi } from '@/api/system/systemData';
2025-12-08 14:54:38 +08:00
import editPerformancePage from './editPerformancePage.vue';
import { getTaskAchieveStyleClass } from '../common/statusDot/statusMap';
import { useDict } from '@/utils/useDict';
import StatusDot from '@/components/common/statusDot/index.vue';
import { syncKeyResultToTaskApi } from '@/api/project/run';
2025-10-30 19:30:06 +08:00
const props = defineProps({
taskId: {
2025-11-28 11:25:35 +08:00
type: String,
default: '',
2025-10-30 19:30:06 +08:00
},
runInfo: {
type: Object,
default: () => {},
},
taskInfo: {
type: Object,
default: () => {},
},
showSaveButton: {
type: Boolean,
default: false,
},
paramType: {
type: String,
default: 'task',
},
fullHeight: {
type: Boolean,
default: false,
},
showLeftOptions: {
type: Boolean,
default: true,
},
2026-02-02 10:30:24 +08:00
showSetting: {
type: Boolean,
default: true,
},
2025-10-30 19:30:06 +08:00
});
2026-01-09 15:58:28 +08:00
2025-10-30 19:30:06 +08:00
const baseTableRef = ref();
const performanceVisible = ref(false);
2025-12-08 14:54:38 +08:00
const editPerformanceVisible = ref(false);
2025-10-30 19:30:06 +08:00
const performanceData = ref<any>([]);
2025-11-26 18:49:29 +08:00
const getTaskPerformanceDataFun = async () => {
const res: any =
props.paramType === 'task'
? await getTaskPerformanceApi({ taskId: props.taskInfo?.uuid })
: await getRunPerformanceApi({ runId: props.runInfo?.uuid });
2025-10-30 19:30:06 +08:00
if (res && res.code === 200) {
performanceData.value = res.data.map((item: any) => {
const completeStatus = getPerformanceSTatus(item) || 0;
return {
...item,
completeStatus,
};
});
2025-10-30 19:30:06 +08:00
}
};
2026-01-09 15:58:28 +08:00
const { RESULT_ACHIEVE_STATUS, PERFORMANCE_UNIT } = useDict(
'RESULT_ACHIEVE_STATUS',
'PERFORMANCE_UNIT'
);
2025-11-26 18:49:29 +08:00
const openAddPerformanceWindFun = () => {
2025-10-30 19:30:06 +08:00
performanceVisible.value = true;
};
2025-11-26 18:49:29 +08:00
const addPerformanceFun = async (data: any) => {
2025-10-30 19:30:06 +08:00
data.flag = 'add';
2026-01-19 20:28:01 +08:00
// const { fullData } = baseTableRef.value.tableRef.getTableData();
2025-10-30 19:30:06 +08:00
2026-01-19 20:28:01 +08:00
// const existPerformance =
// fullData.find((item: any) => {
// return item.nodeName === data.nodeName;
// }) || null;
2025-10-30 19:30:06 +08:00
2026-01-19 20:28:01 +08:00
// if (existPerformance) {
// ElMessage.warning('已存在该指标,无法新增!');
// } else {
// baseTableRef.value.tableRef.insertAt(data, -1);
// }
const list = [data];
2025-10-30 19:30:06 +08:00
performanceVisible.value = false;
2026-01-19 20:28:01 +08:00
await batchAddTaskPerformanceFun(list);
2025-10-30 19:30:06 +08:00
};
const deletePerformanceList = ref<any>([]);
const delPerformance = (row: any) => {
baseTableRef.value.tableRef.remove(row);
if (row.flag != 'add') {
deletePerformanceList.value.push(row);
2026-01-19 20:28:01 +08:00
batchDeleteTaskPerformanceFun([row.id]);
2025-10-30 19:30:06 +08:00
}
};
2026-01-19 20:28:01 +08:00
const batchAddTaskPerformanceFun = async (list: any) => {
// const list = baseTableRef.value.tableRef.getInsertRecords();
2025-10-30 19:30:06 +08:00
const performanceList: any = [];
for (let i = 0; i < list.length; i++) {
const obj: any = {
2025-10-30 19:30:06 +08:00
uuid: '',
nodeId: '',
performanceName: list[i].performanceName,
nodeName: list[i].nodeName,
englishName: list[i].englishName,
nodeCode: list[i].nodeCode,
poolName: list[i].poolName,
performanceType: list[i].performanceType,
unit: list[i].unit,
targetValue: list[i].targetValue,
resultValue: list[i].resultValue,
2025-10-30 19:30:06 +08:00
lowValue: list[i].lowValue,
highValue: list[i].highValue,
method: list[i].method,
description: list[i].description,
taskName: list[i].taskName,
standard: list[i].standard,
tenantId: list[i].tenantId,
createTime: list[i].createTime,
pid: 0,
};
if (props.paramType === 'task') {
obj.taskId = props.taskInfo?.uuid;
}
if (props.paramType === 'run') {
obj.runId = props.runInfo.uuid;
obj.taskId = props.runInfo.taskId;
}
2025-10-30 19:30:06 +08:00
performanceList.push(obj);
}
2025-10-30 19:30:06 +08:00
if (!list.length) {
return;
}
const param: any = {
2025-10-30 19:30:06 +08:00
performanceList: performanceList,
};
if (props.paramType === 'task') {
param.taskId = props.taskInfo?.uuid;
}
if (props.paramType === 'run') {
param.taskId = props.runInfo.taskId;
param.runId = props.runInfo.uuid;
}
const res: any = await batchAddTaskPerformanceApi(param);
2025-10-30 19:30:06 +08:00
if (res && res.code === 200) {
2026-01-19 20:28:01 +08:00
ElMessage.success('新增成功!');
2026-01-23 16:21:31 +08:00
await getTaskPerformanceDataFun();
2025-10-30 19:30:06 +08:00
} else {
}
};
2026-01-19 20:28:01 +08:00
const batchDeleteTaskPerformanceFun = async (ids: any) => {
// const ids = deletePerformanceList.value.map((item: any) => {
// return item.id;
// });
2025-10-30 19:30:06 +08:00
if (!ids.length) {
return;
}
const res: any = await batchDeleteTaskPerformanceApi(ids);
if (res && res.code === 200) {
2026-01-19 20:28:01 +08:00
ElMessage.success('删除成功!');
baseTableRef.value.resetFun();
2025-10-30 19:30:06 +08:00
} else {
}
};
2026-01-19 20:28:01 +08:00
const saveFun = async () => {};
2025-10-30 19:30:06 +08:00
const excelHeaders = ref<any>({});
const excelParams = ref<any>({});
const getFormConfigureFun = async () => {
2025-12-08 14:54:38 +08:00
const res: any = await getFormConfigureApi({
formName: 'PERFORMANCE_POOL',
2025-10-30 19:30:06 +08:00
});
if (res && res.code === 200) {
2025-12-08 14:54:38 +08:00
const cloumn: any = JSON.parse(res.data.formConfig) || [];
excelHeaders.value = cloumn.map((item: any) => {
return {
key: item.key,
title: item.title,
};
});
if (props.paramType === 'run') {
excelParams.value = {
runId: props.runInfo.uuid,
};
} else {
excelParams.value = {
2026-01-15 17:34:59 +08:00
taskId: props.taskInfo.uuid,
};
}
}
2025-10-30 19:30:06 +08:00
};
const getPerformanceSTatus = (row: any) => {
let status: any = 0;
// 当指标值,达标方式,目标值有一个不存在时,返回状态未分析
if (!row?.method || !row?.highValue || !row?.targetValue) {
return status;
}
if (row?.method && row?.resultValue && row?.targetValue) {
const highValue = Number(row?.targetValue);
const targetValue = Number(row?.resultValue);
2026-01-04 15:00:34 +08:00
const lowValue = Number(row?.lowValue);
// 小于等于
if (row.method === '≤') {
2026-01-04 15:00:34 +08:00
if (targetValue <= highValue) {
status = 2;
} else {
status = 1;
}
}
2026-01-04 15:00:34 +08:00
// 小于
if (row.method === '<') {
2026-01-04 15:00:34 +08:00
if (targetValue < highValue) {
status = 2;
} else {
status = 1;
}
}
// 大于
if (row.method === '>') {
2026-01-04 15:00:34 +08:00
if (targetValue > highValue) {
status = 2;
} else {
status = 1;
}
}
// 大于等于
if (row.method === '≥') {
2026-01-04 15:00:34 +08:00
if (targetValue >= highValue) {
status = 2;
} else {
status = 1;
}
}
// 包含
if (row.method === '[]') {
2026-01-04 15:00:34 +08:00
if (targetValue <= highValue && targetValue >= lowValue) {
status = 2;
} else {
status = 1;
}
}
}
return status;
};
2026-02-02 10:30:24 +08:00
const deleteFun = async () => {
const checkData: any = baseTableRef.value.tableRef.getCheckboxRecords();
if (checkData.length) {
for (let i = 0; i < checkData.length; i++) {
delPerformance(checkData[i]);
}
} else {
ElMessage.warning('请选择数值结果后删除');
}
};
2025-10-30 19:30:06 +08:00
defineExpose({
2025-11-26 18:49:29 +08:00
saveFun,
baseTableRef,
2025-10-30 19:30:06 +08:00
});
const actionList = ref([
2025-12-08 14:54:38 +08:00
{
title: '编辑',
type: 'primary',
click: (row: any) => {
editPerformanceFun(row);
},
},
{
title: '删除',
type: 'danger',
needConfirm: true,
confirmTip: '确认删除吗?',
click: (row: any) => {
delPerformance(row);
},
},
]);
2025-12-08 14:54:38 +08:00
const currentPerformance = ref<any>({});
const editPerformanceFun = (row: any) => {
currentPerformance.value = row;
editPerformanceVisible.value = true;
};
const updatePerformanceFun = async (data: any) => {
editPerformanceVisible.value = false;
const res: any = await editPerformanceApi(data);
if (res && res.code === 200) {
ElMessage.success('操作成功');
await getTaskPerformanceDataFun();
2025-12-08 14:54:38 +08:00
}
};
// 归档
const ArchiveRunDataFun = async () => {
const param = {
runId: props.runInfo.uuid,
};
try {
const res: any = await syncKeyResultToTaskApi(param);
if (res && res.code === 200) {
ElMessage.success('归档成功');
} else {
ElMessage.warning('归档未成功');
}
} catch (error) {
console.error(error);
}
};
2025-10-30 19:30:06 +08:00
onMounted(async () => {
2025-11-26 18:49:29 +08:00
await getTaskPerformanceDataFun();
await getFormConfigureFun();
2025-10-30 19:30:06 +08:00
});
</script>
<style lang="scss" scoped>
.task-performance-page {
width: 100%;
height: 100%;
2026-02-02 10:30:24 +08:00
.table-box {
width: 100%;
// height: calc(100% - 50px);
height: 100%;
2026-02-02 10:30:24 +08:00
}
2025-10-30 19:30:06 +08:00
.operate-box {
width: 100%;
2026-02-02 10:30:24 +08:00
height: 50px;
2025-10-30 19:30:06 +08:00
display: flex;
align-items: center;
2026-02-02 10:30:24 +08:00
justify-content: flex-end;
2025-10-30 19:30:06 +08:00
}
.mr12 {
margin-right: 12px;
}
}
</style>