This commit is contained in:
2026-08-06 14:55:17 +08:00
parent a813426588
commit 4ac0adac62
18 changed files with 379 additions and 352 deletions
@@ -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>