- 入出库详情加载提交前校验公司 ID 与上下文版本,旧公司响应静默丢弃 - 新增 runWithSaving 包裹器,仓库、伙伴、基础配置等直接调接口的页面纳入保存互斥 - 切换守卫卸载时仅撤销自己注册的那一份
24 lines
942 B
JavaScript
24 lines
942 B
JavaScript
// 页面直接调用 API 的写请求的“保存互斥”复用点。
|
||
//
|
||
// 设计约定 3:保存请求执行期间禁止切换公司,避免写请求完成归属不明确。
|
||
// 走 store 的写请求已在各 store 里 `beginSaving()/endSaving()`;本组合式函数给
|
||
// “页面自己直接调 API 的写请求”(如仓库、伙伴、基础配置)提供同一套互斥:
|
||
// 用 runWithSaving 包住写请求,飞行期间组织 store 的 busy 为真,切换被拒。
|
||
import { useOrganizationStore } from '../stores/organization'
|
||
|
||
export function useSavingGuard() {
|
||
const organizationStore = useOrganizationStore()
|
||
|
||
async function runWithSaving(task) {
|
||
organizationStore.beginSaving()
|
||
try {
|
||
return await task()
|
||
} finally {
|
||
// 成功或失败都要复位,避免忙标志被永久卡住、用户再也切不了公司。
|
||
organizationStore.endSaving()
|
||
}
|
||
}
|
||
|
||
return { runWithSaving }
|
||
}
|