This commit is contained in:
zlwu committed 2026-08-26 11:10:40 +08:00
1 parent dd1acdc787
commit 4222eaa593
47 files changed
+1054350 -9663

No files matched your search

@@ -26,15 +26,13 @@ const LOGO_LEFT = 50
const TITLE_STYLE = `${FONT_TITLE}font-weight:700 !important;letter-spacing:6px;line-height:1.35;`
const TITLE_SUB_STYLE = `${TITLE_STYLE}margin-top:2px;letter-spacing:10px;`
const TABLE_ROW_PADDING = '4px'
/** 信息表列宽:收货单位(4) / 联系方式(1,略加宽) / 日期(2) */
/** 信息表列宽:左栏 3/5(收货单位、收货联系方式)/ 右栏 2/5(单据编号、日期) */
const INFO_COLGROUP = `<colgroup>
<col style="width:12.75%;" />
<col style="width:12.75%;" />
<col style="width:12.75%;" />
<col style="width:12.75%;" />
<col style="width:22.5%;" />
<col style="width:13.25%;" />
<col style="width:13.25%;" />
<col style="width:20%;" />
<col style="width:20%;" />
<col style="width:20%;" />
<col style="width:20%;" />
<col style="width:20%;" />
</colgroup>`
/**
* 物料表列宽:单据编号 + 加宽编号/名称,收窄规格/单位;前 5 列合计供条款区使用。
@@ -628,22 +626,30 @@ function buildDeliverySlipInfoTableHtml(): string {
return `<table class="delivery-slip-info-table" style="width:100%;border-collapse:collapse;table-layout:fixed;border:none !important;">
${INFO_COLGROUP}
<tr>
<td colspan="4" style="${INFO_CELL_LEFT}">
<td colspan="3" style="${INFO_CELL_LEFT}">
<div class="delivery-slip-info-row" style="${INFO_ROW}">
<span class="delivery-slip-info-label" style="${INFO_LABEL}">收货单位:</span>
<span class="delivery-slip-info-value-left" style="${INFO_VALUE_INLINE_LEFT}">{{receivingUnit}}&nbsp;</span>
</div>
</td>
<td colspan="1" style="${INFO_CELL_LEFT}">
<td colspan="2" style="${INFO_CELL_RIGHT}">
${buildDeliverySlipTypeCheckboxesHtml()}
<div class="delivery-slip-info-row" style="${INFO_ROW}">
<span class="delivery-slip-info-label" style="${INFO_LABEL}">联系方式:</span>
<span class="delivery-slip-info-label" style="${INFO_LABEL}">单据编号:</span>
<span class="delivery-slip-info-value-center" style="${INFO_VALUE_INLINE_CENTER}">{{planNo}}&nbsp;</span>
</div>
</td>
</tr>
<tr>
<td colspan="3" style="${INFO_CELL_LEFT}">
<div class="delivery-slip-info-row" style="${INFO_ROW}">
<span class="delivery-slip-info-label" style="${INFO_LABEL}">收货联系方式:</span>
<span class="delivery-slip-info-value-left" style="${INFO_VALUE_INLINE_LEFT}">{{receiveContact}}&nbsp;</span>
</div>
</td>
<td colspan="2" style="${INFO_CELL_RIGHT}">
${buildDeliverySlipTypeCheckboxesHtml()}
<div class="delivery-slip-info-row" style="${INFO_ROW}">
<span class="delivery-slip-info-label" style="${INFO_LABEL}">日&nbsp;期:</span>
<span class="delivery-slip-info-label" style="${INFO_LABEL}">日&nbsp;&nbsp;&nbsp;期:</span>
<span class="delivery-slip-info-value-center" style="${INFO_VALUE_INLINE_CENTER}">{{planDateChinese}}&nbsp;</span>
</div>
</td>
@@ -1302,7 +1308,7 @@ function normalizeDeliverySlipGapBeforeProduct(html: string): string {
return html.replace(
new RegExp(
`(<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)?期:<\\/span>[\\s\\S]*?<\\/tr>\\s*)(<!--\\s*中:产品明细表[\\s\\S]*?<tr[\\s\\S]*?<th[^>]*>${productHeader}|<tr[\\s\\S]*?<th[^>]*>${productHeader})`
`(<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)*期:<\\/span>[\\s\\S]*?<\\/tr>\\s*)(<!--\\s*中:产品明细表[\\s\\S]*?<tr[\\s\\S]*?<th[^>]*>${productHeader}|<tr[\\s\\S]*?<th[^>]*>${productHeader})`
),
`$1${gapRow}$2`
)
@@ -1419,34 +1425,39 @@ function normalizeDeliverySlipSignRow(html: string): string {
return normalizeDeliverySlipSignLabelMarkup(result)
}
/** 信息区:收货单位 / 联系方式 / 日期 同一行(兼容旧多行布局) */
/** 信息区:收货单位+单据编号 / 收货联系方式+日期 两行 3/5+2/5(兼容旧单行布局) */
function normalizeDeliverySlipInfoLayout(html: string): string {
if (!html.includes('delivery-slip-info-table')) return html
let result = html.replace(/收货联系方式:/g, '联系方式:')
let result = html.replace(/(收货)?联系方式:/g, '收货联系方式:')
const infoMatch = result.match(/<table class="delivery-slip-info-table"[^>]*>[\s\S]*?<\/table>/i)
if (!infoMatch) return result
const infoHtml = infoMatch[0]
const rowCount = (infoHtml.match(/<tr[\s>]/g) || []).length
const hasPlanNoInInfo = infoHtml.includes('单据编号:')
const layoutOk =
rowCount === 1 &&
rowCount === 2 &&
infoHtml.includes('收货单位:') &&
infoHtml.includes('联系方式:') &&
/日(?:&nbsp;)?期:/.test(infoHtml) &&
!hasPlanNoInInfo &&
/<td[^>]*colspan="4"[^>]*>[\s\S]*?收货单位:/.test(infoHtml) &&
/<td[^>]*colspan="1"[^>]*>[\s\S]*?联系方式:/.test(infoHtml) &&
/<td[^>]*colspan="2"[^>]*>[\s\S]*?日(?:&nbsp;)?期:/.test(infoHtml) &&
!/<td[^>]*colspan="[2-5]"[^>]*>[\s\S]*?联系方式:/.test(infoHtml)
infoHtml.includes('单据编号:') &&
infoHtml.includes('收货联系方式:') &&
/日(?:&nbsp;)*期:/.test(infoHtml) &&
/<td[^>]*colspan="3"[^>]*>[\s\S]*?收货单位:/.test(infoHtml) &&
/<td[^>]*colspan="2"[^>]*>[\s\S]*?单据编号:/.test(infoHtml) &&
/<td[^>]*colspan="3"[^>]*>[\s\S]*?收货联系方式:/.test(infoHtml) &&
/<td[^>]*colspan="2"[^>]*>[\s\S]*?日(?:&nbsp;)*期:/.test(infoHtml)
if (layoutOk) {
return result.replace(
let next = result.replace(
/(<table class="delivery-slip-info-table"[^>]*>\s*)(?:<colgroup>[\s\S]*?<\/colgroup>\s*)?/i,
`$1${INFO_COLGROUP}`
)
// 单据编号值居中(兼容先前左对齐模板)
next = next.replace(
/(<span class="delivery-slip-info-label"[^>]*>单据编号:<\/span>\s*<span class=")delivery-slip-info-value-(?:left|center)(" style=")[^"]*("[^>]*>)/,
`$1delivery-slip-info-value-center$2${INFO_VALUE_INLINE_CENTER}$3`
)
return next
}
return result.replace(infoMatch[0], buildDeliverySlipInfoTableHtml())
@@ -1621,7 +1632,7 @@ function normalizeDeliverySlipDocLayout(html: string): string {
.replace(/top:4px;/g, `top:${DELIVERY_SLIP_SEAL_TOP}px;`)
.replace(/top:-96px !important;/g, `top:${DELIVERY_SLIP_SEAL_TOP}px !important;`)
.replace(/top:-96px;/g, `top:${DELIVERY_SLIP_SEAL_TOP}px;`)
.replace(/>日期:</g, '>日&nbsp;期:<')
.replace(/>日(?:&nbsp;)*期:</g, '>日&nbsp;&nbsp;&nbsp;期:<')
.replace(/border-bottom:2px solid #000 !important;/g, `border-bottom:${INFO_UNDERLINE} !important;`)
.replace(/border-bottom:1px solid #000 !important;/g, `border-bottom:${INFO_UNDERLINE} !important;`)
.replace(/border:2px solid #000 !important;/g, `border:${PRODUCT_GRID_BORDER} !important;`)
@@ -1708,38 +1719,38 @@ function normalizeDeliverySlipTypeCheckRow(html: string): string {
if (!result.includes('delivery-slip-type-check-row')) {
const checkRowHtml = buildDeliverySlipTypeCheckboxesHtml()
const withClass = result.replace(
/(<td colspan="3"[^>]*style="[^"]*"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)?期:)/,
// 优先插在单据编号上方(当前布局:右栏 2/5)
const withPlanNo = result.replace(
/(<td colspan="2"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>单据编号:)/,
`$1${checkRowHtml}\n $2`
)
if (withClass !== result) {
result = withClass
if (withPlanNo !== result) {
result = withPlanNo
} else {
result = result.replace(
/(<td colspan="3"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)?期:)/,
`$1${checkRowHtml}\n $2`
)
}
// 兼容旧模板:日期在 colspan=2 / colspan=1 单元格时仍插多选
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="2"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)?期:)/,
`$1${checkRowHtml}\n $2`
)
}
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="1"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)?期:)/,
`$1${checkRowHtml}\n $2`
)
}
// 兼容更旧模板:单据编号位置仍插多选,随后由 infoLayout 迁移
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="3"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>单据编号:)/,
`$1${checkRowHtml}\n $2`
)
}
// 兼容旧模板:日期单元格仍插多选,随后由 infoLayout 迁移
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="2"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)*期:)/,
`$1${checkRowHtml}\n $2`
)
}
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="3"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)*期:)/,
`$1${checkRowHtml}\n $2`
)
}
if (!result.includes('delivery-slip-type-check-row')) {
result = result.replace(
/(<td colspan="1"[^>]*>\s*)(<div class="delivery-slip-info-row"[^>]*>\s*<span class="delivery-slip-info-label"[^>]*>日(?:&nbsp;)*期:)/,
`$1${checkRowHtml}\n $2`
)
}
}
return refreshDeliverySlipTypeCheckRowStyle(result)