riku
2025-04-21 0746b7bbe6aa3d9f02e03654a2cd4fde2081c335
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()