cmvr-wms/scripts/projectdev/purchase-sheet-check.cjs
lixiaolong e3860a3fd9 feat(production): 优化生产任务操作权限控制与数据查询
- 添加权限检查功能,防止未授权操作
- 实现远程搜索功能优化任务选择体验
- 集成分页查询提高大数据量性能表现
- 增强批量操作界面增加搜索筛选功能
- 完善表单验证与错误处理机制
- 重构数据过滤逻辑支持多条件组合查询
2026-10-13 09:41:46 +08:00

35 lines
3.7 KiB
JavaScript

const assert = require('node:assert/strict')
const fs = require('node:fs')
const path = require('node:path')
;(async () => {
const source = fs.readFileSync(path.resolve(__dirname, '../../ruoyi-ui/src/utils/purchase-sheet.js'), 'utf8')
const {validateRows,pasteRectangle,resolveRow,candidates,itemKey} = await import('data:text/javascript;base64,'+Buffer.from(source).toString('base64'))
const items=[{id:1,productCode:'A',productName:'螺丝',brand:'甲',spec:'M4',unit:'个'},{id:2,productCode:'B',productName:'螺丝',brand:'甲',spec:'M5',unit:'个'},{id:3,productCode:'C',productName:'螺丝',brand:'乙',spec:'M4',unit:'个'},{id:4,productCode:'D',productName:'电机',brand:'乙',spec:'24V',unit:'台'}]
const emptyRow=()=>({projectId:10,expenseCategoryId:20,materialName:'',materialBrand:'',materialParams:'',unit:'',quantity:1,finalUnitPrice:null,purchaseLink:''})
const row=()=>({...emptyRow(),materialName:'螺丝',materialBrand:'甲',materialParams:'M4',unit:'个',category:'零件'})
assert.deepEqual(candidates(items,row(),'spec').map(i=>i.spec),['M4','M5'])
const matched=resolveRow(row(),items);assert.equal(matched.productId,1)
assert.throws(()=>validateRows([{...row(),category:''}],items),/请选择物品类别/)
assert.equal(validateRows([row()],items)[0].category,'零件','explicit category can fill a missing catalog category')
const unknown=resolveRow({...row(),materialParams:'M6',productId:1},items);assert.equal(unknown.productId,null)
assert.throws(()=>resolveRow({...row(),unit:'箱'},items),/单位/)
assert.throws(()=>validateRows([{...row(),materialParams:'M6'},{...row(),materialParams:'M6',unit:'箱'}],items),/不同单位/)
assert.notEqual(itemKey({...row(),materialName:'a|b',materialBrand:'c'}),itemKey({...row(),materialName:'a',materialBrand:'b|c'}))
const fields=['projectId','expenseCategoryId','materialName','materialBrand','materialParams','unit','quantity','finalUnitPrice','purchaseLink']
const context={items,projects:[{id:10,projectName:'研发',projectCode:'P1'},{id:11,projectName:'机器人',projectCode:'P2'}],categories:[{id:20,categoryName:'材料费',categoryCode:'MAT'}],plans:[],units:['个','台'],emptyRow,readonly:r=>!!r.priceLocked}
const original=[row()]
const copied=pasteRectangle(original,'机器人\t材料费\t螺丝\t甲\tM5\t个\t40\t0.5\thttps://jd.com',0,0,fields,context)
assert.equal(copied[0].projectId,11);assert.equal(copied[0].productId,2);assert.equal(copied[0].quantity,40);assert.equal(original[0].materialParams,'M4')
assert.throws(()=>pasteRectangle(original,'研发\t材料费\t螺丝\t甲\tM5\t个\t1\n错误项目\t材料费\t螺丝\t甲\tM5\t个\t1',0,0,fields,context),/项目/)
assert.equal(original[0].materialParams,'M4');assert.equal(original.length,1)
assert.throws(()=>pasteRectangle([{...row(),priceLocked:true}],'M5\t个',0,4,fields,context),/已确认/)
assert.throws(()=>validateRows([{...row(),quantity:1.00001}],items),/4位/)
assert.throws(()=>validateRows([{...row(),finalUnitPrice:-1}],items),/单价/)
const protectedRow={...row(),receivedQuantity:1,finalUnitPrice:5};
assert.throws(()=>pasteRectangle([protectedRow],'2\t99',0,6,fields,{...context,readonly:()=>false,fieldLocked:(r,f)=>r.receivedQuantity>0&&f==='finalUnitPrice'}),/不能修改/);
assert.equal(protectedRow.quantity,1);assert.equal(protectedRow.finalUnitPrice,5);
const forty=Array.from({length:40},()=> '研发\t材料费\t螺丝\t甲\tM4\t个\t10').join('\n')
assert.equal(pasteRectangle([],forty,0,0,fields,context).length,40)
console.log('PASS: catalog linking, units, duplicate identity, atomic rectangular paste, read-only rows, multi-project 40-row input')
})().catch(e=>{console.error(e);process.exitCode=1})