fix: 树下拉treeSelect-搜索选中一个后不清除输入框

--bug=1046360 --user=吕梦园
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001046360
This commit is contained in:
teukkk 2024-09-24 17:28:52 +08:00 committed by 刘瑞斌
parent 6ec666b869
commit 777f1fe300
2 changed files with 44 additions and 0 deletions

View File

@ -127,6 +127,7 @@
:data="item.treeSelectData ?? []" :data="item.treeSelectData ?? []"
:disabled="isValueDisabled(item)" :disabled="isValueDisabled(item)"
allow-clear allow-clear
:multiple="item.treeSelectProps?.multiple"
v-bind="item.treeSelectProps" v-bind="item.treeSelectProps"
:placeholder="t('common.pleaseSelect')" :placeholder="t('common.pleaseSelect')"
:field-names="item.treeSelectProps?.fieldNames" :field-names="item.treeSelectProps?.fieldNames"

View File

@ -8,8 +8,10 @@
> >
<a-tree-select <a-tree-select
v-model:model-value="selectValue" v-model:model-value="selectValue"
v-model:input-value="inputValue"
:data="props.data" :data="props.data"
:disabled="props.disabled" :disabled="props.disabled"
:multiple="props.multiple"
:field-names="props.fieldNames" :field-names="props.fieldNames"
allow-search allow-search
:filter-tree-node="filterTreeNode" :filter-tree-node="filterTreeNode"
@ -20,6 +22,11 @@
}, },
}" }"
v-bind="$attrs" v-bind="$attrs"
@input-value-change="handleInputValueChange"
@popup-visible-change="handlePopupVisibleChange"
@change="handleChange"
@keyup="handleKeyup"
@clear="handleClear"
> >
<template #label="{ data: slotData }"> <template #label="{ data: slotData }">
<div class="one-line-text">{{ slotData.label }}</div> <div class="one-line-text">{{ slotData.label }}</div>
@ -44,9 +51,13 @@
data: TreeNodeData[]; data: TreeNodeData[];
fieldNames?: TreeFieldNames; fieldNames?: TreeFieldNames;
disabled?: boolean; disabled?: boolean;
multiple?: boolean;
}>(); }>();
const selectValue = defineModel<any>('modelValue', { required: true }); const selectValue = defineModel<any>('modelValue', { required: true });
const inputValue = ref('');
const tempInputValue = ref('');
const getTreeSelectTooltip = computed(() => { const getTreeSelectTooltip = computed(() => {
return () => { return () => {
let treeSelectTooltip = ''; let treeSelectTooltip = '';
@ -68,6 +79,38 @@
return treeSelectTooltip; return treeSelectTooltip;
}; };
}); });
/**
* 处理输入框搜索值变化
* @param val 搜索值
*/
function handleInputValueChange(val: string) {
inputValue.value = val;
if (val !== '') {
// arco-tree-select
tempInputValue.value = val;
}
}
function handlePopupVisibleChange(val: boolean) {
if (!val) {
tempInputValue.value = '';
}
}
function handleChange() {
if (props.multiple) {
nextTick(() => {
inputValue.value = tempInputValue.value;
});
}
}
function handleKeyup(e: KeyboardEvent) {
if (e.code === 'Backspace' && inputValue.value === '') {
tempInputValue.value = '';
}
}
function handleClear() {
tempInputValue.value = '';
}
</script> </script>
<style lang="less"> <style lang="less">