update 统计分析代码优化 状态不再使用枚举使用字典

This commit is contained in:
2026-03-27 14:40:56 +08:00
parent 77bd02ab57
commit a253c0ace4
2 changed files with 131 additions and 267 deletions

View File

@@ -46,6 +46,22 @@ export const getTaskStatusColorList = (statusList: string[]): string[] => {
return statusList.map((status) => getTaskStatusColor(status)); return statusList.map((status) => getTaskStatusColor(status));
}; };
/** 任务状态颜色映射 */
export const ACHIEVE_STATUS_COLOR_MAP = {
/** 未分析 */
'0': 'rgb(200, 201, 204)',
/** 合格 */
'2': getThemeColor('--el-color-success'),
/** 不合格 */
'1': getThemeColor('--el-color-danger'),
} as const;
export const getAchieveColor = (status: string): string => {
return ACHIEVE_STATUS_COLOR_MAP[status as keyof typeof ACHIEVE_STATUS_COLOR_MAP] || '#909399';
};
export const getAchieveColorList = (statusList: string[]): string[] => {
return statusList.map((status) => getAchieveColor(status));
};
export enum TASK_APPROVE_STATUS_ENUM { export enum TASK_APPROVE_STATUS_ENUM {
/** /**
* 未审核 * 未审核

View File

@@ -105,23 +105,13 @@ import {
getUserTaskCompleteStatisticsApi, getUserTaskCompleteStatisticsApi,
} from '@/api/project/task'; } from '@/api/project/task';
import { useDict } from '@/utils/useDict'; import { useDict } from '@/utils/useDict';
import { TASK_CALCULATE_STATUS_OPTIONS } from '@/utils/enum/task'; import { getTaskStatusColorList, getAchieveColorList } from '@/utils/enum/task';
import { getThemeColor } from '@/utils/theme';
import { getTaskStatusColorList } from '@/utils/enum/task';
const { TASK_ACHIEVE_STATUS, DIFFICULTY_COEFFICIENT, RESULT_ACHIEVE_STATUS } = useDict( const { TASK_ACHIEVE_STATUS, DIFFICULTY_COEFFICIENT, RESULT_ACHIEVE_STATUS } = useDict(
'TASK_ACHIEVE_STATUS', 'TASK_ACHIEVE_STATUS',
'DIFFICULTY_COEFFICIENT', 'DIFFICULTY_COEFFICIENT',
'RESULT_ACHIEVE_STATUS' 'RESULT_ACHIEVE_STATUS'
); );
const taskCalculateStatusLegendData = TASK_CALCULATE_STATUS_OPTIONS.map((item) => ({
name: item.label,
}));
const taskExeStatusLegendData = TASK_ACHIEVE_STATUS.value.A.map((item: any) => {
return {
name: item.label,
};
});
interface Props { interface Props {
projectUuid: string; projectUuid: string;
@@ -138,18 +128,23 @@ watchEffect(() => {
} }
}); });
const statusColorList = getTaskStatusColorList(Object.keys(TASK_ACHIEVE_STATUS.value.O)); // 未开始|进行中|已驳回|已完成... 颜色和图例
// 完成情况颜色列表:未分析、不合格、合格 const statusColorList = getTaskStatusColorList(
const completionStatusColorList = [ TASK_ACHIEVE_STATUS.value.A.map((v: any) => v.value)
'rgb(200, 201, 204)', );
getThemeColor('--el-color-danger'), const achieveLegendData = RESULT_ACHIEVE_STATUS.value.A.map((item: any) => ({
getThemeColor('--el-color-success'), name: item.label,
]; }));
const performanceColorList = [ // 未分析|不合格|合格 颜色和图例
'rgb(200, 201, 204)', // 未分析 const completionStatusColorList = getAchieveColorList(
getThemeColor('--el-color-danger'), // 不合格 RESULT_ACHIEVE_STATUS.value.A.map((v: any) => v.value)
getThemeColor('--el-color-success'), // 合格 );
]; const performanceColorList = getAchieveColorList(
RESULT_ACHIEVE_STATUS.value.A.map((v: any) => v.value)
);
const taskExeStatusLegendData = TASK_ACHIEVE_STATUS.value.A.map((item: any) => {
return { name: item.label };
});
const difficultyCountColorList = [ const difficultyCountColorList = [
'#67c23a', '#67c23a',
'rgb(179, 225, 157)', 'rgb(179, 225, 157)',
@@ -169,7 +164,7 @@ const sortObjectArray = (arr: any, key: any) => {
const userTaskCompleteOption = ref(); const userTaskCompleteOption = ref();
const getUserTaskCompleteStatistics = async () => { const getUserTaskCompleteStatistics = async () => {
const xData: any = []; const xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getUserTaskCompleteStatisticsApi({ const res: any = await getUserTaskCompleteStatisticsApi({
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
}); });
@@ -177,28 +172,20 @@ const getUserTaskCompleteStatistics = async () => {
res.data.result.forEach((item: any) => { res.data.result.forEach((item: any) => {
xData.push(item.userName); xData.push(item.userName);
}); });
for (let i = 0; i < TASK_ACHIEVE_STATUS.value.A.length; i++) { seriesData = TASK_ACHIEVE_STATUS.value.A.map((item: any) => ({
const item = TASK_ACHIEVE_STATUS.value.A[i]; name: item.label,
const obj: any = { stack: 'total',
name: item.label, emphasis: {
stack: 'total', focus: 'series',
emphasis: { },
focus: 'series', data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
label: {
show: true,
formatter: function (params: { value: any }) {
return params.value === 0 ? '' : params.value;
}, },
data: [], },
label: { }));
show: true,
formatter: function (params: { value: any }) {
// 当值为0时返回空字符串
return params.value === 0 ? '' : params.value;
},
},
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
return { return {
xData, xData,
@@ -209,18 +196,10 @@ const queryUserTaskCompletion = async () => {
const { xData, seriesData } = await getUserTaskCompleteStatistics(); const { xData, seriesData } = await getUserTaskCompleteStatistics();
const option = { const option = {
color: statusColorList, color: statusColorList,
legend: { legend: { data: taskExeStatusLegendData },
data: taskExeStatusLegendData, grid: { bottom: xData.length > 5 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 5 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 5, dataZoom: xData.length > 5,
series: seriesData, series: seriesData,
}; };
@@ -236,7 +215,7 @@ const userDifficultyCoefficientOption = ref();
const queryUserDifficultStatistics = async () => { const queryUserDifficultStatistics = async () => {
let xData: any = []; let xData: any = [];
let titles: any = []; let titles: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getUserDifficultyStatisticsApi({ const res: any = await getUserDifficultyStatisticsApi({
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
}); });
@@ -245,37 +224,25 @@ const queryUserDifficultStatistics = async () => {
return item.userName; return item.userName;
}); });
titles = res.data.alldifficultyValue; titles = res.data.alldifficultyValue;
for (let i = 0; i < titles.length; i++) { seriesData = titles.map((title: any) => {
const str = titles[i].toFixed(1); const str = title.toFixed(1);
const obj: any = { return {
name: getDifficultyLevel(Number(str)) + str, name: getDifficultyLevel(Number(str)) + str,
coefficient: Number(str), coefficient: Number(str),
type: 'bar', type: 'bar',
emphasis: { emphasis: {
focus: 'series', focus: 'series',
}, },
data: [], data: res.data.result.map((result: any) => result?.difficultyCount[str]),
}; };
for (let j = 0; j < res.data.result.length; j++) { });
obj.data.push(res.data.result[j]?.difficultyCount[str]);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: difficultyCountColorList, color: difficultyCountColorList,
legend: { legend: { data: titles },
data: titles, grid: { bottom: xData.length > 5 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 5 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 5, dataZoom: xData.length > 5,
series: sortObjectArray(seriesData, 'coefficient'), series: sortObjectArray(seriesData, 'coefficient'),
}; };
@@ -286,7 +253,7 @@ const queryUserDifficultStatistics = async () => {
const taskCompletionAtWorkstations = ref(); const taskCompletionAtWorkstations = ref();
const queryTaskCompletionByWorkspace = async () => { const queryTaskCompletionByWorkspace = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getTaskCompleteStatisticsApi({ const res: any = await getTaskCompleteStatisticsApi({
resultTagType: 'tag4', resultTagType: 'tag4',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
@@ -295,38 +262,19 @@ const queryTaskCompletionByWorkspace = async () => {
xData = res.data.result.map((item: any) => { xData = res.data.result.map((item: any) => {
return item.name; return item.name;
}); });
for (let i = 0; i < TASK_ACHIEVE_STATUS.value.A.length; i++) { seriesData = TASK_ACHIEVE_STATUS.value.A.map((item: any) => ({
const item = TASK_ACHIEVE_STATUS.value.A[i]; name: item.label,
const obj: any = { type: 'bar',
name: item.label, emphasis: { focus: 'series' },
type: 'bar', data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
emphasis: { }));
focus: 'series',
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: statusColorList, color: statusColorList,
legend: { legend: { data: taskExeStatusLegendData },
data: taskExeStatusLegendData, grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -338,7 +286,7 @@ const queryTaskCompletionByWorkspace = async () => {
const taskCompletionAtDisciplineOption = ref(); const taskCompletionAtDisciplineOption = ref();
const queryTaskCompletionByDiscipline = async () => { const queryTaskCompletionByDiscipline = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getTaskCompleteStatisticsApi({ const res: any = await getTaskCompleteStatisticsApi({
resultTagType: 'tag6', resultTagType: 'tag6',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
@@ -347,38 +295,19 @@ const queryTaskCompletionByDiscipline = async () => {
xData = res.data.result.map((item: any) => { xData = res.data.result.map((item: any) => {
return item.name; return item.name;
}); });
for (let i = 0; i < TASK_ACHIEVE_STATUS.value.A.length; i++) { seriesData = TASK_ACHIEVE_STATUS.value.A.map((item: any) => ({
const item = TASK_ACHIEVE_STATUS.value.A[i]; name: item.label,
const obj: any = { type: 'bar',
name: item.label, emphasis: { focus: 'series' },
type: 'bar', data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
emphasis: { }));
focus: 'series',
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: statusColorList, color: statusColorList,
legend: { legend: { data: taskExeStatusLegendData },
data: taskExeStatusLegendData, grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -390,47 +319,27 @@ const queryTaskCompletionByDiscipline = async () => {
const taskAchieveAtWorkstations = ref(); const taskAchieveAtWorkstations = ref();
const queryTaskQualityByWorkspace = async () => { const queryTaskQualityByWorkspace = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getTaskAchieveStatisticsApi({ const res: any = await getTaskAchieveStatisticsApi({
resultTagType: 'tag4', resultTagType: 'tag4',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
}); });
if (res && res.code === 200) { if (res && res.code === 200) {
xData = res.data.result.map((item: any) => { xData = res.data.result.map((item: any) => item.name);
return item.name; const allExeStatus = RESULT_ACHIEVE_STATUS.value.A;
}); seriesData = allExeStatus.map((item: any) => ({
for (let i = 0; i < TASK_CALCULATE_STATUS_OPTIONS.length; i++) { name: item.label,
const item = TASK_CALCULATE_STATUS_OPTIONS[i]; type: 'bar',
const obj: any = { emphasis: { focus: 'series' },
name: item.label, data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
type: 'bar', }));
emphasis: {
focus: 'series',
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: completionStatusColorList, color: completionStatusColorList,
legend: { legend: { data: achieveLegendData },
data: taskCalculateStatusLegendData, grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -441,7 +350,7 @@ const queryTaskQualityByWorkspace = async () => {
const performanceCompletionAtWorkstationsOption = ref(); const performanceCompletionAtWorkstationsOption = ref();
const queryPerfCompletionByWorkspace = async () => { const queryPerfCompletionByWorkspace = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getPerformanceCompleteStatisticsApi({ const res: any = await getPerformanceCompleteStatisticsApi({
resultTagType: 'tag4', resultTagType: 'tag4',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
@@ -451,36 +360,19 @@ const queryPerfCompletionByWorkspace = async () => {
return item.name; return item.name;
}); });
const allExeStatus = RESULT_ACHIEVE_STATUS.value.A; const allExeStatus = RESULT_ACHIEVE_STATUS.value.A;
for (let i = 0; i < allExeStatus.length; i++) { seriesData = allExeStatus.map((item: any) => ({
const item = allExeStatus[i]; name: item.label,
const obj: any = { type: 'bar',
name: item.label, emphasis: { focus: 'series' },
type: 'bar', data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
emphasis: { }));
focus: 'series',
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: performanceColorList, color: performanceColorList,
legend: { legend: { data: achieveLegendData },
data: Object.values(RESULT_ACHIEVE_STATUS.value.O), grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -491,7 +383,7 @@ const queryPerfCompletionByWorkspace = async () => {
const taskAchieveAtDisciplineOption = ref(); const taskAchieveAtDisciplineOption = ref();
const queryTaskQualityByDiscipline = async () => { const queryTaskQualityByDiscipline = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getTaskAchieveStatisticsApi({ const res: any = await getTaskAchieveStatisticsApi({
resultTagType: 'tag6', resultTagType: 'tag6',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
@@ -500,38 +392,20 @@ const queryTaskQualityByDiscipline = async () => {
xData = res.data.result.map((item: any) => { xData = res.data.result.map((item: any) => {
return item.name; return item.name;
}); });
for (let i = 0; i < TASK_CALCULATE_STATUS_OPTIONS.length; i++) { const allExeStatus = RESULT_ACHIEVE_STATUS.value.A;
const item = TASK_CALCULATE_STATUS_OPTIONS[i]; seriesData = allExeStatus.map((item: any) => ({
const obj: any = { name: item.label,
name: item.label, type: 'bar',
type: 'bar', emphasis: { focus: 'series' },
emphasis: { data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
focus: 'series', }));
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: completionStatusColorList, color: completionStatusColorList,
legend: { legend: { data: achieveLegendData },
data: taskCalculateStatusLegendData, grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -542,7 +416,7 @@ const queryTaskQualityByDiscipline = async () => {
const performanceCompletionAtDisciplineOption = ref(); const performanceCompletionAtDisciplineOption = ref();
const queryPerfCompletionByDiscipline = async () => { const queryPerfCompletionByDiscipline = async () => {
let xData: any = []; let xData: any = [];
const seriesData: any = []; let seriesData: any = [];
const res: any = await getPerformanceCompleteStatisticsApi({ const res: any = await getPerformanceCompleteStatisticsApi({
resultTagType: 'tag6', resultTagType: 'tag6',
tag1: currentProjectUuid.value, tag1: currentProjectUuid.value,
@@ -552,36 +426,19 @@ const queryPerfCompletionByDiscipline = async () => {
return item.name; return item.name;
}); });
const allExeStatus = RESULT_ACHIEVE_STATUS.value.A; const allExeStatus = RESULT_ACHIEVE_STATUS.value.A;
for (let i = 0; i < allExeStatus.length; i++) { seriesData = allExeStatus.map((item: any) => ({
const item = allExeStatus[i]; name: item.label,
const obj: any = { type: 'bar',
name: item.label, emphasis: { focus: 'series' },
type: 'bar', data: res.data.result.map((result: any) => result?.statusCount[item.value] || 0),
emphasis: { }));
focus: 'series',
},
data: [],
};
for (let j = 0; j < res.data.result.length; j++) {
obj.data.push(res.data.result[j]?.statusCount[item.value] || 0);
}
seriesData.push(obj);
}
} }
const option = { const option = {
color: performanceColorList, color: performanceColorList,
legend: { legend: { data: achieveLegendData },
data: Object.values(RESULT_ACHIEVE_STATUS.value.O), grid: { bottom: xData.length > 4 ? '50' : '10' },
}, xAxis: { data: xData },
grid: { yAxis: { minInterval: 1 },
bottom: xData.length > 4 ? '50' : '10',
},
xAxis: {
data: xData,
},
yAxis: {
minInterval: 1,
},
dataZoom: xData.length > 4, dataZoom: xData.length > 4,
series: seriesData, series: seriesData,
}; };
@@ -618,7 +475,6 @@ onMounted(async () => {});
<style lang="scss" scoped> <style lang="scss" scoped>
.gl-page-content-grey-full { .gl-page-content-grey-full {
overflow: auto; overflow: auto;
.content { .content {
height: 100%; height: 100%;
display: flex; display: flex;
@@ -626,39 +482,31 @@ onMounted(async () => {});
flex-wrap: wrap; flex-wrap: wrap;
gap: 12px; gap: 12px;
overflow: auto; overflow: auto;
.margin-style { .margin-style {
width: 100% !important; width: 100% !important;
} }
.chart-box { .chart-box {
width: calc(50% - 8px); width: calc(50% - 8px);
height: 400px; height: 400px;
position: relative; position: relative;
.el-form { .el-form {
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
.el-form-item { .el-form-item {
margin-bottom: 0 !important; margin-bottom: 0 !important;
margin-right: 0 !important; margin-right: 0 !important;
.el-select { .el-select {
width: 215px; width: 215px;
} }
.select-width { .select-width {
width: 90px !important; width: 90px !important;
} }
.margin-right-12 { .margin-right-12 {
margin-right: 12px; margin-right: 12px;
} }
} }
} }
.chart-item { .chart-item {
width: 100%; width: 100%;
height: 100%; height: 100%;