fix(ui): 又给你加回来加载界面,但让他不会nodata了

This commit is contained in:
Alirea
2025-09-21 00:13:28 +08:00
parent 14c61815c6
commit 887f10ef3f
2 changed files with 22 additions and 9 deletions

View File

@@ -42,10 +42,15 @@ export function useScriptApi() {
} }
} }
// 获取脚本列表 // 获取脚本列表(可选择是否管理 loading 状态,避免嵌套调用时提前结束 loading
const getScripts = async (): Promise<ScriptDetail[]> => { const getScripts = async (manageLoading: boolean = true): Promise<ScriptDetail[]> => {
loading.value = true if (manageLoading) {
error.value = null loading.value = true
error.value = null
} else {
// 仅清理错误,不改变外部 loading
error.value = null
}
try { try {
const response = await Service.getScriptsApiScriptsGetPost({}) const response = await Service.getScriptsApiScriptsGetPost({})
@@ -73,18 +78,20 @@ export function useScriptApi() {
} }
return [] return []
} finally { } finally {
loading.value = false if (manageLoading) {
loading.value = false
}
} }
} }
// 获取脚本列表及其用户数据 // 获取脚本列表及其用户数据(统一管理一次 loading
const getScriptsWithUsers = async (): Promise<ScriptDetail[]> => { const getScriptsWithUsers = async (): Promise<ScriptDetail[]> => {
loading.value = true loading.value = true
error.value = null error.value = null
try { try {
// 首先获取脚本列表 // 首先获取脚本列表,但不在内部结束 loading
const scriptDetails = await getScripts() const scriptDetails = await getScripts(false)
// 为每个脚本获取用户数据 // 为每个脚本获取用户数据
const scriptsWithUsers = await Promise.all( const scriptsWithUsers = await Promise.all(

View File

@@ -40,7 +40,8 @@
</div> </div>
<!-- 空状态 --> <!-- 空状态 -->
<div v-if="scripts.length === 0" class="empty-state"> <!-- 增加 loadedOnce 条件避免初始渲染时闪烁 -->
<div v-if="!loading && loadedOnce && scripts.length === 0" class="empty-state">
<div class="empty-content"> <div class="empty-content">
<div class="empty-image-container"> <div class="empty-image-container">
<img src="@/assets/NoData.png" alt="暂无数据" class="empty-image" /> <img src="@/assets/NoData.png" alt="暂无数据" class="empty-image" />
@@ -270,6 +271,8 @@ const md = new MarkdownIt({
}) })
const scripts = ref<Script[]>([]) const scripts = ref<Script[]>([])
// 增加:标记是否已经完成过一次脚本列表加载(成功或失败都算一次)
const loadedOnce = ref(false)
const typeSelectVisible = ref(false) const typeSelectVisible = ref(false)
const generalModeSelectVisible = ref(false) const generalModeSelectVisible = ref(false)
const templateSelectVisible = ref(false) const templateSelectVisible = ref(false)
@@ -327,6 +330,9 @@ const loadScripts = async () => {
} catch (error) { } catch (error) {
console.error('加载脚本列表失败:', error) console.error('加载脚本列表失败:', error)
message.error('加载脚本列表失败') message.error('加载脚本列表失败')
} finally {
// 首次加载结束(不论成功失败)后置位,避免初始闪烁
loadedOnce.value = true
} }
} }