From 36939f36ee1d968d10b8cf20e28d52497a90196e Mon Sep 17 00:00:00 2001 From: dap <15891557205@163.com> Date: Fri, 29 Nov 2024 15:01:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8A=82=E7=82=B9=E6=A0=91=E5=9C=A8?= =?UTF-8?q?=E7=BC=96=E8=BE=91=20&=20=E7=A9=BA=E6=95=B0=E7=BB=84(=E4=B8=8D?= =?UTF-8?q?=E5=8B=BE=E9=80=89)=E6=83=85=E5=86=B5=20=E5=8B=BE=E9=80=89?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E4=BC=9A=E9=80=A0=E6=88=90watch=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F=E8=A7=A6=E5=8F=91=20=E5=AF=BC=E8=87=B4=E4=BC=9A?= =?UTF-8?q?=E5=B8=A6=E4=B8=8A=E7=88=B6=E8=8A=82=E7=82=B9id=E9=80=A0?= =?UTF-8?q?=E6=88=90id=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ .../src/components/tree/src/tree-select-panel.vue | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34a94800..b0f6ad97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 1.1.3 + +**Bug Fixes** + +- 节点树在编辑 & 空数组(不勾选)情况 勾选节点会造成watch延迟触发 导致会带上父节点id造成id重复 + # 1.1.2 **Features** diff --git a/apps/web-antd/src/components/tree/src/tree-select-panel.vue b/apps/web-antd/src/components/tree/src/tree-select-panel.vue index 5c9a6a81..5e6350b6 100644 --- a/apps/web-antd/src/components/tree/src/tree-select-panel.vue +++ b/apps/web-antd/src/components/tree/src/tree-select-panel.vue @@ -8,6 +8,7 @@ import { computed, nextTick, onMounted, type PropType, ref, watch } from 'vue'; import { findGroupParentIds, treeToList } from '@vben/utils'; import { Checkbox, Tree } from 'ant-design-vue'; +import { uniq } from 'lodash-es'; /** 需要禁止透传 */ defineOptions({ inheritAttrs: false }); @@ -73,6 +74,8 @@ const checkedRealKeys = ref<(number | string)[]>([]); /** * 取第一次的menuTree id 设置到checkedMenuKeys * 主要为了解决没有任何修改 直接点击保存的情况 + * + * length为0情况(即新增时候没有勾选节点) 勾选这里会延迟触发 节点会拼接上父节点 导致ID重复 */ const stop = watch([checkedKeys, () => props.treeData], () => { if ( @@ -86,7 +89,10 @@ const stop = watch([checkedKeys, () => props.treeData], () => { checkedKeys.value as any, { id: props.fieldNames.key }, ); - checkedRealKeys.value = [...parentIds, ...checkedKeys.value]; + /** + * uniq 解决上面的id重复问题 + */ + checkedRealKeys.value = uniq([...parentIds, ...checkedKeys.value]); stop(); } if (!props.checkStrictly && checkedKeys.value.length > 0) { @@ -137,9 +143,10 @@ function handleCheckStrictlyChange(e: CheckboxChangeEvent) { /** * 暴露方法来获取用于提交的全部节点 + * uniq去重(保险方案) */ defineExpose({ - getCheckedKeys: () => checkedRealKeys.value, + getCheckedKeys: () => uniq(checkedRealKeys.value), }); onMounted(async () => {