Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 319b7fcd
authored
Sep 17, 2025
by
Jin Mao
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'main' of
https://github.com/zouawen/vue-vben-admin
into zouawen-main
2 parents
4de8220c
9114692f
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
78 deletions
packages/@core/base/icons/src/lucide.ts
packages/@core/ui-kit/shadcn-ui/src/ui/tree/index.ts
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue
packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts
packages/effects/common-ui/src/components/index.ts
playground/src/views/system/role/modules/form.vue
packages/@core/base/icons/src/lucide.ts
View file @
319b7fc
...
@@ -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
,
...
...
packages/@core/ui-kit/shadcn-ui/src/ui/tree/index.ts
View file @
319b7fc
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'
;
packages/@core/ui-kit/shadcn-ui/src/ui/tree/tree.vue
View file @
319b7fc
...
@@ -14,25 +14,9 @@ import { cn, get } from '@vben-core/shared/utils';
...
@@ -14,25 +14,9 @@ import { cn, get } from '@vben-core/shared/utils';
import
{
TreeItem
,
TreeRoot
}
from
'radix-vue'
;
import
{
TreeItem
,
TreeRoot
}
from
'radix-vue'
;
import
{
Checkbox
}
from
'../checkbox'
;
import
{
Checkbox
}
from
'../checkbox'
;
import
{
treePropsDefaults
}
from
'./types'
;
const
props
=
withDefaults
(
defineProps
<
TreeProps
>
(),
{
const
props
=
withDefaults
(
defineProps
<
TreeProps
>
(),
treePropsDefaults
());
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'
,
});
const
emits
=
defineEmits
<
{
const
emits
=
defineEmits
<
{
expand
:
[
value
:
FlattenedItem
<
Recordable
<
any
>>
];
expand
:
[
value
:
FlattenedItem
<
Recordable
<
any
>>
];
...
@@ -41,7 +25,9 @@ const emits = defineEmits<{
...
@@ -41,7 +25,9 @@ const emits = defineEmits<{
interface
InnerFlattenItem
<
T
=
Recordable
<
any
>
,
P
=
number
|
string
>
{
interface
InnerFlattenItem
<
T
=
Recordable
<
any
>
,
P
=
number
|
string
>
{
hasChildren
:
boolean
;
hasChildren
:
boolean
;
id
:
P
;
level
:
number
;
level
:
number
;
parentId
:
null
|
P
;
parents
:
P
[];
parents
:
P
[];
value
:
T
;
value
:
T
;
}
}
...
@@ -50,24 +36,25 @@ function flatten<T = Recordable<any>, P = number | string>(
...
@@ -50,24 +36,25 @@ function flatten<T = Recordable<any>, P = number | string>(
items
:
T
[],
items
:
T
[],
childrenField
:
string
=
'children'
,
childrenField
:
string
=
'children'
,
level
=
0
,
level
=
0
,
parentId
:
null
|
P
=
null
,
parents
:
P
[]
=
[],
parents
:
P
[]
=
[],
):
InnerFlattenItem
<
T
,
P
>
[]
{
):
InnerFlattenItem
<
T
,
P
>
[]
{
const
result
:
InnerFlattenItem
<
T
,
P
>
[]
=
[];
const
result
:
InnerFlattenItem
<
T
,
P
>
[]
=
[];
items
.
forEach
((
item
)
=>
{
items
.
forEach
((
item
)
=>
{
const
children
=
get
(
item
,
childrenField
)
as
Array
<
T
>
;
const
children
=
get
(
item
,
childrenField
)
as
Array
<
T
>
;
const
val
=
{
const
id
=
get
(
item
,
props
.
valueField
)
as
P
;
const
val
:
InnerFlattenItem
<
T
,
P
>
=
{
hasChildren
:
Array
.
isArray
(
children
)
&&
children
.
length
>
0
,
hasChildren
:
Array
.
isArray
(
children
)
&&
children
.
length
>
0
,
id
,
level
,
level
,
parentId
,
parents
:
[...
parents
],
parents
:
[...
parents
],
value
:
item
,
value
:
item
,
};
};
result
.
push
(
val
);
result
.
push
(
val
);
if
(
val
.
hasChildren
)
if
(
val
.
hasChildren
)
result
.
push
(
result
.
push
(
...
flatten
(
children
,
childrenField
,
level
+
1
,
[
...
flatten
(
children
,
childrenField
,
level
+
1
,
id
,
[...
parents
,
id
]),
...
parents
,
get
(
item
,
props
.
valueField
),
]),
);
);
});
});
return
result
;
return
result
;
...
@@ -103,15 +90,10 @@ function updateTreeValue() {
...
@@ -103,15 +90,10 @@ function updateTreeValue() {
treeValue
.
value
=
undefined
;
treeValue
.
value
=
undefined
;
}
else
{
}
else
{
if
(
Array
.
isArray
(
val
))
{
if
(
Array
.
isArray
(
val
))
{
le
t
filteredValues
=
val
.
filter
((
v
)
=>
{
cons
t
filteredValues
=
val
.
filter
((
v
)
=>
{
const
item
=
getItemByValue
(
v
);
const
item
=
getItemByValue
(
v
);
return
item
&&
!
get
(
item
,
props
.
disabledField
);
return
item
&&
!
get
(
item
,
props
.
disabledField
);
});
});
if
(
!
props
.
checkStrictly
&&
props
.
autoCheckParent
)
{
filteredValues
=
processParentSelection
(
filteredValues
);
}
treeValue
.
value
=
filteredValues
.
map
((
v
)
=>
getItemByValue
(
v
));
treeValue
.
value
=
filteredValues
.
map
((
v
)
=>
getItemByValue
(
v
));
if
(
filteredValues
.
length
!==
val
.
length
)
{
if
(
filteredValues
.
length
!==
val
.
length
)
{
...
@@ -128,35 +110,7 @@ function updateTreeValue() {
...
@@ -128,35 +110,7 @@ function updateTreeValue() {
}
}
}
}
}
}
function
processParentSelection
(
selectedValues
:
Array
<
number
|
string
>
,
):
Array
<
number
|
string
>
{
if
(
props
.
checkStrictly
)
return
selectedValues
;
const
result
=
[...
selectedValues
];
for
(
let
i
=
result
.
length
-
1
;
i
>=
0
;
i
--
)
{
const
currentValue
=
result
[
i
];
if
(
currentValue
===
undefined
)
continue
;
const
currentItem
=
getItemByValue
(
currentValue
);
if
(
!
currentItem
)
continue
;
const
children
=
get
(
currentItem
,
props
.
childrenField
);
if
(
Array
.
isArray
(
children
)
&&
children
.
length
>
0
)
{
const
hasSelectedChildren
=
children
.
some
((
child
)
=>
{
const
childValue
=
get
(
child
,
props
.
valueField
);
return
result
.
includes
(
childValue
);
});
if
(
!
hasSelectedChildren
)
{
result
.
splice
(
i
,
1
);
}
}
}
return
result
;
}
function
updateModelValue
(
val
:
Arrayable
<
Recordable
<
any
>>
)
{
function
updateModelValue
(
val
:
Arrayable
<
Recordable
<
any
>>
)
{
if
(
Array
.
isArray
(
val
))
{
if
(
Array
.
isArray
(
val
))
{
const
filteredVal
=
val
.
filter
((
v
)
=>
!
get
(
v
,
props
.
disabledField
));
const
filteredVal
=
val
.
filter
((
v
)
=>
!
get
(
v
,
props
.
disabledField
));
...
@@ -204,6 +158,24 @@ function collapseAll() {
...
@@ -204,6 +158,24 @@ function collapseAll() {
expanded
.
value
=
[];
expanded
.
value
=
[];
}
}
function
checkAll
()
{
if
(
!
props
.
multiple
)
return
;
modelValue
.
value
=
[
...
new
Set
(
flattenData
.
value
.
filter
((
item
)
=>
!
get
(
item
.
value
,
props
.
disabledField
))
.
map
((
item
)
=>
get
(
item
.
value
,
props
.
valueField
)),
),
];
updateTreeValue
();
}
function
unCheckAll
()
{
if
(
!
props
.
multiple
)
return
;
modelValue
.
value
=
[];
updateTreeValue
();
}
function
isNodeDisabled
(
item
:
FlattenedItem
<
Recordable
<
any
>>
)
{
function
isNodeDisabled
(
item
:
FlattenedItem
<
Recordable
<
any
>>
)
{
return
props
.
disabled
||
get
(
item
.
value
,
props
.
disabledField
);
return
props
.
disabled
||
get
(
item
.
value
,
props
.
disabledField
);
}
}
...
@@ -228,12 +200,51 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) {
...
@@ -228,12 +200,51 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) {
get
(
i
.
value
,
props
.
valueField
)
===
get
(
item
.
value
,
props
.
valueField
)
get
(
i
.
value
,
props
.
valueField
)
===
get
(
item
.
value
,
props
.
valueField
)
);
);
})
})
?.
parents
?.
forEach
((
p
)
=>
{
?.
parents
?.
filter
((
item
)
=>
!
get
(
item
,
props
.
disabledField
))
?.
forEach
((
p
)
=>
{
if
(
Array
.
isArray
(
modelValue
.
value
)
&&
!
modelValue
.
value
.
includes
(
p
))
{
if
(
Array
.
isArray
(
modelValue
.
value
)
&&
!
modelValue
.
value
.
includes
(
p
))
{
modelValue
.
value
.
push
(
p
);
modelValue
.
value
.
push
(
p
);
}
}
});
});
}
}
if
(
!
props
.
checkStrictly
&&
props
.
multiple
&&
props
.
autoCheckParent
&&
!
isSelected
)
{
flattenData
.
value
.
find
((
i
)
=>
{
return
(
get
(
i
.
value
,
props
.
valueField
)
===
get
(
item
.
value
,
props
.
valueField
)
);
})
?.
parents
?.
filter
((
item
)
=>
!
get
(
item
,
props
.
disabledField
))
?.
reverse
()
.
forEach
((
p
)
=>
{
const
children
=
flattenData
.
value
.
filter
((
i
)
=>
{
return
(
i
.
parents
.
length
>
0
&&
i
.
parents
.
includes
(
p
)
&&
i
.
id
!==
item
.
_id
&&
i
.
parentId
===
p
);
});
if
(
Array
.
isArray
(
modelValue
.
value
))
{
const
hasSelectedChild
=
children
.
some
((
child
)
=>
(
modelValue
.
value
as
unknown
[]).
includes
(
get
(
child
.
value
,
props
.
valueField
),
),
);
if
(
!
hasSelectedChild
)
{
const
index
=
modelValue
.
value
.
indexOf
(
p
);
if
(
index
!==
-
1
)
{
modelValue
.
value
.
splice
(
index
,
1
);
}
}
}
});
}
updateTreeValue
();
updateTreeValue
();
emits
(
'select'
,
item
);
emits
(
'select'
,
item
);
}
}
...
@@ -243,6 +254,8 @@ defineExpose({
...
@@ -243,6 +254,8 @@ defineExpose({
collapseNodes
,
collapseNodes
,
expandAll
,
expandAll
,
expandNodes
,
expandNodes
,
checkAll
,
unCheckAll
,
expandToLevel
,
expandToLevel
,
getItemByValue
,
getItemByValue
,
});
});
...
@@ -263,15 +276,41 @@ defineExpose({
...
@@ -263,15 +276,41 @@ defineExpose({
v-slot=
"
{ flattenItems }"
v-slot=
"
{ flattenItems }"
:class="
:class="
cn(
cn(
'text-blackA11 container select-none list-none rounded-lg
p-2
text-sm font-medium',
'text-blackA11 container select-none list-none rounded-lg text-sm font-medium',
$attrs.class as unknown as ClassType,
$attrs.class as unknown as ClassType,
bordered ? 'border' : '',
bordered ? 'border' : '',
)
)
"
"
>
>
<div
class=
"w-full"
v-if=
"$slots.header"
>
<div
:class=
"
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-b' : '')
"
v-if=
"$slots.header"
>
<slot
name=
"header"
>
</slot>
<slot
name=
"header"
>
</slot>
</div>
</div>
<div
:class=
"
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-b' : '')
"
v-if=
"treeData.length > 0"
>
<div
class=
"flex size-5 flex-1 cursor-pointer items-center"
@
click=
"() => (expanded?.length > 0 ? collapseAll() : expandAll())"
>
<ChevronRight
:class=
"
{ 'rotate-90': expanded?.length > 0 }"
class="text-foreground/80 hover:text-foreground size-4 cursor-pointer transition"
/>
<Checkbox
v-if=
"multiple"
@
click
.
stop
@
update:checked=
"(checked) => (checked ? checkAll() : unCheckAll())"
/>
</div>
</div>
<TransitionGroup
:name=
"transition ? 'fade' : ''"
>
<TransitionGroup
:name=
"transition ? 'fade' : ''"
>
<TreeItem
<TreeItem
v-for=
"item in flattenItems"
v-for=
"item in flattenItems"
...
@@ -283,11 +322,11 @@ defineExpose({
...
@@ -283,11 +322,11 @@ defineExpose({
handleToggle,
handleToggle,
}"
}"
:key="item._id"
:key="item._id"
:style="{ '
padding-left': `${item.level - 0.5
}rem` }"
:style="{ '
margin-left': `${item.level - 1
}rem` }"
:class="
:class="
cn('cursor-pointer', getNodeClass?.(item), {
cn('cursor-pointer', getNodeClass?.(item), {
'data-[selected]:bg-accent': !multiple,
'data-[selected]:bg-accent': !multiple,
'cursor-not-allowed': isNodeDisabled(item),
'
text-foreground/50
cursor-not-allowed': isNodeDisabled(item),
})
})
"
"
v-bind="
v-bind="
...
@@ -317,7 +356,7 @@ defineExpose({
...
@@ -317,7 +356,7 @@ defineExpose({
!isNodeDisabled(item)
&&
onToggle(item);
!isNodeDisabled(item)
&&
onToggle(item);
}
}
"
"
class="tree-node focus:ring-grass8 my-0.5 flex items-center rounded p
x-2 py
-1 outline-none focus:ring-2"
class="tree-node focus:ring-grass8 my-0.5 flex items-center rounded p-1 outline-none focus:ring-2"
>
>
<ChevronRight
<ChevronRight
v-if=
"
v-if=
"
...
@@ -325,7 +364,7 @@ defineExpose({
...
@@ -325,7 +364,7 @@ defineExpose({
Array.isArray(item.value[childrenField]) &&
Array.isArray(item.value[childrenField]) &&
item.value[childrenField].length > 0
item.value[childrenField].length > 0
"
"
class=
"size-4 cursor-pointer transition"
class=
"
text-foreground/80 hover:text-foreground
size-4 cursor-pointer transition"
:class=
"
{ 'rotate-90': isExpanded }"
:class=
"
{ 'rotate-90': isExpanded }"
@click.stop="
@click.stop="
() => {
() => {
...
@@ -334,9 +373,8 @@ defineExpose({
...
@@ -334,9 +373,8 @@ defineExpose({
}
}
"
"
/>
/>
<div
v-else
class=
"h-4 w-4"
>
<div
v-else
class=
"h-4 w-4"
></div>
<!--
<IconifyIcon
v-if=
"item.value.icon"
:icon=
"item.value.icon"
/>
-->
<div
class=
"flex items-center gap-1"
>
</div>
<Checkbox
<Checkbox
v-if=
"multiple"
v-if=
"multiple"
:checked=
"isSelected && !isNodeDisabled(item)"
:checked=
"isSelected && !isNodeDisabled(item)"
...
@@ -354,7 +392,7 @@ defineExpose({
...
@@ -354,7 +392,7 @@ defineExpose({
"
"
/>
/>
<div
<div
class=
"flex items-center gap-1 pl-2
"
class=
"flex items-center gap-1
"
@
click=
"
@
click=
"
(event: MouseEvent) =>
{
(event: MouseEvent) =>
{
if (isNodeDisabled(item)) {
if (isNodeDisabled(item)) {
...
@@ -362,8 +400,6 @@ defineExpose({
...
@@ -362,8 +400,6 @@ defineExpose({
event.stopPropagation();
event.stopPropagation();
return;
return;
}
}
event.stopPropagation();
event.preventDefault();
handleSelect();
handleSelect();
}
}
"
"
...
@@ -377,9 +413,16 @@ defineExpose({
...
@@ -377,9 +413,16 @@ defineExpose({
{{
get
(
item
.
value
,
labelField
)
}}
{{
get
(
item
.
value
,
labelField
)
}}
</slot>
</slot>
</div>
</div>
</div>
<div
class=
"h-4 w-4"
></div>
</TreeItem>
</TreeItem>
</TransitionGroup>
</TransitionGroup>
<div
class=
"w-full"
v-if=
"$slots.footer"
>
<div
:class=
"
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-t' : '')
"
v-if=
"$slots.footer"
>
<slot
name=
"footer"
>
</slot>
<slot
name=
"footer"
>
</slot>
</div>
</div>
</TreeRoot>
</TreeRoot>
...
...
packages/@core/ui-kit/shadcn-ui/src/ui/tree/types.ts
View file @
319b7fc
...
@@ -40,3 +40,23 @@ export interface TreeProps {
...
@@ -40,3 +40,23 @@ 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'
,
iconField
:
'icon'
,
labelField
:
'label'
,
multiple
:
false
,
showIcon
:
true
,
transition
:
true
,
valueField
:
'value'
,
childrenField
:
'children'
,
};
}
packages/effects/common-ui/src/components/index.ts
View file @
319b7fc
...
@@ -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'
;
...
...
playground/src/views/system/role/modules/form.vue
View file @
319b7fc
...
@@ -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"
>
<
Vben
Tree
<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
>
</
Vben
Tree>
</Tree>
</Spin>
</Spin>
</template>
</template>
</Form>
</Form>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment