gtsoft-snail-job-admin/src/components/common/select-group.vue

56 lines
1.1 KiB
Vue
Raw Normal View History

<script setup lang="ts">
2024-04-23 09:23:11 +08:00
import { ref, watch } from 'vue';
import { $t } from '@/locales';
import { translateOptions2 } from '@/utils/common';
import { fetchGetAllGroupNameList } from '@/service/api';
2024-04-23 09:23:11 +08:00
defineOptions({
name: 'SelectGroup'
});
const model = defineModel<string | null>();
interface Emits {
2024-04-23 09:23:11 +08:00
(e: 'update:modelValue', value: string): void;
}
const emit = defineEmits<Emits>();
/** 组列表 */
const groupNameList = ref<string[]>([]);
/** 组列表 */
2024-04-23 09:23:11 +08:00
const groupName = ref<string>();
async function getGroupNameList() {
2024-04-23 09:23:11 +08:00
const { data, error } = await fetchGetAllGroupNameList();
if (!error) {
groupNameList.value = data;
}
}
2024-04-23 09:23:11 +08:00
getGroupNameList();
watch(
() => model,
() => {
groupName.value = model.value!;
2024-04-23 09:23:11 +08:00
},
{ immediate: true }
);
2024-04-23 09:23:11 +08:00
const handleUpdate = (value: string) => {
emit('update:modelValue', value);
};
</script>
<template>
<NSelect
2024-04-23 09:23:11 +08:00
v-model:value="groupName"
:placeholder="$t('page.retryTask.form.groupName')"
:options="translateOptions2(groupNameList)"
clearable
filterable
2024-04-23 09:23:11 +08:00
@update:value="handleUpdate"
/>
</template>
<style scoped></style>