Browse Source

feat:树组件补充是否取消逻辑

deploy-dev
xuziqiang 4 months ago
parent
commit
ec94e2b5b4
  1. 1
      lib/component/tree/props.ts
  2. 17
      lib/component/tree/tree-api.vue

1
lib/component/tree/props.ts

@ -46,4 +46,5 @@ export const treeProps = {
type: Function,
default: (data: any) => data,
},
cancelable: PropTypes.bool.def(false), // 选中树节点是否可以取消
};

17
lib/component/tree/tree-api.vue

@ -12,7 +12,7 @@
</div>
<div style="min-height: 150px">
<ns-tree v-if="treeData?.length" v-bind="getBindValue" v-model:selectedKeys="selectedKeys">
<ns-tree v-if="treeData?.length" v-bind="getBindValue" :selectedKeys="selectedKeys">
<template #[item]="data" v-for="(item, index) in Object.keys($slots)" :key="index">
<slot :name="item" v-bind="{ ...data, formModel } || {}"></slot>
</template>
@ -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;

Loading…
Cancel
Save