From f46786f11c5c08ead7501a82e5a71430ad69b782 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期日, 27 四月 2025 17:39:24 +0800 Subject: [PATCH] 修复线索问题定位错误问题 --- miniprogram_npm/tdesign-miniprogram/search/search.js | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 43 insertions(+), 9 deletions(-) diff --git a/miniprogram_npm/tdesign-miniprogram/search/search.js b/miniprogram_npm/tdesign-miniprogram/search/search.js index 6560bb2..bc6e9f6 100644 --- a/miniprogram_npm/tdesign-miniprogram/search/search.js +++ b/miniprogram_npm/tdesign-miniprogram/search/search.js @@ -7,6 +7,7 @@ import { SuperComponent, wxComponent } from '../common/src/index'; import config from '../common/config'; import props from './props'; +import { getCharacterLength } from '../common/utils'; const { prefix } = config; const name = `${prefix}-search`; let Search = class Search extends SuperComponent { @@ -25,36 +26,59 @@ }; this.properties = props; this.observers = { - focus(nextValue) { - this.setData({ 'localValue.focus': nextValue }); + resultList(val) { + const { isSelected } = this.data; + if (val.length) { + if (isSelected) { + this.setData({ + isShowResultList: false, + isSelected: false, + }); + } + else { + this.setData({ + isShowResultList: true, + }); + } + } + else { + this.setData({ + isShowResultList: false, + }); + } }, }; this.data = { classPrefix: name, prefix, - localValue: { - focus: false, - }, + isShowResultList: false, + isSelected: false, }; } onInput(e) { - const { value } = e.detail; - this.setData({ value }); + let { value } = e.detail; + const { maxcharacter } = this.properties; + if (maxcharacter && typeof maxcharacter === 'number' && maxcharacter > 0) { + const { characters } = getCharacterLength('maxcharacter', value, maxcharacter); + value = characters; + } + this.setData({ + value, + }); this.triggerEvent('change', { value }); } onFocus(e) { const { value } = e.detail; - this.setData({ 'localValue.focus': true }); this.triggerEvent('focus', { value }); } onBlur(e) { const { value } = e.detail; - this.setData({ 'localValue.focus': false }); this.triggerEvent('blur', { value }); } handleClear() { this.setData({ value: '' }); this.triggerEvent('clear', { value: '' }); + this.triggerEvent('change', { value: '' }); } onConfirm(e) { const { value } = e.detail; @@ -63,6 +87,16 @@ onActionClick() { this.triggerEvent('action-click'); } + onSelectResultItem(e) { + const { index } = e.currentTarget.dataset; + const item = this.properties.resultList[index]; + this.setData({ + value: item, + isSelected: true, + }); + this.triggerEvent('change', { value: item }); + this.triggerEvent('selectresult', { index, item }); + } }; Search = __decorate([ wxComponent() -- Gitblit v1.9.3