spring
2026-07-03 2540d86f0dbd77f654f558c3bf9d5ddbe7422f16
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
<script lang="ts" setup>
import type { SystemUserApi } from '#/api/system/user';
 
import { onMounted, ref, watch } from 'vue';
 
import { Select } from 'ant-design-vue';
 
import { getSimpleUserList } from '#/api/system/user';
 
defineOptions({ name: 'PdUserSelect', inheritAttrs: false });
 
const props = withDefaults(
  defineProps<{
    disabled?: boolean;
    modelValue?: number;
    placeholder?: string;
  }>(),
  {
    disabled: false,
    modelValue: undefined,
    placeholder: '请选择',
  },
);
 
const emit = defineEmits<{
  'update:modelValue': [value: number | undefined];
}>();
 
const options = ref<{ label: string; value: number }[]>([]);
 
onMounted(async () => {
  const users = await getSimpleUserList();
  options.value = users
    .filter((u): u is SystemUserApi.User & { id: number } => u.id !== undefined)
    .map((u) => ({ label: u.nickname || u.username, value: u.id }));
});
 
watch(
  () => props.modelValue,
  (val) => {
    emit('update:modelValue', val);
  },
);
</script>
 
<template>
  <Select
    v-bind="$attrs"
    :disabled="disabled"
    :options="options"
    :placeholder="placeholder"
    :value="modelValue"
    allow-clear
    show-search
    :filter-option="
      (input: string, option: any) =>
        option?.label?.toLowerCase().includes(input.toLowerCase())
    "
    @change="(val: number) => emit('update:modelValue', val)"
  />
</template>