cmvr-wms/mobile-app/src/core/modules.ts

37 lines
4.4 KiB
TypeScript
Raw Normal View History

export type Row = Record<string, any>;
export type Module = { key: string; title: string; path: string; permissions: string[][];
search: string; titleKey: string; fields: [string, string][]; query?: Row; pages?: string[] };
export const modules: Module[] = [
{ key: 'stock', title: '库存查询', path: '/warehouse/stock/list', permissions: [['warehouse:stock:list']], search: 'productName', titleKey: 'productName',
fields: [['projectName','所属项目'],['areaName','库区'],['stockNum','库存数量'],['unit','单位'],['spec','规格型号'],['brand','品牌'],['averageUnitCost','平均单价'],['stockAmount','库存金额']] },
{ key: 'purchase', title: '采购明细', path: '/warehouse/purchase/list', permissions: [['warehouse:purchase:list','warehouse:purchase:manage']], search: 'materialName', titleKey: 'materialName',
fields: [['projectName','所属项目'],['purchaseBatchNo','采购批次'],['materialParams','规格型号'],['materialBrand','品牌'],['quantity','采购数量'],['unit','单位'],['finalUnitPrice','报价'],['acceptedQuantity','已验收数量']] },
{ key: 'pending', title: '待入库', path: '/warehouse/in/list', permissions: [['warehouse:in:list']], search: 'keyword', titleKey: 'productName', query: { inStatus: 0 },
fields: [['sourceProjectName','来源项目'],['purchaseBatchNo','采购批次'],['spec','规格型号'],['inNum','应入库数量'],['receivedQuantity','已入库数量'],['unit','单位'],['sourceNo','来源单号']] },
{ key: 'in', title: '入库记录', path: '/warehouse/in/list', permissions: [['warehouse:in:list']], search: 'keyword', titleKey: 'productName', query: { inStatus: 1 },
fields: [['sourceProjectName','所属项目'],['areaName','库区'],['inNum','入库数量'],['unit','单位'],['businessDate','业务日期'],['inNo','入库单号']] },
{ key: 'loans', title: '借用与归还', path: '/project/loans', permissions: [['project:project:list','warehouse:stock:list','warehouse:purchase:list','warehouse:purchase:manage']], search: '', titleKey: 'itemName',
fields: [['lenderProjectName','借出项目'],['borrowerProjectName','借入项目'],['quantity','借用数量'],['returnedQuantity','已还数量'],['outstandingQuantity','未还数量'],['unit','单位'],['loanNo','借用编号']] },
{ key: 'check', title: '库存盘点', path: '/warehouse/check/list', permissions: [['warehouse:check:list']], search: 'productName', titleKey: 'productName',
fields: [['projectName','所属项目'],['areaName','库区'],['bookNum','账面数量'],['realNum','实际数量'],['diffNum','差异数量'],['checkNo','盘点单号'],['businessDate','业务日期']] },
{ key: 'out', title: '领用与退回记录', path: '/warehouse/out/list', permissions: [['warehouse:out:list']], search: 'productName', titleKey: 'productName',
fields: [['usageProjectName','使用项目'],['sourceProjectNames','来源项目'],['areaName','库区'],['outNum','数量'],['unit','单位'],['outNo','单号'],['outTime','出库时间']] },
{ key: 'production', title: '生产任务', path: '/production/tasks/page', permissions: [['project:project:list','warehouse:stock:list']],
pages: ['production/tasks/index','production/operations/index','production/cost/index'], search: 'keyword', titleKey: 'item_name',
fields: [['task_no','任务编号'],['project_name','所属项目'],['planned_quantity','计划数量'],['good_quantity','合格数量'],['version_tag','BOM版本'],['status','状态']] },
];
export function routeComponents(routes: Row[]): string[] {
return routes.flatMap(r => [String(r.component || ''), ...routeComponents(r.children || [])]);
}
export function localDate() { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,'0')}-${String(d.getDate()).padStart(2,'0')}`; }
export function display(value: unknown) { return value == null || value === '' ? '—' : typeof value === 'object' ? JSON.stringify(value) : String(value); }
export function validDate(value: string) {
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
const parsed = new Date(`${value}T00:00:00Z`);
return !Number.isNaN(parsed.getTime()) && parsed.toISOString().slice(0,10) === value;
}
export function recordDisplay(module: Module, key: string, value: unknown) {
if (module.key === 'production' && key === 'status') return ({OPEN:'进行中',SETTLED:'已结算',CANCELLED:'已取消'} as Record<string,string>)[String(value)] || display(value);
return display(value);
}