feat: 新增 menu 组件 collapseTransition 属性
This commit is contained in:
parent
0ae76917cb
commit
9c4cebcbd2
@ -140,7 +140,7 @@ export default {
|
|||||||
::: demo
|
::: demo
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-collapse v-model="openKeys5" :isAmin="isAmin">
|
<lay-collapse v-model="openKeys5" :collapseTransition="collapseTransition">
|
||||||
<lay-collapse-item title="标题1" id="1"> 内容1 </lay-collapse-item>
|
<lay-collapse-item title="标题1" id="1"> 内容1 </lay-collapse-item>
|
||||||
<lay-collapse-item title="标题2" id="2"> 内容2 </lay-collapse-item>
|
<lay-collapse-item title="标题2" id="2"> 内容2 </lay-collapse-item>
|
||||||
<lay-collapse-item title="标题3" id="3"> 内容3 </lay-collapse-item>
|
<lay-collapse-item title="标题3" id="3"> 内容3 </lay-collapse-item>
|
||||||
@ -153,12 +153,12 @@ import { ref } from 'vue'
|
|||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
|
|
||||||
const isAmin = ref(false)
|
const collapseTransition = ref(false)
|
||||||
const openKeys5 = ref("2")
|
const openKeys5 = ref("2")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
openKeys5,
|
openKeys5,
|
||||||
isAmin
|
collapseTransition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@
|
|||||||
<li>[新增] transition 组件 type 属性, 默认为 collapse 过渡。</li>
|
<li>[新增] transition 组件 type 属性, 默认为 collapse 过渡。</li>
|
||||||
<li>[新增] transition 组件 enable 属性, 默认为 true 启用动画。</li>
|
<li>[新增] transition 组件 enable 属性, 默认为 true 启用动画。</li>
|
||||||
<li>[新增] transition 组件 type 属性 fade 值, 提供淡出淡入效果。</li>
|
<li>[新增] transition 组件 type 属性 fade 值, 提供淡出淡入效果。</li>
|
||||||
<li>[新增] collapse 组件 isAmin 属性, 是否启用折叠动画, 默认为 true。</li>
|
<li>[新增] collapse 组件 collapseTransition 属性, 是否启用折叠动画, 默认为 true。</li>
|
||||||
|
<li>[新增] tree 组件 collapseTransition 属性, 是否启用折叠动画, 默认为 true。</li>
|
||||||
<li>[新增] input 组件 allow-clear 属性, 提供输入清空。</li>
|
<li>[新增] input 组件 allow-clear 属性, 提供输入清空。</li>
|
||||||
<li>[新增] input 组件 prefix 插槽, 提供前缀设置。</li>
|
<li>[新增] input 组件 prefix 插槽, 提供前缀设置。</li>
|
||||||
<li>[新增] input 组件 suffix 插槽, 提供后缀设置。</li>
|
<li>[新增] input 组件 suffix 插槽, 提供后缀设置。</li>
|
||||||
|
@ -11,13 +11,13 @@ import { withDefaults, provide, ref, watch } from "vue";
|
|||||||
export interface LayCollapseProps {
|
export interface LayCollapseProps {
|
||||||
modelValue?: number | string | [];
|
modelValue?: number | string | [];
|
||||||
accordion?: boolean;
|
accordion?: boolean;
|
||||||
isAmin?: boolean;
|
collapseTransition?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<LayCollapseProps>(), {
|
const props = withDefaults(defineProps<LayCollapseProps>(), {
|
||||||
modelValue: () => [],
|
modelValue: () => [],
|
||||||
accordion: false,
|
accordion: false,
|
||||||
isAmin: true,
|
collapseTransition: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 监听传入的值
|
// 监听传入的值
|
||||||
@ -33,7 +33,7 @@ const activeValues = ref<Array<any>>(([] as any[]).concat(props.modelValue));
|
|||||||
|
|
||||||
provide("layCollapse", {
|
provide("layCollapse", {
|
||||||
accordion: props.accordion,
|
accordion: props.accordion,
|
||||||
isAmin: props.isAmin,
|
collapseTransition: props.collapseTransition,
|
||||||
activeValues,
|
activeValues,
|
||||||
emit,
|
emit,
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,7 @@ const props = withDefaults(defineProps<LayCollapseItemProps>(), {
|
|||||||
disabled: false,
|
disabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const { accordion, activeValues, emit, isAmin } = inject("layCollapse") as any;
|
const { accordion, activeValues, emit, collapseTransition } = inject("layCollapse") as any;
|
||||||
|
|
||||||
let isShow = computed(() => {
|
let isShow = computed(() => {
|
||||||
return activeValues.value.includes(props.id);
|
return activeValues.value.includes(props.id);
|
||||||
@ -57,7 +57,7 @@ const showHandle = function () {
|
|||||||
<slot name="title" :props="props">{{ title }}</slot>
|
<slot name="title" :props="props">{{ title }}</slot>
|
||||||
<i class="layui-icon layui-colla-icon">{{ isShow ? "" : "" }}</i>
|
<i class="layui-icon layui-colla-icon">{{ isShow ? "" : "" }}</i>
|
||||||
</h2>
|
</h2>
|
||||||
<lay-transition :enable="isAmin">
|
<lay-transition :enable="collapseTransition">
|
||||||
<div v-if="isShow">
|
<div v-if="isShow">
|
||||||
<div class="layui-colla-content">
|
<div class="layui-colla-content">
|
||||||
<p>
|
<p>
|
||||||
|
@ -253,7 +253,7 @@
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-nav-itemed > .layui-nav-child {
|
.layui-nav-tree .layui-nav-child {
|
||||||
display: block;
|
display: block;
|
||||||
background-color: rgba(0, 0, 0, 0.2);
|
background-color: rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
@ -297,7 +297,7 @@
|
|||||||
* {
|
* {
|
||||||
color: grey !important;
|
color: grey !important;
|
||||||
}
|
}
|
||||||
.layui-nav-itemed > .layui-nav-child {
|
.layui-nav-child {
|
||||||
background-color: rgba(0, 0, 0, 0.02);
|
background-color: rgba(0, 0, 0, 0.02);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ export interface LayMenuProps {
|
|||||||
inverted?: boolean | string;
|
inverted?: boolean | string;
|
||||||
level?: boolean | string;
|
level?: boolean | string;
|
||||||
collapse?: boolean | string;
|
collapse?: boolean | string;
|
||||||
|
collapseTransition?: boolean | string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const emit = defineEmits(["update:selectedKey", "update:openKeys"]);
|
const emit = defineEmits(["update:selectedKey", "update:openKeys"]);
|
||||||
@ -28,12 +29,14 @@ const props = withDefaults(defineProps<LayMenuProps>(), {
|
|||||||
inverted: false,
|
inverted: false,
|
||||||
level: false,
|
level: false,
|
||||||
collapse: false,
|
collapse: false,
|
||||||
|
collapseTransition: true
|
||||||
});
|
});
|
||||||
|
|
||||||
let oldOpenKeys = ref<string[]>([]);
|
let oldOpenKeys = ref<string[]>([]);
|
||||||
|
|
||||||
const isTree = computed(() => props.tree);
|
const isTree = computed(() => props.tree);
|
||||||
const isCollapse = computed(() => props.collapse);
|
const isCollapse = computed(() => props.collapse);
|
||||||
|
const isCollapseTransition = computed(() => props.collapseTransition);
|
||||||
|
|
||||||
const openKeys = computed({
|
const openKeys = computed({
|
||||||
get() {
|
get() {
|
||||||
@ -72,6 +75,7 @@ provide("isTree", isTree);
|
|||||||
provide("selectedKey", selectedKey);
|
provide("selectedKey", selectedKey);
|
||||||
provide("openKeys", openKeys);
|
provide("openKeys", openKeys);
|
||||||
provide("isCollapse", isCollapse);
|
provide("isCollapse", isCollapse);
|
||||||
|
provide("isCollapseTransition", isCollapseTransition);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
watch,
|
watch,
|
||||||
} from "vue";
|
} from "vue";
|
||||||
import { onClickOutside } from "@vueuse/core";
|
import { onClickOutside } from "@vueuse/core";
|
||||||
|
import LayTransition from "../transition";
|
||||||
|
|
||||||
export interface LaySubMenuProps {
|
export interface LaySubMenuProps {
|
||||||
id: string;
|
id: string;
|
||||||
@ -29,6 +30,9 @@ const isTree: Ref<boolean> = inject("isTree") as Ref<boolean>;
|
|||||||
const selectedKey: Ref<string> = inject("selectedKey") as Ref<string>;
|
const selectedKey: Ref<string> = inject("selectedKey") as Ref<string>;
|
||||||
const openKeys: Ref<string[]> = inject("openKeys") as Ref<string[]>;
|
const openKeys: Ref<string[]> = inject("openKeys") as Ref<string[]>;
|
||||||
const isCollapse: Ref<boolean> = inject("isCollapse") as Ref<boolean>;
|
const isCollapse: Ref<boolean> = inject("isCollapse") as Ref<boolean>;
|
||||||
|
const isCollapseTransition: Ref<boolean> = inject(
|
||||||
|
"isCollapseTransition"
|
||||||
|
) as Ref<boolean>;
|
||||||
|
|
||||||
const isOpen = computed(() => {
|
const isOpen = computed(() => {
|
||||||
return openKeys.value.includes(props.id);
|
return openKeys.value.includes(props.id);
|
||||||
@ -84,7 +88,6 @@ onBeforeUnmount(() => window.removeEventListener("resize", setPosition));
|
|||||||
<template>
|
<template>
|
||||||
<li
|
<li
|
||||||
class="layui-nav-item"
|
class="layui-nav-item"
|
||||||
:class="[isOpen && isTree ? 'layui-nav-itemed' : '']"
|
|
||||||
>
|
>
|
||||||
<a href="javascript:void(0)" @click="openHandle()">
|
<a href="javascript:void(0)" @click="openHandle()">
|
||||||
<i>
|
<i>
|
||||||
@ -98,16 +101,23 @@ onBeforeUnmount(() => window.removeEventListener("resize", setPosition));
|
|||||||
class="layui-icon layui-icon-down layui-nav-more"
|
class="layui-icon layui-icon-down layui-nav-more"
|
||||||
></i>
|
></i>
|
||||||
</a>
|
</a>
|
||||||
|
<template v-if="isTree">
|
||||||
|
<lay-transition :enable="isCollapseTransition">
|
||||||
|
<div v-if="isOpen">
|
||||||
|
<dl class="layui-nav-child" v-if="isOpen">
|
||||||
|
<slot></slot>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</lay-transition>
|
||||||
|
</template>
|
||||||
|
<template v-else>
|
||||||
<dl
|
<dl
|
||||||
class="layui-nav-child"
|
|
||||||
ref="subMenuRef"
|
ref="subMenuRef"
|
||||||
:class="[
|
class="layui-nav-child layui-anim layui-anim-upbit"
|
||||||
position,
|
:class="{ 'layui-show': isOpen, position }"
|
||||||
isOpen && !isTree ? 'layui-show' : '',
|
|
||||||
!isTree ? 'layui-anim layui-anim-upbit' : '',
|
|
||||||
]"
|
|
||||||
>
|
>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</dl>
|
</dl>
|
||||||
|
</template>
|
||||||
</li>
|
</li>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user