diff --git a/src/components/formTable/index.vue b/src/components/formTable/index.vue
index 718fa58..d82288c 100644
--- a/src/components/formTable/index.vue
+++ b/src/components/formTable/index.vue
@@ -636,7 +636,7 @@ function checkRangedUserTreesAndGet(){
onMounted(() => {
getAsfs()
- checkRangedUserTreesAndGet()
+
getInitModel()
nextTick(() => {
@@ -1915,6 +1915,7 @@ watch(
}) */
const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree'
const orgAndManTree = ref()
+
function getOrgAndManTree() {
return request({
url: treeUrl,
@@ -1925,15 +1926,196 @@ function getTree1() {
getOrgAndManTree().then(({ data }) => {
orgAndManTree.value = data
- })
+ }).finally(()=>{
+ console.log(rangedUserTrees)
+
+ // 使用示例
+ const configArray = rangedUserTrees;
+ const groupedNames = groupExpandUserConfigs(configArray);
+ console.log(groupedNames);
+ groupedNames.forEach((element:any) => {
+ let keys = element.keys
+ let arr = []
+ arr.push(modifyTreeData(orgAndManTree.value,keys))
+ element.tree = arr
+
+ rangedUserTrees.forEach((item:any) => {
+ let i = 0
+ element.groupArray.forEach((el:any) => {
+ if(item.name==el){
+ i++
+ }
+ });
+ if(i>0){
+ item.tree = element.tree
+ }
+ });
+ });
+ rangedUserTrees1.value = rangedUserTrees
+ })
+
+
}
-const rangedUserTrees: any[] = [];
+
+function modifyTreeData(treeData, idList) {
+ console.log("modifyTreeDataMinimal 执行了");
+
+ const idArray = Array.isArray(idList) ? idList : [idList];
+ if (idArray.length === 0 || !treeData) {
+ return Array.isArray(treeData) ? [] : null;
+ }
+
+ const roots = Array.isArray(treeData) ? treeData : [treeData];
+
+ // 创建节点映射和父节点映射
+ const nodeMap = new Map();
+ const parentMap = new Map();
+
+ // 使用迭代而非递归构建映射,避免栈溢出
+ const stack = [...roots];
+
+ while (stack.length > 0) {
+ const node = stack.pop();
+ if (!node?.id) continue;
+
+ nodeMap.set(node.id, node);
+
+ if (node.children) {
+ for (const child of node.children) {
+ if (child?.id) {
+ parentMap.set(child.id, node.id);
+ stack.push(child);
+ }
+ }
+ }
+ }
+
+ // 找到需要保留的节点(目标节点及其祖先)
+ const keepIds = new Set();
+ for (const id of idArray) {
+ let currentId = id;
+ while (currentId && nodeMap.has(currentId)) {
+ keepIds.add(currentId);
+ currentId = parentMap.get(currentId);
+ }
+ }
+
+ // 构建结果树 - 修复重复问题
+ const result = [];
+ const processedIds = new Set(); // 跟踪已处理的节点ID,防止重复
+
+ // 只处理根节点中需要保留的节点
+ for (const root of roots) {
+ if (!root?.id || !keepIds.has(root.id) || processedIds.has(root.id)) {
+ continue;
+ }
+
+ processedIds.add(root.id);
+ result.push(buildNodeTree(root, keepIds, idArray, processedIds));
+ }
+
+ // 清理临时数据
+ nodeMap.clear();
+ parentMap.clear();
+ keepIds.clear();
+ processedIds.clear();
+
+ return Array.isArray(treeData) ? result : result[0] || null;
+}
+
+// 辅助函数:递归构建节点树
+function buildNodeTree(node, keepIds, idArray, processedIds) {
+ const newNode = {
+ id: node.id,
+ label: node.label,
+ value: node.value
+ };
+
+ // 修改目标节点的标签
+ if (idArray.includes(node.id)) {
+ newNode.label = `${node.label}(${node.value || ''})`;
+ newNode.number = newNode.label;
+ }
+
+ // 处理子节点
+ if (node.children && node.children.length > 0) {
+ const children = [];
+ for (const child of node.children) {
+ if (child?.id && keepIds.has(child.id) && !processedIds.has(child.id)) {
+ processedIds.add(child.id);
+ children.push(buildNodeTree(child, keepIds, idArray, processedIds));
+ }
+ }
+ if (children.length > 0) {
+ newNode.children = children;
+ }
+ }
+
+ return newNode;
+}
+
+
+
+
+function groupExpandUserConfigs(configs) {
+ // 用于存储分组结果的Map
+ // key是排序后的范围数组字符串,value是包含names和原始keys的对象
+ const groupMap = new Map();
+
+ configs.forEach(config => {
+ // 根据queryBy确定使用哪个范围数组
+ let range, rangeType;
+ if (config.control.queryBy === 'org') {
+ range = config.control.orgRange;
+ rangeType = 'orgRange';
+ } else {
+ range = config.control.roleRange;
+ rangeType = 'roleRange';
+ }
+
+ // 对范围数组进行排序并转换为字符串作为分组key
+ const sortedRange = [...range].sort().join(',');
+
+ // 如果该分组key不存在,创建新的分组
+ if (!groupMap.has(sortedRange)) {
+ groupMap.set(sortedRange, {
+ names: [],
+ keys: range, // 存储原始keys,不排序
+ rangeType: rangeType
+ });
+ }
+
+ // 将当前配置的name添加到对应分组
+ groupMap.get(sortedRange).names.push(config.name);
+ });
+
+ // 将Map转换为要求的输出格式
+ const result = [];
+ for (const groupInfo of groupMap.values()) {
+ result.push({
+ groupArray: groupInfo.names,
+ keys: groupInfo.keys,
+ rangeType: groupInfo.rangeType // 可选:添加范围类型信息
+ });
+ }
+
+ return result;
+}
+
+
+
+
+
+const rangedUserTrees1= ref([]);
+const rangedUserTrees :any= [];
function getAsfs() {
- setTimeout(() => {
+ /* setTimeout(() => { */
+
+ if(props.formData.list&&props.formData.list.length>0){
let dataList = ref({});
dataList.value = props.formData.list;
@@ -2011,8 +2193,15 @@ function getAsfs() {
}
}
}
+ checkRangedUserTreesAndGet()
}
- }, 500);
+ }else{
+ setTimeout(()=>{
+ getAsfs()
+ },100)
+ }
+
+ /* }, 500); */
}
/* function getAsfs() {
@@ -2114,7 +2303,7 @@ defineExpose({
'design-form': type === 5,
'detail-form': type === 3
}">
-
+
diff --git a/src/components/lowCode/assistant/rangedUserTree.vue b/src/components/lowCode/assistant/rangedUserTree.vue
index 64b51b0..20ab48d 100644
--- a/src/components/lowCode/assistant/rangedUserTree.vue
+++ b/src/components/lowCode/assistant/rangedUserTree.vue
@@ -1,10 +1,8 @@