From 3743e482b0c7ce7792c8e5a9c2bb824c7cba5da4 Mon Sep 17 00:00:00 2001 From: liwenxuan <1298531568@qq.com> Date: Tue, 11 Nov 2025 11:12:58 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E7=94=A8=E6=88=B7=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E5=8D=95=E9=80=89=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formTable/index.vue | 15 ++- .../lowCode/assistant/rangedUserTree.vue | 123 +++++++++++++++--- 2 files changed, 116 insertions(+), 22 deletions(-) diff --git a/src/components/formTable/index.vue b/src/components/formTable/index.vue index 75c292e..92ecc53 100644 --- a/src/components/formTable/index.vue +++ b/src/components/formTable/index.vue @@ -1951,13 +1951,23 @@ function getTree1() { } }); }); - rangedUserTrees1.value = rangedUserTrees + + + rangedUserTrees1.value = JSON.parse(JSON.stringify(rangedUserTrees)) + rangedUserTrees.forEach((item:any) => { + // 判断对象自身是否存在 tree 属性(不检查原型链) + if (item.hasOwnProperty('tree')) { + // 删除 tree 属性 + delete item.tree; + } + }) + + }) } - function modifyTreeData(treeData, idList) { //console.log("modifyTreeDataMinimal 执行了"); let gkFlag = true @@ -2178,7 +2188,6 @@ function formatAllNodes(node, processedIds) { } - function groupExpandUserConfigs(configs) { // 用于存储分组结果的Map // key是排序后的范围数组字符串,value是包含names和原始keys的对象 diff --git a/src/components/lowCode/assistant/rangedUserTree.vue b/src/components/lowCode/assistant/rangedUserTree.vue index 66da44f..26cc3ca 100644 --- a/src/components/lowCode/assistant/rangedUserTree.vue +++ b/src/components/lowCode/assistant/rangedUserTree.vue @@ -17,27 +17,79 @@ const emits = defineEmits<{ (e: 'update:modelValue', value: string): void }>() + const value = ref([]) const treeData = ref([]) // 存储懒加载的数据 const isDataLoaded = ref(false) // 标记数据是否已加载 const loading = ref(false) // 是否正在加载 const treeSelectRef = ref() // 树选择器引用 -watch(value, (newValue) => { - if (newValue.length > 0) { - let str = "" - let userAry = new Array - - newValue.forEach(item => { - userAry.push(item) - }) - str = userAry.join(',') - emits('update:modelValue', str) +// 上一次选择的值,用于比较 +const lastSelectedValue = ref(null) + +// 处理值变化 +const handleValueChange = (newValue) => { + if (!multiSelect.value) { + // 单选模式 + if (newValue.length === 0) { + // 清空选择 + emits('update:modelValue', ''); + lastSelectedValue.value = null; + } else if (newValue.length === 1) { + // 单选模式下只有一个选择 + const currentValue = newValue[0]; + emits('update:modelValue', currentValue); + lastSelectedValue.value = currentValue; + } else { + // 当有多个选择时,找出新增的那个 + const newSelections = newValue.filter(item => item !== lastSelectedValue.value); + if (newSelections.length > 0) { + // 只保留最新选择的那个 + const latestSelection = newSelections[newSelections.length - 1]; + value.value = [latestSelection]; + emits('update:modelValue', latestSelection); + lastSelectedValue.value = latestSelection; + } else { + // 如果没有新增的选择,可能是取消选择,保持原样 + value.value = newValue; + } + } } else { - let str = "" - emits('update:modelValue', str) + // 多选模式下的处理 + if (newValue.length > 0) { + let str = "" + let userAry = new Array + if(Array.isArray(newValue)){ + newValue.forEach(item => { + userAry.push(item) + }) + str = userAry.join(',') + emits('update:modelValue', str) + }else{ + let a = new Array + a.push(newValue) + a.forEach(item => { + userAry.push(item) + }) + str = userAry.join(',') + emits('update:modelValue', str) + } + } else { + let str = "" + emits('update:modelValue', str) + } } -}, { deep: true }) +} + +watch(value, handleValueChange, { deep: true }) + +const multiSelect = computed(()=>{ + if(props.data.control.multiSelect && props.data.control.multiSelect == "1"){ + return true + }else{ + return false + } +}) function parseStringToArray(str: string) { try { @@ -54,10 +106,33 @@ function parseStringToArray(str: string) { onBeforeMount(() => { setTimeout(() => { - value.value = parseStringToArray(props.modelValue) + const initialValue = parseStringToArray(props.modelValue) + value.value = initialValue; + if (initialValue.length > 0 && !multiSelect.value) { + lastSelectedValue.value = initialValue[initialValue.length - 1]; + } }, 500) }) +// 递归处理树节点,将部门节点设置为禁用 +const processTreeData = (data: any[]) => { + return data.map(node => { + const newNode = { ...node }; + + // 如果multiSelect为false且id长度小于5,设置为禁用 + if (!multiSelect.value && node.id && node.id.toString().length < 5) { + newNode.disabled = true; + } + + // 递归处理子节点 + if (newNode.children && Array.isArray(newNode.children)) { + newNode.children = processTreeData(newNode.children); + } + + return newNode; + }); +} + // 加载完整数据的函数 const loadFullData = async () => { if (isDataLoaded.value) return treeData.value; @@ -69,9 +144,13 @@ const loadFullData = async () => { await new Promise(resolve => setTimeout(resolve, 800)); const result = await checkorgAndManTree1(); - treeData.value = result; + + // 根据multiSelect的值处理数据 + const processedData = !multiSelect.value ? processTreeData(result) : result; + + treeData.value = processedData; isDataLoaded.value = true; - return result; + return processedData; } catch (error) { console.error('加载组织数据失败:', error); return []; @@ -111,7 +190,7 @@ function checkorgAndManTree1() { if (i == props.orgAndManTree.length) { props.orgAndManTree.forEach((item: any) => { if (props.data.name == item.name) { - console.log(item.tree) + //console.log(item.tree) result = item.tree } }); @@ -167,9 +246,9 @@ const valPrint = (val: any) => { node-key="number" v-model="value" :data="resData" - multiple + multiple :render-after-expand="false" - show-checkbox + show-checkbox clearable collapse-tags collapse-tags-tooltip @@ -234,4 +313,10 @@ const valPrint = (val: any) => { color: #909399; font-size: 14px; } + +.el-select-dropdown__item.is-disabled { + background-color: unset; + color: #606266; + cursor: not-allowed; +} \ No newline at end of file