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

44 lines
5.5 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[]; guide?: string };
export const modules: Module[] = [
{ key: 'stock', title: '库存查询', path: '/warehouse/stock/list', permissions: [['warehouse:stock:list']], search: 'productName', titleKey: 'productName',
guide: '同项目换库区用「移库」,跨项目临时调配用「借用」;归还到「借用与归还」办理。',
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',
guide: '一批采购对应一个项目;确认采购后再登记到货,验收合格后到「待入库」办理入库。',
fields: [['purchaseStatus','采购状态'],['projectName','所属项目'],['purchaseBatchNo','采购批次'],['materialParams','规格型号'],['materialBrand','品牌'],['quantity','采购数量'],['unit','单位'],['finalUnitPrice','报价'],['acceptedQuantity','已验收数量'],['remainingQuantity','未到数量']] },
{ key: 'pending', title: '待入库', path: '/warehouse/in/list', permissions: [['warehouse:in:list']], search: 'keyword', titleKey: 'productName', query: { inStatus: 0 },
guide: '采购验收合格或生产完工验收后,记录才会进入待入库;选择实际存放库区并确认后,才计入库存。',
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',
guide: '先从「库存查询」选择物品办理跨项目借用,再在此查看待还数量;借用不等于领用。',
fields: [['lenderProjectName','借出项目'],['borrowerProjectName','借入项目'],['quantity','借用数量'],['returnedQuantity','已还数量'],['outstandingQuantity','未还数量'],['unit','单位'],['loanNo','借用编号']] },
{ key: 'check', title: '库存盘点', path: '/warehouse/check/list', permissions: [['warehouse:check:list']], search: 'productName', titleKey: 'productName',
guide: '从「库存查询」登记实际清点数量,不是差异数量;保存仅生成待确认记录,确认后才调整库存。',
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']],
guide: '先维护物品、产品和 BOM,再选择项目建立生产任务;完工验收后到「待入库」办理成品入库。',
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==='purchase'&&key==='purchaseStatus')return ({0:'待采购',1:'已下单',2:'采购中',3:'部分到货',4:'已到齐',5:'已取消'} as Record<string,string>)[String(value)]||'待核对';
if (module.key === 'production' && key === 'status') return ({OPEN:'进行中',SETTLED:'已结算',CANCELLED:'已取消'} as Record<string,string>)[String(value)] || display(value);
return display(value);
}