From ec94e2b5b47040be547d5a52a274997e462046e0 Mon Sep 17 00:00:00 2001
From: xuziqiang <1344691446@qq.com>
Date: Fri, 19 Jul 2024 16:13:01 +0800
Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E6=A0=91=E7=BB=84=E4=BB=B6?=
=?UTF-8?q?=E8=A1=A5=E5=85=85=E6=98=AF=E5=90=A6=E5=8F=96=E6=B6=88=E9=80=BB?=
=?UTF-8?q?=E8=BE=91?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
lib/component/tree/props.ts | 1 +
lib/component/tree/tree-api.vue | 17 ++++++++++++++---
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/lib/component/tree/props.ts b/lib/component/tree/props.ts
index 618bcd4..242dd25 100644
--- a/lib/component/tree/props.ts
+++ b/lib/component/tree/props.ts
@@ -46,4 +46,5 @@ export const treeProps = {
type: Function,
default: (data: any) => data,
},
+ cancelable: PropTypes.bool.def(false), // 选中树节点是否可以取消
};
diff --git a/lib/component/tree/tree-api.vue b/lib/component/tree/tree-api.vue
index 4aa9076..3bb3574 100644
--- a/lib/component/tree/tree-api.vue
+++ b/lib/component/tree/tree-api.vue
@@ -12,7 +12,7 @@
-
+
@@ -27,7 +27,7 @@
import { TreeDataItem } from 'ant-design-vue/es/tree/Tree';
import { useApi } from '/nerv-lib/use/use-api';
import { AxiosRequestConfig } from 'axios';
- import { get } from 'lodash-es';
+ import { get, isEmpty } from 'lodash-es';
import { useRoute } from 'vue-router';
import { debounce } from 'lodash-es';
import { treeProps, treeFormProps } from '/nerv-lib/component/tree/props';
@@ -35,7 +35,7 @@
defineOptions({
name: 'NsTreeApi',
});
- const emit = defineEmits(['update:treeData']);
+ const emit = defineEmits(['update:treeData', 'select']);
// const model = defineModel('treeData');
const formElRef = ref();
@@ -69,14 +69,25 @@
const isSticky: any = computed(() => {
return props.isSticky ? 'sticky' : 'static';
});
+
const formFinish = debounce((data: object) => {
selectedKeys.value = [];
getData(data);
}, 200);
+
+ const handleSelect = (keys: any, selectedRows: any) => {
+ if (props.cancelable || !isEmpty(keys)) {
+ selectedKeys.value = keys;
+ // props.onSelect && props.onSelect(keys, selectedRows);
+ emit('select', keys, selectedRows);
+ }
+ };
+
const getBindValue = computed(() => ({
...attrs,
...props,
treeData: treeData.value,
+ onSelect: handleSelect,
}));
const setLoading = (loading: boolean) => {
treeState.loading = loading;