Commit 39820c78 by zouawen

fix:

1、VbenTree新增是否全选、展开折叠功能;
2、解决当点击子节点label文字区域,而非checkbox时,关联父组件不能选中问题;
3、优化子节点选中时关联父节点选中功能:删除VbenTree中processParentSelection方法,改为在onSelect中实现,原因:processParentSelection在每次模型值更新时都会被调用,且计算复杂度为O(n^2),onSelect只在交互时触发,复杂度为O(n);
4、新增中间层tree组件,处理无数据时显示场景(显示图标Inbox和国际化comom.noData文本);
5、为防止父组件传值子组件boolean类型默认false问题,新增treePropsDefaults方法,为TreeProps赋默认值,Tree组件和VbenTree组件统一使用;
6、优化VbenTree组件整体样式(优化padding、margin、gap值,优化type为button时outline左右空白区域不对称问题),优化内部header、footer插槽样式。
1 parent 6a85b3ab
...@@ -32,6 +32,7 @@ export { ...@@ -32,6 +32,7 @@ export {
Grip, Grip,
GripVertical, GripVertical,
Menu as IconDefault, Menu as IconDefault,
Inbox,
Info, Info,
InspectionPanel, InspectionPanel,
Languages, Languages,
......
export { default as VbenTree } from './tree.vue'; export { default as VbenTree } from './tree.vue';
export type { TreeProps } from './types';
export { treePropsDefaults } from './types';
export type { FlattenedItem } from 'radix-vue'; export type { FlattenedItem } from 'radix-vue';
...@@ -40,3 +40,24 @@ export interface TreeProps { ...@@ -40,3 +40,24 @@ export interface TreeProps {
/** 值字段 */ /** 值字段 */
valueField?: string; valueField?: string;
} }
export function treePropsDefaults() {
return {
allowClear: false,
autoCheckParent: true,
bordered: false,
checkStrictly: false,
defaultExpandedKeys: () => [],
defaultExpandedLevel: 0,
disabled: false,
disabledField: 'disabled',
expanded: () => [],
iconField: 'icon',
labelField: 'label',
multiple: false,
showIcon: true,
transition: true,
valueField: 'value',
childrenField: 'children',
};
}
...@@ -9,6 +9,7 @@ export * from './loading'; ...@@ -9,6 +9,7 @@ export * from './loading';
export * from './page'; export * from './page';
export * from './resize'; export * from './resize';
export * from './tippy'; export * from './tippy';
export * from './tree';
export * from '@vben-core/form-ui'; export * from '@vben-core/form-ui';
export * from '@vben-core/popup-ui'; export * from '@vben-core/popup-ui';
...@@ -27,7 +28,6 @@ export { ...@@ -27,7 +28,6 @@ export {
VbenPinInput, VbenPinInput,
VbenSelect, VbenSelect,
VbenSpinner, VbenSpinner,
VbenTree,
} from '@vben-core/shadcn-ui'; } from '@vben-core/shadcn-ui';
export type { FlattenedItem } from '@vben-core/shadcn-ui'; export type { FlattenedItem } from '@vben-core/shadcn-ui';
......
export { default as Tree } from './tree.vue';
<script setup lang="ts">
import type { TreeProps } from '@vben-core/shadcn-ui';
import { Inbox } from '@vben/icons';
import { $t } from '@vben/locales';
import { treePropsDefaults, VbenTree } from '@vben-core/shadcn-ui';
const props = withDefaults(defineProps<TreeProps>(), treePropsDefaults());
</script>
<template>
<VbenTree v-if="props.treeData?.length > 0" v-bind="props">
<template v-for="(_, key) in $slots" :key="key" #[key]="slotProps">
<slot :name="key" v-bind="slotProps"> </slot>
</template>
</VbenTree>
<div
v-else
class="flex-col-center text-muted-foreground cursor-pointer rounded-lg border p-10 text-sm font-medium"
>
<Inbox class="size-10" />
<div class="mt-1">{{ $t('common.noData') }}</div>
</div>
</template>
...@@ -7,7 +7,7 @@ import type { SystemRoleApi } from '#/api/system/role'; ...@@ -7,7 +7,7 @@ import type { SystemRoleApi } from '#/api/system/role';
import { computed, nextTick, ref } from 'vue'; import { computed, nextTick, ref } from 'vue';
import { useVbenDrawer, VbenTree } from '@vben/common-ui'; import { Tree, useVbenDrawer } from '@vben/common-ui';
import { IconifyIcon } from '@vben/icons'; import { IconifyIcon } from '@vben/icons';
import { Spin } from 'ant-design-vue'; import { Spin } from 'ant-design-vue';
...@@ -92,9 +92,6 @@ function getNodeClass(node: Recordable<any>) { ...@@ -92,9 +92,6 @@ function getNodeClass(node: Recordable<any>) {
const classes: string[] = []; const classes: string[] = [];
if (node.value?.type === 'button') { if (node.value?.type === 'button') {
classes.push('inline-flex'); classes.push('inline-flex');
if (node.index % 3 >= 1) {
classes.push('!pl-0');
}
} }
return classes.join(' '); return classes.join(' ');
...@@ -105,7 +102,7 @@ function getNodeClass(node: Recordable<any>) { ...@@ -105,7 +102,7 @@ function getNodeClass(node: Recordable<any>) {
<Form> <Form>
<template #permissions="slotProps"> <template #permissions="slotProps">
<Spin :spinning="loadingPermissions" wrapper-class-name="w-full"> <Spin :spinning="loadingPermissions" wrapper-class-name="w-full">
<VbenTree <Tree
:tree-data="permissions" :tree-data="permissions"
multiple multiple
bordered bordered
...@@ -120,7 +117,7 @@ function getNodeClass(node: Recordable<any>) { ...@@ -120,7 +117,7 @@ function getNodeClass(node: Recordable<any>) {
<IconifyIcon v-if="value.meta.icon" :icon="value.meta.icon" /> <IconifyIcon v-if="value.meta.icon" :icon="value.meta.icon" />
{{ $t(value.meta.title) }} {{ $t(value.meta.title) }}
</template> </template>
</VbenTree> </Tree>
</Spin> </Spin>
</template> </template>
</Form> </Form>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!