刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
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
<script lang="ts" setup>
import { onMounted, ref } from 'vue';
 
import { useDebounceFn } from '@vueuse/core';
 
import { getPermissionGroups } from '#/api/x/dms/permission';
 
defineProps<{
  value?: string;
}>();
 
const emit = defineEmits<{
  'update:value': [value?: string];
}>();
 
const loading = ref(false);
const options = ref<Array<{ label: string; value: string }>>([]);
const loadOptionsDebounced = useDebounceFn(loadOptions, 300);
 
async function loadOptions(keyword = '') {
  loading.value = true;
  try {
    const response = await getPermissionGroups({ keyword, pageSize: 100 });
    options.value = (response.data || []).map((item) => ({ label: item.name, value: item.id }));
  } finally {
    loading.value = false;
  }
}
 
function handleSearch(value: string) {
  loadOptionsDebounced(value.trim());
}
 
onMounted(() => loadOptions());
</script>
 
<template>
  <a-select
    class="w-full"
    :filter-option="false"
    :loading="loading"
    :options="options"
    :value="value"
    allow-clear
    placeholder="请选择权限组"
    show-search
    @search="handleSearch"
    @update:value="emit('update:value', $event)" />
</template>