✨(component): 实现 select 组件单选多选禁用
This commit is contained in:
parent
c97fedb8c5
commit
8ed10c4a67
@ -13,8 +13,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-select-options {
|
.layui-select-content {
|
||||||
padding: 5px 0;
|
max-height: 300px;
|
||||||
|
padding: 5px 0px;
|
||||||
|
overflow: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-select .layui-icon-triangle-d {
|
.layui-select .layui-icon-triangle-d {
|
||||||
@ -27,7 +29,7 @@
|
|||||||
transform: rotate(180deg);
|
transform: rotate(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-select-options .layui-select-option {
|
.layui-select-content .layui-select-option {
|
||||||
padding: 0 10px;
|
padding: 0 10px;
|
||||||
line-height: 36px;
|
line-height: 36px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
@ -35,11 +37,16 @@
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-select-options .layui-select-option .layui-form-checkbox[lay-skin="primary"] {
|
.layui-select-content .layui-select-option.layui-disabled {
|
||||||
|
color: var(--global-neutral-color-6)!important;
|
||||||
|
cursor: not-allowed!important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.layui-select-content .layui-select-option .layui-form-checkbox[lay-skin="primary"] {
|
||||||
padding-left: 12px;
|
padding-left: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.layui-select-options .layui-select-option.layui-this {
|
.layui-select-content .layui-select-option.layui-this {
|
||||||
background-color: var(--global-neutral-color-2);
|
background-color: var(--global-neutral-color-2);
|
||||||
color: var(--global-checked-color);
|
color: var(--global-checked-color);
|
||||||
font-size: 700;
|
font-size: 700;
|
||||||
|
@ -56,7 +56,7 @@ const props = withDefaults(defineProps<LaySelectProps>(), {
|
|||||||
multiple: false,
|
multiple: false,
|
||||||
size: "md",
|
size: "md",
|
||||||
allowClear: false,
|
allowClear: false,
|
||||||
showSearch: false
|
showSearch: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const slots = useSlots();
|
const slots = useSlots();
|
||||||
@ -100,7 +100,7 @@ onMounted(() => {
|
|||||||
|
|
||||||
const handleSearch = (value: string) => {
|
const handleSearch = (value: string) => {
|
||||||
searchValue.value = value;
|
searchValue.value = value;
|
||||||
}
|
};
|
||||||
|
|
||||||
const getOption = function (nodes: VNode[]) {
|
const getOption = function (nodes: VNode[]) {
|
||||||
nodes?.map((item: VNode) => {
|
nodes?.map((item: VNode) => {
|
||||||
@ -174,7 +174,7 @@ provide("multiple", multiple);
|
|||||||
</template>
|
</template>
|
||||||
</lay-input>
|
</lay-input>
|
||||||
<template #content>
|
<template #content>
|
||||||
<dl class="layui-select-options">
|
<dl class="layui-select-content">
|
||||||
<div class="layui-select-search" v-if="multiple && showSearch">
|
<div class="layui-select-search" v-if="multiple && showSearch">
|
||||||
<lay-input
|
<lay-input
|
||||||
v-model="searchValue"
|
v-model="searchValue"
|
||||||
|
@ -37,7 +37,7 @@ const searchValue: Ref<string> = inject("searchValue") as Ref<string>;
|
|||||||
const multiple: ComputedRef = inject("multiple") as ComputedRef;
|
const multiple: ComputedRef = inject("multiple") as ComputedRef;
|
||||||
|
|
||||||
const handleSelect = () => {
|
const handleSelect = () => {
|
||||||
if (!multiple.value) {
|
if (!multiple.value && !props.disabled) {
|
||||||
openState.value = false;
|
openState.value = false;
|
||||||
selectedValue.value = props.value;
|
selectedValue.value = props.value;
|
||||||
select();
|
select();
|
||||||
@ -95,12 +95,13 @@ onMounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<dd
|
<dd
|
||||||
v-show="display"
|
v-show="display"
|
||||||
:class="['layui-select-option', { 'layui-this': selected && !multiple }]"
|
:class="['layui-select-option', { 'layui-this': selected && !multiple, 'layui-disabled': disabled}]"
|
||||||
@click="handleSelect"
|
@click="handleSelect"
|
||||||
>
|
>
|
||||||
<template v-if="multiple">
|
<template v-if="multiple">
|
||||||
<lay-checkbox
|
<lay-checkbox
|
||||||
v-model="selectedValue"
|
v-model="selectedValue"
|
||||||
|
:disabled="disabled"
|
||||||
:value="value"
|
:value="value"
|
||||||
skin="primary"
|
skin="primary"
|
||||||
></lay-checkbox>
|
></lay-checkbox>
|
||||||
|
@ -99,7 +99,6 @@ npm install @layui/icons-vue
|
|||||||
|
|
||||||
```vue
|
```vue
|
||||||
<template>
|
<template>
|
||||||
<!-- 组件图标 -->
|
|
||||||
<AlignCenterIcon></AlignCenterIcon>
|
<AlignCenterIcon></AlignCenterIcon>
|
||||||
<DiamondIcon></DiamondIcon>
|
<DiamondIcon></DiamondIcon>
|
||||||
</template>
|
</template>
|
||||||
|
@ -109,7 +109,6 @@ export default {
|
|||||||
|
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
|
||||||
::: title 传入选项
|
::: title 传入选项
|
||||||
:::
|
:::
|
||||||
|
|
||||||
@ -139,123 +138,6 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
:::
|
:::
|
||||||
|
|
||||||
::: title 检索回调
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: demo
|
|
||||||
<template>
|
|
||||||
<lay-select @search="search" v-model="selected">
|
|
||||||
<lay-select-option value="1" label="学习"></lay-select-option>
|
|
||||||
<lay-select-option value="2" label="编码" disabled></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');
|
|
||||||
function search(txt){
|
|
||||||
console.log('关键词:',txt)
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
selected,search
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: title 定义标识
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: demo
|
|
||||||
<template>
|
|
||||||
<lay-select v-model="selected">
|
|
||||||
<lay-select-option value="1" label="学习" keyword="学习xuexi"></lay-select-option>
|
|
||||||
<lay-select-option value="2" label="编码" disabled></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>
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: title 传入选项
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: demo
|
|
||||||
<template>
|
|
||||||
<lay-select v-model="selected" :items="items">
|
|
||||||
</lay-select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
setup() {
|
|
||||||
const selected = ref('1');
|
|
||||||
const items=ref([
|
|
||||||
{label:'选项1',value:1,keyword:'选项xuanxiang1'},
|
|
||||||
{label:'选项2',value:2,keyword:'选项xuanxiang2'},
|
|
||||||
{label:'选项3',value:3,keyword:'选项xuanxiang3',disabled:true},
|
|
||||||
])
|
|
||||||
return {
|
|
||||||
items,
|
|
||||||
selected,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: title 创建回调
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: demo
|
|
||||||
<template>
|
|
||||||
<lay-select v-model="selected" :items="items" :create="true" @create="createEvent"></lay-select>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import { ref } from 'vue'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
setup() {
|
|
||||||
const selected = ref('1');
|
|
||||||
const items=ref([
|
|
||||||
{label:'选项1',value:'1',keyword:'选项xuanxiang1'},
|
|
||||||
{label:'选项2',value:2,keyword:'选项xuanxiang2'},
|
|
||||||
{label:'选项3',value:3,keyword:'选项xuanxiang3',disabled:true},
|
|
||||||
]);
|
|
||||||
function createEvent(v){
|
|
||||||
items.value.push({
|
|
||||||
label:v,
|
|
||||||
value:items.value.length
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
selected,items,createEvent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: title 海量数据
|
::: title 海量数据
|
||||||
:::
|
:::
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user