优化
This commit is contained in:
@@ -37,11 +37,11 @@ describe('platform pallet API', () => {
|
||||
})
|
||||
|
||||
await expect(listPlatformPallets({
|
||||
tenantId: '9223372036854775806', page: 2, size: 20, warehouseId: '19001', palletCode: ' TP ', palletType: ' 木托盘 ',
|
||||
page: 2, size: 20, warehouseId: '19001', palletCode: ' TP ', palletType: ' 木托盘 ',
|
||||
})).resolves.toEqual({ records: [], page: 2, size: 20, total: 41, pages: 3 })
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/v1/pallets', {
|
||||
params: {
|
||||
tenantId: '9223372036854775806', page: 2, size: 20, warehouseId: '19001', palletCode: 'TP', palletType: '木托盘',
|
||||
page: 2, size: 20, warehouseId: '19001', palletCode: 'TP', palletType: '木托盘',
|
||||
},
|
||||
})
|
||||
})
|
||||
@@ -65,14 +65,14 @@ describe('platform pallet API', () => {
|
||||
vi.mocked(http.put).mockResolvedValue({ code: '200', data: null })
|
||||
vi.mocked(http.delete).mockResolvedValue({ code: '200', data: null })
|
||||
|
||||
await expect(getPlatformPallet(10001, '19001', '20001')).resolves.toEqual({ id: '20001' })
|
||||
await expect(createPlatformPallet(10001, payload)).resolves.toBe('20001')
|
||||
await expect(updatePlatformPallet(10001, '19001', '20001', payload)).resolves.toBeNull()
|
||||
await expect(deletePlatformPallet(10001, '19001', '20001')).resolves.toBeNull()
|
||||
await expect(getPlatformPallet('19001', '20001')).resolves.toEqual({ id: '20001' })
|
||||
await expect(createPlatformPallet(payload)).resolves.toBe('20001')
|
||||
await expect(updatePlatformPallet('19001', '20001', payload)).resolves.toBeNull()
|
||||
await expect(deletePlatformPallet('19001', '20001')).resolves.toBeNull()
|
||||
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/v1/pallets/20001', { params: { tenantId: 10001, warehouseId: '19001' } })
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/v1/pallets', payload, { params: { tenantId: 10001 } })
|
||||
expect(http.put).toHaveBeenCalledWith('/platform/v1/pallets/20001', payload, { params: { tenantId: 10001, warehouseId: '19001' } })
|
||||
expect(http.delete).toHaveBeenCalledWith('/platform/v1/pallets/20001', { params: { tenantId: 10001, warehouseId: '19001' } })
|
||||
expect(http.get).toHaveBeenCalledWith('/platform/v1/pallets/20001', { params: { tenantId: 0, warehouseId: '19001' } })
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/v1/pallets', payload, { params: { tenantId: 0 } })
|
||||
expect(http.put).toHaveBeenCalledWith('/platform/v1/pallets/20001', payload, { params: { tenantId: 0, warehouseId: '19001' } })
|
||||
expect(http.delete).toHaveBeenCalledWith('/platform/v1/pallets/20001', { params: { tenantId: 0, warehouseId: '19001' } })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface PlatformPalletResource {
|
||||
palletType: string
|
||||
capacityCbm: number | string
|
||||
weightKg: number | string | null
|
||||
color: string | null
|
||||
color: string
|
||||
remark: string | null
|
||||
createdAt: string | null
|
||||
updatedAt: string | null
|
||||
@@ -23,7 +23,6 @@ export interface PlatformPalletPage {
|
||||
}
|
||||
|
||||
export interface PlatformPalletQuery {
|
||||
tenantId?: number | string
|
||||
page: number
|
||||
size: number
|
||||
warehouseId?: number | string
|
||||
@@ -36,16 +35,16 @@ export interface SavePlatformPalletRequest {
|
||||
palletType: string
|
||||
capacityCbm: number
|
||||
weightKg: number
|
||||
color: string | null
|
||||
color: string
|
||||
remark: string | null
|
||||
}
|
||||
|
||||
const basePath = '/platform/v1/pallets'
|
||||
const platformResourceScope = 0
|
||||
|
||||
export async function listPlatformPallets(query: PlatformPalletQuery) {
|
||||
const response = await http.get<ApiEnvelope<PlatformPalletPage>, ApiEnvelope<PlatformPalletPage>>(basePath, {
|
||||
params: {
|
||||
...(query.tenantId === undefined || query.tenantId === '' ? {} : { tenantId: query.tenantId }),
|
||||
page: query.page,
|
||||
size: query.size,
|
||||
...(query.warehouseId === undefined || query.warehouseId === '' ? {} : { warehouseId: query.warehouseId }),
|
||||
@@ -64,43 +63,40 @@ export async function listPlatformPallets(query: PlatformPalletQuery) {
|
||||
}
|
||||
|
||||
export async function getPlatformPallet(
|
||||
tenantId: number | string,
|
||||
warehouseId: number | string,
|
||||
id: number | string,
|
||||
) {
|
||||
const response = await http.get<ApiEnvelope<PlatformPalletResource>, ApiEnvelope<PlatformPalletResource>>(
|
||||
`${basePath}/${id}`,
|
||||
{ params: { tenantId, warehouseId } },
|
||||
{ params: { tenantId: platformResourceScope, warehouseId } },
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function createPlatformPallet(tenantId: number | string, payload: SavePlatformPalletRequest) {
|
||||
export async function createPlatformPallet(payload: SavePlatformPalletRequest) {
|
||||
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
|
||||
params: { tenantId },
|
||||
params: { tenantId: platformResourceScope },
|
||||
})
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function updatePlatformPallet(
|
||||
tenantId: number | string,
|
||||
warehouseId: number | string,
|
||||
id: number | string,
|
||||
payload: SavePlatformPalletRequest,
|
||||
) {
|
||||
const response = await http.put<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, payload, {
|
||||
params: { tenantId, warehouseId },
|
||||
params: { tenantId: platformResourceScope, warehouseId },
|
||||
})
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
export async function deletePlatformPallet(
|
||||
tenantId: number | string,
|
||||
warehouseId: number | string,
|
||||
id: number | string,
|
||||
) {
|
||||
const response = await http.delete<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, {
|
||||
params: { tenantId, warehouseId },
|
||||
params: { tenantId: platformResourceScope, warehouseId },
|
||||
})
|
||||
return unwrapApiResponse(response)
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ describe('PalletsView', () => {
|
||||
vi.mocked(createPlatformPallet).mockReset().mockResolvedValue('20002')
|
||||
})
|
||||
|
||||
it('starts with all warehouse candidates for querying using compact filters', async () => {
|
||||
it('starts with enabled domestic warehouse candidates for querying using compact filters', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const fields = toolbar.props('fields')
|
||||
@@ -132,8 +132,6 @@ describe('PalletsView', () => {
|
||||
expect(fields.find((field) => field.key === 'warehouseId')?.placeholder).toBe('全部仓库')
|
||||
expect(fields.find((field) => field.key === 'warehouseId')?.options).toEqual([
|
||||
{ label: '义乌收货仓(CN-YW-01)', value: '19001' },
|
||||
{ label: 'ONT8 FBA 仓(FBA-ONT8)', value: '19002' },
|
||||
{ label: '洛杉矶海外仓(US-LAX-01)', value: '19003' },
|
||||
])
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
@@ -205,8 +203,6 @@ describe('PalletsView', () => {
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(warehouseField?.options).toEqual([
|
||||
{ label: '义乌收货仓(CN-YW-01)', value: '19001' },
|
||||
{ label: 'ONT8 FBA 仓(FBA-ONT8)', value: '19002' },
|
||||
{ label: '洛杉矶海外仓(US-LAX-01)', value: '19003' },
|
||||
])
|
||||
})
|
||||
|
||||
@@ -256,7 +252,7 @@ describe('PalletsView', () => {
|
||||
await saveButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(createPlatformPallet).toHaveBeenCalledWith(0, {
|
||||
expect(createPlatformPallet).toHaveBeenCalledWith({
|
||||
warehouseId: 19001, palletType: '塑料托盘', capacityCbm: 1.5, weightKg: 10, color: '黑色', remark: '标准托盘',
|
||||
})
|
||||
})
|
||||
@@ -322,7 +318,7 @@ describe('PalletsView', () => {
|
||||
await viewButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(getPlatformPallet).toHaveBeenCalledWith(0, 19001, '20001')
|
||||
expect(getPlatformPallet).toHaveBeenCalledWith(19001, '20001')
|
||||
expect(document.body.textContent).toContain('资源作用域')
|
||||
expect(document.body.textContent).toContain('平台公共资源')
|
||||
expect(document.body.textContent).not.toContain('所属企业')
|
||||
|
||||
@@ -50,7 +50,7 @@ const queryFields = computed<QueryField[]>(() => [
|
||||
type: 'select',
|
||||
width: 300,
|
||||
placeholder: warehouseLoading.value ? '正在加载所属仓库' : warehouseError.value ? '所属仓库加载失败' : '全部仓库',
|
||||
options: warehouses.value.map((warehouse) => ({
|
||||
options: domesticWarehouses.value.map((warehouse) => ({
|
||||
label: `${warehouse.warehouseName}(${warehouse.warehouseCode})`,
|
||||
value: String(warehouse.id),
|
||||
})),
|
||||
@@ -71,7 +71,7 @@ const queryFields = computed<QueryField[]>(() => [
|
||||
},
|
||||
])
|
||||
|
||||
const emptyForm = () => ({ id: '', customerId: '', warehouseId: '', palletCode: '', palletType: '', capacityCbm: null as number | null, weightKg: null as number | null, color: '', remark: '' })
|
||||
const emptyForm = () => ({ id: '', warehouseId: '', palletCode: '', palletType: '', capacityCbm: null as number | null, weightKg: null as number | null, color: '', remark: '' })
|
||||
const form = reactive(emptyForm())
|
||||
const rules: FormRules<typeof form> = {
|
||||
warehouseId: [{ required: true, message: '请选择国内仓', trigger: 'change' }],
|
||||
@@ -226,7 +226,6 @@ function resetFilters() {
|
||||
function openCreate() {
|
||||
Object.assign(form, emptyForm())
|
||||
form.warehouseId = isActiveDomesticWarehouse(filters.value.warehouseId) ? filters.value.warehouseId : ''
|
||||
form.customerId = editorWarehouse.value ? String(editorWarehouse.value.tenantId) : ''
|
||||
editorOpen.value = true
|
||||
captureBaseline()
|
||||
void formRef.value?.clearValidate()
|
||||
@@ -235,7 +234,6 @@ function openCreate() {
|
||||
function assignForm(resource: PlatformPalletResource) {
|
||||
Object.assign(form, {
|
||||
id: String(resource.id),
|
||||
customerId: String(resource.tenantId),
|
||||
warehouseId: String(resource.warehouseId),
|
||||
palletCode: resource.palletCode,
|
||||
palletType: resource.palletType,
|
||||
@@ -250,7 +248,7 @@ function assignForm(resource: PlatformPalletResource) {
|
||||
}
|
||||
|
||||
async function fetchDetail(row: PlatformPalletResource) {
|
||||
return getPlatformPallet(apiId(String(row.tenantId)), apiId(String(row.warehouseId)), row.id)
|
||||
return getPlatformPallet(apiId(String(row.warehouseId)), row.id)
|
||||
}
|
||||
|
||||
async function openDetail(row: PlatformPalletResource) {
|
||||
@@ -289,20 +287,18 @@ async function savePallet() {
|
||||
ElMessage.error(form.id ? '托盘仅支持归属国内仓' : '新增托盘仅支持选择启用的国内仓')
|
||||
return
|
||||
}
|
||||
form.customerId = String(warehouse.tenantId)
|
||||
saving.value = true
|
||||
const payload: SavePlatformPalletRequest = {
|
||||
warehouseId: apiId(form.warehouseId),
|
||||
palletType: form.palletType.trim(),
|
||||
capacityCbm: form.capacityCbm,
|
||||
weightKg: form.weightKg,
|
||||
color: form.color.trim() || null,
|
||||
color: form.color.trim(),
|
||||
remark: form.remark.trim() || null,
|
||||
}
|
||||
try {
|
||||
const customerId = apiId(form.customerId)
|
||||
if (form.id) await updatePlatformPallet(customerId, apiId(form.warehouseId), form.id, payload)
|
||||
else await createPlatformPallet(customerId, payload)
|
||||
if (form.id) await updatePlatformPallet(apiId(form.warehouseId), form.id, payload)
|
||||
else await createPlatformPallet(payload)
|
||||
ElMessage.success(form.id ? '托盘已更新' : '托盘已新增')
|
||||
editorOpen.value = false
|
||||
await loadPallets()
|
||||
@@ -326,7 +322,7 @@ async function removePallet(row: PlatformPalletResource) {
|
||||
const id = String(row.id)
|
||||
deletingIds.value = new Set([...deletingIds.value, id])
|
||||
try {
|
||||
await deletePlatformPallet(apiId(String(row.tenantId)), apiId(String(row.warehouseId)), row.id)
|
||||
await deletePlatformPallet(apiId(String(row.warehouseId)), row.id)
|
||||
ElMessage.success('托盘已删除')
|
||||
if (rows.value.length === 1 && page.value > 1) page.value -= 1
|
||||
else await loadPallets()
|
||||
|
||||
Reference in New Issue
Block a user