[新增] select组件支持关键词筛选列表
This commit is contained in:
parent
d686c7ef41
commit
49f5997934
@ -4,7 +4,7 @@
|
|||||||
::: title 基本介绍
|
::: title 基本介绍
|
||||||
:::
|
:::
|
||||||
|
|
||||||
::: describe 用于代替原生的选择器,或者需要一个更优雅的多选器时。
|
::: describe 用于代替原生的选择器,或者需要一个更优雅的多选器时。支持关键词查询
|
||||||
:::
|
:::
|
||||||
|
|
||||||
::: title 基础使用
|
::: title 基础使用
|
||||||
@ -40,10 +40,10 @@ export default {
|
|||||||
::: demo
|
::: demo
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-button @click="change1">切换-当前值 : {{value}}</lay-button>
|
<lay-button @click="change1">切换-当前值 : {{value2}}</lay-button>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<lay-select v-model="value">
|
<lay-select v-model="value2">
|
||||||
<lay-select-option value="1" label="学习"></lay-select-option>
|
<lay-select-option value="1" label="学习"></lay-select-option>
|
||||||
<lay-select-option value="2" label="编码"></lay-select-option>
|
<lay-select-option value="2" label="编码"></lay-select-option>
|
||||||
<lay-select-option value="3" label="运动"></lay-select-option>
|
<lay-select-option value="3" label="运动"></lay-select-option>
|
||||||
@ -55,13 +55,13 @@ import { ref } from 'vue'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
const value = ref(null);
|
const value2 = ref(null);
|
||||||
var i = 1;
|
var i = 1;
|
||||||
function change1(){
|
function change1(){
|
||||||
value.value=i++%3+1
|
value2.value=i++%3+1
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
value,
|
value2,
|
||||||
change1
|
change1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ export default {
|
|||||||
::: demo
|
::: demo
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<lay-select v-model="selected">
|
<lay-select v-model="selected2">
|
||||||
<lay-select-option value="1" label="学习"></lay-select-option>
|
<lay-select-option value="1" label="学习"></lay-select-option>
|
||||||
<lay-select-option value="3" label="运动"></lay-select-option>
|
<lay-select-option value="3" label="运动"></lay-select-option>
|
||||||
<lay-select-option value="1" label="学习"></lay-select-option>
|
<lay-select-option value="1" label="学习"></lay-select-option>
|
||||||
@ -132,10 +132,10 @@ import { ref } from 'vue'
|
|||||||
export default {
|
export default {
|
||||||
setup() {
|
setup() {
|
||||||
|
|
||||||
const selected = ref('1')
|
const selected2 = ref('1')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
selected
|
selected2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +96,22 @@ watch(props, () => {
|
|||||||
|
|
||||||
// 禁止操作子项
|
// 禁止操作子项
|
||||||
const disabledItemMap: { [key: string | number]: boolean } = {};
|
const disabledItemMap: { [key: string | number]: boolean } = {};
|
||||||
|
const txt = ref("")
|
||||||
|
const input = ref(false)
|
||||||
|
const value = computed({
|
||||||
|
set(v: any) {
|
||||||
|
txt.value = v;
|
||||||
|
},
|
||||||
|
get() {
|
||||||
|
if (input.value) {
|
||||||
|
return txt.value;
|
||||||
|
}
|
||||||
|
// return txt.value;
|
||||||
|
return !selectItem.value.multiple && selectItem.value.value !== null
|
||||||
|
? selectItem.value.label
|
||||||
|
: null
|
||||||
|
}
|
||||||
|
})
|
||||||
const selectItemHandle = function (
|
const selectItemHandle = function (
|
||||||
_selectItem: SelectItem,
|
_selectItem: SelectItem,
|
||||||
isChecked?: boolean
|
isChecked?: boolean
|
||||||
@ -103,6 +119,7 @@ const selectItemHandle = function (
|
|||||||
if (!props.multiple) {
|
if (!props.multiple) {
|
||||||
openState.value = false;
|
openState.value = false;
|
||||||
}
|
}
|
||||||
|
txt.value = ""
|
||||||
disabledItemMap[_selectItem.value as string | number] =
|
disabledItemMap[_selectItem.value as string | number] =
|
||||||
_selectItem.disabled as boolean;
|
_selectItem.disabled as boolean;
|
||||||
if (typeof isChecked !== "boolean") {
|
if (typeof isChecked !== "boolean") {
|
||||||
@ -144,6 +161,7 @@ const selectItemPush = function (p: SelectItem) {
|
|||||||
provide("selectItemHandle", selectItemHandle);
|
provide("selectItemHandle", selectItemHandle);
|
||||||
provide("selectItemPush", selectItemPush);
|
provide("selectItemPush", selectItemPush);
|
||||||
provide("selectItem", selectItem);
|
provide("selectItem", selectItem);
|
||||||
|
provide("keyword", txt)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -163,12 +181,9 @@ provide("selectItem", selectItem);
|
|||||||
: emptyMessage ?? placeholder
|
: emptyMessage ?? placeholder
|
||||||
"
|
"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
readonly
|
v-model="value"
|
||||||
:value="
|
@input="input = true"
|
||||||
!selectItem.multiple && selectItem.value !== null
|
@blur="input = false"
|
||||||
? selectItem.label
|
|
||||||
: null
|
|
||||||
"
|
|
||||||
:name="name"
|
:name="name"
|
||||||
:class="[
|
:class="[
|
||||||
'layui-input',
|
'layui-input',
|
||||||
@ -204,8 +219,7 @@ provide("selectItem", selectItem);
|
|||||||
: null,
|
: null,
|
||||||
})
|
})
|
||||||
"
|
"
|
||||||
>
|
></i>
|
||||||
</i>
|
|
||||||
</lay-badge>
|
</lay-badge>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
@ -22,6 +22,7 @@ const props = withDefaults(defineProps<LaySelectOptionProps>(), {
|
|||||||
const selectItemHandle = inject("selectItemHandle") as SelectItemHandle;
|
const selectItemHandle = inject("selectItemHandle") as SelectItemHandle;
|
||||||
const selectItem = inject("selectItem") as Ref<SelectItem>;
|
const selectItem = inject("selectItem") as Ref<SelectItem>;
|
||||||
const selectItemPush = inject("selectItemPush") as Ref<SelectItemPush>;
|
const selectItemPush = inject("selectItemPush") as Ref<SelectItemPush>;
|
||||||
|
const keyword = inject('keyword') as Ref<string>
|
||||||
|
|
||||||
const selectHandle = function () {
|
const selectHandle = function () {
|
||||||
!props.disabled && callSelectItemHandle(!selected.value);
|
!props.disabled && callSelectItemHandle(!selected.value);
|
||||||
@ -45,7 +46,7 @@ const selected = computed({
|
|||||||
}
|
}
|
||||||
return selectItem.value.value === props.value;
|
return selectItem.value.value === props.value;
|
||||||
},
|
},
|
||||||
set(val) {},
|
set(val) { },
|
||||||
});
|
});
|
||||||
const callSelectItemPush = function () {
|
const callSelectItemPush = function () {
|
||||||
let item = {
|
let item = {
|
||||||
@ -64,17 +65,13 @@ onMounted(() => {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<dd
|
<dd
|
||||||
|
v-show="keyword ? props.label.includes(keyword) : true"
|
||||||
:value="value"
|
:value="value"
|
||||||
:class="[{ 'layui-this': selected }, { 'layui-disabled': disabled }]"
|
:class="[{ 'layui-this': selected }, { 'layui-disabled': disabled }]"
|
||||||
@click="selectHandle"
|
@click="selectHandle"
|
||||||
>
|
>
|
||||||
<template v-if="selectItem.multiple">
|
<template v-if="selectItem.multiple">
|
||||||
<lay-checkbox
|
<lay-checkbox skin="primary" v-model="selected" @change="selectHandle" label />
|
||||||
skin="primary"
|
|
||||||
v-model="selected"
|
|
||||||
@change="selectHandle"
|
|
||||||
label=""
|
|
||||||
/>
|
|
||||||
</template>
|
</template>
|
||||||
<slot>{{ label }}</slot>
|
<slot>{{ label }}</slot>
|
||||||
</dd>
|
</dd>
|
||||||
|
Loading…
Reference in New Issue
Block a user