feat(tab): 新增 allowClose 属性, change close 事件

This commit is contained in:
就眠仪式 2021-10-15 23:52:01 +08:00
parent b083b50111
commit 6c0cb3041a
8 changed files with 104 additions and 16 deletions

View File

@ -1,7 +1,12 @@
::: demo
<template>
<lay-carousel></lay-carousel>
<lay-carousel>
<lay-carousel-item>条目一</lay-carousel-item>
<lay-carousel-item>条目二</lay-carousel-item>
<lay-carousel-item>条目三</lay-carousel-item>
<lay-carousel-item>条目四</lay-carousel-item>
</lay-carousel>
</template>
<script>

View File

@ -76,12 +76,59 @@ export default {
:::
::: demo
<template>
<lay-tab type="card" v-model="current3" :allow-close="allowClose" @change="change" @close="close">
<lay-tab-item title="选项一" id="1"><div style="padding:20px">选项一</div></lay-tab-item>
<lay-tab-item title="选项二" id="2"><div style="padding:20px">选项二</div></lay-tab-item>
</lay-tab>
</template>
<script>
import { ref } from 'vue'
export default {
setup() {
const current4 = ref("1")
const allowClose = ref(true)
const change = function(id){
console.log("当前值:" +id)
}
const close = function(id){
console.log("需要关闭:" + id)
}
return {
current3,
allowClose,
change,
close
}
}
}
</script>
:::
::: field tab attributes
:::
| | | |
| Name | Description | Accepted Values |
| ------- | -------- | -------------- |
| v-model | 当前激活 | -- |
| type | 主题样式 | `card` `brief` |
| type | 主题样式 | -- |
| allow-close | 允许关闭 | `true` `false` |
::: field tab events
:::
| Name | Description | Accepted Params |
| -------- | ---- | ----------------------- |
| change | 选中切换 | -- |
| close | 关闭事件 | -- |

View File

@ -56,7 +56,7 @@ import LayTransfer from './module/transfer/index'
import LayCheckboxGroup from './module/checkboxGroup/index'
import LaySlider from './module/slider/index'
import LayCarousel from './module/carousel/index'
import LayCarouselItem from './module/carouselItem/index'
const components: Record<string, IDefineComponent> = {
LayRadio,
@ -112,7 +112,8 @@ const components: Record<string, IDefineComponent> = {
LayTransfer,
LayCheckboxGroup,
LaySlider,
LayCarousel
LayCarousel,
LayCarouselItem
}
const install = (app: App, options?: InstallOptions): void => {
@ -125,8 +126,6 @@ const install = (app: App, options?: InstallOptions): void => {
}
}
console.log('document Site : http://layui-vue.pearadmin.com')
export {
LayRadio,
LayIcon,
@ -182,6 +181,7 @@ export {
LayCheckboxGroup,
LaySlider,
LayCarousel,
LayCarouselItem,
install,
}

View File

@ -1,13 +1,12 @@
<template>
<div
class="layui-carousel"
id="test1"
lay-anim=""
lay-anim
lay-indicator="inside"
lay-arrow="always"
style="width: 100%; height: 280px"
:style="{width:width,height:height}"
>
<div carousel-item="">
<div carousel-item>
<div> </div>
<div> </div>
<div> </div>
@ -28,4 +27,16 @@
</div>
</template>
<script setup name="LayCarousel" lang="ts">
import { withDefaults, defineProps } from 'vue'
const props = withDefaults(
defineProps<{
width: string,
height: string
}>(),
{
width: '100%',
height: '280px'
}
)
</script>

View File

@ -0,0 +1,9 @@
import type { App } from 'vue'
import Component from './index.vue'
import type { IDefineComponent } from '../type/index'
Component.install = (app: App) => {
app.component(Component.name || 'LayCarouselItem', Component)
}
export default Component as IDefineComponent

View File

@ -0,0 +1,9 @@
<template>
<li class="layui-this">
<slot></slot>
</li>
</template>
<script setup name="LayCarousel" lang="ts">
import { withDefaults, defineProps } from 'vue'
</script>

View File

@ -1,5 +1,5 @@
<template>
<div class="layui-checkbox-group"></div>
</template>
<script setup name="LayCheckbox" lang="ts">

View File

@ -5,9 +5,10 @@
v-for="ss in slots"
:key="ss"
:class="[ss.props.id === modelValue ? 'layui-this' : '']"
@click="change(ss.props.id)"
@click.stop="change(ss.props.id)"
>
{{ ss.props.title }}
<i @click.stop="close(ss.props.id)" v-if="allowClose" class="layui-icon layui-icon-close layui-unselect layui-tab-close"></i>
</li>
</ul>
<div class="layui-tab-content">
@ -17,7 +18,7 @@
</template>
<script setup name="LayTab" lang="ts">
import { defineProps, inject, provide, ref, useSlots } from 'vue'
import { defineProps, provide, ref, useSlots } from 'vue'
const slot = useSlots() as any
const slots = slot.default && slot.default()
@ -25,17 +26,23 @@ const slots = slot.default && slot.default()
const props = defineProps<{
type?: string
modelValue: string
allowClose?: boolean
}>()
// select update , change
const emit = defineEmits(['update:modelValue'])
const emit = defineEmits(['update:modelValue','change','close'])
const active = ref(props.modelValue)
const change = function (id: any) {
emit('update:modelValue', id)
emit('change', id)
active.value = id
}
const close = function(id: any) {
emit('close', id)
}
provide('active', active)
</script>