feat(包材资料库): 基于新主线添加包材资料库独立页面
- 新增 catalog.ts: 6个一级分类(含其他) + 20+二级品类模板 - 新增 /asset-center/packaging-materials 独立页面 - 四栏可拖拽布局: L1|L2|列表|详情 - 顶部统一工具栏: 新增/复制/启停/新建品类 - AssetCenterClient 包装tab添加"包材资料库"入口卡片
This commit is contained in:
parent
5821d73291
commit
d9b4478472
@ -571,6 +571,21 @@ export default function AssetCenterClient({
|
||||
|
||||
{/* 资产族列表 */}
|
||||
<div className="space-y-1">
|
||||
{activeTab === 'PACKAGING' && (
|
||||
<Link
|
||||
href="/asset-center/packaging-materials"
|
||||
className="flex items-center justify-between rounded-apple-lg border border-apple-blue/20 bg-apple-blue/5 px-3 py-3 hover:bg-apple-blue/10 transition mb-2"
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<Package2 className="h-4 w-4 text-apple-blue" />
|
||||
<div>
|
||||
<p className="text-sm font-apple-medium text-apple-blue">包材资料库</p>
|
||||
<p className="text-xs text-apple-label-secondary">品类模板化管理 · 复制新增 · 启停控制</p>
|
||||
</div>
|
||||
</div>
|
||||
<ArrowRight className="h-4 w-4 text-apple-blue" />
|
||||
</Link>
|
||||
)}
|
||||
{currentFamilies.length === 0 ? (
|
||||
<div className="py-8 text-center">
|
||||
<p className="text-sm text-apple-label-tertiary">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -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 (
|
||||
<PackagingMaterialsClient
|
||||
initialFamilies={families}
|
||||
initialVariants={variants}
|
||||
user={user}
|
||||
/>
|
||||
)
|
||||
}
|
||||
343
furniture-3d-system/src/lib/packaging-materials/catalog.ts
Normal file
343
furniture-3d-system/src/lib/packaging-materials/catalog.ts
Normal file
@ -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<Level1CategoryKey, Level2CategoryDefinition[]> =
|
||||
LEVEL1_CATEGORIES.reduce(
|
||||
(acc, cat) => {
|
||||
acc[cat.key] = LEVEL2_CATEGORIES.filter((c) => c.level1 === cat.key)
|
||||
return acc
|
||||
},
|
||||
{} as Record<Level1CategoryKey, Level2CategoryDefinition[]>,
|
||||
)
|
||||
|
||||
/* ============================================================
|
||||
* 通用规格字段(所有包材共有)
|
||||
* ============================================================ */
|
||||
|
||||
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<string, unknown> | 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<string, unknown> | 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
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user