+
+ )}
{currentFamilies.length === 0 ? (
diff --git a/furniture-3d-system/src/app/asset-center/packaging-materials/PackagingMaterialsClient.tsx b/furniture-3d-system/src/app/asset-center/packaging-materials/PackagingMaterialsClient.tsx
new file mode 100644
index 00000000..30369695
--- /dev/null
+++ b/furniture-3d-system/src/app/asset-center/packaging-materials/PackagingMaterialsClient.tsx
@@ -0,0 +1,1016 @@
+'use client'
+
+import { useCallback, useMemo, useState, useRef } from 'react'
+import Link from 'next/link'
+import { Badge } from '@/components/ui/Badge'
+import Button from '@/components/ui/Button'
+import { Input, Textarea } from '@/components/ui/Input'
+import Select from '@/components/ui/Select'
+import {
+ Package2,
+ Plus,
+ Search,
+ ArrowLeft,
+ ChevronRight,
+ Copy,
+ ToggleLeft,
+ ToggleRight,
+ FolderPlus,
+} from 'lucide-react'
+import { cn } from '@/lib/utils'
+import {
+ LEVEL1_CATEGORIES,
+ LEVEL2_CATEGORIES,
+ LEVEL2_MAP,
+ LEVEL2_BY_LEVEL1,
+ UNIT_OPTIONS,
+ MATERIAL_STATUS_OPTIONS,
+ getLevel1FromFamily,
+ getLevel2FromFamily,
+ getLevel1Label,
+ getLevel2Label,
+ type Level1CategoryKey,
+ type FieldTemplate,
+} from '@/lib/packaging-materials/catalog'
+import {
+ createAssetFamily,
+ createAssetVariant,
+ updateAssetVariant,
+} from '@/lib/open-product/platform-api'
+import type { AssetFamilyDTO, AssetVariantDTO } from '@/server/services'
+
+/* ============================================================
+ * Types
+ * ============================================================ */
+
+interface PackagingMaterialsClientProps {
+ initialFamilies: AssetFamilyDTO[]
+ initialVariants: AssetVariantDTO[]
+ user: {
+ id: string
+ name: string
+ email: string
+ role: string
+ avatar: string | null
+ department: { id: string; name: string } | null
+ }
+}
+
+interface EditingMaterial {
+ id: string
+ assetFamilyId: string
+ code: string
+ name: string
+ status: string
+ sizeLabel: string
+ unit: string
+ length: string
+ width: string
+ height: string
+ thickness: string
+ weightKg: string
+ costPrice: string
+ materialType: string
+ templateFields: Record
+ customAttributes: { key: string; value: string }[]
+ notes: string
+ imageUrl: string
+}
+
+/* ============================================================
+ * Helpers
+ * ============================================================ */
+
+function emptyEditingMaterial(familyId: string): EditingMaterial {
+ return {
+ id: '',
+ assetFamilyId: familyId,
+ code: '',
+ name: '',
+ status: 'DRAFT',
+ sizeLabel: '',
+ unit: 'piece',
+ length: '',
+ width: '',
+ height: '',
+ thickness: '',
+ weightKg: '',
+ costPrice: '',
+ materialType: '',
+ templateFields: {},
+ customAttributes: [],
+ notes: '',
+ imageUrl: '',
+ }
+}
+
+function variantToEditing(v: AssetVariantDTO): EditingMaterial {
+ const meta = (v.businessData ?? {}) as Record
+ const templateFields = (meta.templateFields ?? {}) as Record
+ const customAttributes = (meta.customAttributes ?? []) as { key: string; value: string }[]
+ const dims = (v.dimensions ?? {}) as Record
+
+ return {
+ id: v.id,
+ assetFamilyId: v.assetFamilyId,
+ code: v.code,
+ name: v.name,
+ status: v.status,
+ sizeLabel: v.sizeLabel ?? '',
+ unit: (meta.unit as string) ?? 'piece',
+ length: String(dims.length ?? ''),
+ width: String(dims.width ?? ''),
+ height: String(dims.height ?? ''),
+ thickness: String(dims.thickness ?? ''),
+ weightKg: v.weightKg != null ? String(v.weightKg) : '',
+ costPrice: v.costPrice != null ? String(v.costPrice) : '',
+ materialType: (meta.materialType as string) ?? '',
+ templateFields,
+ customAttributes,
+ notes: (meta.notes as string) ?? '',
+ imageUrl: v.thumbnailUrl ?? '',
+ }
+}
+
+function getStatusTone(status: string) {
+ if (status === 'AVAILABLE') return 'success'
+ if (status === 'DISABLED') return 'warning'
+ return 'default'
+}
+
+function getStatusLabel(status: string) {
+ if (status === 'AVAILABLE') return '启用中'
+ if (status === 'DISABLED') return '停用中'
+ return '草稿'
+}
+
+/* ============================================================
+ * Drag-to-resize hook — supports N columns
+ * ============================================================ */
+
+function useColumnResize(initialWidths: number[]) {
+ const [widths, setWidths] = useState(initialWidths)
+ const dragging = useRef<{ index: number; startX: number; startWidths: number[] } | null>(null)
+
+ const onMouseDown = useCallback((index: number, e: React.MouseEvent) => {
+ e.preventDefault()
+ dragging.current = { index, startX: e.clientX, startWidths: [...widths] }
+
+ const onMouseMove = (ev: MouseEvent) => {
+ if (!dragging.current) return
+ const dx = ev.clientX - dragging.current.startX
+ const i = dragging.current.index
+ setWidths((prev) => {
+ const next = [...prev]
+ const minW = 100
+ next[i] = Math.max(minW, dragging.current!.startWidths[i] + dx)
+ if (i + 1 < next.length) {
+ next[i + 1] = Math.max(minW, dragging.current!.startWidths[i + 1] - dx)
+ }
+ return next
+ })
+ }
+
+ const onMouseUp = () => {
+ dragging.current = null
+ window.removeEventListener('mousemove', onMouseMove)
+ window.removeEventListener('mouseup', onMouseUp)
+ }
+
+ window.addEventListener('mousemove', onMouseMove)
+ window.addEventListener('mouseup', onMouseUp)
+ }, [widths])
+
+ return { widths, onMouseDown }
+}
+
+/* ============================================================
+ * Resize Handle component
+ * ============================================================ */
+
+function ResizeHandle({ onMouseDown }: { onMouseDown: (e: React.MouseEvent) => void }) {
+ return (
+
+ )
+}
+
+/* ============================================================
+ * Main Client Component
+ * ============================================================ */
+
+export default function PackagingMaterialsClient({
+ initialFamilies,
+ initialVariants,
+ user,
+}: PackagingMaterialsClientProps) {
+ const [families, setFamilies] = useState(initialFamilies)
+ const [variants, setVariants] = useState(initialVariants)
+
+ const [selectedLevel1, setSelectedLevel1] = useState('outer')
+ const [selectedFamilyId, setSelectedFamilyId] = useState(null)
+ const [searchQuery, setSearchQuery] = useState('')
+ const [statusFilter, setStatusFilter] = useState('all')
+ const [selectedVariantId, setSelectedVariantId] = useState(null)
+ const [editingMaterial, setEditingMaterial] = useState(null)
+ const [isNew, setIsNew] = useState(false)
+ const [saving, setSaving] = useState(false)
+ const [error, setError] = useState(null)
+ const [showNewFamily, setShowNewFamily] = useState(false)
+ const [newFamilyName, setNewFamilyName] = useState('')
+ const [newFamilyCode, setNewFamilyCode] = useState('')
+ const [newFamilyLevel1, setNewFamilyLevel1] = useState('outer')
+ const [newFamilyLevel2, setNewFamilyLevel2] = useState('carton')
+
+ // 4 resizable columns: [L1, L2, List, Detail]
+ const { widths: colWidths, onMouseDown: onColResize } = useColumnResize([140, 140, 400, 400])
+
+ // ---- Filtered data ----
+ const filteredFamilies = useMemo(() => {
+ return families.filter((f) => getLevel1FromFamily(f.metadata) === selectedLevel1)
+ }, [families, selectedLevel1])
+
+ const filteredFamilyIds = useMemo(
+ () => new Set(filteredFamilies.map((f) => f.id)),
+ [filteredFamilies],
+ )
+
+ const l2Categories = useMemo(
+ () => LEVEL2_BY_LEVEL1[selectedLevel1] ?? [],
+ [selectedLevel1],
+ )
+
+ const filteredVariants = useMemo(() => {
+ let result = variants.filter((v) => filteredFamilyIds.has(v.assetFamilyId))
+ if (selectedFamilyId) {
+ result = result.filter((v) => v.assetFamilyId === selectedFamilyId)
+ }
+ if (searchQuery.trim()) {
+ const q = searchQuery.trim().toLowerCase()
+ result = result.filter(
+ (v) => v.name.toLowerCase().includes(q) || v.code.toLowerCase().includes(q),
+ )
+ }
+ if (statusFilter !== 'all') {
+ result = result.filter((v) => v.status === statusFilter)
+ }
+ return result
+ }, [variants, filteredFamilyIds, selectedFamilyId, searchQuery, statusFilter])
+
+ // ---- Template for current family ----
+ const currentFamily = useMemo(
+ () => families.find((f) => f.id === editingMaterial?.assetFamilyId) ?? null,
+ [families, editingMaterial],
+ )
+
+ const templateFields = useMemo(() => {
+ const level2Key = getLevel2FromFamily(currentFamily?.metadata ?? null)
+ return level2Key ? (LEVEL2_MAP.get(level2Key)?.fields ?? []) : []
+ }, [currentFamily])
+
+ // ---- Stats ----
+ const stats = useMemo(() => {
+ const enabled = variants.filter((v) => v.status === 'AVAILABLE').length
+ return { total: variants.length, enabled, families: families.length }
+ }, [variants, families])
+
+ // ---- Handlers ----
+ const handleNew = useCallback(
+ (familyId?: string) => {
+ const fid = familyId ?? filteredFamilies[0]?.id ?? families[0]?.id
+ if (!fid) return
+ setEditingMaterial(emptyEditingMaterial(fid))
+ setIsNew(true)
+ setError(null)
+ },
+ [filteredFamilies, families],
+ )
+
+ const handleEdit = useCallback((variant: AssetVariantDTO) => {
+ setEditingMaterial(variantToEditing(variant))
+ setIsNew(false)
+ setError(null)
+ }, [])
+
+ const handleCopyNew = useCallback((variant: AssetVariantDTO) => {
+ const editing = variantToEditing(variant)
+ editing.id = ''
+ editing.code = ''
+ editing.name = `${editing.name} (副本)`
+ setEditingMaterial(editing)
+ setIsNew(true)
+ setError(null)
+ }, [])
+
+ const handleSave = useCallback(async () => {
+ if (!editingMaterial) return
+ if (!editingMaterial.name.trim()) { setError('包材名称不能为空'); return }
+ if (!editingMaterial.code.trim()) { setError('包材编码不能为空'); return }
+
+ setSaving(true)
+ setError(null)
+
+ try {
+ const dimensions: Record = {}
+ if (editingMaterial.length) dimensions.length = Number(editingMaterial.length) || 0
+ if (editingMaterial.width) dimensions.width = Number(editingMaterial.width) || 0
+ if (editingMaterial.height) dimensions.height = Number(editingMaterial.height) || 0
+ if (editingMaterial.thickness) dimensions.thickness = Number(editingMaterial.thickness) || 0
+
+ const businessData = {
+ unit: editingMaterial.unit,
+ materialType: editingMaterial.materialType || undefined,
+ templateFields: editingMaterial.templateFields,
+ customAttributes: editingMaterial.customAttributes.filter(
+ (a) => a.key.trim() && a.value.trim(),
+ ),
+ notes: editingMaterial.notes || undefined,
+ }
+
+ const weightKg = editingMaterial.weightKg ? Number(editingMaterial.weightKg) : null
+ const costPrice = editingMaterial.costPrice ? Number(editingMaterial.costPrice) : null
+
+ if (isNew) {
+ const created = await createAssetVariant({
+ assetFamilyId: editingMaterial.assetFamilyId,
+ code: editingMaterial.code.trim(),
+ name: editingMaterial.name.trim(),
+ status: editingMaterial.status as 'DRAFT' | 'AVAILABLE' | 'DISABLED',
+ sizeLabel: editingMaterial.sizeLabel || undefined,
+ dimensions,
+ modelUrl: '',
+ thumbnailUrl: editingMaterial.imageUrl || undefined,
+ mountPoints: [{ name: 'origin', position: [0, 0, 0] }],
+ weightKg,
+ costPrice,
+ businessData,
+ })
+ setVariants((prev) => [created, ...prev])
+ setSelectedVariantId(created.id)
+ } else {
+ const updated = await updateAssetVariant(editingMaterial.id, {
+ name: editingMaterial.name.trim(),
+ code: editingMaterial.code.trim(),
+ status: editingMaterial.status as 'DRAFT' | 'AVAILABLE' | 'DISABLED',
+ sizeLabel: editingMaterial.sizeLabel || undefined,
+ dimensions,
+ weightKg,
+ costPrice,
+ businessData,
+ thumbnailUrl: editingMaterial.imageUrl || undefined,
+ })
+ setVariants((prev) => prev.map((v) => (v.id === updated.id ? updated : v)))
+ }
+
+ setEditingMaterial(null)
+ setIsNew(false)
+ } catch (saveError) {
+ setError(saveError instanceof Error ? saveError.message : '保存失败')
+ } finally {
+ setSaving(false)
+ }
+ }, [editingMaterial, isNew])
+
+ const handleCreateFamily = useCallback(async () => {
+ if (!newFamilyName.trim() || !newFamilyCode.trim()) return
+ setSaving(true)
+ setError(null)
+ try {
+ const created = await createAssetFamily({
+ type: 'PACKAGING' as const,
+ code: newFamilyCode.trim(),
+ name: newFamilyName.trim(),
+ metadata: {
+ categoryLevel1: newFamilyLevel1,
+ categoryLevel2: newFamilyLevel2,
+ },
+ })
+ setFamilies((prev) => [...prev, created])
+ setShowNewFamily(false)
+ setNewFamilyName('')
+ setNewFamilyCode('')
+ } catch (err) {
+ setError(err instanceof Error ? err.message : '创建品类失败')
+ } finally {
+ setSaving(false)
+ }
+ }, [newFamilyName, newFamilyCode, newFamilyLevel1, newFamilyLevel2])
+
+ const handleToggleStatus = useCallback(
+ async (variant: AssetVariantDTO) => {
+ const newStatus = variant.status === 'AVAILABLE' ? 'DISABLED' : 'AVAILABLE'
+ try {
+ const updated = await updateAssetVariant(variant.id, { status: newStatus })
+ setVariants((prev) => prev.map((v) => (v.id === updated.id ? updated : v)))
+ } catch {
+ /* ignore */
+ }
+ },
+ [],
+ )
+
+ const selectedVariant = useMemo(
+ () => variants.find((v) => v.id === selectedVariantId) ?? null,
+ [variants, selectedVariantId],
+ )
+
+ return (
+
+ {/* ====== Top Header & Toolbar ====== */}
+
+
+
+
+
+
+ {stats.families} 品类
+ {stats.total} 档案
+ {stats.enabled} 启用
+
+
+
+
+
+
+
+
+
+ {/* ====== Four-column body ====== */}
+
+ {/* Column 1: L1 */}
+
+
+
+ 一级分类
+
+ {LEVEL1_CATEGORIES.map((cat) => {
+ const count = variants.filter((v) => {
+ const fam = families.find((f) => f.id === v.assetFamilyId)
+ return fam && getLevel1FromFamily(fam.metadata) === cat.key
+ }).length
+ return (
+
+ )
+ })}
+
+
+
+
onColResize(0, e)} />
+
+ {/* Column 2: L2 */}
+
+
+
+ 二级品类
+
+ {l2Categories.map((cat) => {
+ const matchingFamilies = filteredFamilies.filter(
+ (f) => getLevel2FromFamily(f.metadata) === cat.key,
+ )
+ const isActive = selectedFamilyId
+ ? matchingFamilies.some((f) => f.id === selectedFamilyId)
+ : false
+ const count = variants.filter((v) =>
+ matchingFamilies.some((f) => f.id === v.assetFamilyId),
+ ).length
+
+ return (
+
+ )
+ })}
+ {l2Categories.length === 0 && (
+
+ 请先选择一级分类
+
+ )}
+
+
+
+ onColResize(1, e)} />
+
+ {/* Column 3: Material List */}
+
+ {/* Search bar */}
+
+
+
+ setSearchQuery(e.target.value)}
+ placeholder="搜索编码或名称..."
+ className="w-full rounded-apple-md border border-black/10 bg-white/80 pl-8 pr-3 py-1.5 text-sm placeholder:text-apple-label-tertiary focus:outline-none focus:ring-1 focus:ring-apple-blue/40"
+ />
+
+
+
+ {/* List */}
+
+ {filteredVariants.length === 0 ? (
+
+
+
暂无包材记录
+
选择品类后点击"新增包材"
+
+ ) : (
+ filteredVariants.map((variant) => {
+ const isSelected = selectedVariantId === variant.id
+ const family = families.find((f) => f.id === variant.assetFamilyId)
+ const level2Key = getLevel2FromFamily(family?.metadata ?? null)
+ const level2Label = getLevel2Label(level2Key)
+ const dims = (variant.dimensions ?? {}) as Record
+ const hasDims = dims.length || dims.width || dims.height || dims.thickness
+
+ return (
+ setSelectedVariantId(variant.id)}
+ onDoubleClick={() => handleEdit(variant)}
+ className={cn(
+ 'rounded-apple-lg border px-3 py-2 text-left transition cursor-pointer group',
+ isSelected
+ ? 'border-apple-blue/30 bg-apple-blue/6'
+ : 'border-transparent hover:border-black/5 hover:bg-white/80',
+ )}
+ >
+
+
+
+ {variant.name}
+
+
+ {variant.code}
+ {level2Label !== '未分类' && (
+
+ {level2Label}
+
+ )}
+
+
+
+ {getStatusLabel(variant.status)}
+
+
+
+ {hasDims && (
+ {dims.length ?? 0} × {dims.width ?? 0} × {dims.height ?? 0} mm
+ )}
+ {variant.costPrice != null && ¥{variant.costPrice}}
+ {variant.weightKg != null && {variant.weightKg} kg}
+
+
+ )
+ })
+ )}
+
+
+
+ onColResize(2, e)} />
+
+ {/* Column 4: Detail */}
+
+ {editingMaterial ? (
+
0 ? filteredFamilies : families}
+ onChange={(patch) =>
+ setEditingMaterial((cur) => (cur ? { ...cur, ...patch } : cur))
+ }
+ onTemplateFieldChange={(key, value) =>
+ setEditingMaterial((cur) =>
+ cur
+ ? { ...cur, templateFields: { ...cur.templateFields, [key]: value } }
+ : cur,
+ )
+ }
+ onAddCustomAttribute={() =>
+ setEditingMaterial((cur) =>
+ cur
+ ? { ...cur, customAttributes: [...cur.customAttributes, { key: '', value: '' }] }
+ : cur,
+ )
+ }
+ onUpdateCustomAttribute={(index, field, value) =>
+ setEditingMaterial((cur) => {
+ if (!cur) return cur
+ const attrs = [...cur.customAttributes]
+ attrs[index] = { ...attrs[index], [field]: value }
+ return { ...cur, customAttributes: attrs }
+ })
+ }
+ onRemoveCustomAttribute={(index) =>
+ setEditingMaterial((cur) => {
+ if (!cur) return cur
+ return { ...cur, customAttributes: cur.customAttributes.filter((_, i) => i !== index) }
+ })
+ }
+ onSave={handleSave}
+ onCancel={() => { setEditingMaterial(null); setIsNew(false); setError(null) }}
+ />
+ ) : selectedVariant ? (
+ f.id === selectedVariant.assetFamilyId) ?? null}
+ onEdit={() => handleEdit(selectedVariant)}
+ onCopy={() => handleCopyNew(selectedVariant)}
+ onToggleStatus={() => handleToggleStatus(selectedVariant)}
+ />
+ ) : (
+
+ )}
+
+
+
+ {/* ====== New Family Modal ====== */}
+ {showNewFamily && (
+
+
+
新建包材品类
+ {error && (
+
+ {error}
+
+ )}
+
+
+ )}
+
+ )
+}
+
+/* ============================================================
+ * VariantPreview
+ * ============================================================ */
+
+function VariantPreview({
+ variant,
+ family,
+ onEdit,
+ onCopy,
+ onToggleStatus,
+}: {
+ variant: AssetVariantDTO
+ family: AssetFamilyDTO | null
+ onEdit: () => void
+ onCopy: () => void
+ onToggleStatus: () => void
+}) {
+ const meta = (variant.businessData ?? {}) as Record
+ const unit = meta.unit as string | undefined
+ const dims = (variant.dimensions ?? {}) as Record
+ const level2Key = getLevel2FromFamily(family?.metadata ?? null)
+ const level1Key = getLevel1FromFamily(family?.metadata ?? null)
+ const templateDef = level2Key ? LEVEL2_MAP.get(level2Key) : null
+ const templateFieldValues = (meta.templateFields ?? {}) as Record
+
+ return (
+
+
+
+
+
{variant.name}
+
+ {variant.code}
+ {getStatusLabel(variant.status)}
+
+
+ {level1Key && {getLevel1Label(level1Key)}}
+ {level2Key && {getLevel2Label(level2Key)}}
+ {unit && {UNIT_OPTIONS.find(u => u.value === unit)?.label ?? unit}}
+
+
+
+ {(dims.length || dims.width || dims.height || dims.thickness) ? (
+
+
规格
+
+ {dims.length ?
长 {dims.length} mm
: null}
+ {dims.width ?
宽 {dims.width} mm
: null}
+ {dims.height ?
高 {dims.height} mm
: null}
+ {dims.thickness ?
厚度 {dims.thickness} mm
: null}
+
+
+ ) : null}
+
+ {templateDef && templateDef.fields.length > 0 && (
+
+
品类属性
+
+ {templateDef.fields.map((field) => {
+ const val = templateFieldValues[field.key]
+ if (!val) return null
+ return (
+
+ {field.label}{' '}
+ {val}{field.unit ? ` ${field.unit}` : ''}
+
+ )
+ })}
+
+
+ )}
+
+ {(variant.costPrice != null || variant.weightKg != null) && (
+
+
成本
+
+ {variant.costPrice != null && (
+
单价 ¥{variant.costPrice}
+ )}
+ {variant.weightKg != null && (
+
重量 {variant.weightKg} kg
+ )}
+
+
+ )}
+
+
+
+
+
+
+ )
+}
+
+/* ============================================================
+ * DetailEditor
+ * ============================================================ */
+
+interface DetailEditorProps {
+ material: EditingMaterial
+ isNew: boolean
+ saving: boolean
+ error: string | null
+ templateFields: FieldTemplate[]
+ families: AssetFamilyDTO[]
+ onChange: (patch: Partial) => void
+ onTemplateFieldChange: (key: string, value: string) => void
+ onAddCustomAttribute: () => void
+ onUpdateCustomAttribute: (index: number, field: 'key' | 'value', value: string) => void
+ onRemoveCustomAttribute: (index: number) => void
+ onSave: () => void
+ onCancel: () => void
+}
+
+function DetailEditor({
+ material,
+ isNew,
+ saving,
+ error,
+ templateFields,
+ families,
+ onChange,
+ onTemplateFieldChange,
+ onAddCustomAttribute,
+ onUpdateCustomAttribute,
+ onRemoveCustomAttribute,
+ onSave,
+ onCancel,
+}: DetailEditorProps) {
+ return (
+
+
+
+ {isNew ? '新增包材' : '编辑包材'}
+
+
+
+
+ {error && (
+
+ {error}
+
+ )}
+
+
+
+
+
+ {templateFields.length > 0 && (
+
+ 品类规格
+
+ {templateFields.map((field) => (
+ onTemplateFieldChange(field.key, value)} />
+ ))}
+
+
+ )}
+
+
+
+
+
+
+ )
+}
+
+/* ============================================================
+ * TemplateFieldInput
+ * ============================================================ */
+
+function TemplateFieldInput({ field, value, onChange }: {
+ field: FieldTemplate
+ value: string
+ onChange: (value: string) => void
+}) {
+ if (field.type === 'boolean') {
+ return (
+
+ )
+ }
+ if (field.type === 'select' && field.options) {
+ return (
+ onChange(e.target.value)}
+ options={[{ value: '', label: '请选择' }, ...field.options.map((o) => ({ value: o, label: o }))]} />
+ )
+ }
+ return (
+ onChange(e.target.value)} />
+ )
+}
diff --git a/furniture-3d-system/src/app/asset-center/packaging-materials/page.tsx b/furniture-3d-system/src/app/asset-center/packaging-materials/page.tsx
new file mode 100644
index 00000000..2744be2f
--- /dev/null
+++ b/furniture-3d-system/src/app/asset-center/packaging-materials/page.tsx
@@ -0,0 +1,23 @@
+import { requireSession } from '@/lib/server-session'
+import { assetCenterService } from '@/server/services'
+import PackagingMaterialsClient from './PackagingMaterialsClient'
+
+export default async function PackagingMaterialsPage() {
+ const { user } = await requireSession('/login')
+
+ const allFamilies = await assetCenterService.listFamilies()
+ const allVariants = await assetCenterService.listVariantsByFamilyIds(
+ allFamilies.map((f) => f.id),
+ )
+
+ const families = allFamilies.filter((f: { type: string }) => f.type === 'PACKAGING')
+ const variants = allVariants.filter((v: { assetType: string }) => v.assetType === 'PACKAGING')
+
+ return (
+
+ )
+}
diff --git a/furniture-3d-system/src/lib/packaging-materials/catalog.ts b/furniture-3d-system/src/lib/packaging-materials/catalog.ts
new file mode 100644
index 00000000..798ec093
--- /dev/null
+++ b/furniture-3d-system/src/lib/packaging-materials/catalog.ts
@@ -0,0 +1,343 @@
+/**
+ * 包材资料库 V1 — 分类常量与品类模板
+ *
+ * 设计依据:docs/superpowers/specs/2026-03-31-packaging-material-library-design.md
+ *
+ * 映射关系:
+ * - 一级分类 → 前端常量,存于 AssetFamily.metadata.categoryLevel1
+ * - 二级品类 → AssetFamily (type=PACKAGING)
+ * - 包材档案 → AssetVariant (assetType=PACKAGING)
+ * - 品类模板字段 → AssetVariant.metadata
+ */
+
+/* ============================================================
+ * 一级分类(固定 5 类,不允许随意新增)
+ * ============================================================ */
+
+export const LEVEL1_CATEGORIES = [
+ { key: 'outer', label: '外包装类', icon: '📦' },
+ { key: 'cushion', label: '内缓冲防护类', icon: '🛡️' },
+ { key: 'surface', label: '表面保护类', icon: '📄' },
+ { key: 'structural', label: '结构固定与填充类', icon: '🔧' },
+ { key: 'accessory', label: '包装辅料与标识类', icon: '🏷️' },
+ { key: 'other', label: '其他', icon: '📋' },
+] as const
+
+export type Level1CategoryKey = (typeof LEVEL1_CATEGORIES)[number]['key']
+
+/* ============================================================
+ * 二级品类与字段模板
+ * ============================================================ */
+
+export type FieldType = 'text' | 'number' | 'boolean' | 'select'
+
+export interface FieldTemplate {
+ key: string
+ label: string
+ type: FieldType
+ unit?: string
+ options?: string[]
+ required?: boolean
+}
+
+export interface Level2CategoryDefinition {
+ key: string
+ label: string
+ level1: Level1CategoryKey
+ fields: FieldTemplate[]
+}
+
+/** 所有二级品类定义 */
+export const LEVEL2_CATEGORIES: Level2CategoryDefinition[] = [
+ // ---- 外包装类 ----
+ {
+ key: 'carton',
+ label: '纸箱',
+ level1: 'outer',
+ fields: [
+ { key: 'fluteType', label: '楞型', type: 'select', options: ['A', 'B', 'C', 'E', 'AB', 'BC', 'AA', 'BB'] },
+ { key: 'layers', label: '层数', type: 'number' },
+ { key: 'isShaped', label: '是否异形', type: 'boolean' },
+ { key: 'innerOuter', label: '内径/外径', type: 'text' },
+ { key: 'gramWeight', label: '克重', type: 'number', unit: 'g/m²' },
+ ],
+ },
+ {
+ key: 'bag',
+ label: '打包袋',
+ level1: 'outer',
+ fields: [
+ { key: 'bagMaterial', label: '材质', type: 'text' },
+ { key: 'sealMethod', label: '封口方式', type: 'text' },
+ { key: 'loadCapacity', label: '承重', type: 'number', unit: 'kg' },
+ ],
+ },
+ {
+ key: 'honeycomb',
+ label: '蜂窝纸板',
+ level1: 'outer',
+ fields: [
+ { key: 'gramWeight', label: '克重', type: 'number', unit: 'g/m²' },
+ { key: 'layers', label: '层数', type: 'number' },
+ { key: 'hardness', label: '硬度/挺度', type: 'text' },
+ ],
+ },
+
+ // ---- 内缓冲防护类 ----
+ {
+ key: 'eps',
+ label: 'EPS',
+ level1: 'cushion',
+ fields: [
+ { key: 'density', label: '密度', type: 'number', unit: 'kg/m³' },
+ { key: 'moldingMethod', label: '成型方式', type: 'text' },
+ { key: 'isCustom', label: '是否定制', type: 'boolean' },
+ ],
+ },
+ {
+ key: 'epe',
+ label: 'EPE / 珍珠棉',
+ level1: 'cushion',
+ fields: [
+ { key: 'density', label: '密度', type: 'number', unit: 'kg/m³' },
+ { key: 'moldingMethod', label: '成型方式', type: 'text' },
+ { key: 'isCustom', label: '是否定制', type: 'boolean' },
+ ],
+ },
+ {
+ key: 'eva',
+ label: 'EVA',
+ level1: 'cushion',
+ fields: [
+ { key: 'density', label: '密度', type: 'number', unit: 'kg/m³' },
+ { key: 'hardness', label: '硬度', type: 'text' },
+ { key: 'isCustom', label: '是否定制', type: 'boolean' },
+ ],
+ },
+ {
+ key: 'bubbleWrap',
+ label: '气泡膜',
+ level1: 'cushion',
+ fields: [
+ { key: 'bubbleDiameter', label: '泡径', type: 'number', unit: 'mm' },
+ { key: 'layers', label: '层数', type: 'number' },
+ ],
+ },
+ {
+ key: 'foam',
+ label: '泡沫',
+ level1: 'cushion',
+ fields: [
+ { key: 'density', label: '密度', type: 'number', unit: 'kg/m³' },
+ { key: 'moldingMethod', label: '成型方式', type: 'text' },
+ { key: 'isCustom', label: '是否定制', type: 'boolean' },
+ ],
+ },
+
+ // ---- 表面保护类 ----
+ {
+ key: 'film',
+ label: '缠绕膜 / 保护膜',
+ level1: 'surface',
+ fields: [
+ { key: 'unfoldSize', label: '展开尺寸', type: 'text' },
+ { key: 'filmThickness', label: '膜厚', type: 'number', unit: 'μm' },
+ { key: 'materialType', label: '材质', type: 'text' },
+ ],
+ },
+ {
+ key: 'nonwoven',
+ label: '无纺布',
+ level1: 'surface',
+ fields: [
+ { key: 'gramWeight', label: '克重', type: 'number', unit: 'g/m²' },
+ { key: 'materialType', label: '材质', type: 'text' },
+ ],
+ },
+ {
+ key: 'tissuePaper',
+ label: '拷贝纸',
+ level1: 'surface',
+ fields: [
+ { key: 'gramWeight', label: '克重', type: 'number', unit: 'g/m²' },
+ ],
+ },
+ {
+ key: 'feltPad',
+ label: '毛毡垫',
+ level1: 'surface',
+ fields: [
+ { key: 'thickness', label: '厚度', type: 'number', unit: 'mm' },
+ { key: 'materialType', label: '材质', type: 'text' },
+ ],
+ },
+
+ // ---- 结构固定与填充类 ----
+ {
+ key: 'cornerProtector',
+ label: '纸护角',
+ level1: 'structural',
+ fields: [
+ { key: 'edgeLength', label: '边长', type: 'number', unit: 'mm' },
+ { key: 'length', label: '长度', type: 'number', unit: 'mm' },
+ { key: 'materialType', label: '材质类型', type: 'text' },
+ ],
+ },
+ {
+ key: 'strapping',
+ label: '打包带',
+ level1: 'structural',
+ fields: [
+ { key: 'width', label: '宽度', type: 'number', unit: 'mm' },
+ { key: 'materialType', label: '材质', type: 'text' },
+ { key: 'breakingStrength', label: '断裂强度', type: 'number', unit: 'N' },
+ ],
+ },
+ {
+ key: 'positioningBlock',
+ label: '定位块',
+ level1: 'structural',
+ fields: [
+ { key: 'materialType', label: '材质', type: 'text' },
+ { key: 'isCustom', label: '是否定制', type: 'boolean' },
+ ],
+ },
+
+ // ---- 包装辅料与标识类 ----
+ {
+ key: 'tape',
+ label: '胶带',
+ level1: 'accessory',
+ fields: [
+ { key: 'width', label: '宽度', type: 'number', unit: 'mm' },
+ { key: 'materialType', label: '材质', type: 'text' },
+ { key: 'length', label: '长度', type: 'number', unit: 'm' },
+ ],
+ },
+ {
+ key: 'desiccant',
+ label: '干燥剂',
+ level1: 'accessory',
+ fields: [
+ { key: 'specification', label: '规格', type: 'text' },
+ { key: 'unitCount', label: '单位包数', type: 'number' },
+ ],
+ },
+ {
+ key: 'label',
+ label: '标签 / 唛头',
+ level1: 'accessory',
+ fields: [
+ { key: 'labelType', label: '类型', type: 'text' },
+ { key: 'size', label: '尺寸', type: 'text' },
+ ],
+ },
+ {
+ key: 'otherAccessory',
+ label: '其他辅料',
+ level1: 'accessory',
+ fields: [
+ { key: 'materialType', label: '材质', type: 'text' },
+ { key: 'specification', label: '规格说明', type: 'text' },
+ ],
+ },
+
+ // ---- 其他 ----
+ {
+ key: 'otherPackaging',
+ label: '其他包材',
+ level1: 'other',
+ fields: [
+ { key: 'materialType', label: '材质', type: 'text' },
+ { key: 'specification', label: '规格说明', type: 'text' },
+ ],
+ },
+]
+
+/** 快速查找:二级品类 key → 定义 */
+export const LEVEL2_MAP = new Map(LEVEL2_CATEGORIES.map((c) => [c.key, c]))
+
+/** 按一级分类分组 */
+export const LEVEL2_BY_LEVEL1: Record =
+ LEVEL1_CATEGORIES.reduce(
+ (acc, cat) => {
+ acc[cat.key] = LEVEL2_CATEGORIES.filter((c) => c.level1 === cat.key)
+ return acc
+ },
+ {} as Record,
+ )
+
+/* ============================================================
+ * 通用规格字段(所有包材共有)
+ * ============================================================ */
+
+export const COMMON_SPEC_FIELDS: FieldTemplate[] = [
+ { key: 'length', label: '长', type: 'number', unit: 'mm' },
+ { key: 'width', label: '宽', type: 'number', unit: 'mm' },
+ { key: 'height', label: '高', type: 'number', unit: 'mm' },
+ { key: 'thickness', label: '厚度', type: 'number', unit: 'mm' },
+ { key: 'weightKg', label: '单件重量', type: 'number', unit: 'kg' },
+ { key: 'materialType', label: '材质', type: 'text' },
+]
+
+/* ============================================================
+ * 计量单位常量
+ * ============================================================ */
+
+export const UNIT_OPTIONS = [
+ { value: 'piece', label: '个' },
+ { value: 'set', label: '套' },
+ { value: 'roll', label: '卷' },
+ { value: 'sheet', label: '张' },
+ { value: 'meter', label: '米' },
+ { value: 'kg', label: '千克' },
+ { value: 'box', label: '箱' },
+ { value: 'bag', label: '袋' },
+] as const
+
+/* ============================================================
+ * 状态常量
+ * ============================================================ */
+
+export const MATERIAL_STATUS_OPTIONS = [
+ { value: 'AVAILABLE', label: '启用中', tone: 'success' as const },
+ { value: 'DISABLED', label: '停用中', tone: 'warning' as const },
+]
+
+/* ============================================================
+ * 工具函数
+ * ============================================================ */
+
+/** 从 AssetFamily.metadata 取出一级分类 key */
+export function getLevel1FromFamily(
+ familyMetadata: Record | null,
+): Level1CategoryKey | null {
+ if (!familyMetadata) return null
+ const val = familyMetadata.categoryLevel1
+ if (typeof val === 'string' && LEVEL1_CATEGORIES.some((c) => c.key === val)) {
+ return val as Level1CategoryKey
+ }
+ return null
+}
+
+/** 从 AssetFamily.metadata 取出二级品类 key */
+export function getLevel2FromFamily(
+ familyMetadata: Record | null,
+): string | null {
+ if (!familyMetadata) return null
+ const val = familyMetadata.categoryLevel2
+ return typeof val === 'string' ? val : null
+}
+
+/** 获取一级分类的显示标签 */
+export function getLevel1Label(key: Level1CategoryKey | string | null): string {
+ if (!key) return '未分类'
+ const found = LEVEL1_CATEGORIES.find((c) => c.key === key)
+ return found?.label ?? '未分类'
+}
+
+/** 获取二级品类的显示标签 */
+export function getLevel2Label(key: string | null): string {
+ if (!key) return '未分类'
+ return LEVEL2_MAP.get(key)?.label ?? key
+}