fix: pages 改为 computed 从 allResults 分组,解析数据单独注入,消除数量不一致
This commit is contained in:
@@ -55,14 +55,13 @@
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 解析加载中 -->
|
||||
<div v-if="parseLoading" style="text-align:center;padding:40px;color:#909399">
|
||||
<el-icon class="is-loading" :size="24"><Loading /></el-icon>
|
||||
<div style="margin-top:8px">正在解析各页面适配结果...</div>
|
||||
<!-- 解析加载中提示(不隐藏已有列表) -->
|
||||
<div v-if="parseLoading" style="text-align:center;padding:12px;color:#909399">
|
||||
<el-icon class="is-loading"><Loading /></el-icon> 正在解析各页面适配结果...
|
||||
</div>
|
||||
|
||||
<!-- 页面卡片列表 -->
|
||||
<div v-else style="display:flex;flex-direction:column;gap:8px">
|
||||
<div style="display:flex;flex-direction:column;gap:8px">
|
||||
<el-card v-for="page in pages" :key="page.url" shadow="hover" size="small">
|
||||
<template #header>
|
||||
<div style="display:flex;justify-content:space-between;align-items:center;flex-wrap:wrap;gap:8px">
|
||||
@@ -119,7 +118,7 @@
|
||||
</template>
|
||||
</el-card>
|
||||
|
||||
<div v-if="pages.length===0 && !loading && !parseLoading" style="text-align:center;padding:60px;color:#909399">
|
||||
<div v-if="pages.length===0 && !loading" style="text-align:center;padding:60px;color:#909399">
|
||||
暂无访问结果
|
||||
</div>
|
||||
</div>
|
||||
@@ -148,7 +147,7 @@ const rejecting = ref(false)
|
||||
|
||||
const allConfigVersions = ref([])
|
||||
const allResults = ref([])
|
||||
const pages = ref([])
|
||||
const pageParsed = ref({}) // url → parsed data
|
||||
const expandedSet = reactive(new Set())
|
||||
|
||||
const totalResults = computed(() => allResults.value.length)
|
||||
@@ -156,6 +155,30 @@ const validCount = computed(() => allResults.value.filter(r => r.isValid===true)
|
||||
const invalidCount = computed(() => allResults.value.filter(r => r.isValid===false).length)
|
||||
const uncheckedCount = computed(() => allResults.value.filter(r => r.isValid==null).length)
|
||||
|
||||
// 始终从 allResults 按 URL 分组生成 pages,解析数据注入
|
||||
const pages = computed(() => {
|
||||
const map = new Map()
|
||||
for (const r of allResults.value) {
|
||||
const key = r.url || '(无URL)'
|
||||
if (!map.has(key)) {
|
||||
map.set(key, { url: key, statusCode: r.statusCode, responseTimeMs: r.responseTimeMs,
|
||||
createdAt: r.createdAt, totalCount: 0, validCount: 0, invalidCount: 0,
|
||||
uncheckedCount: 0, history: [], parsed: null })
|
||||
}
|
||||
const p = map.get(key)
|
||||
p.totalCount++
|
||||
if (r.isValid===true) p.validCount++
|
||||
else if (r.isValid===false) p.invalidCount++
|
||||
else p.uncheckedCount++
|
||||
if (p.history.length < 5) p.history.push(r)
|
||||
}
|
||||
// 合并解析数据
|
||||
for (const [url, parsed] of Object.entries(pageParsed.value)) {
|
||||
if (map.has(url)) map.get(url).parsed = parsed
|
||||
}
|
||||
return Array.from(map.values())
|
||||
})
|
||||
|
||||
// 加载配置版本列表
|
||||
const loadConfigs = async () => {
|
||||
try {
|
||||
@@ -188,7 +211,6 @@ const onConfigChange = async () => {
|
||||
}
|
||||
} catch { selectedConfigJson.value = '' }
|
||||
|
||||
// 自动批量解析
|
||||
await doBatchParse()
|
||||
}
|
||||
|
||||
@@ -197,12 +219,12 @@ const doBatchParse = async () => {
|
||||
parseLoading.value = true
|
||||
try {
|
||||
const r = await api.adapter.parseBatch(selectedConfigId.value, siteId)
|
||||
const data = r.data || {}
|
||||
pages.value = (data.pages || []).map(p => ({
|
||||
...p,
|
||||
history: allResults.value.filter(r => r.url===p.url).slice(0, 5)
|
||||
}))
|
||||
} catch { ElMessage.error('批量解析失败') }
|
||||
const map = {}
|
||||
for (const p of (r.data?.pages || [])) {
|
||||
if (p.parsed) map[p.url] = p.parsed
|
||||
}
|
||||
pageParsed.value = map
|
||||
} catch { /* 非关键 */ }
|
||||
finally { parseLoading.value = false }
|
||||
}
|
||||
|
||||
@@ -214,13 +236,7 @@ const refresh = async () => {
|
||||
const r = await api.accessResults.bySite(siteId)
|
||||
allResults.value = r.data||[]
|
||||
// 刷新解析数据
|
||||
if (selectedConfigId.value) {
|
||||
const data = (await api.adapter.parseBatch(selectedConfigId.value, siteId)).data||{}
|
||||
pages.value = (data.pages||[]).map(p => ({
|
||||
...p,
|
||||
history: allResults.value.filter(r => r.url===p.url).slice(0,5)
|
||||
}))
|
||||
}
|
||||
if (selectedConfigId.value) await doBatchParse()
|
||||
} catch { ElMessage.error('获取访问结果失败') }
|
||||
finally { loading.value = false }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user