perf(select): 新增 select 下拉选择 change 事件, disabled 禁用状态
This commit is contained in:
parent
5ee145909c
commit
7603822299
@ -73,3 +73,11 @@ export default {
|
|||||||
| Name | Description | Accepted Values |
|
| Name | Description | Accepted Values |
|
||||||
| ------- | -------- | --------------- |
|
| ------- | -------- | --------------- |
|
||||||
| trigger | 触发方式 | `click` `hover` |
|
| trigger | 触发方式 | `click` `hover` |
|
||||||
|
|
||||||
|
::: field Dropdown 插槽
|
||||||
|
:::
|
||||||
|
|
||||||
|
| Name | Description | Accepted Values |
|
||||||
|
| ------- | -------- | --------------- |
|
||||||
|
| content | 下拉内容 | -- |
|
||||||
|
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
|
::: field 基础使用
|
||||||
|
:::
|
||||||
|
|
||||||
::: demo
|
::: demo
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-select>
|
<lay-select>
|
||||||
|
<lay-select-option value="1" label="学习"></lay-select-option>
|
||||||
|
<lay-select-option value="2" label="编码"></lay-select-option>
|
||||||
|
<lay-select-option value="3" label="运动"></lay-select-option>
|
||||||
</lay-select>
|
</lay-select>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -18,4 +23,64 @@ export default {
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
::: field 选择禁用
|
||||||
|
:::
|
||||||
|
|
||||||
|
::: demo
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<lay-select v-model="selected">
|
||||||
|
<lay-select-option value="1" label="学习"></lay-select-option>
|
||||||
|
<lay-select-option value="2" label="编码" disabled="true"></lay-select-option>
|
||||||
|
<lay-select-option value="3" label="运动"></lay-select-option>
|
||||||
|
</lay-select>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
setup() {
|
||||||
|
|
||||||
|
const selected = ref('1')
|
||||||
|
|
||||||
|
return {
|
||||||
|
selected
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
:::
|
||||||
|
|
||||||
|
::: field select 属性
|
||||||
|
:::
|
||||||
|
|
||||||
|
| Name | Description | Accepted Values |
|
||||||
|
| -------- | ---- | ----------------------- |
|
||||||
|
| name | 原生 name 属性 | -- |
|
||||||
|
| v-model | 选中值 | -- |
|
||||||
|
|
||||||
|
::: field select-option 属性
|
||||||
|
:::
|
||||||
|
|
||||||
|
| Name | Description | Accepted Values |
|
||||||
|
| -------- | ---- | ----------------------- |
|
||||||
|
| label | 标签 | -- |
|
||||||
|
| value | 值 | -- |
|
||||||
|
|
||||||
|
::: field select-option 插槽
|
||||||
|
:::
|
||||||
|
|
||||||
|
| Name | Description | Accepted Values |
|
||||||
|
| -------- | ---- | ----------------------- |
|
||||||
|
| default | 默认 | -- |
|
||||||
|
|
||||||
|
::: field select 事件
|
||||||
|
:::
|
||||||
|
|
||||||
|
| Name | Description | Accepted Values |
|
||||||
|
| -------- | ---- | ----------------------- |
|
||||||
|
| change | 切换事件 | value |
|
@ -7,6 +7,8 @@
|
|||||||
<lay-timeline-item title="0.1.8">
|
<lay-timeline-item title="0.1.8">
|
||||||
[新增] table 表格 size 属性, 提供不同尺寸。<br>
|
[新增] table 表格 size 属性, 提供不同尺寸。<br>
|
||||||
[新增] transfer 穿梭框 item 插槽, 允许自定义列表项。<br>
|
[新增] transfer 穿梭框 item 插槽, 允许自定义列表项。<br>
|
||||||
|
[新增] select 下拉选择 change 事件, 值变动触发回调。<br>
|
||||||
|
[新增] select-option 下拉选择项 disabled 属性, 允许可选项禁用。<br>
|
||||||
[修复] transfer 穿梭框 切换 逻辑。<br>
|
[修复] transfer 穿梭框 切换 逻辑。<br>
|
||||||
[删除] dropdown 下拉菜单 padding 样式。<br>
|
[删除] dropdown 下拉菜单 padding 样式。<br>
|
||||||
</lay-timeline-item>
|
</lay-timeline-item>
|
||||||
|
@ -322,6 +322,12 @@ export default {
|
|||||||
subTitle: 'carousel',
|
subTitle: 'carousel',
|
||||||
path: '/zh-CN/components/carousel',
|
path: '/zh-CN/components/carousel',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: 39,
|
||||||
|
title: '下拉选择',
|
||||||
|
subTitle: 'select',
|
||||||
|
path: '/zh-CN/components/select',
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const selected = ref(1)
|
const selected = ref(1)
|
||||||
|
@ -214,6 +214,10 @@ const zhCN = [
|
|||||||
path: '/zh-CN/components/carousel',
|
path: '/zh-CN/components/carousel',
|
||||||
component: () => import('../../docs/zh-CN/components/carousel.md'),
|
component: () => import('../../docs/zh-CN/components/carousel.md'),
|
||||||
meta: { title: '轮播' },
|
meta: { title: '轮播' },
|
||||||
|
},{
|
||||||
|
path: '/zh-CN/components/select',
|
||||||
|
component: () => import('../../docs/zh-CN/components/select.md'),
|
||||||
|
meta: { title: '下拉选择' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -1,21 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<select :name="name" lay-verify="required" />
|
|
||||||
<div
|
<div
|
||||||
|
ref="selectRef"
|
||||||
class="layui-unselect layui-form-select"
|
class="layui-unselect layui-form-select"
|
||||||
:class="[openState ? 'layui-form-selected' : '']"
|
:class="[openState ? 'layui-form-selected' : '']"
|
||||||
@click="open"
|
|
||||||
>
|
>
|
||||||
<div class="layui-select-title">
|
<div class="layui-select-title" @click="open">
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="请选择"
|
placeholder="请选择"
|
||||||
:value="selectItem.label"
|
:value="selectItem.label"
|
||||||
readonly=""
|
readonly=""
|
||||||
|
:name="name"
|
||||||
class="layui-input layui-unselect"
|
class="layui-input layui-unselect"
|
||||||
/><i class="layui-edge" />
|
/><i class="layui-edge" />
|
||||||
</div>
|
</div>
|
||||||
<dl class="layui-anim layui-anim-upbit" style="">
|
<dl class="layui-anim layui-anim-upbit">
|
||||||
<dd lay-value="" class="layui-select-tips" @click="clean">请选择</dd>
|
|
||||||
<slot />
|
<slot />
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
@ -23,6 +22,16 @@
|
|||||||
|
|
||||||
<script setup name="LaySelect" lang="ts">
|
<script setup name="LaySelect" lang="ts">
|
||||||
import { defineProps, provide, reactive, ref, watch } from 'vue'
|
import { defineProps, provide, reactive, ref, watch } from 'vue'
|
||||||
|
import useClickOutside from '../../use/useClickOutside'
|
||||||
|
|
||||||
|
const selectRef = ref<null | HTMLElement>(null)
|
||||||
|
const isClickOutside = useClickOutside(selectRef)
|
||||||
|
|
||||||
|
watch(isClickOutside, () => {
|
||||||
|
if (isClickOutside.value) {
|
||||||
|
openState.value = false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
modelValue?: string
|
modelValue?: string
|
||||||
@ -32,22 +41,19 @@ const props = defineProps<{
|
|||||||
const openState = ref(false)
|
const openState = ref(false)
|
||||||
|
|
||||||
const open = function () {
|
const open = function () {
|
||||||
openState.value = !openState.value
|
openState.value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
const selectItem = reactive({ label: '', value: props.modelValue })
|
const selectItem = reactive({ label: '', value: props.modelValue })
|
||||||
|
|
||||||
provide('selectItem', selectItem)
|
provide('selectItem', selectItem)
|
||||||
|
provide('openState', openState)
|
||||||
|
|
||||||
// select update 时, 通知 change 事件
|
// select update 时, 通知 change 事件
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue','change'])
|
||||||
|
|
||||||
watch(selectItem, function (item) {
|
watch(selectItem, function (item) {
|
||||||
|
emit('change', item.value)
|
||||||
emit('update:modelValue', item.value)
|
emit('update:modelValue', item.value)
|
||||||
})
|
})
|
||||||
|
|
||||||
const clean = function () {
|
|
||||||
selectItem.value = ''
|
|
||||||
selectItem.label = ''
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<dd
|
<dd
|
||||||
:value="value"
|
:value="value"
|
||||||
:class="[selectItem.value === value ? 'layui-this' : '']"
|
:class="[selectItem.value === value ? 'layui-this' : '',disabled ? 'layui-disabled':'']"
|
||||||
@click="selectHandle"
|
@click="selectHandle"
|
||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
@ -10,22 +10,27 @@
|
|||||||
|
|
||||||
<script setup name="LaySelectOption" lang="ts">
|
<script setup name="LaySelectOption" lang="ts">
|
||||||
import { SelectItem } from '../type'
|
import { SelectItem } from '../type'
|
||||||
import { defineProps, inject } from 'vue'
|
import { defineProps, inject, Ref } from 'vue'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
value?: string
|
value?: string
|
||||||
label?: string
|
label?: string
|
||||||
|
disabled?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const selectItem = inject('selectItem') as SelectItem
|
const selectItem = inject('selectItem') as SelectItem
|
||||||
|
const openState = inject('openState') as Ref<boolean>
|
||||||
|
|
||||||
const selectHandle = function () {
|
const selectHandle = function () {
|
||||||
|
if(props.disabled) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
openState.value = false
|
||||||
selectItem.value = props.value
|
selectItem.value = props.value
|
||||||
selectItem.label = props.label
|
selectItem.label = props.label
|
||||||
}
|
}
|
||||||
|
|
||||||
// init selected
|
// init selected
|
||||||
|
|
||||||
if (selectItem.value === props.value) {
|
if (selectItem.value === props.value) {
|
||||||
selectItem.value = props.value
|
selectItem.value = props.value
|
||||||
selectItem.label = props.label
|
selectItem.label = props.label
|
||||||
|
Loading…
Reference in New Issue
Block a user