gm-printer 10.42.3-beta.0 → 10.42.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/demo.js +9 -9
- package/package.json +1 -1
- package/src/common/editor_store.js +21 -29
- package/src/printer/compute_pages.js +2 -1
- package/src/printer/printer.js +7 -0
- package/src/printer/store.js +123 -34
package/package.json
CHANGED
|
@@ -263,24 +263,6 @@ class EditorStore {
|
|
|
263
263
|
this.remainPageHeihgt = remainHeight
|
|
264
264
|
}
|
|
265
265
|
|
|
266
|
-
@action
|
|
267
|
-
getFilledTableData(tableData) {
|
|
268
|
-
const { autoFillConfig } = this.config
|
|
269
|
-
if (!this.selectedRegion && !autoFillConfig?.checked) return []
|
|
270
|
-
let tr_count = 0
|
|
271
|
-
|
|
272
|
-
tr_count = Math.floor(
|
|
273
|
-
this.remainPageHeihgt / this.computedTableCustomerRowHeight
|
|
274
|
-
)
|
|
275
|
-
if (tr_count <= 0) return []
|
|
276
|
-
|
|
277
|
-
const sample = (tableData || []).find(item => item && !item._isEmptyData)
|
|
278
|
-
const dataKey =
|
|
279
|
-
this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
|
|
280
|
-
const colNumber = detectColNumber(dataKey, tableData)
|
|
281
|
-
return createEmptyRows(tr_count, sample, colNumber)
|
|
282
|
-
}
|
|
283
|
-
|
|
284
266
|
/** 多栏表缺失时(如双栏切三栏),从单栏/双栏源表现场打包到 mockData */
|
|
285
267
|
@action
|
|
286
268
|
ensureMockMultiTable(dataKey) {
|
|
@@ -345,18 +327,14 @@ class EditorStore {
|
|
|
345
327
|
this.ensureMockMultiTable(getDataKey(dataKey, 'vertical'))
|
|
346
328
|
}
|
|
347
329
|
|
|
330
|
+
// 开启时不在编辑器侧预推空行:预推依赖挂载时上报的剩余高度,布局(纸张/表格/
|
|
331
|
+
// 排列)变化后会过期,第一次开启填充会按旧基准多推,把已渲染完的表格撑到下一页。
|
|
332
|
+
// 空行统一由 Printer 侧「先分页拿基准 → 补空 → 重分页」写入(见 printer.js)
|
|
348
333
|
const syncEmptyRows = key => {
|
|
349
334
|
if (!this.mockData._table?.[key]) return
|
|
350
|
-
const list = this.mockData._table[key]
|
|
351
|
-
const hasHadEmptyData = _.some(list, data => data?._isEmptyData)
|
|
352
|
-
if (isAutoFilling && !hasHadEmptyData) {
|
|
353
|
-
list.push(...this.getFilledTableData(list))
|
|
354
|
-
}
|
|
355
335
|
if (!isAutoFilling) {
|
|
356
336
|
this.clearExtraTableData(key)
|
|
357
|
-
return
|
|
358
337
|
}
|
|
359
|
-
this.mockData._table[key] = list
|
|
360
338
|
}
|
|
361
339
|
|
|
362
340
|
const numberEmptyRows = key => {
|
|
@@ -385,13 +363,12 @@ class EditorStore {
|
|
|
385
363
|
const baseRowCount = sourceItems.length
|
|
386
364
|
? Math.max(1, Math.ceil(sourceItems.length / colNumber))
|
|
387
365
|
: 0
|
|
388
|
-
// 钉死总行:repack 后 _isEmptyData 会变少,不能再用 emptyTable.length
|
|
366
|
+
// 钉死总行:repack 后 _isEmptyData 会变少,不能再用 emptyTable.length;
|
|
367
|
+
// 无空行时不预推,交由 Printer 按当前分页基准补
|
|
389
368
|
const emptyCount = resolveVerticalEmptyCount(
|
|
390
369
|
list.length,
|
|
391
370
|
baseRowCount,
|
|
392
|
-
emptyTable.length
|
|
393
|
-
? emptyTable.length
|
|
394
|
-
: this.getFilledTableData(list).length,
|
|
371
|
+
emptyTable.length,
|
|
395
372
|
emptyTable.length > 0
|
|
396
373
|
)
|
|
397
374
|
const dataRows = baseRowCount
|
|
@@ -497,6 +474,11 @@ class EditorStore {
|
|
|
497
474
|
@action.bound
|
|
498
475
|
setPageSize(field, value) {
|
|
499
476
|
this.config.page.size[field] = value
|
|
477
|
+
// 页面几何变化会让预览 Printer 重挂载;行数填充开启时清掉按旧页高算出的空行,
|
|
478
|
+
// 重挂载后按新几何重补(对齐切换商品排列时的处理,见 setTableDataKeyEffect)
|
|
479
|
+
if (this.isAutoFilling || this.config?.autoFillConfig?.checked) {
|
|
480
|
+
this.clearAllTableEmptyData()
|
|
481
|
+
}
|
|
500
482
|
}
|
|
501
483
|
|
|
502
484
|
@computed
|
|
@@ -548,6 +530,10 @@ class EditorStore {
|
|
|
548
530
|
height: size.width
|
|
549
531
|
}
|
|
550
532
|
}
|
|
533
|
+
// 可用页高变了,行数填充开启时清掉按旧方向算出的空行,重挂载后重补
|
|
534
|
+
if (this.isAutoFilling || this.config?.autoFillConfig?.checked) {
|
|
535
|
+
this.clearAllTableEmptyData()
|
|
536
|
+
}
|
|
551
537
|
}
|
|
552
538
|
}
|
|
553
539
|
|
|
@@ -588,6 +574,12 @@ class EditorStore {
|
|
|
588
574
|
gap,
|
|
589
575
|
name
|
|
590
576
|
}
|
|
577
|
+
// 纸张类型/内边距变了,可用页高随之变化;行数填充开启时清掉按旧纸张算出的
|
|
578
|
+
// 空行(fillTableEmptyIndex 对已有空行沿用旧数量不重算,旧数量会把同页后续
|
|
579
|
+
// 表格挤到下一页),交给 Printer 重挂载后按新页高重补
|
|
580
|
+
if (this.isAutoFilling || this.config?.autoFillConfig?.checked) {
|
|
581
|
+
this.clearAllTableEmptyData()
|
|
582
|
+
}
|
|
591
583
|
}
|
|
592
584
|
|
|
593
585
|
@action
|
|
@@ -62,7 +62,8 @@ function init() {
|
|
|
62
62
|
* 影响合计行渲染与行高,进而影响分页边界)
|
|
63
63
|
* @returns {Promise<{pages: Array, remainPageHeight: number, tableCustomerRowHeight: number}>}
|
|
64
64
|
* pages: [[{type, index, begin, end}, ...], ...] 对 data._table[contents[i].dataKey] 行号的切片
|
|
65
|
-
* remainPageHeight:
|
|
65
|
+
* remainPageHeight: 行数填充基准高度(填充表格最后一段所在页的剩余高度,
|
|
66
|
+
* 无填充表格时为末页剩余;供行数填充换算)
|
|
66
67
|
* tableCustomerRowHeight: 表格行高(供行数填充换算)
|
|
67
68
|
*/
|
|
68
69
|
function computePages({ data, config, isSomeSubtotalTr }) {
|
package/src/printer/printer.js
CHANGED
|
@@ -100,6 +100,13 @@ class Printer extends React.Component {
|
|
|
100
100
|
await this.props.printerStore.setFillIndex(nextProps.fillIndex)
|
|
101
101
|
await this.props.printerStore.setData(nextProps.data)
|
|
102
102
|
await this.props.printerStore.setReady(true)
|
|
103
|
+
// 与 componentDidMount 同序:先按当前数据分页拿到行数填充基准,再补空行、
|
|
104
|
+
// 按补空后的数据重新分页。缺前置分页时 changeTableData 只能用上一轮
|
|
105
|
+
// (可能已含空行)的 remainPageHeight 换算行数,开关填充时行数会偏小或偏大
|
|
106
|
+
await this.props.printerStore.computedPages()
|
|
107
|
+
// 把「未补空」基准回报给编辑器,与挂载流程同口径
|
|
108
|
+
this.props.getremainpageHeight &&
|
|
109
|
+
this.props.getremainpageHeight(this.props.printerStore.remainPageHeight)
|
|
103
110
|
await this.props.printerStore.changeTableData()
|
|
104
111
|
await this.props.printerStore.computedPages()
|
|
105
112
|
}
|
package/src/printer/store.js
CHANGED
|
@@ -68,7 +68,7 @@ class PrinterStore {
|
|
|
68
68
|
|
|
69
69
|
@observable pages = [] // [{type, index, begin, end}]
|
|
70
70
|
|
|
71
|
-
/**
|
|
71
|
+
/** 行数填充基准:填充表格最后一段所在页的剩余空白高度;无填充表格时为末页剩余 */
|
|
72
72
|
@observable remainPageHeight = 0
|
|
73
73
|
@observable isSave = false
|
|
74
74
|
/** data._table 非 observable,变更后递增以驱动预览重渲 */
|
|
@@ -327,6 +327,8 @@ class PrinterStore {
|
|
|
327
327
|
|
|
328
328
|
// 使用本地数组累积分页结果,避免循环中反复触发 observable 更新
|
|
329
329
|
const pages = []
|
|
330
|
+
// 各表格的行高数组(含明细拆分 splice 后的结果),供行数填充基准按同一口径复算
|
|
331
|
+
const splicedHeightsMap = {}
|
|
330
332
|
// 每页必有 页眉header, 页脚footer , 签名
|
|
331
333
|
const allPagesHaveThisHeight = heightMap.header + heightMap.footer
|
|
332
334
|
// 退出计算! 因为页眉 + 页脚 > currentPageHeight,页面装不下其他东西
|
|
@@ -362,37 +364,9 @@ class PrinterStore {
|
|
|
362
364
|
index++
|
|
363
365
|
continue
|
|
364
366
|
}
|
|
365
|
-
const {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
summaryConfig,
|
|
369
|
-
overallOrder,
|
|
370
|
-
diySubtotal
|
|
371
|
-
} = content
|
|
372
|
-
// 如果显示每页合计,那么table高度多预留一行高度
|
|
373
|
-
const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
|
|
374
|
-
// 如果显示整单合计,那么table高度多预留一行高度
|
|
375
|
-
const overallOrderTrHeight = overallOrder?.show
|
|
376
|
-
? getOverallOrderTrHeight(overallOrder)
|
|
377
|
-
: 0
|
|
378
|
-
// 如果每页合计(新的),那么table高度多预留一行高度
|
|
379
|
-
const pageSummaryTrHeight =
|
|
380
|
-
summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
|
|
381
|
-
? getSumTrHeight(summaryConfig)
|
|
382
|
-
: 0
|
|
383
|
-
|
|
384
|
-
// 如果显示自定义每页合计,那么table高度多预留一行高度
|
|
385
|
-
const diySubtotalTrHeight = diySubtotal?.show
|
|
386
|
-
? getOverallOrderTrHeight(diySubtotal) // 使用相同的计算方式
|
|
387
|
-
: 0
|
|
388
|
-
|
|
389
|
-
// 每个表格都具有的高度
|
|
390
|
-
const allTableHaveThisHeight =
|
|
391
|
-
table.head.height +
|
|
392
|
-
subtotalTrHeight +
|
|
393
|
-
pageSummaryTrHeight +
|
|
394
|
-
overallOrderTrHeight +
|
|
395
|
-
diySubtotalTrHeight
|
|
367
|
+
const { dataKey } = content
|
|
368
|
+
// 每个表格都具有的高度(表头 + 各类合计行),提取成方法供填充基准复用同一口径
|
|
369
|
+
const allTableHaveThisHeight = this.getTableAllHaveHeight(index)
|
|
396
370
|
|
|
397
371
|
/** 当前page页面的最小高度 */
|
|
398
372
|
const currentPageMinimumHeight =
|
|
@@ -408,6 +382,8 @@ class PrinterStore {
|
|
|
408
382
|
const heights = [
|
|
409
383
|
...this.getNormalTableBodyHeights(table.body.heights, dataKey)
|
|
410
384
|
]
|
|
385
|
+
// 保留引用:该数组会被明细拆分 splice,填充基准需要用拆分后的行高
|
|
386
|
+
splicedHeightsMap[index] = heights
|
|
411
387
|
const tableData = tableDataMap[dataKey] || []
|
|
412
388
|
// 表格行的索引,用于table.slice(begin, end), 分割到不同页面中
|
|
413
389
|
let begin = 0
|
|
@@ -609,14 +585,127 @@ class PrinterStore {
|
|
|
609
585
|
currentPageHeight += this.getSignHeight()
|
|
610
586
|
}
|
|
611
587
|
|
|
612
|
-
|
|
613
|
-
|
|
588
|
+
// 行数填充基准:优先取「填充表格最后一段所在页」的剩余高度(表格底部与该页
|
|
589
|
+
// 可用底边之间的空白)。旧口径固定取末页剩余,当填充表格不在末页(下方内容
|
|
590
|
+
// 被挤到下一页)时,行数按末页空间换算会超出所在页容量:多出的空行被切到
|
|
591
|
+
// 下一页渲染成空表格,或把同页后续表格挤到下一页。
|
|
592
|
+
// 填充基准不做 Math.round 向上取整,避免整行边界多算 ≤1px 导致重分页时溢出
|
|
593
|
+
const fillRemainHeight = this.computeFillTableRemainHeight(
|
|
594
|
+
pages,
|
|
595
|
+
pageHeight,
|
|
596
|
+
heightMap,
|
|
597
|
+
splicedHeightsMap
|
|
614
598
|
)
|
|
599
|
+
this.remainPageHeight =
|
|
600
|
+
fillRemainHeight != null
|
|
601
|
+
? Math.max(0, fillRemainHeight)
|
|
602
|
+
: Math.max(0, Math.round(pageHeight - currentPageHeight))
|
|
615
603
|
this.isSave = false
|
|
616
604
|
this.config.isSave = false
|
|
617
605
|
this.repackVerticalMultiByPages()
|
|
618
606
|
}
|
|
619
607
|
|
|
608
|
+
/** 表格固定高度:表头 + 每页/整单/自定义合计行(不含数据行),与 computedPages 分页口径一致 */
|
|
609
|
+
getTableAllHaveHeight(contentIndex) {
|
|
610
|
+
const table = this.tablesInfo[`contents.table.${contentIndex}`]
|
|
611
|
+
if (!table?.head) return 0
|
|
612
|
+
const content = this.config.contents[contentIndex]
|
|
613
|
+
const {
|
|
614
|
+
subtotal,
|
|
615
|
+
dataKey,
|
|
616
|
+
summaryConfig,
|
|
617
|
+
overallOrder,
|
|
618
|
+
diySubtotal
|
|
619
|
+
} = content
|
|
620
|
+
// 如果显示每页合计,那么table高度多预留一行高度
|
|
621
|
+
const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
|
|
622
|
+
// 如果显示整单合计,那么table高度多预留一行高度
|
|
623
|
+
const overallOrderTrHeight = overallOrder?.show
|
|
624
|
+
? getOverallOrderTrHeight(overallOrder)
|
|
625
|
+
: 0
|
|
626
|
+
// 如果每页合计(新的),那么table高度多预留一行高度
|
|
627
|
+
const pageSummaryTrHeight =
|
|
628
|
+
summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
|
|
629
|
+
? getSumTrHeight(summaryConfig)
|
|
630
|
+
: 0
|
|
631
|
+
// 如果显示自定义每页合计,那么table高度多预留一行高度
|
|
632
|
+
const diySubtotalTrHeight = diySubtotal?.show
|
|
633
|
+
? getOverallOrderTrHeight(diySubtotal) // 使用相同的计算方式
|
|
634
|
+
: 0
|
|
635
|
+
|
|
636
|
+
return (
|
|
637
|
+
table.head.height +
|
|
638
|
+
subtotalTrHeight +
|
|
639
|
+
pageSummaryTrHeight +
|
|
640
|
+
overallOrderTrHeight +
|
|
641
|
+
diySubtotalTrHeight
|
|
642
|
+
)
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** 行数填充目标表格在 contents 中的索引(对齐 tableConfig 的解析口径),无法解析返回 null */
|
|
646
|
+
getFillTableContentIndex() {
|
|
647
|
+
const { autoFillConfig } = this.config
|
|
648
|
+
// checked 为 false 时 region 也保留着(编辑器开关来回切),此时同样能定位,
|
|
649
|
+
// 让基准在「未开启填充」的分页里也保持正确口径
|
|
650
|
+
if (!this.selectedRegion && !autoFillConfig?.region) return null
|
|
651
|
+
const region = this.selectedRegion || autoFillConfig.region
|
|
652
|
+
const contentIndex = Number(region.split('.')[2])
|
|
653
|
+
const content = this.config.contents[contentIndex]
|
|
654
|
+
if (!content || !_.has(content, 'dataKey')) return null
|
|
655
|
+
return contentIndex
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* 填充表格最后一段所在页的剩余高度(表格底部到该页可用底边的空白)。
|
|
660
|
+
* 高度口径与 computedPages 一致:页眉页脚 + 该页各内容
|
|
661
|
+
* (表格固定高度 + 分段行高 / panel 实测高),所在页为末页时再扣签名区。
|
|
662
|
+
* 定位不到填充表格(未配置 / 表格无数据被跳过)时返回 null,由调用方退回旧口径。
|
|
663
|
+
*/
|
|
664
|
+
computeFillTableRemainHeight(
|
|
665
|
+
pages,
|
|
666
|
+
pageHeight,
|
|
667
|
+
heightMap,
|
|
668
|
+
splicedHeightsMap
|
|
669
|
+
) {
|
|
670
|
+
const fillIndex = this.getFillTableContentIndex()
|
|
671
|
+
if (fillIndex == null || !pages?.length) return null
|
|
672
|
+
|
|
673
|
+
// 定位填充表格最后一个分段所在的页(一个表格每页至多一个分段)
|
|
674
|
+
let pageIndex = -1
|
|
675
|
+
for (let i = pages.length - 1; i >= 0; i--) {
|
|
676
|
+
if (
|
|
677
|
+
(pages[i] || []).some(
|
|
678
|
+
panel => panel?.type === 'table' && panel.index === fillIndex
|
|
679
|
+
)
|
|
680
|
+
) {
|
|
681
|
+
pageIndex = i
|
|
682
|
+
break
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (pageIndex < 0) return null
|
|
686
|
+
|
|
687
|
+
// 按分页同一套口径累计该页已用高度:表格下方还有内容时一并计入,
|
|
688
|
+
// 填充就只会补「表格与后续内容之间」的空隙,不会把它们挤到下一页
|
|
689
|
+
let used = heightMap.header + heightMap.footer
|
|
690
|
+
;(pages[pageIndex] || []).forEach(panel => {
|
|
691
|
+
if (panel.type === 'table') {
|
|
692
|
+
const heights = splicedHeightsMap[panel.index] || []
|
|
693
|
+
used += this.getTableAllHaveHeight(panel.index)
|
|
694
|
+
for (let r = panel.begin; r < panel.end; r++) {
|
|
695
|
+
used += heights[r] || 0
|
|
696
|
+
}
|
|
697
|
+
} else {
|
|
698
|
+
used += heightMap[`contents.panel.${panel.index}`] || 0
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
|
|
702
|
+
// 签名只渲染在最后一页,填充所在页为末页时同样要预留
|
|
703
|
+
const signReserve =
|
|
704
|
+
pageIndex === pages.length - 1 ? this.getSignHeight() : 0
|
|
705
|
+
const remain = pageHeight - used - signReserve
|
|
706
|
+
return Number.isFinite(remain) ? remain : null
|
|
707
|
+
}
|
|
708
|
+
|
|
620
709
|
getTablePageRanges(contentIndex, rows) {
|
|
621
710
|
const ranges = []
|
|
622
711
|
this.pages.forEach(page => {
|