fix: 修复密钥页面重复请求问题

This commit is contained in:
tbphp
2025-07-13 21:18:17 +08:00
parent 469008acb0
commit 6ca84fc7e3
2 changed files with 16 additions and 3 deletions

View File

@@ -80,6 +80,8 @@ const formData = reactive<GroupFormData>({
const channelTypeOptions = ref<{ label: string; value: string }[]>([]); const channelTypeOptions = ref<{ label: string; value: string }[]>([]);
const configOptions = ref<GroupConfigOption[]>([]); const configOptions = ref<GroupConfigOption[]>([]);
const channelTypesFetched = ref(false);
const configOptionsFetched = ref(false);
// 表单验证规则 // 表单验证规则
const rules: FormRules = { const rules: FormRules = {
@@ -124,6 +126,12 @@ watch(
() => props.show, () => props.show,
show => { show => {
if (show) { if (show) {
if (!channelTypesFetched.value) {
fetchChannelTypes();
}
if (!configOptionsFetched.value) {
fetchGroupConfigOptions();
}
resetForm(); resetForm();
if (props.group) { if (props.group) {
loadGroupData(); loadGroupData();
@@ -174,7 +182,6 @@ function loadGroupData() {
}); });
} }
fetchChannelTypes();
async function fetchChannelTypes() { async function fetchChannelTypes() {
const options = (await settingsApi.getChannelTypes()) || []; const options = (await settingsApi.getChannelTypes()) || [];
channelTypeOptions.value = channelTypeOptions.value =
@@ -182,6 +189,7 @@ async function fetchChannelTypes() {
label: type, label: type,
value: type, value: type,
})) || []; })) || [];
channelTypesFetched.value = true;
} }
// 添加上游地址 // 添加上游地址
@@ -199,10 +207,10 @@ function removeUpstream(index: number) {
} }
} }
fetchGroupConfigOptions();
async function fetchGroupConfigOptions() { async function fetchGroupConfigOptions() {
const options = await keysApi.getGroupConfigOptions(); const options = await keysApi.getGroupConfigOptions();
configOptions.value = options || []; configOptions.value = options || [];
configOptionsFetched.value = true;
} }
// 添加配置项 // 添加配置项

View File

@@ -79,9 +79,14 @@ watch(
() => props.selectedGroup, () => props.selectedGroup,
async newGroup => { async newGroup => {
if (newGroup) { if (newGroup) {
// 检查重置页面是否会触发分页观察者。
const willWatcherTrigger = currentPage.value !== 1 || statusFilter.value !== "all";
resetPage(); resetPage();
// 如果分页观察者不触发,则手动加载。
if (!willWatcherTrigger) {
await loadKeys(); await loadKeys();
} }
}
}, },
{ immediate: true } { immediate: true }
); );