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

62 lines
1.2 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'
});
interface Props {
modelValue?: string | null;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
interface Emits {
2024-04-23 09:23:11 +08:00
(e: 'update:modelValue', value: string): void;
}
/** 组列表 */
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(
2024-04-23 09:23:11 +08:00
() => props.modelValue,
() => {
2024-04-23 09:23:11 +08:00
groupName.value = props.modelValue!;
},
{ 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>