优化
This commit is contained in:
@@ -151,7 +151,7 @@ describe('LocationsView', () => {
|
||||
vi.mocked(createPlatformLocation).mockReset()
|
||||
})
|
||||
|
||||
it('loads all warehouse candidates for querying while restricting write scope to domestic warehouses', async () => {
|
||||
it('loads only domestic warehouse candidates for querying and writes', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const fields = toolbar.props('fields') as QueryField[]
|
||||
@@ -160,14 +160,12 @@ describe('LocationsView', () => {
|
||||
expect(fields[0]?.placeholder).toBe('全部仓库')
|
||||
expect(fields[0]?.options).toEqual([
|
||||
{ value: warehouseId, label: '义乌收货仓(CN-YW-01)' },
|
||||
{ value: fbaWarehouse.id, label: 'ONT8 FBA 仓(FBA-ONT8)' },
|
||||
{ value: overseasWarehouse.id, label: '洛杉矶海外仓(US-LAX-01)' },
|
||||
])
|
||||
expect(fields.map(({ key, width }) => [key, width])).toEqual([
|
||||
['warehouseId', 300], ['zoneCode', 210],
|
||||
['locationCode', 220], ['locationType', 170], ['status', 160],
|
||||
])
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith({ warehouseType: 'DOMESTIC' })
|
||||
expect(listPlatformLocations).toHaveBeenCalledWith({
|
||||
page: 1,
|
||||
size: 20,
|
||||
@@ -196,7 +194,7 @@ describe('LocationsView', () => {
|
||||
expect(panelHeading.text()).toContain('共 2 个库位')
|
||||
expect(panelHeading.text()).toContain('新增库位')
|
||||
expect(wrapper.findComponent(QueryToolbar).text()).not.toContain('新增库位')
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith({ warehouseType: 'DOMESTIC' })
|
||||
expect(listPlatformLocations).toHaveBeenLastCalledWith({
|
||||
page: 1,
|
||||
size: 20,
|
||||
@@ -274,7 +272,7 @@ describe('LocationsView', () => {
|
||||
await detailButton.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(getPlatformLocation).toHaveBeenCalledWith(tenantId, warehouseId, availableLocation.id)
|
||||
expect(getPlatformLocation).toHaveBeenCalledWith(warehouseId, availableLocation.id)
|
||||
expect(document.body.textContent).toContain('库位详情')
|
||||
expect(document.body.textContent).toContain('义乌收货仓(CN-YW-01)')
|
||||
expect(document.body.textContent).toContain('资源作用域平台公共资源')
|
||||
|
||||
@@ -105,7 +105,6 @@ const queryFields = computed<QueryField[]>(() => [
|
||||
|
||||
const emptyForm = () => ({
|
||||
id: '',
|
||||
customerId: '',
|
||||
warehouseId: '',
|
||||
zoneCode: '',
|
||||
zoneName: '',
|
||||
@@ -236,11 +235,11 @@ function requireCreateScope() {
|
||||
ElMessage.warning('请选择国内仓')
|
||||
return null
|
||||
}
|
||||
return { customerId: apiId(String(selectedWarehouse.value.tenantId)), warehouseId: apiId(form.warehouseId) }
|
||||
return { warehouseId: apiId(form.warehouseId) }
|
||||
}
|
||||
|
||||
function recordScope(row: PlatformLocationResource) {
|
||||
return { customerId: apiId(String(row.tenantId)), warehouseId: apiId(String(row.warehouseId)) }
|
||||
return { warehouseId: apiId(String(row.warehouseId)) }
|
||||
}
|
||||
|
||||
async function loadWarehouses() {
|
||||
@@ -249,9 +248,11 @@ async function loadWarehouses() {
|
||||
warehouseError.value = null
|
||||
warehouses.value = []
|
||||
try {
|
||||
const records = await listAllPlatformWarehouses()
|
||||
// 库位只属于国内仓,查询候选仓库时直接限制仓库类型,避免把 FBA/海外仓带入页面。
|
||||
const records = await listAllPlatformWarehouses({ warehouseType: 'DOMESTIC' })
|
||||
if (sequence !== warehouseLoadSequence) return
|
||||
warehouses.value = records
|
||||
// 保留前端兜底过滤,避免旧接口或异常响应返回其他仓库类型。
|
||||
warehouses.value = records.filter((warehouse) => warehouse.warehouseType === 'DOMESTIC')
|
||||
} catch (error) {
|
||||
if (sequence !== warehouseLoadSequence) return
|
||||
warehouseError.value = getApiErrorDetails(error, '仓库列表加载失败,请稍后重试')
|
||||
@@ -303,7 +304,6 @@ function applyFilters(model: QueryModel) {
|
||||
function assignForm(resource: PlatformLocationResource) {
|
||||
Object.assign(form, {
|
||||
id: String(resource.id),
|
||||
customerId: String(resource.tenantId),
|
||||
warehouseId: String(resource.warehouseId),
|
||||
zoneCode: resource.zoneCode,
|
||||
zoneName: resource.zoneName,
|
||||
@@ -320,7 +320,6 @@ function assignForm(resource: PlatformLocationResource) {
|
||||
function openCreate() {
|
||||
Object.assign(form, emptyForm())
|
||||
form.warehouseId = isActiveDomesticWarehouse(selectedWarehouseId.value) ? selectedWarehouseId.value : ''
|
||||
form.customerId = selectedWarehouse.value ? String(selectedWarehouse.value.tenantId) : ''
|
||||
form.status = selectedWarehouse.value?.status === 'INACTIVE' ? 'DISABLED' : 'AVAILABLE'
|
||||
detail.value = null
|
||||
drawerError.value = null
|
||||
@@ -342,7 +341,7 @@ async function loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit')
|
||||
drawerError.value = null
|
||||
detail.value = null
|
||||
try {
|
||||
const result = await getPlatformLocation(scope.customerId, scope.warehouseId, row.id)
|
||||
const result = await getPlatformLocation(scope.warehouseId, row.id)
|
||||
detail.value = result
|
||||
if (mode === 'edit') {
|
||||
assignForm(result.location)
|
||||
@@ -381,15 +380,13 @@ async function saveLocation() {
|
||||
ElMessage.error(form.id ? '库位仅支持归属国内仓' : '新增库位仅支持选择启用的国内仓')
|
||||
return
|
||||
}
|
||||
const scope = form.id
|
||||
? { customerId: apiId(form.customerId), warehouseId: apiId(form.warehouseId) }
|
||||
: requireCreateScope()
|
||||
const scope = form.id ? { warehouseId: apiId(form.warehouseId) } : requireCreateScope()
|
||||
if (!scope) return
|
||||
saving.value = true
|
||||
try {
|
||||
const payload = buildPayload()
|
||||
if (form.id) await updatePlatformLocation(scope.customerId, scope.warehouseId, form.id, payload)
|
||||
else await createPlatformLocation(scope.customerId, payload)
|
||||
if (form.id) await updatePlatformLocation(scope.warehouseId, form.id, payload)
|
||||
else await createPlatformLocation(payload)
|
||||
drawerOpen.value = false
|
||||
ElMessage.success(form.id ? '库位资料已更新' : '库位已创建')
|
||||
await loadLocations()
|
||||
@@ -426,7 +423,7 @@ async function toggleStatus(row: PlatformLocationResource) {
|
||||
}
|
||||
setActionLoading(row.id, true)
|
||||
try {
|
||||
await changePlatformLocationStatus(scope.customerId, scope.warehouseId, row.id, nextStatus, row.version)
|
||||
await changePlatformLocationStatus(scope.warehouseId, row.id, nextStatus, row.version)
|
||||
ElMessage.success(`库位 ${row.locationCode} 已${action}`)
|
||||
await loadLocations()
|
||||
} catch (error) {
|
||||
@@ -451,7 +448,7 @@ async function removeLocation(row: PlatformLocationResource) {
|
||||
}
|
||||
setActionLoading(row.id, true)
|
||||
try {
|
||||
await deletePlatformLocation(scope.customerId, scope.warehouseId, row.id, row.version)
|
||||
await deletePlatformLocation(scope.warehouseId, row.id, row.version)
|
||||
ElMessage.success(`库位 ${row.locationCode} 已删除`)
|
||||
await loadLocations()
|
||||
} catch (error) {
|
||||
@@ -480,7 +477,6 @@ watch([page, pageSize], () => { void loadLocations() })
|
||||
watch(() => form.warehouseId, (warehouseId) => {
|
||||
if (drawerMode.value !== 'create') return
|
||||
const warehouse = warehouses.value.find((item) => String(item.id) === warehouseId)
|
||||
form.customerId = warehouse ? String(warehouse.tenantId) : ''
|
||||
form.status = warehouse?.status === 'INACTIVE' ? 'DISABLED' : 'AVAILABLE'
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user