cmvr-wms/scripts/projectdev/operations-optimization-ui-check.cjs
lixiaolong a82258561b feat(auth): 添加认证cookie名称配置并优化表单布局
- 在 .env.production 中新增 VITE_AUTH_COOKIE_NAME 配置项用于设置认证cookie名称
- 将 AcceptanceException.vue 中的表单标签宽度从固定90px改为自动适配
- 在 ActionDialog.vue 中将多个表单项标记为必填项并调整标签宽度为自动适配
- 重构 ActionHistory.vue 中的按钮布局结构并添加表格列样式类名
- 更新 api-contract-audit.cjs 添加生产任务和BOM相关接口的契约测试
- 修改 auth.js 使用动态认证cookie键名替换硬编码的Admin-Token
- 调整系统角色授权用户页面的表单布局和表格样式类名
- 优化 ReceiptDialog Batch 组件的对话框尺寸、表单验证和分页功能
2026-10-16 15:30:10 +08:00

62 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const assert=require('node:assert/strict'),path=require('node:path')
const {chromium}=require('C:/Users/Administrator/.cache/codex-runtimes/codex-primary-runtime/dependencies/node/node_modules/playwright')
;(async()=>{
const login=await(await fetch('http://127.0.0.1:8080/login',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({username:'admin',password:'admin123',code:'',uuid:''})})).json();assert.equal(login.code,200)
const browser=await chromium.launch({channel:'chrome',headless:true,args:['--disable-gpu','--js-flags=--max-old-space-size=256']})
try{
const context=await browser.newContext({viewport:{width:1440,height:900}});await context.addCookies([{name:'Admin-Token',value:login.token,url:'http://127.0.0.1:8088'}]);const page=await context.newPage();page.setDefaultTimeout(20000)
const errors=[],calls=[],writes=[];let fixture,arrivals=[],receiptFixtures=[],pendingGroups=[],shortages=[]
page.on('pageerror',e=>errors.push(e.message));page.on('request',r=>{if(r.url().includes('/dev-api/'))calls.push(new URL(r.url()).pathname)})
await page.route('**/dev-api/**',async route=>{
const req=route.request(),p=new URL(req.url()).pathname,m=req.method()
if(p==='/dev-api/warehouse/purchase/sheet/987654321')return route.fulfill({json:{code:200,data:fixture}})
if(p==='/dev-api/warehouse/purchase/sheet/987654321/quote-preview'){writes.push({kind:'quote-preview'});return route.fulfill({json:{code:200,data:[{line:2,productCode:fixture.rows[0].productCode,name:'模拟报价',price:'12.345678',unitPrice:12.345678,rowIds:[987654301,987654302],error:null}]}})}
if(p==='/dev-api/warehouse/purchase/sheet'&&m==='POST'){const data=req.postDataJSON();writes.push({kind:'sheet',data});fixture={...data,batch:{...data.batch,id:987654321,batchNo:'CG2026109999'},rows:data.rows.map((r,i)=>({...r,id:r.id||987654301+i,remainingQuantity:r.quantity,purchaseStatus:r.purchaseStatus||0})),version:'fixture-v2'};return route.fulfill({json:{code:200,data:fixture}})}
if(p==='/dev-api/warehouse/purchase/arrival'&&m==='POST'){const data=req.postDataJSON();writes.push({kind:'arrival',data});arrivals.push({...data,id:987655001,acceptanceStatus:0});return route.fulfill({json:{code:200,data:arrivals.at(-1)}})}
if(p==='/dev-api/warehouse/purchase/arrival/987654301'&&m==='GET')return route.fulfill({json:{code:200,data:arrivals}})
if(p==='/dev-api/warehouse/purchase/arrival/987655001/accept'&&m==='PUT'){const data=req.postDataJSON();writes.push({kind:'accept',data});arrivals[0].acceptanceStatus=1;return route.fulfill({json:{code:200}})}
if(p==='/dev-api/warehouse/in/pending-groups'&&pendingGroups.length)return route.fulfill({json:{code:200,data:{rows:pendingGroups,total:pendingGroups.length}}})
if(p==='/dev-api/warehouse/in/pending-groups/B:987654321')return route.fulfill({json:{code:200,data:receiptFixtures}})
if(p.startsWith('/dev-api/warehouse/in/')&&m==='GET'){const id=Number(p.split('/').at(-1)),record=receiptFixtures.find(r=>r.id===id);if(record)return route.fulfill({json:{code:200,data:record}})}
if(p.startsWith('/dev-api/warehouse/in/receive/')&&m==='POST'){writes.push({kind:'receipt',data:req.postDataJSON()});return route.fulfill({json:{code:200}})}
if(p==='/dev-api/production/tasks/shortages'&&shortages.length)return route.fulfill({json:{code:200,data:shortages}})
if(p==='/dev-api/production/tasks/actions'&&m==='POST'){writes.push({kind:'issue',data:req.postDataJSON()});return route.fulfill({json:{code:200,data:{id:987655123}}})}
if(!['GET','HEAD'].includes(m))throw Error('Unexpected real business write: '+m+' '+p)
await route.continue()
})
await page.goto('http://127.0.0.1:8088/index',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.business-home')?.__vue__?.loadedOnce)
const home=await page.evaluate(()=>{const vm=document.querySelector('.business-home').__vue__;return{failures:vm.failures,queues:vm.queues.map(q=>({count:q.count,length:q.rows.length}))}});assert.deepEqual(home.failures,[]);assert.ok(home.queues.every(q=>q.length<=6&&q.count>=q.length));assert.ok(calls.includes('/dev-api/business/home'));assert.ok(!calls.includes('/dev-api/warehouse/purchase/filtered'));console.log('PASS: bounded homepage summaries, no full purchase download')
await page.goto('http://127.0.0.1:8088/procurement/details',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>{const vm=document.querySelector('.purchase-sheet')?.__vue__;return vm?.items?.length>0&&!vm.loading})
fixture=await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__,item=vm.items.find(i=>i.unit&&i.category),project=vm.projects[0],category=vm.categories[0];const row={id:987654301,projectId:project.id,expenseCategoryId:category.id,materialName:item.productName,materialBrand:item.brand||'',materialParams:item.spec||'',productId:item.id,productCode:item.productCode,unit:item.unit,category:item.category,quantity:20,finalUnitPrice:10,purchaseStatus:2,priceLocked:true,receivedQuantity:0,acceptedQuantity:0,pendingArrivalQuantity:0,remainingQuantity:20,purchasePurpose:'SELF',purchaseLink:'',remark:''};return{batch:{id:987654321,batchNo:'CG2026109999',supplierId:null,batchName:'模拟清单',businessDate:'2026-10-12'},rows:[row,{...row,id:987654302,quantity:10},{...row,id:987654303,receivedQuantity:1}],version:'fixture-v1'}})
await page.evaluate(f=>document.querySelector('.purchase-sheet').__vue__.install(f),fixture)
const locked=await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.startEditing();return{before:vm.fieldLocked(vm.sheet.rows[0],'finalUnitPrice'),after:vm.fieldLocked(vm.sheet.rows[2],'finalUnitPrice')}});assert.equal(locked.before,false);assert.equal(locked.after,true)
await page.evaluate(()=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.sheet.rows[0].finalUnitPrice=19;vm.persistDraft()})
const draftKey=await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.draftPrefix()+'987654321');await page.reload({waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.purchase-sheet')?.__vue__?.drafts?.length>0)
await page.evaluate(key=>document.querySelector('.purchase-sheet').__vue__.restoreDraft(key),draftKey);assert.equal(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows[0].finalUnitPrice),19);assert.equal(writes.length,0)
await page.evaluate(f=>{const vm=document.querySelector('.purchase-sheet').__vue__;vm.clearDraft(987654321);vm.install(f)},fixture)
await page.getByRole('button',{name:'回填供应商报价',exact:true}).click();const quoteDialog=page.getByRole('dialog',{name:'供应商询价与报价回填',exact:true});await quoteDialog.locator('input[type=file]').setInputFiles({name:'quote.xlsx',mimeType:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',buffer:Buffer.from('mock preview intercepted')});await quoteDialog.getByRole('button',{name:'回填有效报价(1 项)',exact:true}).click()
assert.deepEqual(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows.map(r=>r.finalUnitPrice)),[12.345678,12.345678,10]);assert.deepEqual(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.sheet.rows.map(r=>r.quantity)),[20,10,20]);assert.equal(writes.filter(w=>w.kind==='sheet').length,0)
await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.save());assert.equal(writes.filter(w=>w.kind==='sheet').length,1);console.log('PASS: explicit quote save, multiple project-line match, received-price guard, draft recovery')
await page.evaluate(async()=>{const vm=document.querySelector('.purchase-sheet').__vue__,batch=vm.$refs.arrival;await batch.open(vm.sheet.rows.slice(0,2),'arrival')})
assert.deepEqual(await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.rows.map(r=>r.quantity)),[0,0])
await page.evaluate(async()=>{const batch=document.querySelector('.purchase-sheet').__vue__.$refs.arrival;batch.rows[0].quantity=7;batch.remark='模拟京东直送';await batch.submit()})
assert.equal(writes.filter(w=>w.kind==='arrival').length,1);assert.equal(writes.find(w=>w.kind==='arrival').data.arrivalQuantity,7);assert.equal(writes.find(w=>w.kind==='arrival').data.remark,'模拟京东直送');assert.equal(writes.find(w=>w.kind==='accept').data.acceptanceRemark,'模拟京东直送');console.log('PASS: partial arrival skips zero rows, arrival and acceptance remarks retained')
await page.evaluate(()=>document.querySelector('.purchase-sheet').__vue__.$refs.arrival.visible=false)
receiptFixtures=Array.from({length:40},(_,i)=>({id:987656001+i,inNo:'RK202610'+String(i+1).padStart(4,'0'),sourceNo:'DH2026100001',purchaseBatchNo:'CG2026109999',sourceProjectName:'模拟项目',sourceProjectId:fixture.rows[0].projectId,productId:fixture.rows[0].productId,productName:fixture.rows[0].materialName,unit:fixture.rows[0].unit,inNum:2,receivedQuantity:0,inStatus:0,receiptRoot:true}));pendingGroups=[{key:'B:987654321',title:'CG2026109999',projects:'模拟项目',supplierName:'模拟供应商',recordCount:40}]
await page.goto('http://127.0.0.1:8088/warehouse/pending',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.desktop-viewport .app-container')?.__vue__?.groupRows?.length===1)
assert.ok(await page.getByText('CG2026109999',{exact:true}).count()>0)
const count=await page.evaluate(async()=>{const vm=document.querySelector('.desktop-viewport .app-container').__vue__;await vm.batchGroup(vm.groupRows[0]);const batch=vm.$refs.batchReceipt;batch.setArea(batch.areas[0].id);return{rows:batch.rows.length,areas:batch.rows.every(r=>r.areaId===batch.areas[0].id)}});assert.deepEqual(count,{rows:40,areas:true});console.log('PASS: source-group pagination opens the entire 40-line batch and one common area')
await page.evaluate(()=>document.querySelector('.desktop-viewport .app-container').__vue__.$refs.batchReceipt.visible=false)
await page.goto('http://127.0.0.1:8088/production/tasks',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.production-workspace')?.__vue__&&!document.querySelector('.production-workspace').__vue__.loading)
const meta=await page.evaluate(()=>{const vm=document.querySelector('.production-workspace').__vue__;return{rows:vm.rows.length,pageSize:vm.query.pageSize,total:vm.total}});assert.ok(meta.rows<=meta.pageSize);assert.ok(calls.includes('/dev-api/production/tasks/page'))
const row=fixture.rows[0];shortages=[{taskId:987657001,taskNo:'SC-A',projectId:row.projectId,projectName:'项目A',itemId:row.productId,itemName:row.materialName,brand:row.materialBrand,spec:row.materialParams,category:row.category,unit:row.unit,outstanding:20,allocatedStock:5,requested:2,purchasing:3,pendingAcceptance:0,pendingReceipt:0,purchaseSuggestion:10},{taskId:987657002,taskNo:'SC-B',projectId:row.projectId,projectName:'项目A',itemId:row.productId,itemName:row.materialName,brand:row.materialBrand,spec:row.materialParams,category:row.category,unit:row.unit,outstanding:20,allocatedStock:0,requested:0,purchasing:0,pendingAcceptance:0,pendingReceipt:0,purchaseSuggestion:20}]
await page.evaluate(async()=>{const vm=document.querySelector('.production-workspace').__vue__;await vm.$refs.shortagePurchase.open([{id:987657001,status:'OPEN'},{id:987657002,status:'OPEN'}])});await page.waitForFunction(()=>document.querySelector('.production-workspace').__vue__.$refs.shortagePurchase.selected.length===2)
await page.evaluate(async()=>{const vm=document.querySelector('.production-workspace').__vue__;await vm.$refs.shortagePurchase.save()});const bulk=writes.filter(w=>w.kind==='sheet').at(-1).data;assert.equal(bulk.rows.length,2);assert.deepEqual(bulk.rows.map(r=>r.productionTaskId),[987657001,987657002]);assert.deepEqual(bulk.rows.map(r=>r.quantity),[10,20]);console.log('PASS: multi-task shortage generates one purchase batch with each task allocation retained')
await page.goto('http://127.0.0.1:8088/production/tasks',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.production-workspace')?.__vue__&&!document.querySelector('.production-workspace').__vue__.loading)
const suggestions=await page.evaluate(async row=>{const vm=document.querySelector('.production-workspace').__vue__,task={id:987657001,status:'OPEN',project_id:row.projectId,item_id:999999999,item_name:'模拟产品',task_no:'SC-A',needs:[{itemId:row.productId,required:20,issued:0,returned:0,scrapped:0}]};await vm.$refs.stockOperations.open([{id:1,projectId:row.projectId,productId:row.productId,stockNum:5},{id:2,projectId:row.projectId,productId:row.productId,stockNum:25}],'ISSUE',task);return vm.$refs.stockOperations.rows.map(r=>r.quantity)},row);assert.deepEqual(suggestions,[5,15]);console.log('PASS: issue suggestions split actual demand across warehouses, not one per row')
await page.evaluate(()=>document.querySelector('.production-workspace').__vue__.$refs.stockOperations.visible=false)
await page.goto('http://127.0.0.1:8088/index',{waitUntil:'domcontentloaded'});await page.waitForFunction(()=>document.querySelector('.business-home')?.__vue__?.loadedOnce);await page.evaluate(async()=>{const vm=document.querySelector('.business-home').__vue__;vm.$store.commit('SET_PERMISSIONS',['project:project:list','project:project:edit']);await vm.$router.push('/production/tasks')});await page.locator('.production-workspace').waitFor();assert.equal(await page.getByRole('button',{name:'新建生产任务',exact:true}).count(),0);assert.equal(await page.getByRole('button',{name:'批量完工验收',exact:true}).count(),0);console.log('PASS: project edit alone does not show inventory-dependent production actions')
assert.deepEqual(errors,[]);console.log('PASS: optimization workflow checks; all business mutations intercepted, no database writes. Mock writes:',writes.length)
}finally{await browser.close()}
})().catch(e=>{console.error(e);process.exitCode=1})