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>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref, provide } from 'vue';
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { getThemeColor } from '@/utils/theme';
|
||||
// 引入子组件
|
||||
import fileOperateChart from './dataStatistics/fileOperateChart.vue';
|
||||
@@ -44,9 +44,12 @@ import {
|
||||
getUserFormConfigureApi,
|
||||
updateUserFormConfigureApi,
|
||||
} from '@/api/system/systemData';
|
||||
import { queryNodeListApi } from '@/api/project/node';
|
||||
import { getTaskStatusColorList } from '@/utils/enum/task';
|
||||
import { useDict } from '@/utils/useDict';
|
||||
import { useProjectList } from '@/utils/useProjectList';
|
||||
|
||||
// 统一请求项目列表
|
||||
useProjectList();
|
||||
|
||||
const { TASK_ACHIEVE_STATUS } = useDict('TASK_ACHIEVE_STATUS');
|
||||
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(() => {
|
||||
getFormConfigure();
|
||||
getProjectListFun();
|
||||
// 注入i项目列表,不在子组件中获取
|
||||
provide('projectProvide', true);
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
:nodata="achieveBarOption?.xAxis.data.length === 0"
|
||||
:option="achieveBarOption"
|
||||
:showChangeModel="true"
|
||||
:filterItems="['projectName', 'projectCode', 'discipline']"
|
||||
:filterItems="['projectName', 'projectCode', 'discipline', 'workspace']"
|
||||
@update="achieveBarChartUpdate"
|
||||
>
|
||||
</commonFilterChart>
|
||||
@@ -46,7 +46,7 @@
|
||||
:bar-type="'pieChart'"
|
||||
:nodata="achievePieChartNodata"
|
||||
:option="achievePieOption"
|
||||
:filterItems="['projectName', 'projectCode', 'discipline']"
|
||||
:filterItems="['projectName', 'projectCode', 'discipline', 'workspace']"
|
||||
@update="achievePieChartUpdate"
|
||||
>
|
||||
</commonFilterChart>
|
||||
@@ -57,13 +57,17 @@
|
||||
|
||||
<script lang="ts" setup>
|
||||
import commonFilterChart from '@/components/common/echartCard/commonFilterChart.vue';
|
||||
import { ref, provide } from 'vue';
|
||||
import { ref } from 'vue';
|
||||
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 { useDict } from '@/utils/useDict';
|
||||
import { getTaskStatusColorList } 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(
|
||||
'TASK_ACHIEVE_STATUS',
|
||||
@@ -167,7 +171,8 @@ const achieveBarChartUpdate = async (data: any) => {
|
||||
const res: any = await getTaskAchieveStatisticsApi({
|
||||
resultTagType: 'tag6',
|
||||
tag1: data.tag1,
|
||||
discipline: data.discipline,
|
||||
tag5: data.workspace,
|
||||
tag6: data.discipline,
|
||||
});
|
||||
if (res && res.code === 200) {
|
||||
const xData = res.data.result.map((item: any) => {
|
||||
@@ -201,7 +206,8 @@ const achievePieChartUpdate = async (data: any) => {
|
||||
const res: any = await getTaskAchieveStatisticsApi({
|
||||
resultTagType: 'tag6',
|
||||
tag1: data.tag1,
|
||||
discipline: data.discipline,
|
||||
tag5: data.workspace,
|
||||
tag6: data.discipline,
|
||||
});
|
||||
if (res.code === 200) {
|
||||
achievePieChartNodata.value = res.data.allAchieveStatus.length === 0;
|
||||
@@ -306,23 +312,6 @@ const getPieOptions = (statusColorList: any, seriesData: any) => {
|
||||
};
|
||||
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>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user