SearchBox.js 910 Bytes
// components/SearchBox/SearchBox.js
Component({
  properties: {
    placeholder: {
      type: String,
      value: '请输入搜索内容'
    },
    value: {
      type: String,
      value: ''
    },
    searchType: {
      type: Number,
      value: 1
    },
    inputAlign: {
      type: String,
      value: 'left' // 输入位置可配置: left, center, right
    }
  },
  data: {},
  methods: {
    input(e) {
      let { value } = e.detail;
      this.setData({ value });
    },
    blur(e){
      let { value } = this.data;
      this.setData({ value });
    },
    clear() {
      this.setData({ value: '' }, () => {
        this.triggerEvent('search', '');
      });
    },
    confirm(e) {
      let { value } = e?.detail || {};
      this.triggerEvent('search', value);
    },
    search(e) {
      let { value } = e.currentTarget.dataset;
      this.triggerEvent('search', value);
    }
  }
});