fix: 修复组名称查询组件

This commit is contained in:
xlsea 2024-04-23 09:23:11 +08:00
parent dffa22e4a1
commit 8ac203b885
3 changed files with 30 additions and 14 deletions

View File

@ -1,44 +1,60 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref, watch } from 'vue'; import { ref, watch } from 'vue';
import { $t } from '@/locales'; import { $t } from '@/locales';
import { translateOptions2 } from '@/utils/common'; import { translateOptions2 } from '@/utils/common';
import { fetchGetAllGroupNameList } from '@/service/api'; import { fetchGetAllGroupNameList } from '@/service/api';
defineOptions({
name: 'SelectGroup'
});
interface Props {
modelValue?: string | null;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>(); const emit = defineEmits<Emits>();
interface Emits { interface Emits {
(e: 'update:value', value: string): void; (e: 'update:modelValue', value: string): void;
} }
/** 组列表 */ /** 组列表 */
const groupNameList = ref<string[]>([]); const groupNameList = ref<string[]>([]);
/** 组列表 */ /** 组列表 */
const groupNameRef = ref<string>(''); const groupName = ref<string>();
async function getGroupNameList() { async function getGroupNameList() {
const res = await fetchGetAllGroupNameList(); const { data, error } = await fetchGetAllGroupNameList();
groupNameList.value = res.data as string[]; if (!error) {
groupNameList.value = data;
}
} }
onMounted(() => { getGroupNameList();
getGroupNameList();
});
watch( watch(
() => groupNameRef.value, () => props.modelValue,
() => { () => {
emit('update:value', groupNameRef.value); groupName.value = props.modelValue!;
} },
{ immediate: true }
); );
const handleUpdate = (value: string) => {
emit('update:modelValue', value);
};
</script> </script>
<template> <template>
<NSelect <NSelect
v-model:value="groupNameRef" v-model:value="groupName"
:placeholder="$t('page.retryTask.form.groupName')" :placeholder="$t('page.retryTask.form.groupName')"
:options="translateOptions2(groupNameList)" :options="translateOptions2(groupNameList)"
clearable clearable
filterable filterable
@update:value="handleUpdate"
/> />
</template> </template>

View File

@ -61,7 +61,7 @@ function search() {
<!-- @update:value="handleGroupNameUpdate"--> <!-- @update:value="handleGroupNameUpdate"-->
<!-- />--> <!-- />-->
<SelectGroup v-model:value="model.groupName" /> <SelectGroup v-model="model.groupName" />
</NFormItemGi> </NFormItemGi>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.retryScene.sceneName')" path="userName" class="pr-24px"> <NFormItemGi span="24 s:12 m:6" :label="$t('page.retryScene.sceneName')" path="userName" class="pr-24px">
<!-- <NSelect--> <!-- <NSelect-->

View File

@ -29,7 +29,7 @@ function search() {
<template> <template>
<SearchForm :model="model" @search="search" @reset="reset"> <SearchForm :model="model" @search="search" @reset="reset">
<NFormItemGi span="24 s:12 m:6" :label="$t('page.workflow.groupName')" path="groupName" class="pr-24px"> <NFormItemGi span="24 s:12 m:6" :label="$t('page.workflow.groupName')" path="groupName" class="pr-24px">
<SelectGroup v-model:value="model.groupName" /> <SelectGroup v-model="model.groupName" />
</NFormItemGi> </NFormItemGi>
<NFormItemGi span="24 s:12 m:6" :label="$t('page.workflow.workflowName')" path="workflowName" class="pr-24px"> <NFormItemGi span="24 s:12 m:6" :label="$t('page.workflow.workflowName')" path="workflowName" class="pr-24px">
<NInput v-model:value="model.workflowName" :placeholder="$t('page.workflow.form.workflowName')" /> <NInput v-model:value="model.workflowName" :placeholder="$t('page.workflow.form.workflowName')" />