schangxiang@126.com
2025-05-21 496f78c085e7f8c5ba261835f9b8bda99c25b4cb
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
import { defineComponent, reactive, ref, onMounted } from 'vue'
import { CaretBottom } from '@element-plus/icons-vue'
import Option from './Option'
import { Base } from '@/libs/Base/Base'
const request = Base.request
 
export default defineComponent({
  props: ['disabled', 'options', 'urlConfig'],
  setup(props: any, { attrs, slots, emit }: any) {
    const options = ref([])
 
    const dataObj = reactive({
      loading: false,
    })
 
    const remoteMethod = async (query?: string) => {
      dataObj.loading = true
      const params = {
        ...props.urlConfig.params,
        Filter: query || '',
      }
      const str = new URLSearchParams(params).toString()
      const res = await request.get(`${props.urlConfig.url}?${str}`)
      //extend类扩展属性后端只传收字符串
      options.value = props.urlConfig.optionString
        ? res.map((item: any) => ({ ...item, value: String(item.value) }))
        : res
      dataObj.loading = false
    }
 
    onMounted(() => {
      remoteMethod()
    })
 
    return () => {
      const disabled =
        typeof props.disabled?.value === 'boolean'
          ? props.disabled?.value
          : (props.disabled as boolean)
      return (
        <el-select
          {...attrs}
          filterable
          remote
          disabled={disabled}
          remote-method={remoteMethod}
          loading={dataObj.loading}
        >
          {options.value
            ? options.value.map((item: any) => {
              const label = item.label || item.name || item.description
              return <Option {...item} label={label} />
            })
            : slots.default?.()}
        </el-select>
      )
    }
  },
})