优化
This commit is contained in:
@@ -336,4 +336,33 @@ describe('LocationsView', () => {
|
||||
status: '',
|
||||
})
|
||||
})
|
||||
|
||||
it('keeps the latest detail when an older location request finishes last', async () => {
|
||||
const secondLocation = { ...availableLocation, id: '9223372036854775800', locationCode: 'A1-03' }
|
||||
const firstDetail = { location: availableLocation, warehouseCode: warehouse.warehouseCode, warehouseName: warehouse.warehouseName }
|
||||
const secondDetail = { location: secondLocation, warehouseCode: warehouse.warehouseCode, warehouseName: warehouse.warehouseName }
|
||||
let resolveFirst!: (value: typeof firstDetail) => void
|
||||
let resolveSecond!: (value: typeof secondDetail) => void
|
||||
vi.mocked(getPlatformLocation).mockImplementation((_warehouseId, locationId) => new Promise((resolve) => {
|
||||
if (String(locationId) === String(availableLocation.id)) resolveFirst = resolve
|
||||
else resolveSecond = resolve
|
||||
}))
|
||||
const wrapper = await mountView()
|
||||
const vm = wrapper.vm as unknown as {
|
||||
drawerOpen: boolean
|
||||
detail: typeof firstDetail | null
|
||||
loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit'): Promise<void>
|
||||
}
|
||||
|
||||
void vm.loadDetail(availableLocation, 'view')
|
||||
vm.drawerOpen = false
|
||||
await wrapper.vm.$nextTick()
|
||||
void vm.loadDetail(secondLocation, 'view')
|
||||
resolveSecond(secondDetail)
|
||||
await flushPromises()
|
||||
resolveFirst(firstDetail)
|
||||
await flushPromises()
|
||||
|
||||
expect(vm.detail?.location.locationCode).toBe('A1-03')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -61,6 +61,7 @@ const actionLoadingIds = ref(new Set<string>())
|
||||
const formRef = ref<FormInstance>()
|
||||
let warehouseLoadSequence = 0
|
||||
let locationLoadSequence = 0
|
||||
let drawerLoadSequence = 0
|
||||
|
||||
const filters = ref<LocationFilters>({ warehouseId: '', zoneCode: '', locationCode: '', locationType: '', status: '' })
|
||||
const appliedFilters = ref<AppliedLocationFilters>({ warehouseId: '', zoneCode: '', locationCode: '', locationType: '', status: '' })
|
||||
@@ -335,6 +336,7 @@ async function loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit')
|
||||
ElMessage.warning('仅支持编辑国内仓库位')
|
||||
return
|
||||
}
|
||||
const sequence = ++drawerLoadSequence
|
||||
const scope = recordScope(row)
|
||||
drawerMode.value = mode
|
||||
drawerOpen.value = true
|
||||
@@ -343,6 +345,7 @@ async function loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit')
|
||||
detail.value = null
|
||||
try {
|
||||
const result = await getPlatformLocation(scope.warehouseId, row.id)
|
||||
if (sequence !== drawerLoadSequence || !drawerOpen.value) return
|
||||
detail.value = result
|
||||
if (mode === 'edit') {
|
||||
assignForm(result.location)
|
||||
@@ -350,9 +353,10 @@ async function loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit')
|
||||
void formRef.value?.clearValidate()
|
||||
}
|
||||
} catch (error) {
|
||||
if (sequence !== drawerLoadSequence) return
|
||||
drawerError.value = getApiErrorDetails(error, '库位详情加载失败,请稍后重试')
|
||||
} finally {
|
||||
drawerLoading.value = false
|
||||
if (sequence === drawerLoadSequence) drawerLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -475,6 +479,13 @@ watch(
|
||||
)
|
||||
|
||||
watch([page, pageSize], () => { void loadLocations() })
|
||||
watch(drawerOpen, (open) => {
|
||||
if (open) return
|
||||
drawerLoadSequence += 1
|
||||
drawerLoading.value = false
|
||||
drawerError.value = null
|
||||
detail.value = null
|
||||
})
|
||||
watch(() => form.warehouseId, (warehouseId) => {
|
||||
if (drawerMode.value !== 'create') return
|
||||
const warehouse = warehouses.value.find((item) => String(item.id) === warehouseId)
|
||||
|
||||
Reference in New Issue
Block a user