From 0466ee1a4264710581f225279d5f5831d9f4c6ce Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Thu, 23 Oct 2025 11:13:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=94=A8=E6=88=B7,=E6=80=A7?= =?UTF-8?q?=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../public/expand/rangedUserTree.vue | 370 +++++++++--------- .../DesignForm/public/form/childTable.vue | 4 + .../DesignForm/public/form/form.vue | 23 ++ .../DesignForm/public/form/formGroup.vue | 15 +- .../DesignForm/public/form/formItem.vue | 2 + .../lowcodetransfer/lowcodeTransfer1.vue | 6 +- 6 files changed, 232 insertions(+), 188 deletions(-) diff --git a/src/components/DesignForm/public/expand/rangedUserTree.vue b/src/components/DesignForm/public/expand/rangedUserTree.vue index 0725cb3..901d947 100644 --- a/src/components/DesignForm/public/expand/rangedUserTree.vue +++ b/src/components/DesignForm/public/expand/rangedUserTree.vue @@ -9,75 +9,54 @@ const props = withDefaults( defineProps<{ modelValue?: string disabled?: boolean + orgAndManTree?: any; }>(), {} ) + + + interface User { - id: number - name: string - number: string - key: string - icon: string - department: string - role: string + id: number + name: string + number: string + key: string + icon: string + department: string + role: string + label: string + value: string } const emits = defineEmits<{ (e: 'update:modelValue', value: string): void }>() -const userDialogEl = ref() - - -const loading = ref(true) const value = ref([]) - - - -watch(value, (newValue) => { - - const checkReady = () => { - - if (loading.value == false) { - if (newValue.length > 0) { - let str = "" - - let userAry = new Array - - - newValue.forEach(item => { - - userAry.push(item) - - }) - - str = userAry.join(',') - //console.log(str) - emits('update:modelValue', str) - - } else { - let str = "" - - emits('update:modelValue', str) - } - } else { - // 未就绪,100ms 后重试(非阻塞) - setTimeout(checkReady, 100) - } - - } - - // 启动检查 - checkReady() -}, { deep: true }) - - - -const openDialog = () => { - // console.log("value-----》",value.value) - userDialogEl.value.open() -} - -function parseStringToArray(str: string) { +const loading = ref(true) +watch(value,(newValue)=>{ + if(newValue.length > 0){ + let str = "" + + let userAry = new Array + + newValue.forEach(item =>{ + //console.log(item) + userAry.push(item) + + }) + str = userAry.join(',') + //console.log(str) + emits('update:modelValue', str) + // userlist.value = userAry.join(',') + // + }else{ + let str = "" + //console.log(str) + emits('update:modelValue', str) + } +},{ deep: true }) + +function parseStringToArray(str:string) { try { // 尝试解析JSON格式字符串 const result = JSON.parse(str); @@ -94,127 +73,144 @@ function parseStringToArray(str: string) { } } onBeforeMount(() => { - getManConts() - getTree() - setTimeout(() => { - value.value = parseStringToArray(props.modelValue) - }, 700) + // 启动检查 + //checkReady() + + //getTree() + setTimeout(()=>{ + value.value = parseStringToArray(props.modelValue) + },500 ) }) + const url = "/javasys/lowCode/manCont/getManContsByKeys" //console.log(attrs.value) -const keys = computed(() => { - if (attrs.queryBy == 'role') { - return attrs.roleRange - } else { - return attrs.orgRange - } +const keys = computed(()=>{ + if(attrs.queryBy == 'role'){ + return attrs.roleRange + }else{ + return attrs.orgRange + } }) -function getManContsByKeys() { - //console.log(11111) - - return request({ - url: url, - method: "post", - data: { - keys: keys.value, - }, - }); -} const options = ref([]) - -function getManConts() { - getManContsByKeys().then(({ data }) => { - data.forEach((element: any) => { - element.icon = element.name + "(" + element.number + ")" - element.deparment = "[" + element.deparment + "] - " + element.icon - element.label = element.deparment - element.value = element.icon - }); - options.value = data - //console.log(options.value) - - }) -} - - -const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree' -function getOrgAndManTree() { - return request({ - url: treeUrl, - method: 'post', - }); -} - -function processTreeData(node: any) { - - // 检查节点及其所有子孙节点中是否存在id长度大于4的节点 - function hasLongIdNode(node: { id: string | any[]; children: string | any[]; }) { - // 检查当前节点id长度 - if (node.id && node.id.length > 4) { - return true; +const convertToAFormatComplate = ref(false) +function convertToAFormat(bTree, idArray) { + const nodeMap = {}; + + // 递归收集节点,增加详细日志 + function collectNodes(node, level = 0) { + if (!node) { + //console.log(`跳过无效节点: ${node}`); + return; } - - // 处理子节点(考虑children为null的情况) - if (node.children && Array.isArray(node.children) && node.children.length > 0) { - for (const child of node.children) { - if (hasLongIdNode(child)) { - return true; - } - } + // 记录当前节点信息(方便调试) + //console.log(`收集节点 [层级${level}]: id=${node.id}, label=${node.label}`); + // 必须有id才存入映射表(避免非节点元素) + if (node.id !== undefined && node.id !== null) { + nodeMap[node.id] = node; + } else { + //console.warn(`节点缺少id,跳过:`, node); } + // 处理子节点(确保是数组,且元素有效) + if (Array.isArray(node.children)) { + node.children.forEach((child, index) => { + collectNodes(child, level + 1); // 层级+1,方便查看嵌套关系 + }); + } else if (node.children !== null && node.children !== undefined) { + //console.warn(`节点children不是数组,跳过:`, node.children); + } + } - return false; + // 处理根节点(兼容数组或单个对象) + if (Array.isArray(bTree)) { + //console.log(`bTree是数组,共${bTree.length}个根节点`); + bTree.forEach((root, index) => { + //console.log(`处理根节点${index + 1}`); + collectNodes(root); + }); + } else { + //console.log(`bTree是单个根节点`); + collectNodes(bTree); } - // 递归处理节点 - function processNode(node: any) { - // 如果当前节点及其所有子孙都没有长id,则移除该节点 - if (!hasLongIdNode(node)) { - return null; - } + // 打印收集到的所有节点id(关键调试信息) + //console.log(`收集到的节点id列表:`, Object.keys(nodeMap)); + + // 匹配idArray并转换 + const result = idArray.map(id => { + // 打印当前匹配的id,检查是否在nodeMap中 + //console.log(`匹配id: ${id},是否存在: ${id in nodeMap}`); + const targetNode = nodeMap[id]; + if (!targetNode) return null; + + return { + id: targetNode.id, + number: targetNode.value ?? '', // 用空字符串替代null/undefined + name: targetNode.label ?? '', + icon: null, + key: String(targetNode.id), // 确保key是字符串(与a格式一致) + role: '', + deparment: '', + parentId: targetNode.parentId ?? '' + }; + }).filter(Boolean); + + //console.log(`最终转换结果:`, result); + convertToAFormatComplate.value = true + return result; +} - // 复制节点避免修改原对象 - const newNode = { ...node }; +function getManConts(){ - // 处理子节点 - if (newNode.children && Array.isArray(newNode.children) && newNode.children.length > 0) { - // 递归处理每个子节点并过滤掉需要移除的 - newNode.children = newNode.children - .map((child: any) => processNode(child)) - .filter((child: null) => child !== null); - // 如果所有子节点都被移除,保持children为null - if (newNode.children.length === 0) { - newNode.children = null; - } - } + let data = convertToAFormat(props.orgAndManTree,keys.value) + data.forEach((element: any) => { + element.icon = element.name+"("+element.number+")" + element.deparment = ""+element.deparment+">"+element.icon + element.label = element.deparment + element.value = element.icon + }); + options.value = data - return newNode; - } - return processNode(node); } -let resData = ref([]) - -const userList = computed({ - get() { +/** +@ 作者: 秦东 +@ 时间: 2025-06-10 11:13:06 +@ 功能: 输出结果 +*/ +const valPrint = (val:any) => { + + if(Array.isArray(val)){ + return val.join("、") + } + +} - return [{ - id: '全选', - label: '全选', - children: [...resData.value] - }] +const resData = computed(()=>{ + if(props.orgAndManTree){ + let data1 = processTreeData(props.orgAndManTree) + //console.log(data1) + getManConts() + + let data2 = filterTreeByList(data1.children, options.value) + data1.children = data2 - }, - set() { + + loading.value = false + return enrichTreeWithEmployeeInfo(options.value, data2) + }else{ + return [] } + + }) + /** * 根据列表数据过滤树形数据,保留value值在列表number中匹配的节点及其祖先 * @param {Array} treeData - 树形数据 @@ -334,39 +330,55 @@ function enrichTreeWithEmployeeInfo(employees: any[], treeData: string | any[]) return treeData; } -function getTree() { - getOrgAndManTree().then(({ data }) => { - - - let data1 = processTreeData(data) - //console.log(data1) - let data2 = filterTreeByList(data1.children, options.value) - - //console.log(data2) - data1.children = data2 - - //console.log(resData.value) - //console.log(`获取穿梭框接口数据`); - resData.value = data1.children - userList.value = [{ - id: '全选', - label: '全选', - children: [...resData.value] - }] - - enrichTreeWithEmployeeInfo(options.value, userList.value) - loading.value = false +function processTreeData(node: any) { - }) -} + // 检查节点及其所有子孙节点中是否存在id长度大于4的节点 + function hasLongIdNode(node: { id: string | any[]; children: string | any[]; }) { + // 检查当前节点id长度 + if (node.id && node.id.length > 4) { + return true; + } + // 处理子节点(考虑children为null的情况) + if (node.children && Array.isArray(node.children) && node.children.length > 0) { + for (const child of node.children) { + if (hasLongIdNode(child)) { + return true; + } + } + } + return false; + } + // 递归处理节点 + function processNode(node: any) { + // 如果当前节点及其所有子孙都没有长id,则移除该节点 + if (!hasLongIdNode(node)) { + return null; + } + // 复制节点避免修改原对象 + const newNode = { ...node }; + // 处理子节点 + if (newNode.children && Array.isArray(newNode.children) && newNode.children.length > 0) { + // 递归处理每个子节点并过滤掉需要移除的 + newNode.children = newNode.children + .map((child: any) => processNode(child)) + .filter((child: null) => child !== null); + // 如果所有子节点都被移除,保持children为null + if (newNode.children.length === 0) { + newNode.children = null; + } + } + return newNode; + } + return processNode(node); +} @@ -374,7 +386,7 @@ function getTree() {
-
diff --git a/src/components/DesignForm/public/form/childTable.vue b/src/components/DesignForm/public/form/childTable.vue index 284a865..185ea33 100644 --- a/src/components/DesignForm/public/form/childTable.vue +++ b/src/components/DesignForm/public/form/childTable.vue @@ -19,6 +19,7 @@ import { SCOPE } from "element-plus"; const props = withDefaults( defineProps<{ data: any; + orgAndManTree?: any; }>(), { data: () => { @@ -351,6 +352,7 @@ function optionsValue3Get1(data: any, fieldName: string) { :data="item" @asf-value-changed="asfValueChanged" @optionsValue3Get1="optionsValue3Get1" + :org-and-man-tree="orgAndManTree" /> @@ -362,6 +364,7 @@ function optionsValue3Get1(data: any, fieldName: string) { :data="item" @asf-value-changed="asfValueChanged" @optionsValue3Get1="optionsValue3Get1" + :org-and-man-tree="orgAndManTree" /> @@ -375,6 +378,7 @@ function optionsValue3Get1(data: any, fieldName: string) { :data="item" @asf-value-changed="asfValueChanged" @optionsValue3Get1="optionsValue3Get1" + :org-and-man-tree="orgAndManTree" /> diff --git a/src/components/DesignForm/public/form/form.vue b/src/components/DesignForm/public/form/form.vue index bc8546a..3551b0e 100644 --- a/src/components/DesignForm/public/form/form.vue +++ b/src/components/DesignForm/public/form/form.vue @@ -1716,6 +1716,27 @@ watch( } ); // ------------------------数据处理结束------------------------ + + + +const treeUrl = '/javasys/lowCode/transfer/getOrgAndManTree' +const orgAndManTree = ref() +function getOrgAndManTree() { + return request({ + url: treeUrl, + method: 'post', + }); +} +function getTree1() { + getOrgAndManTree().then(({ data }) => { + orgAndManTree.value = data + + }) +} + + + + const asfs: any[] = []; const tables: any[] = []; function getAsfs() { @@ -1803,6 +1824,7 @@ onMounted(() => { }); showOrHide("kong"); getAsfs(); + getTree1(); }); onUnmounted(() => { if (eventName) { @@ -2251,6 +2273,7 @@ const webPage = computed({ :node-key="nodeKey" :purview="purview" @optionsValue3Get2="optionsValue3Get2" + :org-and-man-tree="orgAndManTree" /> diff --git a/src/components/DesignForm/public/form/formGroup.vue b/src/components/DesignForm/public/form/formGroup.vue index a40d76c..2099408 100644 --- a/src/components/DesignForm/public/form/formGroup.vue +++ b/src/components/DesignForm/public/form/formGroup.vue @@ -26,6 +26,7 @@ const props = withDefaults( nodeKey?: string; purview?: any[]; alldata?: any; + orgAndManTree?: any; }>(), { data: () => { @@ -788,7 +789,7 @@ function optionsValue3GetTable(data: any, fieldName: string) { :label="item.label" :key="tIndex" > - + @@ -818,7 +819,7 @@ function optionsValue3GetTable(data: any, fieldName: string) {
{{ element.item ? (element.item.label ? element.item.label : 2) : 3 }} - +
@@ -846,7 +848,7 @@ function optionsValue3GetTable(data: any, fieldName: string) { :key="i" @click.stop="groupClick(col, 'gridChild')" > - +
- + @@ -888,7 +890,7 @@ function optionsValue3GetTable(data: any, fieldName: string) { [element.config?.textAlign]: element.config?.textAlign, }" > - +
@@ -898,7 +900,7 @@ function optionsValue3GetTable(data: any, fieldName: string) { data-type="not-nested" v-if="type === 5" /> --> - + diff --git a/src/components/DesignForm/public/form/formItem.vue b/src/components/DesignForm/public/form/formItem.vue index c78d412..117c37d 100644 --- a/src/components/DesignForm/public/form/formItem.vue +++ b/src/components/DesignForm/public/form/formItem.vue @@ -75,6 +75,7 @@ const props = withDefaults( tablekey?: any; numrun?: any; rowIndex?: any; + orgAndManTree?: any; }>(), {} ); @@ -1545,6 +1546,7 @@ const diGuiJilian = (val: any, options: any[]) => { :type="type" :rowIndex="rowIndex" v-model="value" + :org-and-man-tree="orgAndManTree" />
-
+
@@ -878,7 +878,7 @@ watch(selectedValueCompu, (newValue, oldValue) => { .leftArea { border: 1px solid gainsboro; - width: 300px; + width: 500px; border-radius: 5px; height: 456px; position: relative;