[新增] selectOption 支持传入keyword属性用于自定义关键词查询内容

This commit is contained in:
castleiMac 2022-04-03 17:44:55 +08:00
parent 1cdfa5d112
commit 18ee8db079
2 changed files with 39 additions and 3 deletions

View File

@ -131,6 +131,34 @@ export default {
:::
::: title 选择项自定义搜索内容可以在keyword属性中传入拼音用于支持拼音搜索
:::
::: 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 海量数据
:::
@ -236,6 +264,7 @@ export default {
| 属性 | 描述 | 接收值 |
| ------ | ---------- | --------------- |
| change | 切换事件 | value |
| search | 关键词变化事件 | 用户输入的关键词 string |
:::
@ -251,6 +280,7 @@ export default {
| ------------ | --------------------- | ------------------------- | -------------- | -------- |
| label | 标签值(`必填`) | `string` | - | - |
| value | 值 | `string` / `number` | - | - |
| keyword | 用于匹配关键词的数据,传入文本+拼音可以支持拼音搜索 | `string` | - | - |
| disabled | 是否禁用 | `boolean` | `true` `false` | `false` |
:::

View File

@ -7,16 +7,19 @@ export default {
<script setup lang="ts">
import LayCheckbox from "../checkbox";
import { SelectItem, SelectItemHandle, SelectItemPush } from "../../types";
import { computed, inject, onMounted, Ref } from "vue";
import { computed, inject, onMounted, Ref, ref } from "vue";
export interface LaySelectOptionProps {
value: string | null | undefined;
label?: string;
label: string;
keyword?: string;
disabled?: boolean;
}
const props = withDefaults(defineProps<LaySelectOptionProps>(), {
disabled: false,
keyword: "",
label: ""
});
const selectItemHandle = inject("selectItemHandle") as SelectItemHandle;
@ -57,15 +60,18 @@ const callSelectItemPush = function () {
// @ts-ignore
selectItemPush(item);
};
const search = ref("")
onMounted(() => {
search.value = props.keyword || props.label
callSelectItemPush();
selected.value && callSelectItemHandle();
});
</script>
<template>
<dd
v-show="keyword ? props.label.includes(keyword) : true"
v-show="keyword ? search.includes(keyword) : true"
:value="value"
:class="[{ 'layui-this': selected }, { 'layui-disabled': disabled }]"
@click="selectHandle"