fix: 防止出库编辑请求串扰

This commit is contained in:
zhouz
2026-07-22 15:48:08 +08:00
parent 88b70e6729
commit a841118805
3 changed files with 69 additions and 5 deletions

View File

@@ -27,6 +27,7 @@ import {
filterOutboundBillTypeOptions, filterOutboundBillTypeOptions,
mergeOutboundInventory, mergeOutboundInventory,
type OutboundFormDetail, type OutboundFormDetail,
shouldApplyEditResult,
shouldClearDetailsForWarehouseChange, shouldClearDetailsForWarehouseChange,
} from './outbound-form'; } from './outbound-form';
@@ -36,6 +37,9 @@ const details = ref<OutboundFormDetail[]>([]);
const currentStorId = ref<string>(); const currentStorId = ref<string>();
let manualRowSequence = 0; let manualRowSequence = 0;
let billTypeRequest: null | ReturnType<typeof getSimpleDictDataList> = null; let billTypeRequest: null | ReturnType<typeof getSimpleDictDataList> = null;
let mainModalOpen = false;
let mainOpenToken = 0;
let activeEditId: string | undefined;
const isEdit = computed(() => Boolean(formData.value?.iostorinvId)); const isEdit = computed(() => Boolean(formData.value?.iostorinvId));
const getTitle = computed(() => const getTitle = computed(() =>
@@ -297,18 +301,25 @@ const [Modal, modalApi] = useVbenModal({
} }
}, },
async onOpenChange(open) { async onOpenChange(open) {
const token = ++mainOpenToken;
mainModalOpen = open;
if (!open) { if (!open) {
activeEditId = undefined;
formData.value = undefined; formData.value = undefined;
details.value = []; details.value = [];
currentStorId.value = undefined; currentStorId.value = undefined;
return; return;
} }
// 新会话不继承上一编辑详情请求留下的锁状态。
modalApi.unlock();
const data = modalApi.getData<WmsIostorInvApi.IostorInv>(); const data = modalApi.getData<WmsIostorInvApi.IostorInv>();
if (!data?.iostorinvId) { if (!data?.iostorinvId) {
activeEditId = undefined;
formData.value = undefined; formData.value = undefined;
details.value = []; details.value = [];
currentStorId.value = undefined; currentStorId.value = undefined;
await outboundFormApi.resetForm(); await outboundFormApi.resetForm();
if (!mainModalOpen || mainOpenToken !== token || activeEditId) return;
await outboundFormApi.setValues({ await outboundFormApi.setValues({
billCode: '保存时自动生成', billCode: '保存时自动生成',
billStatus: '生成', billStatus: '生成',
@@ -316,17 +327,42 @@ const [Modal, modalApi] = useVbenModal({
detailCount: 0, detailCount: 0,
totalWeight: '0.000', totalWeight: '0.000',
}); });
if (!mainModalOpen || mainOpenToken !== token || activeEditId) return;
await loadBillTypeOptions(); await loadBillTypeOptions();
return; return;
} }
const editId = data.iostorinvId;
activeEditId = editId;
formData.value = data;
modalApi.lock(); modalApi.lock();
try { try {
formData.value = data; const editResult = await getIostorInv(editId);
formData.value = await getIostorInv(data.iostorinvId); if (
await legacyFormApi.setValues(formData.value); !shouldApplyEditResult(
mainModalOpen,
mainOpenToken,
token,
activeEditId,
editId,
)
) {
return;
}
formData.value = editResult;
await legacyFormApi.setValues(editResult);
} finally { } finally {
if (
shouldApplyEditResult(
mainModalOpen,
mainOpenToken,
token,
activeEditId,
editId,
)
) {
modalApi.unlock(); modalApi.unlock();
} }
}
}, },
}); });
</script> </script>
@@ -358,7 +394,9 @@ const [Modal, modalApi] = useVbenModal({
<InputNumber <InputNumber
v-model:value="record.planQty" v-model:value="record.planQty"
class="w-full" class="w-full"
:min="0" :min="0.001"
:precision="3"
:step="0.001"
@change="refreshSummary" @change="refreshSummary"
/> />
</template> </template>

View File

@@ -4,9 +4,20 @@ import {
buildOutboundPayload, buildOutboundPayload,
filterOutboundBillTypeOptions, filterOutboundBillTypeOptions,
mergeOutboundInventory, mergeOutboundInventory,
shouldApplyEditResult,
shouldClearDetailsForWarehouseChange, shouldClearDetailsForWarehouseChange,
} from './outbound-form'; } from './outbound-form';
describe('shouldApplyEditResult', () => {
it('只允许当前打开会话中同一编辑单据的响应落表', () => {
expect(shouldApplyEditResult(true, 2, 2, 'B', 'B')).toBe(true);
expect(shouldApplyEditResult(true, 2, 1, 'B', 'A')).toBe(false);
expect(shouldApplyEditResult(true, 2, 2, 'B', 'A')).toBe(false);
expect(shouldApplyEditResult(true, 2, 1, undefined, 'A')).toBe(false);
expect(shouldApplyEditResult(false, 2, 2, 'B', 'B')).toBe(false);
});
});
describe('filterOutboundBillTypeOptions', () => { describe('filterOutboundBillTypeOptions', () => {
it('从冷缓存接口结果中只提取启用的出库业务类型', () => { it('从冷缓存接口结果中只提取启用的出库业务类型', () => {
expect( expect(

View File

@@ -7,6 +7,21 @@ export interface OutboundDictItem {
value: string; value: string;
} }
export function shouldApplyEditResult(
modalOpen: boolean,
currentToken: number,
requestToken: number,
activeEditId?: string,
requestEditId?: string,
) {
return (
modalOpen &&
currentToken === requestToken &&
Boolean(requestEditId) &&
activeEditId === requestEditId
);
}
export interface OutboundFormValues { export interface OutboundFormValues {
billType?: string; billType?: string;
bizDate?: number | string | { valueOf: () => number }; bizDate?: number | string | { valueOf: () => number };