fix: extra

This commit is contained in:
JiangSheng
2026-03-24 10:52:01 +08:00
parent e91f598a95
commit 789992bde6
4 changed files with 83 additions and 152 deletions

View File

@@ -746,7 +746,6 @@ import { ElMessage } from 'element-plus';
import { FLOW_APPROVE_STATUS_ENUM } from '@/utils/enum/flow';
import ApprovalProcess from '@/components/common/approvalProcess/index.vue';
import { getTaskDetailApi } from '@/api/project/task';
import { getFormConfigureApi } from '@/api/system/systemData';
const commonStore = CommonStore();
const allDictData = ref(commonStore.dictData);
@@ -776,58 +775,6 @@ const { TASK_ACHIEVE_STATUS, RESULT_ACHIEVE_STATUS, TASK_APPROVE_STATUS, TASK_PR
const treeData = ref<any>([]);
const taskStore = useTaskStore();
const reportStore = useReportStore();
const extraFieldList = ref<string[]>([]);
const syncRowExtraFun = (row: any) => {
if (!row || extraFieldList.value.length === 0) {
return;
}
extraFieldList.value.forEach((key) => {
const currentValue = row[key];
const extras = Array.isArray(row.extras) ? row.extras : (row.extras = []);
const targetExtra = extras.find((item: any) => item.propertyName === key);
const hasCurrentValue = currentValue !== undefined && currentValue !== null;
if (!hasCurrentValue && !targetExtra) {
return;
}
const nextValue = hasCurrentValue ? currentValue : '';
if (targetExtra) {
if (targetExtra.propertyValue !== nextValue) {
targetExtra.propertyValue = nextValue;
}
return;
}
extras.push({
propertyName: key,
propertyValue: nextValue,
valueType: '',
propertyClass: 'default',
});
});
};
const syncTreeDataExtrasFun = (rows: any[] = []) => {
rows.forEach((row: any) => {
syncRowExtraFun(row);
});
};
const getExtraFieldListFun = async () => {
if (!props.tableName) {
extraFieldList.value = [];
return;
}
const res: any = await getFormConfigureApi({
formName: props.tableName,
});
if (res.code === 200 && res.data?.formConfig) {
const columns = JSON.parse(res.data.formConfig);
extraFieldList.value = Array.from(
new Set(columns.filter((item: any) => item.type === 2).map((item: any) => item.key))
);
syncTreeDataExtrasFun(treeData.value);
}
};
const treeDataFormatFun = (data: any, build: any, pId: any) => {
data.forEach((item: any) => {
@@ -855,22 +802,6 @@ watch(
{ immediate: true }
);
watch(
() => treeData.value,
(rows: any[]) => {
// syncTreeDataExtrasFun(rows);
},
{ deep: true }
);
watch(
() => props.tableName,
() => {
getExtraFieldListFun();
},
{ immediate: true }
);
const getCheckboxRecordsFun = (isFull: boolean) => {
return TreeTableRef.value?.getCheckboxRecordsFun(isFull);
};

View File

@@ -665,7 +665,8 @@ const updateTaskPoolFun = async (formData: any) => {
Object.assign(req, addObj);
}
if (normalizedUpdateRecords.length > 0) {
const updateObj = formatUpdateFun(cloneDeep(normalizedUpdateRecords));
const dynamicExtraFieldsMap = await getExtraFieldsMapFun();
const updateObj = formatUpdateFun(cloneDeep(normalizedUpdateRecords), dynamicExtraFieldsMap);
Object.assign(req, updateObj);
}
if (removeRecords.length > 0) {
@@ -810,7 +811,10 @@ const formatAddFun = (insertRecords: TreeNode[]) => {
addPerformanceExtras: performanceExtras,
};
};
const formatUpdateFun = (updateRecords: TreeNode[]) => {
const formatUpdateFun = (
updateRecords: TreeNode[],
dynamicExtraFieldsMap?: Record<string, string[]>
) => {
const updateNodes: any[] = [];
const updateNodeExtras: any[] = [];
const addNodeExtras: any[] = [];
@@ -832,7 +836,7 @@ const formatUpdateFun = (updateRecords: TreeNode[]) => {
} else {
updateNodes.push(item);
}
item.extras = getNodeExtras(item, poolNodeExtraPropPickMap);
item.extras = getNodeExtras(item, poolNodeExtraPropPickMap, dynamicExtraFieldsMap);
if (Array.isArray(item.extras) && item.extras.length > 0) {
item.extras.forEach((extra) => {
if (extra.uuid) {
@@ -1160,44 +1164,6 @@ const openDelPoolFun = () => {
const onDelPoolConfirmFun = () => {
queryPoolListFun();
};
// const compareTree = (originArr:TreeNode[], insertArr:TreeNode[]) => {
// const insertData: any = [];
// const findInsert = (originArr: any, insertArr: any, originNode: any = null) => {
// insertArr.forEach((insertNode: any) => {
// let found = false;
// // 在第一个树中查找是否存在相同的节点
// originArr.some((originNode: any) => {
// if (insertNode.nodeName === originNode.nodeName && insertNode.nodeType === originNode.nodeType) {
// found = true;
// for (const key in insertNode) {
// if (!['children', 'fakeId', 'parentId', 'highValue', 'oldValue'].includes(key)) {
// originNode[key] = insertNode[key];
// }
// }
// // 如果存在相同节点且有子节点,则递归比较子节点
// if (insertNode.children && originNode.children) {
// findInsert(originNode.children, insertNode.children, originNode);
// }
// return true; // 停止遍历
// }
// return false;
// });
// // 如果在第一个树中未找到相同的节点,则插入
// if (!found) {
// if (originNode?.fakeId) {
// insertNode.parentId = originNode?.fakeId;
// insertNode.fakeId = insertNode.fakeId + random(0, 1, true);
// }
// insertNode._X_ROW_CHILD = [];
// insertNode._X_ROW_KEY = null;
// insertData.push(insertNode);
// }
// });
// };
// findInsert(originArr, insertArr);
// return insertData;
// };
const dict = computed(() => ({
difficult: commonStore.getDictData('DIFFICULTY_COEFFICIENT').A,
discipline: commonStore.getDictData('DISCIPLINE_TYPE').A,
@@ -1229,6 +1195,28 @@ const getFilterColumnsFun = async () => {
return [];
};
const getExtraFieldsMapFun = async (): Promise<Record<string, string[]>> => {
const tableNameMap: Record<string, string> = {
[NODE_TYPE.TASK]: TABLE_NAME.STANDARD_SCENE_TASK,
[NODE_TYPE.PERFORMANCE]: TABLE_NAME.STANDARD_SCENE_PERFORMANCE,
};
const entries = Object.entries(tableNameMap);
const results = await Promise.all(
entries.map(([, formName]) => getFormConfigureApi({ formName }))
);
const map: Record<string, string[]> = {};
entries.forEach(([nodeType], index) => {
const res: any = results[index];
if (res?.code === 200 && res.data?.formConfig) {
const columns = JSON.parse(res.data.formConfig);
map[nodeType] = columns.filter((col: any) => col.type === 2).map((col: any) => col.key);
} else {
map[nodeType] = [];
}
});
return map;
};
const onImportPoolConfirmFun = async (formData: any) => {
importPoolModalVisible.value = false;
const filterColumns = await getFilterColumnsFun();

View File

@@ -179,7 +179,11 @@ export const pickTreeNodeProp = (
return newNode;
});
};
export const getNodeExtras = (node: TreeNode, extraPickMap: Record<string, string[]>) => {
export const getNodeExtras = (
node: TreeNode,
extraPickMap: Record<string, string[]>,
dynamicExtraFieldsMap?: Record<string, string[]>
) => {
let extras = [];
if (!node.extras) {
let props = [];
@@ -204,6 +208,25 @@ export const getNodeExtras = (node: TreeNode, extraPickMap: Record<string, strin
};
});
}
if (dynamicExtraFieldsMap) {
const nodeTypeKey = isCategoryNodeType(node.nodeType) ? NODE_TYPE.CATEGORY : node.nodeType;
const fields = dynamicExtraFieldsMap[nodeTypeKey] || [];
if (fields.length > 0) {
const existingKeys = new Set(extras.map((e: any) => e.propertyName));
fields.forEach((key) => {
if (!existingKeys.has(key) && node[key] !== undefined && node[key] !== null) {
extras.push({
propertyName: key,
propertyValue: node[key],
valueType: '',
propertyClass: 'default',
});
}
});
}
}
return extras;
};
export const transformTreeToPoolNodes = (tree: TreeNode[]) => {

View File

@@ -609,7 +609,8 @@ const updateTaskPoolFun = async (formData: any) => {
Object.assign(req, addObj);
}
if (normalizedUpdateRecords.length > 0) {
const updateObj = formatUpdateFun(cloneDeep(normalizedUpdateRecords));
const dynamicExtraFieldsMap = await getExtraFieldsMapFun();
const updateObj = formatUpdateFun(cloneDeep(normalizedUpdateRecords), dynamicExtraFieldsMap);
Object.assign(req, updateObj);
}
if (removeRecords.length > 0) {
@@ -734,7 +735,10 @@ const formatAddFun = (insertRecords: TreeNode[]) => {
addPerformanceExtras: performanceExtras,
};
};
const formatUpdateFun = (updateRecords: TreeNode[]) => {
const formatUpdateFun = (
updateRecords: TreeNode[],
dynamicExtraFieldsMap?: Record<string, string[]>
) => {
const updateNodes: any[] = [];
const updateNodeExtras: any[] = [];
const addNodeExtras: any[] = [];
@@ -757,7 +761,7 @@ const formatUpdateFun = (updateRecords: TreeNode[]) => {
} else {
updateNodes.push(item);
}
item.extras = getNodeExtras(item, poolNodeExtraPropPickMap);
item.extras = getNodeExtras(item, poolNodeExtraPropPickMap, dynamicExtraFieldsMap);
if (Array.isArray(item.extras) && item.extras.length > 0) {
item.extras.forEach((extra) => {
if (extra.uuid) {
@@ -1106,44 +1110,6 @@ const importPoolModalVisible = ref(false);
const openImportPoolFun = () => {
importPoolModalVisible.value = true;
};
// const compareTree = (originArr:TreeNode[], insertArr:TreeNode[]) => {
// const insertData: any = [];
// const findInsert = (originArr: any, insertArr: any, originNode: any = null) => {
// insertArr.forEach((insertNode: any) => {
// let found = false;
// // 在第一个树中查找是否存在相同的节点
// originArr.some((originNode: any) => {
// if (insertNode.nodeName === originNode.nodeName && insertNode.nodeType === originNode.nodeType) {
// found = true;
// for (const key in insertNode) {
// if (!['children', 'fakeId', 'parentId', 'highValue', 'oldValue'].includes(key)) {
// originNode[key] = insertNode[key];
// }
// }
// // 如果存在相同节点且有子节点,则递归比较子节点
// if (insertNode.children && originNode.children) {
// findInsert(originNode.children, insertNode.children, originNode);
// }
// return true; // 停止遍历
// }
// return false;
// });
// // 如果在第一个树中未找到相同的节点,则插入
// if (!found) {
// if (originNode?.fakeId) {
// insertNode.parentId = originNode?.fakeId;
// insertNode.fakeId = insertNode.fakeId + random(0, 1, true);
// }
// insertNode._X_ROW_CHILD = [];
// insertNode._X_ROW_KEY = null;
// insertData.push(insertNode);
// }
// });
// };
// findInsert(originArr, insertArr);
// return insertData;
// };
const dict = computed(() => ({
difficult: commonStore.getDictData('DIFFICULTY_COEFFICIENT').A,
discipline: commonStore.getDictData('DISCIPLINE_TYPE').A,
@@ -1175,6 +1141,29 @@ const getFilterColumnsFun = async () => {
return [];
};
const getExtraFieldsMapFun = async (): Promise<Record<string, string[]>> => {
const tableNameMap: Record<string, string> = {
[NODE_TYPE.CATEGORY]: TABLE_NAME.TASK_POOL_CATEGORY,
[NODE_TYPE.TASK]: TABLE_NAME.TASK_POOL_TASK,
[NODE_TYPE.PERFORMANCE]: TABLE_NAME.TASK_POOL_PERFORMANCE,
};
const entries = Object.entries(tableNameMap);
const results = await Promise.all(
entries.map(([, formName]) => getFormConfigureApi({ formName }))
);
const map: Record<string, string[]> = {};
entries.forEach(([nodeType], index) => {
const res: any = results[index];
if (res?.code === 200 && res.data?.formConfig) {
const columns = JSON.parse(res.data.formConfig);
map[nodeType] = columns.filter((col: any) => col.type === 2).map((col: any) => col.key);
} else {
map[nodeType] = [];
}
});
return map;
};
const onImportPoolConfirmFun = async (formData: any) => {
importPoolModalVisible.value = false;
const filterColumns = await getFilterColumnsFun();