支持耳钉货盘克重与对数同步库存及历史盘点基准

This commit is contained in:
summer committed 2026-11-08 15:47:07 +08:00
1 parent ba15795f0a
commit b6a0213a0c
28 files changed
+906 -161

No files matched your search

+4 -3
View File
@@ -14,11 +14,12 @@ function zip(files){
}
const index=Buffer.concat(directory),end=Buffer.alloc(22),count=Object.keys(files).length;end.writeUInt32LE(0x06054b50,0);end.writeUInt16LE(count,8);end.writeUInt16LE(count,10);end.writeUInt32LE(index.length,12);end.writeUInt32LE(offset,16);return Buffer.concat([...locals,index,end]);
}
function workbook(rows,{sheetName='库存流水',widths=[8,14,16,18,20,48,18,24,30],numericColumns=[0,3]}={}){
function workbook(rows,{sheetName='库存流水',widths=[8,14,16,18,20,48,18,24,30],numericColumns=[0,3],optionalNumericColumns=[]}={}){
if(rows.length>1048576)throw new Error('超过Excel单表行数上限,请缩小筛选范围');
const column=index=>{let name='';for(index++;index;index=Math.floor((index-1)/26))name=String.fromCharCode(65+(index-1)%26)+name;return name;};
const cells=rows.map((row,index)=>`<row r="${index+1}">${row.map((value,col)=>{const ref=column(col)+(index+1);if(index&&numericColumns.includes(col)){if(typeof value!=='number'||!Number.isFinite(value))throw new Error('导出数值无效');return `<c r="${ref}" s="${col===3?2:0}" t="n"><v>${value}</v></c>`;}return `<c r="${ref}"${index?'':' s="1"'} t="inlineStr"><is><t xml:space="preserve">${xml(value)}</t></is></c>`;}).join('')}</row>`).join('');
const sheet=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><dimension ref="A1:I${rows.length}"/><sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/></sheetView></sheetViews><cols>${widths.map((width,index)=>`<col min="${index+1}" max="${index+1}" width="${width}" customWidth="1"/>`).join('')}</cols><sheetData>${cells}</sheetData><autoFilter ref="A1:I${rows.length}"/></worksheet>`;
const cells=rows.map((row,index)=>`<row r="${index+1}">${row.map((value,col)=>{const ref=column(col)+(index+1);if(index&&(numericColumns.includes(col)||optionalNumericColumns.includes(col)&&typeof value==='number')){if(typeof value!=='number'||!Number.isFinite(value))throw new Error('导出数值无效');return `<c r="${ref}" s="${col===3?2:0}" t="n"><v>${value}</v></c>`;}return `<c r="${ref}"${index?'':' s="1"'} t="inlineStr"><is><t xml:space="preserve">${xml(value)}</t></is></c>`;}).join('')}</row>`).join('');
const lastColumn=column(rows.reduce((max,row)=>Math.max(max,row.length),1)-1),range=`A1:${lastColumn}${rows.length}`;
const sheet=`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><dimension ref="${range}"/><sheetViews><sheetView workbookViewId="0"><pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/></sheetView></sheetViews><cols>${widths.map((width,index)=>`<col min="${index+1}" max="${index+1}" width="${width}" customWidth="1"/>`).join('')}</cols><sheetData>${cells}</sheetData><autoFilter ref="${range}"/></worksheet>`;
return zip({
'[Content_Types].xml':'<?xml version="1.0" encoding="UTF-8"?><Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/></Types>',
'_rels/.rels':'<?xml version="1.0" encoding="UTF-8"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>',