From 33b556546a03e240cfcb3662286cc6dc70b70263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=91=B8=E9=B1=BC=E5=8E=BB?= <1780903673@qq.com> Date: Tue, 13 May 2025 13:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=20Inpu?= =?UTF-8?q?t=E3=80=81Textarea=E3=80=81Search=20=E7=BB=84=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=B8=85=E7=A9=BA=E5=90=8E=E4=B8=8D=E8=81=9A=E7=84=A6?= =?UTF-8?q?=E6=97=B6=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E5=A4=B1=E7=84=A6?= =?UTF-8?q?=E4=BA=8B=E4=BB=B6=E7=9A=84=E9=97=AE=E9=A2=98=20(#1046)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/wd-input/wd-input.vue | 2 +- .../components/wd-search/wd-search.vue | 86 ++++++++----------- .../components/wd-textarea/wd-textarea.vue | 2 +- 3 files changed, 38 insertions(+), 52 deletions(-) diff --git a/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue b/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue index 75a477db..a8e36caf 100644 --- a/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue +++ b/src/uni_modules/wot-design-uni/components/wd-input/wd-input.vue @@ -236,10 +236,10 @@ function togglePwdVisible() { isPwdVisible.value = !isPwdVisible.value } async function handleClear() { - clearing.value = true focusing.value = false inputValue.value = '' if (props.focusWhenClear) { + clearing.value = true focused.value = false } await pause() diff --git a/src/uni_modules/wot-design-uni/components/wd-search/wd-search.vue b/src/uni_modules/wot-design-uni/components/wd-search/wd-search.vue index a9c97b51..b15ee90a 100644 --- a/src/uni_modules/wot-design-uni/components/wd-search/wd-search.vue +++ b/src/uni_modules/wot-design-uni/components/wd-search/wd-search.vue @@ -7,24 +7,24 @@ {{ placeholder || translate('search') }} - + - + @@ -61,14 +61,14 @@ const { translate } = useTranslate('search') const isFocused = ref(false) // 是否聚焦中 const showInput = ref(false) // 是否显示输入框 用于实现聚焦的hack -const str = ref('') +const inputValue = ref('') // 输入框的值 const showPlaceHolder = ref(true) const clearing = ref(false) watch( () => props.modelValue, (newValue) => { - str.value = newValue + inputValue.value = newValue if (newValue) { showInput.value = true } @@ -98,7 +98,7 @@ const rootClass = computed(() => { const coverStyle = computed(() => { const coverStyle: CSSProperties = { - display: str.value === '' && showPlaceHolder.value ? 'flex' : 'none' + display: inputValue.value === '' && showPlaceHolder.value ? 'flex' : 'none' } return objToStyle(coverStyle) @@ -116,27 +116,22 @@ async function closeCover() { showPlaceHolder.value = false hackFocus(true) } -/** - * @description input的input事件handle - * @param value - */ -function inputValue(event: any) { - str.value = event.detail.value + +function handleInput(event: any) { + inputValue.value = event.detail.value emit('update:modelValue', event.detail.value) emit('change', { value: event.detail.value }) } -/** - * @description 点击清空icon的handle - */ -async function clearSearch() { - str.value = '' - clearing.value = true + +async function handleClear() { + inputValue.value = '' if (props.focusWhenClear) { + clearing.value = true isFocused.value = false } - await pause(100) + await pause() if (props.focusWhenClear) { showPlaceHolder.value = false hackFocus(true) @@ -150,49 +145,40 @@ async function clearSearch() { emit('update:modelValue', '') emit('clear') } -/** - * @description 点击搜索按钮时的handle - * @param value - */ -function search({ detail: { value } }: any) { + +function handleConfirm({ detail: { value } }: any) { // 组件触发search事件 emit('search', { value }) } -/** - * @description 输入框聚焦时的handle - */ -function searchFocus() { + +function handleFocus() { + showPlaceHolder.value = false + emit('focus', { + value: inputValue.value + }) +} + +async function handleBlur() { + // 等待150毫秒,clear执行完毕 + await pause(150) if (clearing.value) { clearing.value = false return } - showPlaceHolder.value = false - emit('focus', { - value: str.value - }) -} -/** - * @description 输入框失焦的handle - */ -function searchBlur() { - if (clearing.value) return // 组件触发blur事件 - showPlaceHolder.value = !str.value + showPlaceHolder.value = !inputValue.value showInput.value = !showPlaceHolder.value isFocused.value = false emit('blur', { - value: str.value + value: inputValue.value }) } -/** - * @description 点击取消搜索按钮的handle - */ + function handleCancel() { - // 组件触发cancel事件 emit('cancel', { - value: str.value + value: inputValue.value }) } diff --git a/src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue b/src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue index 0a04af38..b47c6332 100644 --- a/src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue +++ b/src/uni_modules/wot-design-uni/components/wd-textarea/wd-textarea.vue @@ -233,10 +233,10 @@ function formatValue(value: string | number) { } async function handleClear() { - clearing.value = true focusing.value = false inputValue.value = '' if (props.focusWhenClear) { + clearing.value = true focused.value = false } await pause()