Commit 14c53a62 by MT-Joer

style: 风格同步测试

1 parent ae3b7cab
...@@ -20,17 +20,25 @@ ...@@ -20,17 +20,25 @@
@update:model-value="updateModelValue"> @update:model-value="updateModelValue">
<div v-if="$slots.header" <div v-if="$slots.header"
:class=" :class="
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-b' : '') cn(
'my-0.5 flex w-full items-center p-1',
bordered ? 'border-b' : '',
)
"> ">
<slot name="header"> <slot name="header">
</slot> </slot>
</div> </div>
<div v-if="treeData.length > 0" <div v-if="treeData.length > 0"
:class=" :class="
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-b' : '') cn(
'my-0.5 flex w-full items-center p-1',
bordered ? 'border-b' : '',
)
"> ">
<div class="flex size-5 flex-1 cursor-pointer items-center" <div class="flex size-5 flex-1 cursor-pointer items-center"
@click="() => (expanded?.length > 0 ? collapseAll() : expandAll())"> @click="
() => (expanded?.length > 0 ? collapseAll() : expandAll())
">
<ChevronRight class="size-4 cursor-pointer text-foreground/80 transition hover:text-foreground" <ChevronRight class="size-4 cursor-pointer text-foreground/80 transition hover:text-foreground"
:class="{ 'rotate-90': expanded?.length > 0 }" /> :class="{ 'rotate-90': expanded?.length > 0 }" />
<Checkbox v-if="multiple" <Checkbox v-if="multiple"
...@@ -53,7 +61,9 @@ ...@@ -53,7 +61,9 @@
}" }"
v-bind=" v-bind="
Object.assign(item.bind, { Object.assign(item.bind, {
onfocus: isNodeDisabled(item) ? 'this.blur()' : undefined, onfocus: isNodeDisabled(item)
? 'this.blur()'
: undefined,
disabled: isNodeDisabled(item), disabled: isNodeDisabled(item),
}) })
" "
...@@ -61,7 +71,8 @@ ...@@ -61,7 +71,8 @@
: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 text-foreground/50': isNodeDisabled(item), 'cursor-not-allowed text-foreground/50':
isNodeDisabled(item),
}) })
" "
:style="{ 'margin-left': `${item.level - 1}rem` }" :style="{ 'margin-left': `${item.level - 1}rem` }"
...@@ -103,7 +114,9 @@ ...@@ -103,7 +114,9 @@
<div class="flex items-center gap-1"> <div class="flex items-center gap-1">
<Checkbox v-if="multiple" <Checkbox v-if="multiple"
:disabled="isNodeDisabled(item)" :disabled="isNodeDisabled(item)"
:indeterminate="isIndeterminate && !isNodeDisabled(item)" :indeterminate="
isIndeterminate && !isNodeDisabled(item)
"
:model-value="isSelected && !isNodeDisabled(item)" :model-value="isSelected && !isNodeDisabled(item)"
@click=" @click="
(event: MouseEvent) => { (event: MouseEvent) => {
...@@ -139,7 +152,10 @@ ...@@ -139,7 +152,10 @@
</TransitionGroup> </TransitionGroup>
<div v-if="$slots.footer" <div v-if="$slots.footer"
:class=" :class="
cn('my-0.5 flex w-full items-center p-1', bordered ? 'border-t' : '') cn(
'my-0.5 flex w-full items-center p-1',
bordered ? 'border-t' : '',
)
"> ">
<slot name="footer"> <slot name="footer">
</slot> </slot>
...@@ -167,17 +183,17 @@ import { treePropsDefaults } from "./types"; ...@@ -167,17 +183,17 @@ import { treePropsDefaults } from "./types";
const props = withDefaults(defineProps<TreeProps>(), treePropsDefaults()); const props = withDefaults(defineProps<TreeProps>(), treePropsDefaults());
const emits = defineEmits<{ const emits = defineEmits<{
expand: [value: FlattenedItem<Recordable<any>>]; expand: [value: FlattenedItem<Recordable<any>>];
select: [value: FlattenedItem<Recordable<any>>]; select: [value: FlattenedItem<Recordable<any>>];
}>(); }>();
interface InnerFlattenItem<T = Recordable<any>, P = number | string> { interface InnerFlattenItem<T = Recordable<any>, P = number | string> {
hasChildren: boolean; hasChildren: boolean;
id: P; id: P;
level: number; level: number;
parentId: null | P; parentId: null | P;
parents: P[]; parents: P[];
value: T; value: T;
} }
function flatten<T = Recordable<any>, P = number | string>( function flatten<T = Recordable<any>, P = number | string>(
...@@ -202,7 +218,10 @@ function flatten<T = Recordable<any>, P = number | string>( ...@@ -202,7 +218,10 @@ function flatten<T = Recordable<any>, P = number | string>(
result.push(val); result.push(val);
if (val.hasChildren) if (val.hasChildren)
result.push( result.push(
...flatten(children, childrenField, level + 1, id, [ ...parents, id ]), ...flatten(children, childrenField, level + 1, id, [
...parents,
id,
]),
); );
}); });
return result; return result;
...@@ -220,7 +239,7 @@ onMounted(() => { ...@@ -220,7 +239,7 @@ onMounted(() => {
updateTreeValue(); updateTreeValue();
if ( if (
props.defaultExpandedLevel !== undefined && props.defaultExpandedLevel !== undefined &&
props.defaultExpandedLevel > 0 props.defaultExpandedLevel > 0
) )
expandToLevel(props.defaultExpandedLevel); expandToLevel(props.defaultExpandedLevel);
}); });
...@@ -338,33 +357,38 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) { ...@@ -338,33 +357,38 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) {
if ( if (
!props.checkStrictly && !props.checkStrictly &&
props.multiple && props.multiple &&
props.autoCheckParent && props.autoCheckParent &&
isSelected isSelected
) { ) {
flattenData.value flattenData.value
.find((i) => { .find((i) => {
return ( return (
get(i.value, props.valueField) === get(item.value, props.valueField) get(i.value, props.valueField) ===
get(item.value, props.valueField)
); );
}) })
?.parents?.filter((item) => !get(item, props.disabledField)) ?.parents?.filter((item) => !get(item, props.disabledField))
?.forEach((p) => { ?.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 ( if (
!props.checkStrictly && !props.checkStrictly &&
props.multiple && props.multiple &&
props.autoCheckParent && props.autoCheckParent &&
!isSelected !isSelected
) { ) {
flattenData.value flattenData.value
.find((i) => { .find((i) => {
return ( return (
get(i.value, props.valueField) === get(item.value, props.valueField) get(i.value, props.valueField) ===
get(item.value, props.valueField)
); );
}) })
?.parents?.filter((item) => !get(item, props.disabledField)) ?.parents?.filter((item) => !get(item, props.disabledField))
...@@ -373,9 +397,9 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) { ...@@ -373,9 +397,9 @@ function onSelect(item: FlattenedItem<Recordable<any>>, isSelected: boolean) {
const children = flattenData.value.filter((i) => { const children = flattenData.value.filter((i) => {
return ( return (
i.parents.length > 0 && i.parents.length > 0 &&
i.parents.includes(p) && i.parents.includes(p) &&
i.id !== item._id && i.id !== item._id &&
i.parentId === p i.parentId === p
); );
}); });
if (Array.isArray(modelValue.value)) { if (Array.isArray(modelValue.value)) {
...@@ -410,36 +434,36 @@ defineExpose({ ...@@ -410,36 +434,36 @@ defineExpose({
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.container { .container {
position: relative; position: relative;
padding: 0; padding: 0;
list-style-type: none; list-style-type: none;
} }
.item { .item {
box-sizing: border-box; box-sizing: border-box;
width: 100%; width: 100%;
height: 30px; height: 30px;
background-color: #f3f3f3; background-color: #f3f3f3;
border: 1px solid #666; border: 1px solid #666;
} }
/* 1. 声明过渡效果 */ /* 1. 声明过渡效果 */
.fade-move, .fade-move,
.fade-enter-active, .fade-enter-active,
.fade-leave-active { .fade-leave-active {
transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1); transition: all 0.5s cubic-bezier(0.55, 0, 0.1, 1);
} }
/* 2. 声明进入和离开的状态 */ /* 2. 声明进入和离开的状态 */
.fade-enter-from, .fade-enter-from,
.fade-leave-to { .fade-leave-to {
opacity: 0; opacity: 0;
transform: scaleY(0.01) translate(30px, 0); transform: scaleY(0.01) translate(30px, 0);
} }
/* 3. 确保离开的项目被移除出了布局流 /* 3. 确保离开的项目被移除出了布局流
以便正确地计算移动时的动画效果。 */ 以便正确地计算移动时的动画效果。 */
.fade-leave-active { .fade-leave-active {
position: absolute; position: absolute;
} }
</style> </style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!