222
schangxiang@126.com
2025-04-30 9bec4dcae002f36aa23231da11cb03a156b40110
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
65
import { computed, defineComponent, ref } from 'vue'
import styles from './Container.module.scss'
import Icon from '@/components/Icon/Icon'
import { useVModel } from '@vueuse/core'
import { debounce } from 'lodash'
import { _t } from '@/libs/Language/Language'
export default defineComponent({
  name: '通用头部',
  props: {
    title: {
      type: String,
      required: true,
    },
    placeholder: {
      type: String,
      default: '请输入搜索',
    },
    modelValue: {
      type: String,
      default: '',
    },
    isSearch: {
      type: Boolean,
      default: true,
    },
  },
  emits: ['confirm', 'update:modelValue'],
  setup(props, { slots, emit }) {
    const innerValue = useVModel(props)
    const isBlur = ref(false)
    const confirm = (event: KeyboardEvent) => {
      if (event.key === 'Enter' || event.keyCode === 13) {
        emit('confirm', innerValue.value)
      }
    }
 
    const onEventChange = (isFocus: boolean) => {
      isBlur.value = isFocus
    }
    return () => {
      return (
        <div class={styles.container}>
          <div class={styles.header}>
            <span class={styles.title}>{props.title}</span>
            {props.isSearch && (
              <el-input
                size="small"
                onKeydown={confirm}
                v-model={innerValue.value}
                class={styles.innerInput}
                onBlur={() => onEventChange(false)}
                onFocus={() => onEventChange(true)}
                placeholder={!isBlur.value ? _t(props.placeholder) : ''}
                prefix-icon={
                  <Icon icon="white_search" width={12} height={12} />
                }
              />
            )}
          </div>
          <div class={styles.content}>{slots.default?.()}</div>
        </div>
      )
    }
  },
})