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;