zs
2025-04-28 1f32ea02c1910c417f159cba81a296e66ae7484c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { defineComponent, ref } from 'vue'
import styles from './Search.module.scss'
import Icon from '../Icon/Icon'
import { useVModel } from '@vueuse/core'
import { debounce } from 'lodash'
export default defineComponent({
  name: '搜索输入',
  props: {
    placeholder: {
      type: String,
      default: '请输入搜索',
    },
    modelValue: {
      type: String,
      default: '',
    },
    tableRef: {
      type: Object,
      default: null,
    },
    field: {
      type: String,
      default: '',
    },
  },
  emits: ['confirm', 'update:modelValue'],
  setup(props, { attrs, slots, emit }) {
    const innerValue = useVModel(props)
    return () => {
      const confirm = (event: KeyboardEvent | string) => {
        if (
          typeof event === 'string' ||
          event.key === 'Enter' ||
          event.keyCode === 13
        ) {
          emit('confirm', innerValue.value)
          const rf = props.tableRef?.value || props.tableRef
          if (rf) {
            rf.getList({
              [props.field || 'Name']: innerValue.value,
            })
          }
        }
      }
 
      const fn = debounce(confirm, 100)
 
      return (
        <div class={styles.inputContent}>
          <el-input
            v-model={innerValue.value}
            class={styles.searchInner}
            // size="small"
            prefix-icon={<Icon icon="s_input" width={12} height={12} />}
            placeholder={props.placeholder}
            {...attrs}
            onKeydown={fn}
            onChange={fn}
          />
        </div>
      )
    }
  },
})