格式化:Prettier统一代码风格(仅格式,无逻辑变化)

仅为 npm run format 的输出;黄金对照、旧库兼容、浏览器流程与单元测试全部通过且零差异。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
黄健铭andClaude Opus 5.5 committed 2026-12-04 08:58:53 -08:00
1 parent 3743d687e7
commit 28c64814f0
221 files changed
+116943 -26708

No files matched your search

+262 -63
View File
@@ -1,82 +1,281 @@
'use strict';
const {test}=require('node:test'),assert=require('node:assert/strict');
const {recoveryCustomerPrintDocument:回收单,exchangeCustomerPrintDocument:置换单}=require('../recovery-printing');
const {notices,care,promise}=require('../printing');
const 样本={
id:'不应打印的内部id',number:'HS20261025001',mode:'exchange',date:'2026-10-25',customer:'合成客户',salesperson:'合成助理',note:'保留确认后的款式说明',
old_lines:[{name:'足金项链',incomingMg:20004,meltedMg:20000,purity:99.9,foldedMg:19980}],oldMg:19980,
newMg:30000,matchedMg:19980,differenceMg:10020,surplusMg:0,newProduct:{name:'足金手镯',quantity:30000,pocket:'不应打印的内部口袋'},
goldRate:100000,laborRate:1000,laborMode:'gram',depreciationMg:19980,depreciationRate:100,buyRate:90000,
goldAmount:1002000,laborAmount:30000,depreciationAmount:1998,charges:[{name:'换绳',amount:300}],chargesAmount:300,discount:1298,
rounding_mode:'none',rounding_adjustment:0,receivable:1033000,purchaseAmount:0,offsetAmount:1798200,netSettlement:1033000,cashReceipt:1033000,cashPayment:0,
paymentMethods:['微信'],order_id:'不应打印的订单关联',purchase_id:'不应打印的采购关联',
costMaterial:123456,profit:'不应打印的利润',costParts:{labor:'不应打印的工费成本'},payer:'不应打印的成员往来'
const { test } = require('node:test'),
assert = require('node:assert/strict');
const {
recoveryCustomerPrintDocument: 回收单,
exchangeCustomerPrintDocument: 置换单,
} = require('../recovery-printing');
const { notices, care, promise } = require('../printing');
const 样本 = {
id: '不应打印的内部id',
number: 'HS20261025001',
mode: 'exchange',
date: '2026-10-25',
customer: '合成客户',
salesperson: '合成助理',
note: '保留确认后的款式说明',
old_lines: [{ name: '足金项链', incomingMg: 20004, meltedMg: 20000, purity: 99.9, foldedMg: 19980 }],
oldMg: 19980,
newMg: 30000,
matchedMg: 19980,
differenceMg: 10020,
surplusMg: 0,
newProduct: { name: '足金手镯', quantity: 30000, pocket: '不应打印的内部口袋' },
goldRate: 100000,
laborRate: 1000,
laborMode: 'gram',
depreciationMg: 19980,
depreciationRate: 100,
buyRate: 90000,
goldAmount: 1002000,
laborAmount: 30000,
depreciationAmount: 1998,
charges: [{ name: '换绳', amount: 300 }],
chargesAmount: 300,
discount: 1298,
rounding_mode: 'none',
rounding_adjustment: 0,
receivable: 1033000,
purchaseAmount: 0,
offsetAmount: 1798200,
netSettlement: 1033000,
cashReceipt: 1033000,
cashPayment: 0,
paymentMethods: ['微信'],
order_id: '不应打印的订单关联',
purchase_id: '不应打印的采购关联',
costMaterial: 123456,
profit: '不应打印的利润',
costParts: { labor: '不应打印的工费成本' },
payer: '不应打印的成员往来',
};
const 无销售条款=文本=>{for(const 条款 of [...notices,...care,promise,'公司承诺','概不退换','无条件退换货'])assert.ok(!文本.includes(条款),条款);};
test('回收客户单逐字段打印Au旧料、二位重量、实际付款方式和保存金额大小写',()=>{
const 单据={...样本,mode:'buy',buyRate:90000,purchaseAmount:1798200,paymentMethods:['支付宝','现金']},原文=JSON.stringify(单据),html=回收单(单据);
for(const 文案 of ['黄金回收单','客户:合成客户','日期:2026-10-25','单号:HS20261025001','开单人:合成助理','经办人:合成助理','Au 黄金 · 足金项链','20.00','99.9%','19.98','¥900.00/克','最终回收金额','¥17982.00','壹万柒仟玖佰捌拾贰元整','付款方式:支付宝、现金'])assert.ok(html.includes(文案),文案);
for(const 内部 of ['不应打印','123456','offsetAmount','costMaterial','costParts','profit','cashReceipt','cashPayment','order_id','purchase_id','金料成本','成员往来','料池'])assert.ok(!html.includes(内部),内部);
assert.equal(JSON.stringify(单据),原文);无销售条款(html);
});
test('置换单完整展示新货全克重和每一项加减,不用净差克重替代新货',()=>{
const html=置换单(样本);
for(const 文案 of ['黄金置换单','旧料折后合计:<strong>19.98 克','换走新货全克重合计:<strong>30.00 克','足金手镯','补金差价','10.02 克 × ¥1000.00/克','新货工费','30.00 克 × ¥10.00/克','折旧费','19.98 克 × ¥1.00/克','附加:换绳','+¥3.00','优惠','−¥12.98','余料回收款','−¥0.00','客户补款:<strong>¥10330.00','壹万零叁佰叁拾元整','收款方式:微信'])assert.ok(html.includes(文案),文案);
for(const 内部 of ['不应打印','offsetAmount','costMaterial','costParts','profit','金料成本','成员往来','料池'])assert.ok(!html.includes(内部),内部);
const 无销售条款 = 文本 => {
for (const 条款 of [...notices, ...care, promise, '公司承诺', '概不退换', '无条件退换货'])
assert.ok(!文本.includes(条款), 条款);
};
test('回收客户单逐字段打印Au旧料、二位重量、实际付款方式和保存金额大小写', () => {
const 单据 = { ...样本, mode: 'buy', buyRate: 90000, purchaseAmount: 1798200, paymentMethods: ['支付宝', '现金'] },
原文 = JSON.stringify(单据),
html = 回收单(单据);
for (const 文案 of [
'黄金回收单',
'客户:合成客户',
'日期:2026-10-25',
'单号:HS20261025001',
'开单人:合成助理',
'经办人:合成助理',
'Au 黄金 · 足金项链',
'20.00',
'99.9%',
'19.98',
'¥900.00/克',
'最终回收金额',
'¥17982.00',
'壹万柒仟玖佰捌拾贰元整',
'付款方式:支付宝、现金',
])
assert.ok(html.includes(文案), 文案);
for (const 内部 of [
'不应打印',
'123456',
'offsetAmount',
'costMaterial',
'costParts',
'profit',
'cashReceipt',
'cashPayment',
'order_id',
'purchase_id',
'金料成本',
'成员往来',
'料池',
])
assert.ok(!html.includes(内部), 内部);
assert.equal(JSON.stringify(单据), 原文);
无销售条款(html);
});
test('置换结算正数客户补款、负数付客户、零无需补退,大写始终使用绝对金额',()=>{
for(const [netSettlement,标签,大写,方式] of [[12345,'客户补款','壹佰贰拾叁元肆角伍分','收款方式:微信'],[-12345,'付客户','壹佰贰拾叁元肆角伍分','付款方式:微信'],[0,'无需补退','零元整','结算方式:无需补退']]){
const html=置换单({...样本,netSettlement});assert.ok(html.includes(`${标签}:<strong>¥${(Math.abs(netSettlement)/100).toFixed(2)}`));assert.ok(html.includes(大写));assert.ok(html.includes(方式));assert.ok(!html.includes('¥-'));
test('置换单完整展示新货全克重和每一项加减,不用净差克重替代新货', () => {
const html = 置换单(样本);
for (const 文案 of [
'黄金置换单',
'旧料折后合计:<strong>19.98 克',
'换走新货全克重合计:<strong>30.00 克',
'足金手镯',
'补金差价',
'10.02 克 × ¥1000.00/克',
'新货工费',
'30.00 克 × ¥10.00/克',
'折旧费',
'19.98 克 × ¥1.00/克',
'附加:换绳',
'+¥3.00',
'优惠',
'−¥12.98',
'余料回收款',
'−¥0.00',
'客户补款:<strong>¥10330.00',
'壹万零叁佰叁拾元整',
'收款方式:微信',
])
assert.ok(html.includes(文案), 文案);
for (const 内部 of [
'不应打印',
'offsetAmount',
'costMaterial',
'costParts',
'profit',
'金料成本',
'成员往来',
'料池',
])
assert.ok(!html.includes(内部), 内部);
无销售条款(html);
});
test('置换结算正数客户补款、负数付客户、零无需补退,大写始终使用绝对金额', () => {
for (const [netSettlement, 标签, 大写, 方式] of [
[12345, '客户补款', '壹佰贰拾叁元肆角伍分', '收款方式:微信'],
[-12345, '付客户', '壹佰贰拾叁元肆角伍分', '付款方式:微信'],
[0, '无需补退', '零元整', '结算方式:无需补退'],
]) {
const html = 置换单({ ...样本, netSettlement });
assert.ok(html.includes(`${标签}:<strong>¥${(Math.abs(netSettlement) / 100).toFixed(2)}`));
assert.ok(html.includes(大写));
assert.ok(html.includes(方式));
assert.ok(!html.includes('¥-'));
}
});
test('总额工费按整单金额显示,不把全部新货重量再乘一遍',()=>{
const html=置换单({...样本,laborMode:'total',laborRate:30000,laborAmount:30000});
assert.ok(html.includes('整单工费 ¥300.00'));assert.ok(!html.includes('30.00 克 × ¥300.00/克'));assert.ok(html.includes('+¥300.00'));
test('总额工费按整单金额显示,不把全部新货重量再乘一遍', () => {
const html = 置换单({ ...样本, laborMode: 'total', laborRate: 30000, laborAmount: 30000 });
assert.ok(html.includes('整单工费 ¥300.00'));
assert.ok(!html.includes('30.00 克 × ¥300.00/克'));
assert.ok(html.includes('+¥300.00'));
});
test('手动核实回收总额时保留单价计算额和最终额说明,不把调整额伪写成乘法等式',()=>{
const 直接=回收单({...样本,oldMg:9900,buyRate:85000,calculatedPurchaseAmount:841500,purchaseAmount:840000});
for(const 文案 of ['按回收单价计算:¥8415.00','核实后调整为:¥8400.00','最终回收金额:<strong>¥8400.00','捌仟肆佰元整'])assert.ok(直接.includes(文案),文案);
for(const 提供计算额 of [true,false]){
const 输入={...样本,surplusMg:10000,buyRate:85000,purchaseAmount:840000,netSettlement:-780000,...(提供计算额?{calculatedPurchaseAmount:850000}:{})};
const html=置换单(输入);
for(const 文案 of ['10.00 克;回收单价 ¥850.00/克','按单价计算 ¥8500.00,核实后调整为 ¥8400.00','−¥8400.00','付客户:<strong>¥7800.00'])assert.ok(html.includes(文案),文案);
test('手动核实回收总额时保留单价计算额和最终额说明,不把调整额伪写成乘法等式', () => {
const 直接 = 回收单({
...样本,
oldMg: 9900,
buyRate: 85000,
calculatedPurchaseAmount: 841500,
purchaseAmount: 840000,
});
for (const 文案 of [
'按回收单价计算:¥8415.00',
'核实后调整为:¥8400.00',
'最终回收金额:<strong>¥8400.00',
'捌仟肆佰元整',
])
assert.ok(直接.includes(文案), 文案);
for (const 提供计算额 of [true, false]) {
const 输入 = {
...样本,
surplusMg: 10000,
buyRate: 85000,
purchaseAmount: 840000,
netSettlement: -780000,
...(提供计算额 ? { calculatedPurchaseAmount: 850000 } : {}),
};
const html = 置换单(输入);
for (const 文案 of [
'10.00 克;回收单价 ¥850.00/克',
'按单价计算 ¥8500.00,核实后调整为 ¥8400.00',
'−¥8400.00',
'付客户:<strong>¥7800.00',
])
assert.ok(html.includes(文案), 文案);
assert.ok(!html.includes('10.00 克 × ¥850.00/克'));
}
});
test('多行旧料和新货全部保留,重量展示只舍入到二位不改后端毫克值',()=>{
const old_lines=Array.from({length:15},(_,序号)=>({name:'多行旧料'+序号,incomingMg:1005+序号,meltedMg:1005+序号,purity:99,foldedMg:1005+序号}));
const new_lines=Array.from({length:15},(_,序号)=>({name:'多行新货'+序号,quantity:12345+序号,pocket:'内部仓位'+序号}));
const 单据={...样本,old_lines,new_lines},原文=JSON.stringify(单据),html=置换单(单据);
for(const 文案 of ['多行旧料14','多行新货14','1.01','12.35'])assert.ok(html.includes(文案),文案);
assert.ok(!html.includes('内部仓位'));assert.equal(JSON.stringify(单据),原文);assert.equal((html.match(/<section class="sheet"/g)||[]).length,1);assert.ok(!html.includes('overflow:hidden'));
test('多行旧料和新货全部保留,重量展示只舍入到二位不改后端毫克值', () => {
const old_lines = Array.from({ length: 15 }, (_, 序号) => ({
name: '多行旧料' + 序号,
incomingMg: 1005 + 序号,
meltedMg: 1005 + 序号,
purity: 99,
foldedMg: 1005 + 序号,
}));
const new_lines = Array.from({ length: 15 }, (_, 序号) => ({
name: '多行新货' + 序号,
quantity: 12345 + 序号,
pocket: '内部仓位' + 序号,
}));
const 单据 = { ...样本, old_lines, new_lines },
原文 = JSON.stringify(单据),
html = 置换单(单据);
for (const 文案 of ['多行旧料14', '多行新货14', '1.01', '12.35']) assert.ok(html.includes(文案), 文案);
assert.ok(!html.includes('内部仓位'));
assert.equal(JSON.stringify(单据), 原文);
assert.equal((html.match(/<section class="sheet"/g) || []).length, 1);
assert.ok(!html.includes('overflow:hidden'));
});
test('取整调整单列显示,最终金额直接取已保存值,不由打印重新计算',()=>{
for(const [rounding_adjustment,符号,netSettlement] of [[45,'+',1033045],[-45,'−',1032955]]){
const html=置换单({...样本,rounding_mode:'yuan',rounding_adjustment,netSettlement});assert.ok(html.includes('整单取整调整'));assert.ok(html.includes(`${符号}¥0.45`));assert.ok(html.includes(`客户补款:<strong>¥${(netSettlement/100).toFixed(2)}`));
test('取整调整单列显示,最终金额直接取已保存值,不由打印重新计算', () => {
for (const [rounding_adjustment, 符号, netSettlement] of [
[45, '+', 1033045],
[-45, '−', 1032955],
]) {
const html = 置换单({ ...样本, rounding_mode: 'yuan', rounding_adjustment, netSettlement });
assert.ok(html.includes('整单取整调整'));
assert.ok(html.includes(`${符号}¥0.45`));
assert.ok(html.includes(`客户补款:<strong>¥${(netSettlement / 100).toFixed(2)}`));
}
assert.ok(!置换单(样本).includes('整单取整调整'));
});
test('文本转义且打印不遍历公开白名单外对象,空支付渠道不会伪称已付款',()=>{
const 单据={...样本,number:'<script>单号</script>',customer:'<客户>',salesperson:'"开单人"',note:'<img src=x onerror=alert(1)>',old_lines:[{...样本.old_lines[0],name:'<旧料>'}],newProduct:{name:'<新货>',quantity:30000},charges:[{name:'<附加>',amount:300}],paymentMethods:[]};
const html=置换单(单据,{store:'<店名>',contact:'<联系电话>'});
for(const 文案 of ['&lt;script&gt;单号&lt;/script&gt;','&lt;客户&gt;','&quot;开单人&quot;','&lt;img src=x onerror=alert(1)&gt;','&lt;旧料&gt;','&lt;新货&gt;','&lt;附加&gt;','&lt;店名&gt;','&lt;联系电话&gt;','收款方式:尚未登记'])assert.ok(html.includes(文案),文案);
assert.ok(!html.includes('<img'));assert.ok(!html.includes('<客户>'));
test('文本转义且打印不遍历公开白名单外对象,空支付渠道不会伪称已付款', () => {
const 单据 = {
...样本,
number: '<script>单号</script>',
customer: '<客户>',
salesperson: '"开单人"',
note: '<img src=x onerror=alert(1)>',
old_lines: [{ ...样本.old_lines[0], name: '<旧料>' }],
newProduct: { name: '<新货>', quantity: 30000 },
charges: [{ name: '<附加>', amount: 300 }],
paymentMethods: [],
};
const html = 置换单(单据, { store: '<店名>', contact: '<联系电话>' });
for (const 文案 of [
'&lt;script&gt;单号&lt;/script&gt;',
'&lt;客户&gt;',
'&quot;开单人&quot;',
'&lt;img src=x onerror=alert(1)&gt;',
'&lt;旧料&gt;',
'&lt;新货&gt;',
'&lt;附加&gt;',
'&lt;店名&gt;',
'&lt;联系电话&gt;',
'收款方式:尚未登记',
])
assert.ok(html.includes(文案), 文案);
assert.ok(!html.includes('<img'));
assert.ok(!html.includes('<客户>'));
});
test('固定241×140mm和192mm内容宽,复用现有单页脚本并保持备注经办人同一行',()=>{
const 原设置={width:300,height:400,offsetX:2,offsetY:3,contentTop:14,rowHeight:12},原文=JSON.stringify(原设置);
for(const 模板 of [回收单,置换单]){
const html=模板(样本,原设置);
assert.match(html,/@page\{size:241mm 140mm;margin:0\}/);assert.match(html,/\.print-frame\{position:absolute;max-width:192mm/);assert.match(html,/data-layout-width-mm="192" data-layout-height-mm="115"/);
assert.match(html,/class="print-canvas"[^>]+preserveAspectRatio="xMinYMin meet"/);assert.ok(html.includes('<script src="/print.js"></script>'));assert.ok(html.includes('id="print" disabled'));assert.ok(html.includes('id="fit-status"'));
assert.match(html,/\.signatures\{display:flex;align-items:flex-start;justify-content:space-between/);assert.match(html,/\.signatures \.salesperson\{margin-left:auto;flex-shrink:0;white-space:nowrap\}/);assert.match(html,/<div class="signatures"><div class="note">备注:[\s\S]+?<\/div><span class="salesperson">经办人:合成助理/);
test('固定241×140mm和192mm内容宽,复用现有单页脚本并保持备注经办人同一行', () => {
const 原设置 = { width: 300, height: 400, offsetX: 2, offsetY: 3, contentTop: 14, rowHeight: 12 },
原文 = JSON.stringify(原设置);
for (const 模板 of [回收单, 置换单]) {
const html = 模板(样本, 原设置);
assert.match(html, /@page\{size:241mm 140mm;margin:0\}/);
assert.match(html, /\.print-frame\{position:absolute;max-width:192mm/);
assert.match(html, /data-layout-width-mm="192" data-layout-height-mm="115"/);
assert.match(html, /class="print-canvas"[^>]+preserveAspectRatio="xMinYMin meet"/);
assert.ok(html.includes('<script src="/print.js"></script>'));
assert.ok(html.includes('id="print" disabled'));
assert.ok(html.includes('id="fit-status"'));
assert.match(html, /\.signatures\{display:flex;align-items:flex-start;justify-content:space-between/);
assert.match(html, /\.signatures \.salesperson\{margin-left:auto;flex-shrink:0;white-space:nowrap\}/);
assert.match(
html,
/<div class="signatures"><div class="note">备注:[\s\S]+?<\/div><span class="salesperson">经办人:合成助理/,
);
无销售条款(html);
}
assert.equal(JSON.stringify(原设置),原文);
assert.equal(JSON.stringify(原设置), 原文);
});
test('非法金额和重量拒绝生成单据,金额不接受字符串或浮点分',()=>{
for(const 值 of [null,undefined,'100',-1,0.1,NaN,Infinity,Number.MAX_SAFE_INTEGER+1])assert.throws(()=>回收单({...样本,purchaseAmount:值}));
for(const 值 of [null,undefined,'100',0.1,NaN,Infinity,Number.MAX_SAFE_INTEGER+1])assert.throws(()=>置换单({...样本,netSettlement:值}));
for(const 值 of [-1,'1000',1000.1])assert.throws(()=>回收单({...样本,oldMg:值}));
for(const 值 of [-1,101,'99'])assert.throws(()=>回收单({...样本,old_lines:[{...样本.old_lines[0],purity:值}]}));
test('非法金额和重量拒绝生成单据,金额不接受字符串或浮点分', () => {
for (const 值 of [null, undefined, '100', -1, 0.1, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1])
assert.throws(() => 回收单({ ...样本, purchaseAmount: 值 }));
for (const 值 of [null, undefined, '100', 0.1, NaN, Infinity, Number.MAX_SAFE_INTEGER + 1])
assert.throws(() => 置换单({ ...样本, netSettlement: 值 }));
for (const 值 of [-1, '1000', 1000.1]) assert.throws(() => 回收单({ ...样本, oldMg: 值 }));
for (const 值 of [-1, 101, '99'])
assert.throws(() => 回收单({ ...样本, old_lines: [{ ...样本.old_lines[0], purity: 值 }] }));
});