notes(ui): polling 静默 refresh + 增量更新 list/selected,不再闪动
deploy notes / build-and-deploy (push) Successful in 1m50s
deploy notes / build-and-deploy (push) Successful in 1m50s
This commit is contained in:
@@ -235,16 +235,39 @@ function logout() {
|
|||||||
stopPoll()
|
stopPoll()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refresh() {
|
async function refresh(silent = false) {
|
||||||
loading.value = true
|
if (!silent) loading.value = true
|
||||||
try { list.value = await listRecordings() }
|
try {
|
||||||
|
const fresh = await listRecordings()
|
||||||
|
// 增量更新:尽量复用已有 ref,避免整 array 替换导致闪动
|
||||||
|
if (!list.value.length) {
|
||||||
|
list.value = fresh
|
||||||
|
} else {
|
||||||
|
const byId = new Map(list.value.map(r => [r.id, r]))
|
||||||
|
list.value = fresh.map(r => {
|
||||||
|
const old = byId.get(r.id)
|
||||||
|
if (old) {
|
||||||
|
Object.assign(old, r)
|
||||||
|
return old
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (e.unauthorized) { logout(); return }
|
if (e.unauthorized) { logout(); return }
|
||||||
}
|
}
|
||||||
finally { loading.value = false }
|
finally { if (!silent) loading.value = false }
|
||||||
// 同步当前选中
|
// 同步当前选中
|
||||||
if (selectedId.value) {
|
if (selectedId.value) {
|
||||||
try { selected.value = await getRecording(selectedId.value) } catch {}
|
try {
|
||||||
|
const fresh = await getRecording(selectedId.value)
|
||||||
|
if (selected.value) {
|
||||||
|
Object.assign(selected.value, fresh)
|
||||||
|
} else {
|
||||||
|
selected.value = fresh
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -336,7 +359,7 @@ function mdLite(s) {
|
|||||||
|
|
||||||
function startPoll() {
|
function startPoll() {
|
||||||
stopPoll()
|
stopPoll()
|
||||||
pollTimer = setInterval(refresh, 5000)
|
pollTimer = setInterval(() => refresh(true), 5000)
|
||||||
}
|
}
|
||||||
function stopPoll() {
|
function stopPoll() {
|
||||||
if (pollTimer) { clearInterval(pollTimer); pollTimer = null }
|
if (pollTimer) { clearInterval(pollTimer); pollTimer = null }
|
||||||
|
|||||||
Reference in New Issue
Block a user