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

View File

@@ -4,9 +4,20 @@ import {
buildOutboundPayload,
filterOutboundBillTypeOptions,
mergeOutboundInventory,
shouldApplyEditResult,
shouldClearDetailsForWarehouseChange,
} 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', () => {
it('从冷缓存接口结果中只提取启用的出库业务类型', () => {
expect(

View File

@@ -7,6 +7,21 @@ export interface OutboundDictItem {
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 {
billType?: string;
bizDate?: number | string | { valueOf: () => number };