gm-printer 10.39.4-beta.2 → 10.41.0
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_customize_config.js +0 -3
- package/src/common/editor_edit_field.js +10 -4
- package/src/common/editor_store.js +42 -242
- package/src/common/util.js +58 -4
- package/src/editor_purchase/editor_special_table.js +28 -9
- package/src/editor_purchase/store.js +7 -4
- package/src/printer/long_print_table/index.js +10 -2
- package/src/printer/printer.js +37 -34
- package/src/printer/store.js +34 -308
- package/src/printer/table.js +16 -5
- package/src/printer/table_overallOrder_tr.js +49 -37
- package/src/util.js +6 -10
- package/src/printer/multi_column.js +0 -461
package/src/printer/printer.js
CHANGED
|
@@ -11,9 +11,22 @@ import Table from './table'
|
|
|
11
11
|
import LongPrintTable from './long_print_table'
|
|
12
12
|
import MergePage from './merge_page'
|
|
13
13
|
import { LONG_PRINT } from '../config'
|
|
14
|
-
import { getDataKey } from '../util'
|
|
15
14
|
import Big from 'big.js'
|
|
16
15
|
|
|
16
|
+
/** 当前 panel 是否为该表格 content 在全部分页中的最后一次出现 */
|
|
17
|
+
const isLastTablePanel = (pages, pageIndex, panelIndexInPage, tableIndex) => {
|
|
18
|
+
for (let pi = pages.length - 1; pi >= 0; pi--) {
|
|
19
|
+
const page = pages[pi] || []
|
|
20
|
+
for (let pji = page.length - 1; pji >= 0; pji--) {
|
|
21
|
+
const p = page[pji]
|
|
22
|
+
if (p?.type === 'table' && p.index === tableIndex) {
|
|
23
|
+
return pi === pageIndex && pji === panelIndexInPage
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
17
30
|
// Header Sign Footer 相对特殊,要单独处理
|
|
18
31
|
const Header = props => (
|
|
19
32
|
<Panel {...props} name='header' placeholder={i18next.t('页眉')} />
|
|
@@ -108,8 +121,6 @@ class Printer extends React.Component {
|
|
|
108
121
|
printerStore.setReady(true)
|
|
109
122
|
// 连续打印不需要分页计算
|
|
110
123
|
if (batchPrintConfig !== 2) {
|
|
111
|
-
// 先分页拿到剩余高度,再补空行,最后按补空后的数据重新分页
|
|
112
|
-
// (若先分页后补空却不重算,panel.end 仍是补空前行数,空行/后半数据会被裁掉)
|
|
113
124
|
printerStore.computedPages()
|
|
114
125
|
if (config.autoFillConfig?.checked) {
|
|
115
126
|
this.props.printerStore.setAutofillConfig(
|
|
@@ -119,8 +130,10 @@ class Printer extends React.Component {
|
|
|
119
130
|
config.autoFillConfig?.fillIndex || false
|
|
120
131
|
)
|
|
121
132
|
printerStore.changeTableData()
|
|
122
|
-
printerStore.computedPages()
|
|
123
133
|
}
|
|
134
|
+
// 开始计算,获取各种数据
|
|
135
|
+
// 如果是自适应要先计算高度,在算出行数 不是自适应就先计算行数 在计算高度
|
|
136
|
+
// 获取剩余空白高度,传到editor
|
|
124
137
|
getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
|
|
125
138
|
}
|
|
126
139
|
|
|
@@ -148,10 +161,7 @@ class Printer extends React.Component {
|
|
|
148
161
|
switch (content.type) {
|
|
149
162
|
case 'table':
|
|
150
163
|
// eslint-disable-next-line no-case-declarations
|
|
151
|
-
const list =
|
|
152
|
-
printerStore.data._table[
|
|
153
|
-
getDataKey(content.dataKey, content.arrange)
|
|
154
|
-
] || printerStore.data._table[content.dataKey]
|
|
164
|
+
const list = printerStore.data._table[content.dataKey]
|
|
155
165
|
return (
|
|
156
166
|
<Table
|
|
157
167
|
key={`contents.table.${index}`}
|
|
@@ -238,9 +248,7 @@ class Printer extends React.Component {
|
|
|
238
248
|
|
|
239
249
|
renderPage() {
|
|
240
250
|
const { printerStore, isSomeSubtotalTr } = this.props
|
|
241
|
-
const { config, isAutoFilling } = printerStore
|
|
242
|
-
// 订阅 dataRevision,保证 _table 重排后预览会刷新
|
|
243
|
-
const dataRevision = printerStore.dataRevision
|
|
251
|
+
const { config, remainPageHeight, isAutoFilling } = printerStore
|
|
244
252
|
return (
|
|
245
253
|
<>
|
|
246
254
|
{_.map(printerStore.pages, (page, i) => {
|
|
@@ -249,40 +257,29 @@ class Printer extends React.Component {
|
|
|
249
257
|
return null
|
|
250
258
|
}
|
|
251
259
|
return (
|
|
252
|
-
<Page key={
|
|
260
|
+
<Page key={i}>
|
|
253
261
|
<Header config={config.header} pageIndex={i} />
|
|
254
262
|
{_.map(page, (panel, ii) => {
|
|
255
263
|
const content = config.contents[panel.index]
|
|
256
264
|
const autoFillConfig = config?.autoFillConfig || {}
|
|
257
|
-
const
|
|
258
|
-
content?.dataKey,
|
|
259
|
-
content?.arrange
|
|
260
|
-
)
|
|
261
|
-
const tableRows =
|
|
262
|
-
printerStore.data._table?.[resolvedDataKey] ||
|
|
263
|
-
printerStore.data._table?.[content?.dataKey] ||
|
|
264
|
-
[]
|
|
265
|
-
const isAutofillTable =
|
|
265
|
+
const isAutofillConfig =
|
|
266
266
|
isLastPage &&
|
|
267
267
|
isAutoFilling &&
|
|
268
|
-
panel.end
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
end = Math.max(panel.end || 0, tableRows.length)
|
|
278
|
-
}
|
|
279
|
-
end = Math.min(end || 0, tableRows.length)
|
|
268
|
+
panel.end &&
|
|
269
|
+
content?.dataKey === autoFillConfig?.dataKey
|
|
270
|
+
const endList = isAutofillConfig
|
|
271
|
+
? Math.floor(
|
|
272
|
+
remainPageHeight /
|
|
273
|
+
printerStore.computedTableCustomerRowHeight
|
|
274
|
+
)
|
|
275
|
+
: 0
|
|
276
|
+
const end = +Big(panel?.end || 0).add(endList)
|
|
280
277
|
|
|
281
278
|
switch (panel.type) {
|
|
282
279
|
case 'table':
|
|
283
280
|
return (
|
|
284
281
|
<Table
|
|
285
|
-
key={`contents.table.${panel.index}.${ii}
|
|
282
|
+
key={`contents.table.${panel.index}.${ii}`}
|
|
286
283
|
name={`contents.table.${panel.index}`}
|
|
287
284
|
config={content}
|
|
288
285
|
range={{
|
|
@@ -292,6 +289,12 @@ class Printer extends React.Component {
|
|
|
292
289
|
placeholder={`${i18next.t('区域')} ${panel.index}`}
|
|
293
290
|
pageIndex={i}
|
|
294
291
|
isSomeSubtotalTr={isSomeSubtotalTr}
|
|
292
|
+
isLastTablePage={isLastTablePanel(
|
|
293
|
+
printerStore.pages,
|
|
294
|
+
i,
|
|
295
|
+
ii,
|
|
296
|
+
panel.index
|
|
297
|
+
)}
|
|
295
298
|
/>
|
|
296
299
|
)
|
|
297
300
|
|
package/src/printer/store.js
CHANGED
|
@@ -3,8 +3,6 @@ import { action, observable, computed } from 'mobx'
|
|
|
3
3
|
import {
|
|
4
4
|
getSumTrHeight,
|
|
5
5
|
isMultiTable,
|
|
6
|
-
getMultiNumber,
|
|
7
|
-
getDataKey,
|
|
8
6
|
caclSingleDetailsPageHeight,
|
|
9
7
|
getArrayMid,
|
|
10
8
|
getOverallOrderTrHeight
|
|
@@ -12,20 +10,6 @@ import {
|
|
|
12
10
|
import _ from 'lodash'
|
|
13
11
|
import Big from 'big.js'
|
|
14
12
|
import { Tip } from '../components'
|
|
15
|
-
import {
|
|
16
|
-
fillEmptyRowIndex,
|
|
17
|
-
fillPartialLastRow,
|
|
18
|
-
getMaxSerial,
|
|
19
|
-
detectColNumber,
|
|
20
|
-
ensureRowSerialKeys,
|
|
21
|
-
flattenHorizontalPackedRows,
|
|
22
|
-
repackVerticalTableByPageRanges,
|
|
23
|
-
packVerticalNewspaper,
|
|
24
|
-
packHorizontalRowMajor,
|
|
25
|
-
createEmptyRows,
|
|
26
|
-
createEmptyRowSkeleton,
|
|
27
|
-
resolveVerticalEmptyCount
|
|
28
|
-
} from './multi_column'
|
|
29
13
|
|
|
30
14
|
export const TR_BASE_HEIGHT = 23
|
|
31
15
|
const price = (n, f = 2) => {
|
|
@@ -51,8 +35,6 @@ class PrinterStore {
|
|
|
51
35
|
/** 当前页剩余空白高度 */
|
|
52
36
|
@observable remainPageHeight = 0
|
|
53
37
|
@observable isSave = false
|
|
54
|
-
/** data._table 非 observable,变更后递增以驱动预览重渲 */
|
|
55
|
-
@observable dataRevision = 0
|
|
56
38
|
|
|
57
39
|
data = {}
|
|
58
40
|
|
|
@@ -222,19 +204,6 @@ class PrinterStore {
|
|
|
222
204
|
this.config = config || {}
|
|
223
205
|
}
|
|
224
206
|
|
|
225
|
-
/**
|
|
226
|
-
* 签名区高度:优先 DOM 测高,否则用配置 style.height。
|
|
227
|
-
* 打印在 iframe 内时测高常为 0,若只用 this.height.sign 会导致末页不扣签名、空行多填。
|
|
228
|
-
*/
|
|
229
|
-
getSignHeight() {
|
|
230
|
-
const measured = this.height?.sign
|
|
231
|
-
if (measured && measured > 0) return measured
|
|
232
|
-
const raw = this.config?.sign?.style?.height
|
|
233
|
-
if (raw == null || raw === '') return 0
|
|
234
|
-
const parsed = parseFloat(raw)
|
|
235
|
-
return Number.isFinite(parsed) ? parsed : 0
|
|
236
|
-
}
|
|
237
|
-
|
|
238
207
|
/** 处理采购单的明细
|
|
239
208
|
一行有多个明细, 并且采购明细是换行展示, 明细数据超多的情况则需要分割到不同页面中
|
|
240
209
|
比如: 一行有20行明细,当前页只能放下17行明细 ,剩下的3行明细需要放到下一页进行展示 */
|
|
@@ -360,13 +329,9 @@ class PrinterStore {
|
|
|
360
329
|
/** 当前page页面的最小高度 */
|
|
361
330
|
const currentPageMinimumHeight =
|
|
362
331
|
allPagesHaveThisHeight + allTableHaveThisHeight
|
|
363
|
-
// 最后一项是表格时,末页仍要渲染签名:装行可用高度预留签名,避免空行顶进签名区
|
|
364
|
-
const isLastContent = index === this.config.contents.length - 1
|
|
365
|
-
const signReserve = isLastContent ? this.getSignHeight() : 0
|
|
366
332
|
/** 当前page可容纳的table高度 */
|
|
367
333
|
let pageAccomodateTableHeight = +new Big(this.pageHeight)
|
|
368
334
|
.minus(currentPageHeight)
|
|
369
|
-
.minus(signReserve)
|
|
370
335
|
.toFixed(2)
|
|
371
336
|
const heights = this.getNormalTableBodyHeights(
|
|
372
337
|
table.body.heights,
|
|
@@ -462,11 +427,10 @@ class PrinterStore {
|
|
|
462
427
|
}
|
|
463
428
|
|
|
464
429
|
begin = end
|
|
465
|
-
//
|
|
466
|
-
pageAccomodateTableHeight = +new Big(this.pageHeight)
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
.toFixed(2)
|
|
430
|
+
// 开启新一页,重置页面高度
|
|
431
|
+
pageAccomodateTableHeight = +new Big(this.pageHeight).minus(
|
|
432
|
+
allPagesHaveThisHeight
|
|
433
|
+
)
|
|
470
434
|
currentTableHeight = allTableHaveThisHeight
|
|
471
435
|
currentPageHeight = currentPageMinimumHeight
|
|
472
436
|
} else {
|
|
@@ -497,7 +461,7 @@ class PrinterStore {
|
|
|
497
461
|
|
|
498
462
|
// 如果是最后一页,必须要加上sign的高度,否则会重叠
|
|
499
463
|
if (index === this.config.contents.length - 1) {
|
|
500
|
-
currentPageHeight += this.
|
|
464
|
+
currentPageHeight += this.height?.sign
|
|
501
465
|
}
|
|
502
466
|
|
|
503
467
|
if (currentPageHeight <= this.pageHeight) {
|
|
@@ -519,85 +483,7 @@ class PrinterStore {
|
|
|
519
483
|
}
|
|
520
484
|
}
|
|
521
485
|
this.pages.push(page)
|
|
522
|
-
|
|
523
|
-
// 末页签名:panel 分支会在「最后一项是 panel」时扣 sign;
|
|
524
|
-
// 最后一项是 table 时上面不会扣,导致 remain 偏大、空行多填溢页
|
|
525
|
-
// 打印 iframe 内 height.sign 可能为 0,必须用 getSignHeight(含配置兜底)
|
|
526
|
-
const lastContent = this.config.contents[this.config.contents.length - 1]
|
|
527
|
-
if (lastContent?.type === 'table') {
|
|
528
|
-
currentPageHeight += this.getSignHeight()
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
this.remainPageHeight = +Big(
|
|
532
|
-
Math.max(0, this.pageHeight - currentPageHeight)
|
|
533
|
-
).toFixed(0)
|
|
534
|
-
this.repackVerticalMultiByPages()
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
getTablePageRanges(contentIndex, rows) {
|
|
538
|
-
const ranges = []
|
|
539
|
-
this.pages.forEach(page => {
|
|
540
|
-
page.forEach(panel => {
|
|
541
|
-
if (panel.type === 'table' && panel.index === contentIndex) {
|
|
542
|
-
ranges.push({ begin: panel.begin, end: panel.end })
|
|
543
|
-
}
|
|
544
|
-
})
|
|
545
|
-
})
|
|
546
|
-
if (!ranges.length || !rows?.length) return ranges
|
|
547
|
-
const last = ranges[ranges.length - 1]
|
|
548
|
-
let end = last.end
|
|
549
|
-
while (end < rows.length && rows[end]?._isEmptyData) {
|
|
550
|
-
end++
|
|
551
|
-
}
|
|
552
|
-
last.end = end
|
|
553
|
-
return ranges
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
@action
|
|
557
|
-
repackVerticalMultiByPages() {
|
|
558
|
-
if (!this.pages?.length) return
|
|
559
|
-
this.config.contents.forEach((content, contentIndex) => {
|
|
560
|
-
if (content?.type !== 'table' || !isMultiTable(content.dataKey)) {
|
|
561
|
-
return
|
|
562
|
-
}
|
|
563
|
-
const dataKey = content.dataKey
|
|
564
|
-
const isVertical =
|
|
565
|
-
content.arrange === 'vertical' || /_vertical$/.test(dataKey)
|
|
566
|
-
if (!isVertical) return
|
|
567
|
-
|
|
568
|
-
const sourceKey = dataKey.replace(/_vertical$/, '')
|
|
569
|
-
const verticalKey = /_vertical$/.test(dataKey)
|
|
570
|
-
? dataKey
|
|
571
|
-
: `${sourceKey}_vertical`
|
|
572
|
-
const colNumber = getMultiNumber(sourceKey)
|
|
573
|
-
const verticalRows = this.data._table[verticalKey]
|
|
574
|
-
if (!verticalRows?.length) return
|
|
575
|
-
|
|
576
|
-
const singleKey = sourceKey.replace(/_multi3?/, '')
|
|
577
|
-
const sourceRows =
|
|
578
|
-
this.data._table[singleKey] || this.data._table[sourceKey] || []
|
|
579
|
-
const sourceColNumber = isMultiTable(singleKey)
|
|
580
|
-
? getMultiNumber(singleKey)
|
|
581
|
-
: isMultiTable(sourceKey)
|
|
582
|
-
? colNumber
|
|
583
|
-
: 1
|
|
584
|
-
const sourceItems = flattenHorizontalPackedRows(
|
|
585
|
-
sourceRows,
|
|
586
|
-
sourceColNumber
|
|
587
|
-
)
|
|
588
|
-
// 无商品时仍可能需要给空行按列编序号
|
|
589
|
-
if (!sourceItems.length && !this.fillIndex) return
|
|
590
|
-
|
|
591
|
-
const pageRanges = this.getTablePageRanges(contentIndex, verticalRows)
|
|
592
|
-
this.data._table[verticalKey] = repackVerticalTableByPageRanges(
|
|
593
|
-
verticalRows,
|
|
594
|
-
colNumber,
|
|
595
|
-
pageRanges,
|
|
596
|
-
this.fillIndex,
|
|
597
|
-
sourceItems
|
|
598
|
-
)
|
|
599
|
-
this.dataRevision += 1
|
|
600
|
-
})
|
|
486
|
+
this.remainPageHeight = +Big(this.pageHeight - currentPageHeight).toFixed(0)
|
|
601
487
|
}
|
|
602
488
|
|
|
603
489
|
@action
|
|
@@ -707,7 +593,7 @@ class PrinterStore {
|
|
|
707
593
|
}
|
|
708
594
|
|
|
709
595
|
templateTable(text, dataKey, index, pageIndex) {
|
|
710
|
-
//
|
|
596
|
+
// 做好保护,出错就返回 text
|
|
711
597
|
try {
|
|
712
598
|
let list = this.data._table[dataKey] || this.data._table.orders
|
|
713
599
|
|
|
@@ -716,39 +602,18 @@ class PrinterStore {
|
|
|
716
602
|
list = _.uniqBy(list, '序号')
|
|
717
603
|
}
|
|
718
604
|
|
|
719
|
-
const colNumber = detectColNumber(dataKey, list)
|
|
720
|
-
const sample = (list || []).find(item => item && !item._isEmptyData)
|
|
721
|
-
let row = list?.[index]
|
|
722
|
-
// 渲染 end 偶发超过数据长度时,用空行骨架兜底,避免 列=undefined 抛错露出 {{列.xxx_MULTI_SUFFIX}}
|
|
723
|
-
if (!row) {
|
|
724
|
-
if (!this.isAutoFilling) return ''
|
|
725
|
-
list = (list || []).slice()
|
|
726
|
-
while (list.length <= index) {
|
|
727
|
-
list.push(createEmptyRowSkeleton(sample, colNumber))
|
|
728
|
-
}
|
|
729
|
-
row = list[index]
|
|
730
|
-
}
|
|
731
|
-
row =
|
|
732
|
-
ensureRowSerialKeys(
|
|
733
|
-
list,
|
|
734
|
-
index,
|
|
735
|
-
colNumber,
|
|
736
|
-
this.fillIndex,
|
|
737
|
-
dataKey
|
|
738
|
-
) || row
|
|
739
|
-
|
|
740
605
|
return _.template(text, {
|
|
741
606
|
interpolate: /{{([\s\S]+?)}}/g
|
|
742
607
|
})({
|
|
743
608
|
...this.data.common,
|
|
744
609
|
|
|
745
|
-
[i18next.t('列')]:
|
|
610
|
+
[i18next.t('列')]: list[index],
|
|
746
611
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
747
612
|
[i18next.t('页码总数')]: Math.max(1, this.pages.length),
|
|
748
613
|
price: price // 提供一个价格处理函数
|
|
749
614
|
})
|
|
750
615
|
} catch (err) {
|
|
751
|
-
return
|
|
616
|
+
return text
|
|
752
617
|
}
|
|
753
618
|
}
|
|
754
619
|
|
|
@@ -818,180 +683,41 @@ class PrinterStore {
|
|
|
818
683
|
const tr_count = Math.floor(
|
|
819
684
|
this.remainPageHeight / this.computedTableCustomerRowHeight
|
|
820
685
|
)
|
|
821
|
-
if (tr_count <= 0) return []
|
|
822
686
|
|
|
823
|
-
const
|
|
824
|
-
|
|
825
|
-
this.tableConfig?.dataKey || autoFillConfig?.dataKey,
|
|
826
|
-
tableData
|
|
827
|
-
)
|
|
828
|
-
return createEmptyRows(tr_count, sample, colNumber)
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
/** 空行高度只由 getNormalTableBodyHeights 虚拟追加,禁止写入 body.heights(会双计溢页) */
|
|
832
|
-
@action
|
|
833
|
-
trimTableBodyHeightsToRealRows(dataKey) {
|
|
834
|
-
if (!dataKey || !this.tablesInfo) return
|
|
835
|
-
this.config.contents.forEach((content, index) => {
|
|
836
|
-
if (content?.type !== 'table') return
|
|
837
|
-
const resolved = getDataKey(content.dataKey, content.arrange)
|
|
838
|
-
if (resolved !== dataKey && content.dataKey !== dataKey) return
|
|
839
|
-
|
|
840
|
-
const name = `contents.table.${index}`
|
|
841
|
-
const info = this.tablesInfo[name]
|
|
842
|
-
if (!info?.body?.heights) return
|
|
843
|
-
|
|
844
|
-
const rows =
|
|
845
|
-
this.data._table[resolved] || this.data._table[dataKey] || []
|
|
846
|
-
const realCount = rows.filter(row => row && !row._isEmptyData).length
|
|
847
|
-
if (info.body.heights.length > realCount) {
|
|
848
|
-
info.body.heights = info.body.heights.slice(0, realCount)
|
|
849
|
-
}
|
|
850
|
-
})
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
/** 多栏表缺失时(如双栏切三栏),从单栏/低栏源表现场打包 */
|
|
854
|
-
ensureMultiTableData(dataKey) {
|
|
855
|
-
const existing = this.data._table[dataKey]
|
|
856
|
-
if (existing?.length) return existing
|
|
857
|
-
if (!isMultiTable(dataKey)) return existing || null
|
|
858
|
-
|
|
859
|
-
const isVertical = /_vertical$/.test(dataKey)
|
|
860
|
-
const sourceKey = dataKey.replace(/_vertical$/, '')
|
|
861
|
-
const colNumber = getMultiNumber(sourceKey)
|
|
862
|
-
const singleKey = sourceKey.replace(/_multi3?/, '')
|
|
863
|
-
|
|
864
|
-
let sourceRows = this.data._table[singleKey]
|
|
865
|
-
let sourceColNumber = 1
|
|
866
|
-
if (!sourceRows?.length && /multi3/.test(sourceKey)) {
|
|
867
|
-
const dualKey = sourceKey.replace('multi3', 'multi')
|
|
868
|
-
sourceRows = this.data._table[dualKey]
|
|
869
|
-
sourceColNumber = 2
|
|
870
|
-
}
|
|
871
|
-
if (!sourceRows?.length) {
|
|
872
|
-
sourceRows = this.data._table[sourceKey]
|
|
873
|
-
sourceColNumber = isMultiTable(sourceKey) ? colNumber : 1
|
|
874
|
-
}
|
|
875
|
-
if (!sourceRows?.length) {
|
|
876
|
-
this.data._table[dataKey] = []
|
|
877
|
-
return []
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
const sourceItems = flattenHorizontalPackedRows(
|
|
881
|
-
sourceRows,
|
|
882
|
-
sourceColNumber
|
|
883
|
-
)
|
|
884
|
-
const baseRowCount = sourceItems.length
|
|
885
|
-
? Math.max(1, Math.ceil(sourceItems.length / colNumber))
|
|
886
|
-
: 0
|
|
887
|
-
const packed = !baseRowCount
|
|
888
|
-
? []
|
|
889
|
-
: isVertical
|
|
890
|
-
? packVerticalNewspaper(sourceItems, colNumber, baseRowCount, false)
|
|
891
|
-
: packHorizontalRowMajor(sourceItems, colNumber)
|
|
892
|
-
this.data._table[dataKey] = packed
|
|
893
|
-
return packed
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
fillTableEmptyIndex(dataKey) {
|
|
897
|
-
let tableData = this.data._table[dataKey]
|
|
898
|
-
if (!tableData && isMultiTable(dataKey)) {
|
|
899
|
-
tableData = this.ensureMultiTableData(dataKey)
|
|
900
|
-
}
|
|
901
|
-
if (!tableData) return
|
|
902
|
-
const emptyTable = tableData.filter(item => item._isEmptyData)
|
|
903
|
-
const table = tableData.filter(item => !item._isEmptyData)
|
|
904
|
-
const toFillEmptyCount =
|
|
905
|
-
emptyTable.length === 0 ? this.getFilledTableData(table).length : 0
|
|
906
|
-
const emptyCount =
|
|
907
|
-
emptyTable.length > 0 ? emptyTable.length : toFillEmptyCount
|
|
908
|
-
|
|
909
|
-
// 纵向多栏:源商品按对半行落位 + 追加空行;左列优先由 repack 按「数据行+空行」整段完成
|
|
910
|
-
if (/_vertical$/.test(dataKey)) {
|
|
911
|
-
const sourceKey = dataKey.replace(/_vertical$/, '')
|
|
912
|
-
const singleKey = sourceKey.replace(/_multi3?/, '')
|
|
913
|
-
const colNumber = getMultiNumber(sourceKey)
|
|
914
|
-
// 横向源表缺失时先生成(双栏→三栏常见)
|
|
915
|
-
if (!this.data._table[sourceKey]?.length) {
|
|
916
|
-
this.ensureMultiTableData(sourceKey)
|
|
917
|
-
}
|
|
918
|
-
const sourceRows =
|
|
919
|
-
this.data._table[singleKey] || this.data._table[sourceKey] || []
|
|
920
|
-
const sourceColNumber = isMultiTable(singleKey)
|
|
921
|
-
? getMultiNumber(singleKey)
|
|
922
|
-
: isMultiTable(sourceKey)
|
|
923
|
-
? colNumber
|
|
924
|
-
: 1
|
|
925
|
-
const sourceItems = flattenHorizontalPackedRows(
|
|
926
|
-
sourceRows,
|
|
927
|
-
sourceColNumber
|
|
928
|
-
)
|
|
929
|
-
const baseRowCount = sourceItems.length
|
|
930
|
-
? Math.max(1, Math.ceil(sourceItems.length / colNumber))
|
|
931
|
-
: 0
|
|
932
|
-
// 钉死总行:left-first repack 后 _isEmptyData 变少,不能用 emptyTable.length 回推
|
|
933
|
-
const emptyCount = resolveVerticalEmptyCount(
|
|
934
|
-
tableData.length,
|
|
935
|
-
baseRowCount,
|
|
936
|
-
emptyTable.length > 0
|
|
937
|
-
? emptyTable.length
|
|
938
|
-
: this.getFilledTableData(table).length,
|
|
939
|
-
emptyTable.length > 0
|
|
940
|
-
)
|
|
941
|
-
const dataRows = baseRowCount
|
|
942
|
-
? packVerticalNewspaper(sourceItems, colNumber, baseRowCount, false)
|
|
943
|
-
: []
|
|
944
|
-
const sample = dataRows[0] || sourceRows[0]
|
|
945
|
-
const emptyRows = createEmptyRows(emptyCount, sample, colNumber)
|
|
946
|
-
this.data._table[dataKey] = dataRows.concat(emptyRows)
|
|
947
|
-
return
|
|
687
|
+
const filledData = {
|
|
688
|
+
_isEmptyData: true // 表示是填充的空白数据
|
|
948
689
|
}
|
|
690
|
+
_.map(tableData[0], (val, key) => {
|
|
691
|
+
filledData[key] = ''
|
|
692
|
+
})
|
|
693
|
+
console.log(tr_count, 'tr_count')
|
|
949
694
|
|
|
950
|
-
|
|
951
|
-
const templates =
|
|
952
|
-
emptyCount === 0
|
|
953
|
-
? []
|
|
954
|
-
: emptyTable.length > 0
|
|
955
|
-
? emptyTable
|
|
956
|
-
: this.getFilledTableData(table)
|
|
957
|
-
const withPartial = fillPartialLastRow(table, colNumber, this.fillIndex)
|
|
958
|
-
const lastKey = getMaxSerial(withPartial, colNumber) + 1
|
|
959
|
-
const sample = table[0]
|
|
960
|
-
const fillList = templates.map((item, index) =>
|
|
961
|
-
fillEmptyRowIndex(
|
|
962
|
-
{
|
|
963
|
-
...createEmptyRowSkeleton(sample, colNumber),
|
|
964
|
-
...item,
|
|
965
|
-
_isEmptyData: true
|
|
966
|
-
},
|
|
967
|
-
index,
|
|
968
|
-
lastKey,
|
|
969
|
-
colNumber,
|
|
970
|
-
this.fillIndex
|
|
971
|
-
)
|
|
972
|
-
)
|
|
973
|
-
withPartial.push(...fillList)
|
|
974
|
-
this.data._table[dataKey] = withPartial
|
|
695
|
+
return Array(tr_count).fill(filledData)
|
|
975
696
|
}
|
|
976
697
|
|
|
977
698
|
@action.bound
|
|
978
699
|
changeTableData() {
|
|
979
700
|
const { autoFillConfig } = this.config
|
|
980
701
|
if (!this.isAutoFilling) return
|
|
981
|
-
const dataKey =
|
|
982
|
-
|
|
983
|
-
this.
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
702
|
+
const dataKey = autoFillConfig?.dataKey
|
|
703
|
+
const table = this.data._table[dataKey]?.filter(item => !item._isEmptyData)
|
|
704
|
+
const emptyTable = this.data._table[dataKey]?.filter(
|
|
705
|
+
item => item._isEmptyData
|
|
706
|
+
)
|
|
707
|
+
const lastKey = _.findLast(table, item => item?.序号)?.序号 + 1
|
|
708
|
+
const fillList = _.map(
|
|
709
|
+
emptyTable?.length === 0 ? this.getFilledTableData(table) : emptyTable,
|
|
710
|
+
(item, index) => {
|
|
711
|
+
if (this.fillIndex) {
|
|
712
|
+
return { ...item, 序号: index + lastKey }
|
|
713
|
+
} else {
|
|
714
|
+
return { ...item, 序号: '' }
|
|
715
|
+
}
|
|
990
716
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
this.
|
|
717
|
+
)
|
|
718
|
+
console.log(fillList, 'fillList')
|
|
719
|
+
table.push(...fillList)
|
|
720
|
+
this.data._table[dataKey] = table
|
|
995
721
|
}
|
|
996
722
|
}
|
|
997
723
|
|
package/src/printer/table.js
CHANGED
|
@@ -169,7 +169,8 @@ class Table extends React.Component {
|
|
|
169
169
|
range,
|
|
170
170
|
pageIndex,
|
|
171
171
|
printerStore,
|
|
172
|
-
isSomeSubtotalTr
|
|
172
|
+
isSomeSubtotalTr,
|
|
173
|
+
isLastTablePage
|
|
173
174
|
} = this.props
|
|
174
175
|
// 数据
|
|
175
176
|
dataKey = getDataKey(dataKey, arrange)
|
|
@@ -359,11 +360,15 @@ class Table extends React.Component {
|
|
|
359
360
|
}
|
|
360
361
|
|
|
361
362
|
// 如果项为空对象展现一个占满一行的td
|
|
362
|
-
const isItemNone = !_.keys(tableData[i]
|
|
363
|
+
const isItemNone = !_.keys(tableData[i]).length
|
|
363
364
|
return (
|
|
364
365
|
<tr style={{ height: `${customerRowHeight}px` }} key={i}>
|
|
365
|
-
{isItemNone
|
|
366
|
-
|
|
366
|
+
{isItemNone ? (
|
|
367
|
+
!printerStore?.isAutoFilling ? (
|
|
368
|
+
<td colSpan='99' />
|
|
369
|
+
) : (
|
|
370
|
+
<></>
|
|
371
|
+
)
|
|
367
372
|
) : (
|
|
368
373
|
_.map(columns, (col, j) => {
|
|
369
374
|
const rowSpan = printerStore.templateTableRowSpan(
|
|
@@ -441,6 +446,7 @@ class Table extends React.Component {
|
|
|
441
446
|
range={range}
|
|
442
447
|
config={config}
|
|
443
448
|
printerStore={printerStore}
|
|
449
|
+
isLastTablePage={isLastTablePage}
|
|
444
450
|
/>
|
|
445
451
|
<DiyOverallOrder
|
|
446
452
|
range={range}
|
|
@@ -499,7 +505,12 @@ Table.propTypes = {
|
|
|
499
505
|
pageIndex: PropTypes.number.isRequired,
|
|
500
506
|
placeholder: PropTypes.string,
|
|
501
507
|
printerStore: PropTypes.object,
|
|
502
|
-
isSomeSubtotalTr: PropTypes.bool
|
|
508
|
+
isSomeSubtotalTr: PropTypes.bool,
|
|
509
|
+
isLastTablePage: PropTypes.bool
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
Table.defaultProps = {
|
|
513
|
+
isLastTablePage: true
|
|
503
514
|
}
|
|
504
515
|
|
|
505
516
|
export default Table
|