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));
};
/** 任务状态颜色映射 */
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 {
/**
* 未审核

View File

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