Appearance
ts
高频行情合批(如果需要)
// 在复杂逻辑上一行加注释:行情高频更新时合批后再换数组引用,降低重算与渲染频次
let scheduled = false
const pending: Record<string, Partial<Account>> = {}
function queueAccountPatch(loginid: string, patch: Partial<Account>) {
pending[loginid] = { ...(pending[loginid] ?? {}), ...patch }
if (scheduled) return
scheduled = true
requestAnimationFrame(() => {
const list = accountList.value ?? []
const next = list.slice()
for (const [id, p] of Object.entries(pending)) {
const idx = next.findIndex(a => a.loginid === id)
if (idx !== -1) Object.assign(next[idx], p)
delete pending[id]
}
accountList.value = next // ← 一次性换引用
scheduled = false
})
}