update 数据统计看板优化--项目列表不在子组件中重复获取

This commit is contained in:
2026-02-02 15:34:38 +08:00
parent 19a66f3c59
commit 5ef93a07b5
2 changed files with 49 additions and 3 deletions

View File

@@ -18,9 +18,9 @@
</template>
<script lang="ts" setup>
import { ref, onMounted, watch } from 'vue';
import { queryNodeListApi } from '@/api/project/node';
import { debounce } from 'lodash-es';
import { ref, onMounted, watch, inject, type Ref } from 'vue';
interface Props {
modelValue: string;
@@ -60,7 +60,9 @@ onMounted(() => {
getlistDataFun();
});
const meg = inject('projectProvide');
const getlistDataFun = () => {
if (meg) return;
const params = {
nodeType: 'project',
current: 1,
@@ -79,6 +81,31 @@ const getlistDataFun = () => {
}
});
};
// 从父组件中获取项目列表
interface ProjectData {
data: {
data: any[];
};
}
const projectListRes = inject<Ref<ProjectData | null>>('projectListRes', ref(null));
// 监听注入的 projectListRes
watch(
() => projectListRes.value,
(newVal) => {
if (newVal) {
listData.value = newVal.data?.data?.map((item: any) => {
return {
...item,
value: String(item[props.resStr]),
label: props.showCodeList ? item.nodeCode : item.nodeName,
};
});
}
},
{ deep: true, immediate: true }
);
const multiplyChangeFun = debounce(() => {
const ids = choseList.value.join(',');
emit('update:modelValue', ids);

View File

@@ -25,7 +25,7 @@
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { onMounted, ref, provide } from 'vue';
import { getThemeColor } from '@/utils/theme';
// 引入子组件
import userGroupProjectChart from './dataStatistics/userGroupProjectChart.vue';
@@ -43,6 +43,7 @@ import {
getUserFormConfigureApi,
updateUserFormConfigureApi,
} from '@/api/system/systemData';
import { queryNodeListApi } from '@/api/project/node';
const statusColorList = [
'rgb(200, 201, 204)', // 未开始
@@ -206,7 +207,7 @@ const getFormConfigure = async () => {
const originalWarning = ElMessage.warning;
// 临时禁用警告消息
ElMessage.warning = () => ({ close: () => {} }) as any;
const res = await getUserFormConfigureApi(params);
const res: any = await getUserFormConfigureApi(params);
if (res.code === 200) {
// 如果存在配置,则使用配置
hasConfig.value = true;
@@ -224,8 +225,26 @@ 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>