diff --git a/frontend/src/composables/useScriptApi.ts b/frontend/src/composables/useScriptApi.ts index 903c7b4..26a76a7 100644 --- a/frontend/src/composables/useScriptApi.ts +++ b/frontend/src/composables/useScriptApi.ts @@ -42,10 +42,15 @@ export function useScriptApi() { } } - // 获取脚本列表 - const getScripts = async (): Promise => { - loading.value = true - error.value = null + // 获取脚本列表(可选择是否管理 loading 状态,避免嵌套调用时提前结束 loading) + const getScripts = async (manageLoading: boolean = true): Promise => { + if (manageLoading) { + loading.value = true + error.value = null + } else { + // 仅清理错误,不改变外部 loading + error.value = null + } try { const response = await Service.getScriptsApiScriptsGetPost({}) @@ -73,18 +78,20 @@ export function useScriptApi() { } return [] } finally { - loading.value = false + if (manageLoading) { + loading.value = false + } } } - // 获取脚本列表及其用户数据 + // 获取脚本列表及其用户数据(统一管理一次 loading) const getScriptsWithUsers = async (): Promise => { loading.value = true error.value = null try { - // 首先获取脚本列表 - const scriptDetails = await getScripts() + // 首先获取脚本列表,但不在内部结束 loading + const scriptDetails = await getScripts(false) // 为每个脚本获取用户数据 const scriptsWithUsers = await Promise.all( diff --git a/frontend/src/views/Scripts.vue b/frontend/src/views/Scripts.vue index 21d39eb..d3fb0bb 100644 --- a/frontend/src/views/Scripts.vue +++ b/frontend/src/views/Scripts.vue @@ -40,7 +40,8 @@ -
+ +
暂无数据 @@ -270,6 +271,8 @@ const md = new MarkdownIt({ }) const scripts = ref([]) +// 增加:标记是否已经完成过一次脚本列表加载(成功或失败都算一次) +const loadedOnce = ref(false) const typeSelectVisible = ref(false) const generalModeSelectVisible = ref(false) const templateSelectVisible = ref(false) @@ -327,6 +330,9 @@ const loadScripts = async () => { } catch (error) { console.error('加载脚本列表失败:', error) message.error('加载脚本列表失败') + } finally { + // 首次加载结束(不论成功失败)后置位,避免初始闪烁 + loadedOnce.value = true } }