From 887f10ef3f76755484674e4946f969106d3142be Mon Sep 17 00:00:00 2001 From: Alirea <2981883527@qq.com> Date: Sun, 21 Sep 2025 00:13:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E5=8F=88=E7=BB=99=E4=BD=A0=E5=8A=A0?= =?UTF-8?q?=E5=9B=9E=E6=9D=A5=E5=8A=A0=E8=BD=BD=E7=95=8C=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E4=BD=86=E8=AE=A9=E4=BB=96=E4=B8=8D=E4=BC=9Anodata=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/composables/useScriptApi.ts | 23 +++++++++++++++-------- frontend/src/views/Scripts.vue | 8 +++++++- 2 files changed, 22 insertions(+), 9 deletions(-) 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 } }