fix(ui): 又给你加回来加载界面,但让他不会nodata了
This commit is contained in:
@@ -42,10 +42,15 @@ export function useScriptApi() {
|
||||
}
|
||||
}
|
||||
|
||||
// 获取脚本列表
|
||||
const getScripts = async (): Promise<ScriptDetail[]> => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
// 获取脚本列表(可选择是否管理 loading 状态,避免嵌套调用时提前结束 loading)
|
||||
const getScripts = async (manageLoading: boolean = true): Promise<ScriptDetail[]> => {
|
||||
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<ScriptDetail[]> => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
|
||||
try {
|
||||
// 首先获取脚本列表
|
||||
const scriptDetails = await getScripts()
|
||||
// 首先获取脚本列表,但不在内部结束 loading
|
||||
const scriptDetails = await getScripts(false)
|
||||
|
||||
// 为每个脚本获取用户数据
|
||||
const scriptsWithUsers = await Promise.all(
|
||||
|
||||
@@ -40,7 +40,8 @@
|
||||
</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-image-container">
|
||||
<img src="@/assets/NoData.png" alt="暂无数据" class="empty-image" />
|
||||
@@ -270,6 +271,8 @@ const md = new MarkdownIt({
|
||||
})
|
||||
|
||||
const scripts = ref<Script[]>([])
|
||||
// 增加:标记是否已经完成过一次脚本列表加载(成功或失败都算一次)
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user