Merge branch 'develop' of https://gitee.com/layui-vue/layui-vue into develop

This commit is contained in:
落小梅
2021-10-18 00:56:16 +08:00
12 changed files with 198 additions and 56 deletions

View File

@@ -10,19 +10,31 @@
disabled ? 'layui-btn-disabled' : '',
]"
>
<slot />
<i
v-if="loading"
class="
layui-icon
layui-icon-loading-1
layui-anim
layui-anim-rotate
layui-anim-loop
"
></i>
<slot v-else />
</button>
</template>
<script setup name="LayButton" lang="ts">
import { defineProps } from 'vue'
const props = defineProps<{
type?: string
size?: string
fluid?: boolean
radius?: boolean
border?: string
disabled?: boolean
}>()
const props =
defineProps<{
type?: string
size?: string
fluid?: boolean
radius?: boolean
border?: string
disabled?: boolean
loading?: boolean
}>()
</script>

View File

@@ -4,39 +4,60 @@
lay-anim
lay-indicator="inside"
lay-arrow="always"
:style="{width:width,height:height}"
:style="{ width: width, height: height }"
>
<div carousel-item>
<div> </div>
<div> </div>
<div> </div>
<div> </div>
<div class="layui-this"></div>
<slot></slot>
</div>
<div class="layui-carousel-ind">
<ul>
<li class=""></li>
<li class=""></li>
<li class=""></li>
<li class=""></li>
<li class="layui-this"></li>
<li
v-for="ss in slots"
:key="ss"
:class="[ss.props.id === modelValue ? 'layui-this' : '']"
@click.stop="change(ss.props.id)"
></li>
</ul>
</div>
<button class="layui-icon layui-carousel-arrow" lay-type="sub"></button
><button class="layui-icon layui-carousel-arrow" lay-type="add"></button>
<button class="layui-icon layui-carousel-arrow" lay-type="sub" @click="prev"></button
><button class="layui-icon layui-carousel-arrow" lay-type="add" @click="next"></button>
</div>
</template>
<script setup name="LayCarousel" lang="ts">
import { withDefaults, defineProps } from 'vue'
import { withDefaults, defineProps, provide, useSlots, ref } from 'vue'
const slot = useSlots() as any
const slots = slot.default && slot.default()
const props = withDefaults(
defineProps<{
width: string,
height: string
width?: string
height?: string
modelValue: string
}>(),
{
width: '100%',
height: '280px'
height: '280px',
}
)
const active = ref(props.modelValue)
const emit = defineEmits(['update:modelValue','change','close'])
const change = function (id: any) {
emit('update:modelValue', id)
emit('change', id)
active.value = id
}
provide('active', active)
const prev = function() {
console.log("上一页")
}
const next = function() {
console.log("下一页")
}
</script>

View File

@@ -1,9 +1,16 @@
<template>
<li class="layui-this">
<slot></slot>
</li>
<li :class="[active === id ? 'layui-this' : '']">
<slot></slot>
</li>
</template>
<script setup name="LayCarousel" lang="ts">
import { withDefaults, defineProps } from 'vue'
<script setup name="LayCarouselItem" lang="ts">
import { defineProps, inject } from 'vue'
const props =
defineProps<{
id: string
}>()
const active = inject('active')
</script>

View File

@@ -2,6 +2,7 @@
<div
v-if="trigger === 'click'"
class="layui-dropdown"
ref="dropdownRef"
:class="[openState ? 'layui-dropdown-up' : '']"
>
<div @click="open">
@@ -30,7 +31,10 @@
</template>
<script setup name="LaySelect" lang="ts">
import { defineProps, ref } from 'vue'
import { defineProps, ref, watch } from 'vue'
import useClickOutside from '../use/useClickOutside'
const dropdownRef = ref<null | HTMLElement>(null)
const props = withDefaults(
defineProps<{
@@ -46,4 +50,13 @@ const openState = ref(false)
const open = function () {
openState.value = !openState.value
}
// 控制点击事件
const isClickOutside = useClickOutside(dropdownRef)
// 通过 watch 去监听事件的变化
watch(isClickOutside, () => {
if (isClickOutside.value) {
openState.value = false
}
})
</script>

View File

@@ -5,22 +5,38 @@
</template>
<script setup name="LayMenu" lang="ts">
import { defineProps, provide, ref } from 'vue'
import { defineProps, provide, ref, watch } from 'vue'
const props = withDefaults(
defineProps<{
selectedKey?: string
openKeys?: string[]
tree?: boolean
}>(),
{
selectedKey: '',
openKeys: function() {
return []
},
tree: false,
}
)
const isTree = ref(props.tree)
const selectKey = ref(props.selectedKey)
const selectedKey = ref(props.selectedKey)
const openKeys = ref([...props.openKeys])
provide('isTree', isTree)
provide('selectKey', selectKey)
provide('selectedKey', selectedKey)
provide('openKeys',openKeys)
const emit = defineEmits(['update:selectedKey','update:openKeys'])
watch(selectedKey, function(val) {
emit('update:selectedKey',val)
})
watch(openKeys, function(val) {
emit('update:openKeys',val)
},{deep : true})
</script>

View File

@@ -1,5 +1,5 @@
<template>
<dd :class="[selectKey === id ? 'layui-this' : '']" @click="selectHandle()">
<dd :class="[selectedKey === id ? 'layui-this' : '']" @click="selectHandle()">
<slot v-if="slots.title" name="title"></slot>
<a v-else href="javascript:void(0)">
{{title}}
@@ -18,9 +18,9 @@ const props =
title: string
}>()
const selectKey: Ref<string> = inject('selectKey') as Ref<string>
const selectedKey: Ref<string> = inject('selectedKey') as Ref<string>
const selectHandle = function () {
selectKey.value = props.id
selectedKey.value = props.id
}
</script>

View File

@@ -2,7 +2,7 @@
<li
v-if="slots.default"
class="layui-nav-item"
:class="[isOpen && isTree ? 'layui-nav-itemed' : '']"
:class="[openKeys.includes(id) && isTree ? 'layui-nav-itemed' : '']"
>
<a href="javascript:void(0)" @click="openHandle">
{{ title }}
@@ -11,7 +11,7 @@
<dl
class="layui-nav-child"
:class="[
isOpen && !isTree ? 'layui-show' : '',
openKeys.includes(id) && !isTree ? 'layui-show' : '',
!isTree ? 'layui-anim layui-anim-upbit' : '',
]"
>
@@ -22,7 +22,7 @@
<li
v-else
class="layui-nav-item"
:class="[selectKey === id ? 'layui-this' : '']"
:class="[selectedKey === id ? 'layui-this' : '']"
@click="selectHandle()"
>
<slot v-if="slots.title" name="title"></slot>
@@ -42,16 +42,20 @@ const props =
title: string
}>()
const isOpen = ref(false)
const isTree = inject('isTree')
const selectKey: Ref<string> = inject('selectKey') as Ref<string>
const selectedKey: Ref<string> = inject('selectedKey') as Ref<string>
const openKeys: Ref<string[]> = inject('openKeys') as Ref<string[]>
const openHandle = function () {
isOpen.value = !isOpen.value
if(openKeys.value.includes(props.id)) {
openKeys.value.splice(openKeys.value.indexOf(props.id),1)
} else {
openKeys.value.push(props.id)
}
}
const selectHandle = function () {
selectKey.value = props.id
selectedKey.value = props.id
}
</script>

View File

@@ -0,0 +1,29 @@
import { ref, onMounted, onUnmounted, Ref } from 'vue'
const useClickOutside = (elementRef: Ref<HTMLElement | null>) => {
// 设置一个导出值
const isClickOutside = ref(false);
// 给界面绑定上事件
const handler = (e: MouseEvent) => {
if (elementRef.value) {
// e.target 有可能是为 null 所以需要断言
if (elementRef.value.contains(e.target as HTMLElement)) {
// 判断目标节点是不是当前的节点
isClickOutside.value = false;
} else {
isClickOutside.value = true
}
}
}
onMounted(() => {
document.addEventListener('click', handler);
});
onUnmounted(() => {
document.removeEventListener('click', handler);
});
return isClickOutside;
}
export default useClickOutside;