优化
This commit is contained in:
@@ -5,16 +5,17 @@ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vites
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import {
|
||||
createPlatformLocation,
|
||||
getPlatformLocation,
|
||||
listPlatformLocations,
|
||||
type PlatformLocationResource,
|
||||
} from '../api/platformLocations'
|
||||
import { listPlatformWarehouses, type PlatformWarehouseResource } from '../../../warehouses/api/platformWarehouses'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '../../../warehouses/api/platformWarehouses'
|
||||
import QueryToolbar, { type QueryField, type QueryModel } from '@/shared/components/QueryToolbar.vue'
|
||||
import DataTable from '@/shared/components/DataTable.vue'
|
||||
import LocationsView from './LocationsView.vue'
|
||||
|
||||
vi.mock('../../../warehouses/api/platformWarehouses', () => ({ listPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('../../../warehouses/api/platformWarehouses', () => ({ listAllPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('../api/platformLocations', () => ({
|
||||
listPlatformLocations: vi.fn(),
|
||||
getPlatformLocation: vi.fn(),
|
||||
@@ -59,6 +60,22 @@ const warehouse: PlatformWarehouseResource = {
|
||||
remark: null,
|
||||
}
|
||||
|
||||
const fbaWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '9223372036854775802',
|
||||
warehouseCode: 'FBA-ONT8',
|
||||
warehouseName: 'ONT8 FBA 仓',
|
||||
warehouseType: 'FBA',
|
||||
}
|
||||
|
||||
const overseasWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '9223372036854775801',
|
||||
warehouseCode: 'US-LAX-01',
|
||||
warehouseName: '洛杉矶海外仓',
|
||||
warehouseType: 'OVERSEAS',
|
||||
}
|
||||
|
||||
const availableLocation: PlatformLocationResource = {
|
||||
id: '9223372036854775804',
|
||||
tenantId,
|
||||
@@ -124,29 +141,33 @@ describe('LocationsView', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(listPlatformWarehouses).mockReset().mockResolvedValue({
|
||||
records: [warehouse], page: 1, size: 200, total: 1, pages: 1,
|
||||
})
|
||||
vi.mocked(listAllPlatformWarehouses).mockReset().mockResolvedValue([warehouse, fbaWarehouse, overseasWarehouse])
|
||||
vi.mocked(listPlatformLocations).mockReset().mockResolvedValue({
|
||||
records: [availableLocation, occupiedLocation], page: 1, size: 20, total: 2, pages: 1,
|
||||
})
|
||||
vi.mocked(getPlatformLocation).mockReset().mockResolvedValue({
|
||||
location: availableLocation, warehouseCode: warehouse.warehouseCode, warehouseName: warehouse.warehouseName,
|
||||
})
|
||||
vi.mocked(createPlatformLocation).mockReset()
|
||||
})
|
||||
|
||||
it('loads all warehouses and queries the full location list without requiring a customer or warehouse', async () => {
|
||||
it('loads all warehouse candidates for querying while restricting write scope to domestic warehouses', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const fields = toolbar.props('fields') as QueryField[]
|
||||
|
||||
expect(wrapper.find('[aria-label="所属企业"]').exists()).toBe(false)
|
||||
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(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformLocations).toHaveBeenCalledWith({
|
||||
page: 1,
|
||||
size: 20,
|
||||
@@ -175,7 +196,7 @@ describe('LocationsView', () => {
|
||||
expect(panelHeading.text()).toContain('共 2 个库位')
|
||||
expect(panelHeading.text()).toContain('新增库位')
|
||||
expect(wrapper.findComponent(QueryToolbar).text()).not.toContain('新增库位')
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformLocations).toHaveBeenLastCalledWith({
|
||||
page: 1,
|
||||
size: 20,
|
||||
@@ -202,7 +223,23 @@ describe('LocationsView', () => {
|
||||
|
||||
expect(document.body.textContent).toContain('新增库位')
|
||||
expect(document.body.textContent).toContain('所属仓库')
|
||||
expect(document.body.textContent).toContain('请选择所属仓库')
|
||||
expect(document.body.textContent).toContain('请选择国内仓')
|
||||
})
|
||||
|
||||
it('does not use an FBA warehouse filter as the creation scope', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
toolbar.vm.$emit('update:modelValue', { ...(toolbar.props('modelValue') as QueryModel), warehouseId: fbaWarehouse.id })
|
||||
await flushPromises()
|
||||
const createButton = wrapper.find('.table-panel .panel-heading').findAll('button').find((button) => button.text().trim() === '新增库位')
|
||||
await createButton!.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
const saveButton = [...document.body.querySelectorAll('button')].find((button) => button.textContent?.trim() === '保存库位')
|
||||
saveButton?.dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
||||
await flushPromises()
|
||||
|
||||
expect(createPlatformLocation).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('keeps the operation column first and hides edit actions for occupied resources', async () => {
|
||||
@@ -218,6 +255,18 @@ describe('LocationsView', () => {
|
||||
expect(bodyRows[1]?.text()).not.toContain('更多')
|
||||
})
|
||||
|
||||
it('does not offer editing for a location outside a domestic warehouse', async () => {
|
||||
vi.mocked(listPlatformLocations).mockResolvedValue({
|
||||
records: [{ ...availableLocation, warehouseId: fbaWarehouse.id }, availableLocation], page: 1, size: 20, total: 2, pages: 1,
|
||||
})
|
||||
const wrapper = await mountView()
|
||||
|
||||
const bodyRows = wrapper.findAll('tbody tr')
|
||||
expect(bodyRows[0]?.text()).toContain('详情')
|
||||
expect(bodyRows[0]?.text()).not.toContain('编辑')
|
||||
expect(bodyRows[1]?.text()).toContain('编辑')
|
||||
})
|
||||
|
||||
it('opens an authenticated detail view with warehouse context', async () => {
|
||||
const wrapper = await mountView()
|
||||
const detailButton = wrapper.find('.el-table__body-wrapper tbody tr button')
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
type PlatformLocationType,
|
||||
type SavePlatformLocationRequest,
|
||||
} from '../api/platformLocations'
|
||||
import { listPlatformWarehouses, type PlatformWarehouseResource } from '../../../warehouses/api/platformWarehouses'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '../../../warehouses/api/platformWarehouses'
|
||||
|
||||
type DrawerMode = 'view' | 'create' | 'edit'
|
||||
type LocationFilters = QueryModel & {
|
||||
@@ -119,7 +119,7 @@ const emptyForm = () => ({
|
||||
})
|
||||
const form = reactive(emptyForm())
|
||||
const rules: FormRules<typeof form> = {
|
||||
warehouseId: [{ required: true, message: '请选择所属仓库', trigger: 'change' }],
|
||||
warehouseId: [{ required: true, message: '请选择国内仓', trigger: 'change' }],
|
||||
zoneCode: [{ required: true, message: '请输入库区编码', trigger: 'blur' }],
|
||||
zoneName: [{ required: true, message: '请输入库区名称', trigger: 'blur' }],
|
||||
locationCode: [
|
||||
@@ -137,6 +137,9 @@ const rules: FormRules<typeof form> = {
|
||||
}
|
||||
|
||||
const selectedWarehouse = computed(() => warehouses.value.find((item) => String(item.id) === form.warehouseId) ?? null)
|
||||
const domesticWarehouses = computed(() => warehouses.value.filter((warehouse) => (
|
||||
warehouse.warehouseType === 'DOMESTIC' && warehouse.status === 'ACTIVE'
|
||||
)))
|
||||
const editorOpen = computed(() => drawerOpen.value && drawerMode.value !== 'view')
|
||||
const editorTitle = computed(() => drawerMode.value === 'create' ? '新增库位' : '编辑库位')
|
||||
const drawerTitle = computed(() => drawerMode.value === 'view' ? '库位详情' : editorTitle.value)
|
||||
@@ -197,6 +200,7 @@ function formatWeight(value: number | string | null) {
|
||||
|
||||
function canEdit(row: PlatformLocationResource) {
|
||||
return access.can('platform:location:edit')
|
||||
&& isDomesticWarehouse(row.warehouseId)
|
||||
&& !row.sharedOverflow
|
||||
&& (row.status === 'AVAILABLE' || row.status === 'DISABLED')
|
||||
}
|
||||
@@ -216,9 +220,20 @@ function actionError(error: unknown, fallback: string) {
|
||||
ElMessage.error(details.requestId ? `${details.message}(requestId: ${details.requestId})` : details.message)
|
||||
}
|
||||
|
||||
function isDomesticWarehouse(warehouseId: number | string) {
|
||||
return warehouses.value.some((warehouse) => (
|
||||
String(warehouse.id) === String(warehouseId)
|
||||
&& warehouse.warehouseType === 'DOMESTIC'
|
||||
))
|
||||
}
|
||||
|
||||
function isActiveDomesticWarehouse(warehouseId: number | string) {
|
||||
return domesticWarehouses.value.some((warehouse) => String(warehouse.id) === String(warehouseId))
|
||||
}
|
||||
|
||||
function requireCreateScope() {
|
||||
if (!selectedWarehouse.value || !form.warehouseId) {
|
||||
ElMessage.warning('请选择所属仓库')
|
||||
ElMessage.warning('请选择国内仓')
|
||||
return null
|
||||
}
|
||||
return { customerId: apiId(String(selectedWarehouse.value.tenantId)), warehouseId: apiId(form.warehouseId) }
|
||||
@@ -234,9 +249,9 @@ async function loadWarehouses() {
|
||||
warehouseError.value = null
|
||||
warehouses.value = []
|
||||
try {
|
||||
const result = await listPlatformWarehouses(1, 200)
|
||||
const records = await listAllPlatformWarehouses()
|
||||
if (sequence !== warehouseLoadSequence) return
|
||||
warehouses.value = result.records
|
||||
warehouses.value = records
|
||||
} catch (error) {
|
||||
if (sequence !== warehouseLoadSequence) return
|
||||
warehouseError.value = getApiErrorDetails(error, '仓库列表加载失败,请稍后重试')
|
||||
@@ -304,7 +319,7 @@ function assignForm(resource: PlatformLocationResource) {
|
||||
|
||||
function openCreate() {
|
||||
Object.assign(form, emptyForm())
|
||||
form.warehouseId = selectedWarehouseId.value
|
||||
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
|
||||
@@ -316,6 +331,10 @@ function openCreate() {
|
||||
}
|
||||
|
||||
async function loadDetail(row: PlatformLocationResource, mode: 'view' | 'edit') {
|
||||
if (mode === 'edit' && !isDomesticWarehouse(row.warehouseId)) {
|
||||
ElMessage.warning('仅支持编辑国内仓库位')
|
||||
return
|
||||
}
|
||||
const scope = recordScope(row)
|
||||
drawerMode.value = mode
|
||||
drawerOpen.value = true
|
||||
@@ -355,6 +374,13 @@ function buildPayload(): SavePlatformLocationRequest {
|
||||
async function saveLocation() {
|
||||
const valid = await formRef.value?.validate().catch(() => false)
|
||||
if (!valid) return
|
||||
const warehouseAllowed = form.id
|
||||
? isDomesticWarehouse(form.warehouseId)
|
||||
: isActiveDomesticWarehouse(form.warehouseId)
|
||||
if (!warehouseAllowed) {
|
||||
ElMessage.error(form.id ? '库位仅支持归属国内仓' : '新增库位仅支持选择启用的国内仓')
|
||||
return
|
||||
}
|
||||
const scope = form.id
|
||||
? { customerId: apiId(form.customerId), warehouseId: apiId(form.warehouseId) }
|
||||
: requireCreateScope()
|
||||
@@ -479,8 +505,8 @@ onMounted(() => {
|
||||
<ApiErrorMeta :details="warehouseError" />
|
||||
<el-button size="small" @click="loadWarehouses()">重新加载仓库</el-button>
|
||||
</el-alert>
|
||||
<el-alert v-else-if="!warehouseLoading && warehouses.length === 0" type="info" :closable="false" show-icon title="暂无可选仓库">
|
||||
请先在仓库管理中建立仓库,再维护库位。
|
||||
<el-alert v-else-if="!warehouseLoading && domesticWarehouses.length === 0" type="info" :closable="false" show-icon title="暂无可选国内仓">
|
||||
请先在仓库管理中建立国内仓,再维护库位。
|
||||
</el-alert>
|
||||
<el-alert v-if="loadError" type="error" :closable="false" show-icon class="state-alert">
|
||||
<template #title>库位列表加载失败</template>
|
||||
@@ -650,9 +676,9 @@ onMounted(() => {
|
||||
<div><strong>{{ detail?.warehouseName || selectedWarehouse?.warehouseName }}({{ detail?.warehouseCode || selectedWarehouse?.warehouseCode }})</strong><span>平台公共资源 · 保存后不可跨仓移动</span></div>
|
||||
</div>
|
||||
<el-form-item v-if="drawerMode === 'create'" label="所属仓库" prop="warehouseId" required>
|
||||
<el-select v-model="form.warehouseId" filterable placeholder="请选择所属仓库" :loading="warehouseLoading">
|
||||
<el-select v-model="form.warehouseId" filterable placeholder="请选择国内仓" :loading="warehouseLoading">
|
||||
<el-option
|
||||
v-for="warehouse in warehouses"
|
||||
v-for="warehouse in domesticWarehouses"
|
||||
:key="String(warehouse.id)"
|
||||
:label="`${warehouse.warehouseName}(${warehouse.warehouseCode})`"
|
||||
:value="String(warehouse.id)"
|
||||
|
||||
@@ -16,9 +16,10 @@ vi.mock('@/shared/api/http', () => ({
|
||||
|
||||
const payload: SavePlatformPalletRequest = {
|
||||
warehouseId: '19001',
|
||||
palletCode: ' TP-001 ',
|
||||
palletType: '木托盘',
|
||||
capacityCbm: 1.2,
|
||||
weightKg: 8,
|
||||
color: '黄色',
|
||||
remark: null,
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ export interface PlatformPalletResource {
|
||||
palletCode: string
|
||||
palletType: string
|
||||
capacityCbm: number | string
|
||||
weightKg: number | string | null
|
||||
color: string | null
|
||||
remark: string | null
|
||||
createdAt: string | null
|
||||
updatedAt: string | null
|
||||
@@ -31,9 +33,10 @@ export interface PlatformPalletQuery {
|
||||
|
||||
export interface SavePlatformPalletRequest {
|
||||
warehouseId: number | string
|
||||
palletCode: string
|
||||
palletType: string
|
||||
capacityCbm: number
|
||||
weightKg: number
|
||||
color: string | null
|
||||
remark: string | null
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { enableAutoUnmount, flushPromises, mount, type VueWrapper } from '@vue/t
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useAuthStore } from '@/core/auth/auth'
|
||||
import { listPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import DataTable from '@/shared/components/DataTable.vue'
|
||||
import QueryToolbar from '@/shared/components/QueryToolbar.vue'
|
||||
import {
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
} from '../api/platformPallets'
|
||||
import PalletsView from './PalletsView.vue'
|
||||
|
||||
vi.mock('@/modules/warehouses', () => ({ listPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('@/modules/warehouses', () => ({ listAllPlatformWarehouses: vi.fn() }))
|
||||
vi.mock('../api/platformPallets', () => ({
|
||||
listPlatformPallets: vi.fn(),
|
||||
getPlatformPallet: vi.fn(),
|
||||
@@ -48,9 +48,25 @@ const warehouse: PlatformWarehouseResource = {
|
||||
contactPhone: null, contactEmail: null, status: 'ACTIVE', remark: null,
|
||||
}
|
||||
|
||||
const fbaWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '19002',
|
||||
warehouseCode: 'FBA-ONT8',
|
||||
warehouseName: 'ONT8 FBA 仓',
|
||||
warehouseType: 'FBA',
|
||||
}
|
||||
|
||||
const overseasWarehouse: PlatformWarehouseResource = {
|
||||
...warehouse,
|
||||
id: '19003',
|
||||
warehouseCode: 'US-LAX-01',
|
||||
warehouseName: '洛杉矶海外仓',
|
||||
warehouseType: 'OVERSEAS',
|
||||
}
|
||||
|
||||
const pallet: PlatformPalletResource = {
|
||||
id: '20001', tenantId: 0, warehouseId: '19001', palletCode: 'TP-001', palletType: '木托盘',
|
||||
capacityCbm: '1.200000', remark: '标准川字托盘', createdAt: '2026-08-04T09:00:00', updatedAt: '2026-08-04T10:00:00',
|
||||
capacityCbm: '1.200000', weightKg: '8.000', color: '黄色', remark: '标准川字托盘', createdAt: '2026-08-04T09:00:00', updatedAt: '2026-08-04T10:00:00',
|
||||
}
|
||||
|
||||
async function mountView(permissions = [
|
||||
@@ -95,13 +111,13 @@ describe('PalletsView', () => {
|
||||
beforeEach(() => {
|
||||
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
||||
document.body.innerHTML = ''
|
||||
vi.mocked(listPlatformWarehouses).mockReset().mockResolvedValue({ records: [warehouse], page: 1, size: 200, total: 1, pages: 1 })
|
||||
vi.mocked(listAllPlatformWarehouses).mockReset().mockResolvedValue([warehouse, fbaWarehouse, overseasWarehouse])
|
||||
vi.mocked(listPlatformPallets).mockReset().mockResolvedValue({ records: [pallet], page: 1, size: 20, total: 1, pages: 1 })
|
||||
vi.mocked(getPlatformPallet).mockReset().mockResolvedValue(pallet)
|
||||
vi.mocked(createPlatformPallet).mockReset().mockResolvedValue('20002')
|
||||
})
|
||||
|
||||
it('starts with all customers and all warehouses using compact filters', async () => {
|
||||
it('starts with all warehouse candidates for querying using compact filters', async () => {
|
||||
const wrapper = await mountView()
|
||||
const toolbar = wrapper.findComponent(QueryToolbar)
|
||||
const fields = toolbar.props('fields')
|
||||
@@ -114,7 +130,12 @@ describe('PalletsView', () => {
|
||||
])
|
||||
expect(wrapper.find('.pallet-filter-toolbar').exists()).toBe(true)
|
||||
expect(fields.find((field) => field.key === 'warehouseId')?.placeholder).toBe('全部仓库')
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
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({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
@@ -124,8 +145,8 @@ describe('PalletsView', () => {
|
||||
const wrapper = await mountView()
|
||||
await loadRows(wrapper)
|
||||
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
@@ -179,8 +200,24 @@ describe('PalletsView', () => {
|
||||
const wrapper = await mountView()
|
||||
const warehouseField = wrapper.findComponent(QueryToolbar).props('fields').find((field) => field.key === 'warehouseId')
|
||||
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledTimes(1)
|
||||
expect(warehouseField?.options).toEqual([{ label: '义乌收货仓(CN-YW-01)', value: '19001' }])
|
||||
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' },
|
||||
])
|
||||
})
|
||||
|
||||
it('does not offer editing for a pallet outside a domestic warehouse', async () => {
|
||||
vi.mocked(listPlatformPallets).mockResolvedValue({
|
||||
records: [{ ...pallet, id: '20002', warehouseId: fbaWarehouse.id }, pallet], page: 1, size: 20, total: 2, pages: 1,
|
||||
})
|
||||
const wrapper = await mountView()
|
||||
|
||||
const bodyRows = wrapper.findAll('.el-table__body-wrapper tbody tr')
|
||||
expect(bodyRows[0]?.text()).toContain('查看')
|
||||
expect(bodyRows[0]?.text()).not.toContain('编辑')
|
||||
expect(bodyRows[1]?.text()).toContain('编辑')
|
||||
})
|
||||
|
||||
it('applies pallet filters only after search', async () => {
|
||||
@@ -206,18 +243,19 @@ describe('PalletsView', () => {
|
||||
await createButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
await wrapper.find('input[placeholder="例如 TP-001"]').setValue('TP-002')
|
||||
const palletTypeItem = wrapper.findAll('.el-form-item').find((item) => item.text().includes('托盘类型'))
|
||||
palletTypeItem?.findComponent({ name: 'ElSelect' }).vm.$emit('update:modelValue', '塑料托盘')
|
||||
const capacity = wrapper.findComponent({ name: 'ElInputNumber' })
|
||||
capacity.vm.$emit('update:modelValue', 1.5)
|
||||
await wrapper.find('textarea[placeholder="可填写规格、材质或现场识别说明"]').setValue('蓝色标准托盘')
|
||||
const inputNumbers = wrapper.findAllComponents({ name: 'ElInputNumber' })
|
||||
inputNumbers[0]?.vm.$emit('update:modelValue', 1.5)
|
||||
inputNumbers[1]?.vm.$emit('update:modelValue', 10)
|
||||
await wrapper.find('input[placeholder="例如 黄色"]').setValue('黑色')
|
||||
await wrapper.find('textarea[placeholder="可填写其他说明"]').setValue('标准托盘')
|
||||
const saveButton = wrapper.findAll('button').find((button) => button.text().trim() === '保存托盘')
|
||||
await saveButton?.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(createPlatformPallet).toHaveBeenCalledWith(0, {
|
||||
warehouseId: 19001, palletCode: 'TP-002', palletType: '塑料托盘', capacityCbm: 1.5, remark: '蓝色标准托盘',
|
||||
warehouseId: 19001, palletType: '塑料托盘', capacityCbm: 1.5, weightKg: 10, color: '黑色', remark: '标准托盘',
|
||||
})
|
||||
})
|
||||
|
||||
@@ -264,7 +302,7 @@ describe('PalletsView', () => {
|
||||
|
||||
expect(wrapper.text()).not.toContain('客户列表暂时无法加载')
|
||||
expect(wrapper.text()).not.toContain('所属企业')
|
||||
expect(listPlatformWarehouses).toHaveBeenCalledWith(1, 200)
|
||||
expect(listAllPlatformWarehouses).toHaveBeenCalledWith()
|
||||
expect(listPlatformPallets).toHaveBeenCalledWith({
|
||||
page: 1, size: 20,
|
||||
})
|
||||
|
||||
@@ -4,7 +4,7 @@ import { ElMessage, ElMessageBox, type FormInstance, type FormRules } from 'elem
|
||||
import { Boxes, Eye, Pencil, Plus, Trash2, Warehouse as WarehouseIcon } from '@lucide/vue'
|
||||
import { useAccessPreviewStore } from '@/core/access/accessPreview'
|
||||
import { useUnsavedWorkRegistration } from '@/core/unsaved-work/useUnsavedWorkRegistration'
|
||||
import { listPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import { listAllPlatformWarehouses, type PlatformWarehouseResource } from '@/modules/warehouses'
|
||||
import { getApiErrorDetails, type ApiErrorDetails } from '@/shared/api/http'
|
||||
import DataTable, { type DataTableColumn } from '@/shared/components/DataTable.vue'
|
||||
import LoadErrorState from '@/shared/components/LoadErrorState.vue'
|
||||
@@ -71,14 +71,10 @@ const queryFields = computed<QueryField[]>(() => [
|
||||
},
|
||||
])
|
||||
|
||||
const emptyForm = () => ({ id: '', customerId: '', warehouseId: '', palletCode: '', palletType: '', capacityCbm: null as number | null, remark: '' })
|
||||
const emptyForm = () => ({ id: '', customerId: '', 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' }],
|
||||
palletCode: [
|
||||
{ required: true, message: '请输入托盘编码', trigger: 'blur' },
|
||||
{ max: 50, message: '托盘编码不能超过 50 个字符', trigger: 'blur' },
|
||||
],
|
||||
warehouseId: [{ required: true, message: '请选择国内仓', trigger: 'change' }],
|
||||
palletType: [
|
||||
{ required: true, message: '请输入托盘类型', trigger: 'blur' },
|
||||
{ max: 32, message: '托盘类型不能超过 32 个字符', trigger: 'blur' },
|
||||
@@ -90,10 +86,24 @@ const rules: FormRules<typeof form> = {
|
||||
},
|
||||
trigger: 'change',
|
||||
}],
|
||||
weightKg: [{
|
||||
validator: (_rule, value, callback) => {
|
||||
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0) callback(new Error('请输入大于 0 的托盘重量'))
|
||||
else callback()
|
||||
},
|
||||
trigger: 'change',
|
||||
}],
|
||||
color: [
|
||||
{ required: true, message: '请输入托盘颜色', trigger: 'blur' },
|
||||
{ max: 32, message: '托盘颜色不能超过 32 个字符', trigger: 'blur' },
|
||||
],
|
||||
remark: [{ max: 500, message: '备注不能超过 500 个字符', trigger: 'blur' }],
|
||||
}
|
||||
|
||||
const editorWarehouse = computed(() => warehouses.value.find((item) => String(item.id) === form.warehouseId) || null)
|
||||
const domesticWarehouses = computed(() => warehouses.value.filter((warehouse) => (
|
||||
warehouse.warehouseType === 'DOMESTIC' && warehouse.status === 'ACTIVE'
|
||||
)))
|
||||
const editorTitle = computed(() => form.id ? '编辑托盘' : '新增托盘')
|
||||
const editorPermission = computed(() => form.id ? 'platform:pallet:edit' : 'platform:pallet:create')
|
||||
const contextLocked = computed(() => editorOpen.value || detailOpen.value || saving.value || deletingIds.value.size > 0)
|
||||
@@ -112,9 +122,9 @@ const columns: DataTableColumn[] = [
|
||||
{ key: 'pallet', label: '托盘编码', minWidth: 190, slotName: 'pallet' },
|
||||
{ prop: 'palletType', label: '托盘类型', minWidth: 140 },
|
||||
{ key: 'capacity', label: '托盘容积(m³)', minWidth: 160, slotName: 'capacity' },
|
||||
{ key: 'warehouse', label: '所属仓库', minWidth: 210, slotName: 'warehouse' },
|
||||
{ key: 'weight', label: '托盘重量(kg)', minWidth: 160, slotName: 'weight' },
|
||||
{ prop: 'color', label: '颜色', minWidth: 120 },
|
||||
{ key: 'remark', label: '备注', minWidth: 220, slotName: 'remark' },
|
||||
{ prop: 'updatedAt', label: '更新时间', minWidth: 160, formatter: (row: PlatformPalletResource) => formatDateTime(row.updatedAt) },
|
||||
]
|
||||
|
||||
function apiId(value: string) {
|
||||
@@ -132,10 +142,25 @@ function formatCapacity(value: number | string) {
|
||||
return `${numeric.toLocaleString('zh-CN', { maximumFractionDigits: 6 })} m³`
|
||||
}
|
||||
|
||||
function formatWeight(value: number | string | null) {
|
||||
if (value === null) return '—'
|
||||
const numeric = Number(value)
|
||||
if (!Number.isFinite(numeric)) return String(value)
|
||||
return `${numeric.toLocaleString('zh-CN', { maximumFractionDigits: 3 })} kg`
|
||||
}
|
||||
|
||||
function warehouseFor(warehouseId: number | string) {
|
||||
return warehouses.value.find((item) => String(item.id) === String(warehouseId)) || null
|
||||
}
|
||||
|
||||
function isDomesticWarehouse(warehouseId: number | string) {
|
||||
return warehouseFor(warehouseId)?.warehouseType === 'DOMESTIC'
|
||||
}
|
||||
|
||||
function isActiveDomesticWarehouse(warehouseId: number | string) {
|
||||
return domesticWarehouses.value.some((warehouse) => String(warehouse.id) === String(warehouseId))
|
||||
}
|
||||
|
||||
function errorMessage(details: ApiErrorDetails) {
|
||||
return details.requestId ? `${details.message}(requestId: ${details.requestId})` : details.message
|
||||
}
|
||||
@@ -146,9 +171,9 @@ async function loadWarehouses() {
|
||||
warehouseError.value = null
|
||||
warehouseLoading.value = true
|
||||
try {
|
||||
const result = await listPlatformWarehouses(1, 200)
|
||||
const records = await listAllPlatformWarehouses()
|
||||
if (sequence !== warehouseSequence) return
|
||||
warehouses.value = result.records
|
||||
warehouses.value = records
|
||||
} catch (error) {
|
||||
if (sequence !== warehouseSequence) return
|
||||
warehouseError.value = getApiErrorDetails(error, '仓库列表加载失败,请稍后重试')
|
||||
@@ -200,7 +225,7 @@ function resetFilters() {
|
||||
|
||||
function openCreate() {
|
||||
Object.assign(form, emptyForm())
|
||||
form.warehouseId = filters.value.warehouseId
|
||||
form.warehouseId = isActiveDomesticWarehouse(filters.value.warehouseId) ? filters.value.warehouseId : ''
|
||||
form.customerId = editorWarehouse.value ? String(editorWarehouse.value.tenantId) : ''
|
||||
editorOpen.value = true
|
||||
captureBaseline()
|
||||
@@ -215,6 +240,8 @@ function assignForm(resource: PlatformPalletResource) {
|
||||
palletCode: resource.palletCode,
|
||||
palletType: resource.palletType,
|
||||
capacityCbm: Number(resource.capacityCbm),
|
||||
weightKg: resource.weightKg === null ? null : Number(resource.weightKg),
|
||||
color: resource.color || '',
|
||||
remark: resource.remark || '',
|
||||
})
|
||||
editorOpen.value = true
|
||||
@@ -241,6 +268,10 @@ async function openDetail(row: PlatformPalletResource) {
|
||||
}
|
||||
|
||||
async function openEdit(row: PlatformPalletResource) {
|
||||
if (!isDomesticWarehouse(row.warehouseId)) {
|
||||
ElMessage.warning('仅支持编辑国内仓托盘')
|
||||
return
|
||||
}
|
||||
try {
|
||||
assignForm(await fetchDetail(row))
|
||||
} catch (error) {
|
||||
@@ -249,19 +280,23 @@ async function openEdit(row: PlatformPalletResource) {
|
||||
}
|
||||
|
||||
async function savePallet() {
|
||||
if (!await formRef.value?.validate().catch(() => false) || form.capacityCbm === null) return
|
||||
if (!await formRef.value?.validate().catch(() => false) || form.capacityCbm === null || form.weightKg === null) return
|
||||
const warehouse = editorWarehouse.value
|
||||
if (!warehouse) {
|
||||
ElMessage.error('所选仓库已不存在,请重新选择')
|
||||
const warehouseAllowed = form.id
|
||||
? warehouse?.warehouseType === 'DOMESTIC'
|
||||
: warehouse?.warehouseType === 'DOMESTIC' && warehouse.status === 'ACTIVE'
|
||||
if (!warehouse || !warehouseAllowed) {
|
||||
ElMessage.error(form.id ? '托盘仅支持归属国内仓' : '新增托盘仅支持选择启用的国内仓')
|
||||
return
|
||||
}
|
||||
form.customerId = String(warehouse.tenantId)
|
||||
saving.value = true
|
||||
const payload: SavePlatformPalletRequest = {
|
||||
warehouseId: apiId(form.warehouseId),
|
||||
palletCode: form.palletCode.trim(),
|
||||
palletType: form.palletType.trim(),
|
||||
capacityCbm: form.capacityCbm,
|
||||
weightKg: form.weightKg,
|
||||
color: form.color.trim() || null,
|
||||
remark: form.remark.trim() || null,
|
||||
}
|
||||
try {
|
||||
@@ -364,7 +399,7 @@ onMounted(() => {
|
||||
<template #actions="{ row }">
|
||||
<div class="table-actions pallet-row-actions">
|
||||
<el-button link type="primary" title="查看托盘" @click="openDetail(row as PlatformPalletResource)"><Eye :size="15" />查看</el-button>
|
||||
<el-button v-if="access.can('platform:pallet:edit')" link type="primary" title="编辑托盘" @click="openEdit(row as PlatformPalletResource)"><Pencil :size="15" />编辑</el-button>
|
||||
<el-button v-if="access.can('platform:pallet:edit') && isDomesticWarehouse((row as PlatformPalletResource).warehouseId)" link type="primary" title="编辑托盘" @click="openEdit(row as PlatformPalletResource)"><Pencil :size="15" />编辑</el-button>
|
||||
<el-button
|
||||
v-if="access.can('platform:pallet:delete')"
|
||||
link
|
||||
@@ -379,7 +414,7 @@ onMounted(() => {
|
||||
<div class="pallet-cell"><span><Boxes :size="18" /></span><strong>{{ (row as PlatformPalletResource).palletCode }}</strong></div>
|
||||
</template>
|
||||
<template #capacity="{ row }"><strong>{{ formatCapacity((row as PlatformPalletResource).capacityCbm) }}</strong></template>
|
||||
<template #warehouse="{ row }"><span>{{ warehouseFor((row as PlatformPalletResource).warehouseId)?.warehouseName || '—' }}</span></template>
|
||||
<template #weight="{ row }"><strong>{{ formatWeight((row as PlatformPalletResource).weightKg) }}</strong></template>
|
||||
<template #remark="{ row }"><span class="remark-text">{{ (row as PlatformPalletResource).remark || '—' }}</span></template>
|
||||
</DataTable>
|
||||
</section>
|
||||
@@ -398,6 +433,8 @@ onMounted(() => {
|
||||
<el-descriptions-item label="托盘编码">{{ detail.palletCode }}</el-descriptions-item>
|
||||
<el-descriptions-item label="托盘类型">{{ detail.palletType }}</el-descriptions-item>
|
||||
<el-descriptions-item label="托盘容积">{{ formatCapacity(detail.capacityCbm) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="托盘重量">{{ formatWeight(detail.weightKg) }}</el-descriptions-item>
|
||||
<el-descriptions-item label="颜色">{{ detail.color || '—' }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注">{{ detail.remark || '—' }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<h3 class="detail-section-title">记录信息</h3>
|
||||
@@ -430,9 +467,9 @@ onMounted(() => {
|
||||
<div><strong>{{ editorWarehouse?.warehouseName || '当前仓库' }}</strong><span>{{ editorWarehouse?.warehouseCode || form.warehouseId }} · 平台公共资源</span></div>
|
||||
</div>
|
||||
<el-form-item v-else label="所属仓库" prop="warehouseId" required>
|
||||
<el-select v-model="form.warehouseId" filterable placeholder="请选择所属仓库" :loading="warehouseLoading">
|
||||
<el-select v-model="form.warehouseId" filterable placeholder="请选择国内仓" :loading="warehouseLoading">
|
||||
<el-option
|
||||
v-for="warehouse in warehouses"
|
||||
v-for="warehouse in domesticWarehouses"
|
||||
:key="String(warehouse.id)"
|
||||
:label="`${warehouse.warehouseName}(${warehouse.warehouseCode})`"
|
||||
:value="String(warehouse.id)"
|
||||
@@ -444,11 +481,11 @@ onMounted(() => {
|
||||
<section class="editor-section" aria-labelledby="pallet-spec-heading">
|
||||
<div class="editor-section-heading">
|
||||
<Boxes :size="18" aria-hidden="true" />
|
||||
<div><h3 id="pallet-spec-heading">托盘规格</h3><p>完善编码、类型与实际可用容积。</p></div>
|
||||
<div><h3 id="pallet-spec-heading">托盘规格</h3><p>编码由系统自动生成,请维护类型、容积、重量和颜色。</p></div>
|
||||
</div>
|
||||
<div class="editor-field-grid">
|
||||
<el-form-item label="托盘编码" prop="palletCode" required>
|
||||
<el-input v-model="form.palletCode" maxlength="50" show-word-limit placeholder="例如 TP-001" />
|
||||
<el-form-item label="托盘编码">
|
||||
<el-input :model-value="form.palletCode || '保存后自动生成'" disabled aria-label="托盘编码(系统生成)" />
|
||||
</el-form-item>
|
||||
<el-form-item label="托盘类型" prop="palletType" required>
|
||||
<el-select
|
||||
@@ -463,12 +500,19 @@ onMounted(() => {
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-form-item label="托盘容积(m³)" prop="capacityCbm" required>
|
||||
<el-input-number v-model="form.capacityCbm" :min="0.000001" :max="999999999999.999999" :precision="6" :step="0.1" controls-position="right" aria-label="标准容积" />
|
||||
<p class="field-help">用于服务端按总体积计算所需托盘数量,请填写托盘实际可用容积。</p>
|
||||
<div class="editor-field-grid">
|
||||
<el-form-item label="托盘容积(m³)" prop="capacityCbm" required>
|
||||
<el-input-number v-model="form.capacityCbm" :min="0.000001" :max="999999999999.999999" :precision="6" :step="0.1" controls-position="right" aria-label="托盘容积" />
|
||||
</el-form-item>
|
||||
<el-form-item label="托盘重量(kg)" prop="weightKg" required>
|
||||
<el-input-number v-model="form.weightKg" :min="0.001" :max="999999999999999.999" :precision="3" :step="0.5" controls-position="right" aria-label="托盘重量" />
|
||||
</el-form-item>
|
||||
</div>
|
||||
<el-form-item label="颜色" prop="color" required>
|
||||
<el-input v-model="form.color" maxlength="32" show-word-limit placeholder="例如 黄色" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark" class="editor-remark-field">
|
||||
<el-input v-model="form.remark" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="可填写规格、材质或现场识别说明" />
|
||||
<el-input v-model="form.remark" type="textarea" :rows="4" maxlength="500" show-word-limit placeholder="可填写其他说明" />
|
||||
</el-form-item>
|
||||
</section>
|
||||
</el-form>
|
||||
|
||||
Reference in New Issue
Block a user