update 代码优化
This commit is contained in:
40
src/utils/useProjectList.ts
Normal file
40
src/utils/useProjectList.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
// 在总页面统一请求项目列表,provide给子组件使用,避免重复请求,用于echarts图表
|
||||||
|
import { ref, provide } from 'vue';
|
||||||
|
import { queryNodeListApi } from '@/api/project/node';
|
||||||
|
|
||||||
|
export function useProjectList() {
|
||||||
|
const projectListRes = ref(null);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const getProjectList = async () => {
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const params = {
|
||||||
|
nodeType: 'project',
|
||||||
|
current: 1,
|
||||||
|
size: 9999,
|
||||||
|
};
|
||||||
|
const res = await queryNodeListApi(params);
|
||||||
|
if (res.code === 200) {
|
||||||
|
projectListRes.value = res;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取项目列表失败:', error);
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 自动调用获取项目列表
|
||||||
|
getProjectList();
|
||||||
|
|
||||||
|
// 自动提供数据给子组件
|
||||||
|
provide('projectProvide', true);
|
||||||
|
provide('projectListRes', projectListRes);
|
||||||
|
|
||||||
|
return {
|
||||||
|
projectListRes,
|
||||||
|
loading,
|
||||||
|
getProjectList,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref, provide } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { getThemeColor } from '@/utils/theme';
|
import { getThemeColor } from '@/utils/theme';
|
||||||
// 引入子组件
|
// 引入子组件
|
||||||
import fileOperateChart from './dataStatistics/fileOperateChart.vue';
|
import fileOperateChart from './dataStatistics/fileOperateChart.vue';
|
||||||
@@ -44,9 +44,12 @@ import {
|
|||||||
getUserFormConfigureApi,
|
getUserFormConfigureApi,
|
||||||
updateUserFormConfigureApi,
|
updateUserFormConfigureApi,
|
||||||
} from '@/api/system/systemData';
|
} from '@/api/system/systemData';
|
||||||
import { queryNodeListApi } from '@/api/project/node';
|
|
||||||
import { getTaskStatusColorList } from '@/utils/enum/task';
|
import { getTaskStatusColorList } from '@/utils/enum/task';
|
||||||
import { useDict } from '@/utils/useDict';
|
import { useDict } from '@/utils/useDict';
|
||||||
|
import { useProjectList } from '@/utils/useProjectList';
|
||||||
|
|
||||||
|
// 统一请求项目列表
|
||||||
|
useProjectList();
|
||||||
|
|
||||||
const { TASK_ACHIEVE_STATUS } = useDict('TASK_ACHIEVE_STATUS');
|
const { TASK_ACHIEVE_STATUS } = useDict('TASK_ACHIEVE_STATUS');
|
||||||
const statusColorList = getTaskStatusColorList(Object.keys(TASK_ACHIEVE_STATUS.value.O));
|
const statusColorList = getTaskStatusColorList(Object.keys(TASK_ACHIEVE_STATUS.value.O));
|
||||||
@@ -226,26 +229,8 @@ const getFormConfigure = async () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const projectListRes = ref(null);
|
|
||||||
const getProjectListFun = async () => {
|
|
||||||
const params = {
|
|
||||||
nodeType: 'project',
|
|
||||||
current: 1,
|
|
||||||
size: 9999,
|
|
||||||
};
|
|
||||||
queryNodeListApi(params).then((res: any) => {
|
|
||||||
if (res.code === 200) {
|
|
||||||
projectListRes.value = res;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
provide('projectListRes', projectListRes);
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getFormConfigure();
|
getFormConfigure();
|
||||||
getProjectListFun();
|
|
||||||
// 注入i项目列表,不在子组件中获取
|
|
||||||
provide('projectProvide', true);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@
|
|||||||
:nodata="achieveBarOption?.xAxis.data.length === 0"
|
:nodata="achieveBarOption?.xAxis.data.length === 0"
|
||||||
:option="achieveBarOption"
|
:option="achieveBarOption"
|
||||||
:showChangeModel="true"
|
:showChangeModel="true"
|
||||||
:filterItems="['projectName', 'projectCode', 'discipline']"
|
:filterItems="['projectName', 'projectCode', 'discipline', 'workspace']"
|
||||||
@update="achieveBarChartUpdate"
|
@update="achieveBarChartUpdate"
|
||||||
>
|
>
|
||||||
</commonFilterChart>
|
</commonFilterChart>
|
||||||
@@ -46,7 +46,7 @@
|
|||||||
:bar-type="'pieChart'"
|
:bar-type="'pieChart'"
|
||||||
:nodata="achievePieChartNodata"
|
:nodata="achievePieChartNodata"
|
||||||
:option="achievePieOption"
|
:option="achievePieOption"
|
||||||
:filterItems="['projectName', 'projectCode', 'discipline']"
|
:filterItems="['projectName', 'projectCode', 'discipline', 'workspace']"
|
||||||
@update="achievePieChartUpdate"
|
@update="achievePieChartUpdate"
|
||||||
>
|
>
|
||||||
</commonFilterChart>
|
</commonFilterChart>
|
||||||
@@ -57,13 +57,17 @@
|
|||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import commonFilterChart from '@/components/common/echartCard/commonFilterChart.vue';
|
import commonFilterChart from '@/components/common/echartCard/commonFilterChart.vue';
|
||||||
import { ref, provide } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { getThemeColor } from '@/utils/theme';
|
import { getThemeColor } from '@/utils/theme';
|
||||||
import { getTaskCompleteStatisticsByDisciplineApi, queryNodeListApi } from '@/api/project/node';
|
import { getTaskCompleteStatisticsByDisciplineApi } from '@/api/project/node';
|
||||||
import { getTaskAchieveStatisticsApi } from '@/api/project/task';
|
import { getTaskAchieveStatisticsApi } from '@/api/project/task';
|
||||||
import { useDict } from '@/utils/useDict';
|
import { useDict } from '@/utils/useDict';
|
||||||
import { getTaskStatusColorList } from '@/utils/enum/task';
|
import { getTaskStatusColorList } from '@/utils/enum/task';
|
||||||
import { TASK_CALCULATE_STATUS_OPTIONS } from '@/utils/enum/task';
|
import { TASK_CALCULATE_STATUS_OPTIONS } from '@/utils/enum/task';
|
||||||
|
import { useProjectList } from '@/utils/useProjectList';
|
||||||
|
|
||||||
|
// 统一请求项目列表
|
||||||
|
useProjectList();
|
||||||
|
|
||||||
const { TASK_ACHIEVE_STATUS, RESULT_ACHIEVE_STATUS } = useDict(
|
const { TASK_ACHIEVE_STATUS, RESULT_ACHIEVE_STATUS } = useDict(
|
||||||
'TASK_ACHIEVE_STATUS',
|
'TASK_ACHIEVE_STATUS',
|
||||||
@@ -167,7 +171,8 @@ const achieveBarChartUpdate = async (data: any) => {
|
|||||||
const res: any = await getTaskAchieveStatisticsApi({
|
const res: any = await getTaskAchieveStatisticsApi({
|
||||||
resultTagType: 'tag6',
|
resultTagType: 'tag6',
|
||||||
tag1: data.tag1,
|
tag1: data.tag1,
|
||||||
discipline: data.discipline,
|
tag5: data.workspace,
|
||||||
|
tag6: data.discipline,
|
||||||
});
|
});
|
||||||
if (res && res.code === 200) {
|
if (res && res.code === 200) {
|
||||||
const xData = res.data.result.map((item: any) => {
|
const xData = res.data.result.map((item: any) => {
|
||||||
@@ -201,7 +206,8 @@ const achievePieChartUpdate = async (data: any) => {
|
|||||||
const res: any = await getTaskAchieveStatisticsApi({
|
const res: any = await getTaskAchieveStatisticsApi({
|
||||||
resultTagType: 'tag6',
|
resultTagType: 'tag6',
|
||||||
tag1: data.tag1,
|
tag1: data.tag1,
|
||||||
discipline: data.discipline,
|
tag5: data.workspace,
|
||||||
|
tag6: data.discipline,
|
||||||
});
|
});
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
achievePieChartNodata.value = res.data.allAchieveStatus.length === 0;
|
achievePieChartNodata.value = res.data.allAchieveStatus.length === 0;
|
||||||
@@ -306,23 +312,6 @@ const getPieOptions = (statusColorList: any, seriesData: any) => {
|
|||||||
};
|
};
|
||||||
return option;
|
return option;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 统一请求任务列表【以后可以封装公共方法】
|
|
||||||
const projectListRes = ref(null);
|
|
||||||
provide('projectProvide', true);
|
|
||||||
provide('projectListRes', projectListRes);
|
|
||||||
const getProjectListFun = async () => {
|
|
||||||
const params = {
|
|
||||||
nodeType: 'project',
|
|
||||||
current: 1,
|
|
||||||
size: 9999,
|
|
||||||
};
|
|
||||||
const res = await queryNodeListApi(params);
|
|
||||||
if (res.code === 200) {
|
|
||||||
projectListRes.value = res;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
getProjectListFun();
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
Reference in New Issue
Block a user