fix(staff): loadWechatStats 加载竞态守卫(token)+ 重查时清空旧窗数字
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -83,18 +83,24 @@ const statsEnd = computed(() => dateRange.value[1].getTime())
|
||||
/** account_id → stats 缓存(wechat 行)。undefined 表示尚未加载,cell 显示 '--'。 */
|
||||
const staffStats = ref<Record<string, StaffChatStats | undefined>>({})
|
||||
|
||||
// 单调递增 token:防止快速切换日期窗时旧 in-flight fetch(捕获旧窗)覆盖新结果。
|
||||
let statsLoadToken = 0
|
||||
async function loadWechatStats(rows: Account[]): Promise<void> {
|
||||
const myToken = ++statsLoadToken
|
||||
const ids = rows.map((r) => r.account_id).filter(Boolean)
|
||||
// 先清空当前批次缓存 → cell 显示 '--'(加载中),并防止旧窗 in-flight 写回覆盖新结果
|
||||
for (const id of ids) staffStats.value[id] = undefined
|
||||
await Promise.all(
|
||||
ids.map(async (id) => {
|
||||
try {
|
||||
staffStats.value[id] = await getStaffChatStats({
|
||||
const stats = await getStaffChatStats({
|
||||
owner_account_id: id,
|
||||
start: statsStart.value,
|
||||
end: statsEnd.value,
|
||||
})
|
||||
if (myToken === statsLoadToken) staffStats.value[id] = stats
|
||||
} catch {
|
||||
staffStats.value[id] = undefined // 失败留空,cell 显示 '--'
|
||||
if (myToken === statsLoadToken) staffStats.value[id] = undefined // 失败留空,cell 显示 '--'
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -111,7 +117,7 @@ function statNum(
|
||||
|
||||
function onStatsDateChange(): void {
|
||||
// 改日期 → 重查当前可见 wechat 行(覆盖其缓存条目)。
|
||||
loadWechatStats(tabState.wechat.items)
|
||||
void loadWechatStats(tabState.wechat.items)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user