gm-printer 10.42.2 → 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/locales/en.json +3 -0
- package/locales/th.json +3 -0
- package/locales/zh-HK.json +3 -0
- package/package.json +1 -1
- package/src/common/common_context_menu.js +6 -4
- package/src/common/component.js +64 -8
- package/src/common/editor_edit_field.js +6 -1
- package/src/common/editor_store.js +34 -32
- package/src/common/hoc_with_store.js +9 -0
- package/src/common/style.lesss +43 -0
- package/src/editor/store.js +13 -0
- package/src/finance_voucher/components/table_subtotal_tr.js +12 -18
- package/src/index.js +2 -0
- package/src/printer/block.js +154 -4
- package/src/printer/compute_pages.js +2 -1
- package/src/printer/multi_column.js +53 -0
- package/src/printer/page_summary.js +3 -1
- package/src/printer/printer.js +8 -1
- package/src/printer/store.js +136 -39
- package/src/printer/table_diy_overallOrder_tr.js +8 -15
- package/src/printer/table_diy_summary_tr.js +18 -35
- package/src/printer/table_subtotal_tr.js +13 -16
- package/src/util.js +20 -1
- package/yarn-error.log +372 -152
package/src/printer/block.js
CHANGED
|
@@ -8,7 +8,12 @@ import BarCode from './barcode'
|
|
|
8
8
|
import QrCode from './qrcode'
|
|
9
9
|
import Tag from './tag'
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// editStore 用函数形式注入:打印态(do_print 的 iframe)没有 editStore Provider,
|
|
12
|
+
// 字符串形式的 inject 会直接抛错,这里降级为 null 关闭编辑能力
|
|
13
|
+
@inject(({ printerStore, editStore }) => ({
|
|
14
|
+
printerStore,
|
|
15
|
+
editStore: editStore || null
|
|
16
|
+
}))
|
|
12
17
|
@observer
|
|
13
18
|
class Block extends React.Component {
|
|
14
19
|
constructor(props) {
|
|
@@ -16,8 +21,10 @@ class Block extends React.Component {
|
|
|
16
21
|
this.state = {
|
|
17
22
|
clientX: null,
|
|
18
23
|
clientY: null,
|
|
19
|
-
isEdit: false
|
|
24
|
+
isEdit: false,
|
|
25
|
+
isResizing: false
|
|
20
26
|
}
|
|
27
|
+
this.resizeState = null
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
componentDidMount() {
|
|
@@ -32,6 +39,7 @@ class Block extends React.Component {
|
|
|
32
39
|
'gm-printer-block-edit',
|
|
33
40
|
this.handleBlockEdit
|
|
34
41
|
)
|
|
42
|
+
this.teardownResize()
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
handleBlockEdit = e => {
|
|
@@ -112,6 +120,118 @@ class Block extends React.Component {
|
|
|
112
120
|
})
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
// 电子签章:图片四角等比例拖拽缩放
|
|
124
|
+
handleResizeStart = (direction, e) => {
|
|
125
|
+
// 阻止触发块的选中/拖动
|
|
126
|
+
e.stopPropagation()
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
|
|
129
|
+
const {
|
|
130
|
+
config: { style, ratio }
|
|
131
|
+
} = this.props
|
|
132
|
+
|
|
133
|
+
const initW = parseFloat(style.width) || 0
|
|
134
|
+
const initH = parseFloat(style.height) || 0
|
|
135
|
+
// 旧模板无 ratio 时按当前显示宽高锁定;宽或高缺失(存量块无 width)时退回 1,
|
|
136
|
+
// 避免比例算出 0 导致高度 Infinity
|
|
137
|
+
const fallbackRatio = initW > 0 && initH > 0 ? initW / initH : 1
|
|
138
|
+
this.resizeState = {
|
|
139
|
+
direction,
|
|
140
|
+
startX: e.clientX,
|
|
141
|
+
startY: e.clientY,
|
|
142
|
+
initW,
|
|
143
|
+
initH,
|
|
144
|
+
initL: parseFloat(style.left) || 0,
|
|
145
|
+
initT: parseFloat(style.top) || 0,
|
|
146
|
+
// ratio = 原始宽/高
|
|
147
|
+
ratio: ratio || fallbackRatio,
|
|
148
|
+
baseStyle: style
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.setState({
|
|
152
|
+
isResizing: true
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
window.addEventListener('mousemove', this.handleResizeMove)
|
|
156
|
+
window.addEventListener('mouseup', this.handleResizeEnd)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
handleResizeMove = e => {
|
|
160
|
+
if (!this.resizeState) return
|
|
161
|
+
|
|
162
|
+
// rAF 节流,避免高频 mousemove 打爆渲染
|
|
163
|
+
if (this.resizePending) return
|
|
164
|
+
this.resizePending = e
|
|
165
|
+
window.requestAnimationFrame(() => {
|
|
166
|
+
const evt = this.resizePending
|
|
167
|
+
this.resizePending = null
|
|
168
|
+
if (!evt || !this.resizeState) return
|
|
169
|
+
this.doResize(evt)
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
doResize = e => {
|
|
174
|
+
const {
|
|
175
|
+
direction,
|
|
176
|
+
startX,
|
|
177
|
+
initW,
|
|
178
|
+
initH,
|
|
179
|
+
initL,
|
|
180
|
+
initT,
|
|
181
|
+
ratio,
|
|
182
|
+
baseStyle
|
|
183
|
+
} = this.resizeState
|
|
184
|
+
const dx = e.clientX - startX
|
|
185
|
+
|
|
186
|
+
// 右侧角向右放大,左侧角向左放大
|
|
187
|
+
let width =
|
|
188
|
+
direction === 'rb' || direction === 'rt' ? initW + dx : initW - dx
|
|
189
|
+
// 最小尺寸兜底,防止翻转
|
|
190
|
+
width = Math.max(width, 10)
|
|
191
|
+
const height = Math.round(width / ratio)
|
|
192
|
+
width = Math.round(width)
|
|
193
|
+
|
|
194
|
+
// 锚定对角:左向角拖拽时右/下边不动,上向角拖拽时下边不动
|
|
195
|
+
let left = initL
|
|
196
|
+
let top = initT
|
|
197
|
+
if (direction === 'lb' || direction === 'lt') {
|
|
198
|
+
left = initL + initW - width
|
|
199
|
+
}
|
|
200
|
+
if (direction === 'rt' || direction === 'lt') {
|
|
201
|
+
top = initT + initH - height
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
dispatchMsg('gm-printer-block-style-set', {
|
|
205
|
+
style: {
|
|
206
|
+
...baseStyle,
|
|
207
|
+
width: width + 'px',
|
|
208
|
+
height: height + 'px',
|
|
209
|
+
left: left + 'px',
|
|
210
|
+
top: top + 'px'
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
handleResizeEnd = () => {
|
|
216
|
+
// 先 flush 掉节流里排队中的最后一帧,避免松手回退
|
|
217
|
+
if (this.resizePending) {
|
|
218
|
+
const evt = this.resizePending
|
|
219
|
+
this.resizePending = null
|
|
220
|
+
this.doResize(evt)
|
|
221
|
+
}
|
|
222
|
+
this.teardownResize()
|
|
223
|
+
this.setState({
|
|
224
|
+
isResizing: false
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
teardownResize = () => {
|
|
229
|
+
window.removeEventListener('mousemove', this.handleResizeMove)
|
|
230
|
+
window.removeEventListener('mouseup', this.handleResizeEnd)
|
|
231
|
+
this.resizeState = null
|
|
232
|
+
this.resizePending = null
|
|
233
|
+
}
|
|
234
|
+
|
|
115
235
|
render() {
|
|
116
236
|
let {
|
|
117
237
|
name,
|
|
@@ -119,6 +239,7 @@ class Block extends React.Component {
|
|
|
119
239
|
pageIndex,
|
|
120
240
|
className,
|
|
121
241
|
printerStore,
|
|
242
|
+
editStore,
|
|
122
243
|
...rest
|
|
123
244
|
} = this.props
|
|
124
245
|
const { isEdit } = this.state
|
|
@@ -186,6 +307,14 @@ class Block extends React.Component {
|
|
|
186
307
|
}
|
|
187
308
|
|
|
188
309
|
const active = name === printerStore.selected
|
|
310
|
+
const { isResizing } = this.state
|
|
311
|
+
const showResizeHandles = !!(
|
|
312
|
+
active &&
|
|
313
|
+
type === 'image' &&
|
|
314
|
+
editStore &&
|
|
315
|
+
editStore.imageConfig &&
|
|
316
|
+
editStore.imageConfig.resizable
|
|
317
|
+
)
|
|
189
318
|
|
|
190
319
|
return (
|
|
191
320
|
<div
|
|
@@ -193,7 +322,7 @@ class Block extends React.Component {
|
|
|
193
322
|
className={classNames('gm-printer-block', className, {
|
|
194
323
|
active
|
|
195
324
|
})}
|
|
196
|
-
draggable
|
|
325
|
+
draggable={!isResizing}
|
|
197
326
|
onDragStart={this.handleDragStart}
|
|
198
327
|
onDragEnd={this.handleDragEnd}
|
|
199
328
|
onClick={this.handleClick}
|
|
@@ -221,6 +350,26 @@ class Block extends React.Component {
|
|
|
221
350
|
/>
|
|
222
351
|
)}
|
|
223
352
|
{content}
|
|
353
|
+
{showResizeHandles && (
|
|
354
|
+
<>
|
|
355
|
+
<div
|
|
356
|
+
className='gm-printer-resize-handle gm-printer-resize-lt'
|
|
357
|
+
onMouseDown={this.handleResizeStart.bind(this, 'lt')}
|
|
358
|
+
/>
|
|
359
|
+
<div
|
|
360
|
+
className='gm-printer-resize-handle gm-printer-resize-rt'
|
|
361
|
+
onMouseDown={this.handleResizeStart.bind(this, 'rt')}
|
|
362
|
+
/>
|
|
363
|
+
<div
|
|
364
|
+
className='gm-printer-resize-handle gm-printer-resize-lb'
|
|
365
|
+
onMouseDown={this.handleResizeStart.bind(this, 'lb')}
|
|
366
|
+
/>
|
|
367
|
+
<div
|
|
368
|
+
className='gm-printer-resize-handle gm-printer-resize-rb'
|
|
369
|
+
onMouseDown={this.handleResizeStart.bind(this, 'rb')}
|
|
370
|
+
/>
|
|
371
|
+
</>
|
|
372
|
+
)}
|
|
224
373
|
</div>
|
|
225
374
|
)
|
|
226
375
|
}
|
|
@@ -231,7 +380,8 @@ Block.propTypes = {
|
|
|
231
380
|
config: PropTypes.object.isRequired,
|
|
232
381
|
pageIndex: PropTypes.number.isRequired,
|
|
233
382
|
className: PropTypes.string,
|
|
234
|
-
printerStore: PropTypes.object
|
|
383
|
+
printerStore: PropTypes.object,
|
|
384
|
+
editStore: PropTypes.object
|
|
235
385
|
}
|
|
236
386
|
|
|
237
387
|
export default Block
|
|
@@ -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 }) {
|
|
@@ -5,6 +5,7 @@ export const INDEX_KEY = '序号'
|
|
|
5
5
|
|
|
6
6
|
const SPECIAL_ROW_KEYS = [
|
|
7
7
|
'_special',
|
|
8
|
+
'_specialText', // 分类标题行(三级分类/商品分类的品类名行),漏掉会在多栏重排时被当普通行丢弃
|
|
8
9
|
'_diyCategorySubtotal',
|
|
9
10
|
'_diyTagSubtotal',
|
|
10
11
|
'_customTr'
|
|
@@ -345,6 +346,58 @@ export const ensureRowSerialKeys = (
|
|
|
345
346
|
return next
|
|
346
347
|
}
|
|
347
348
|
|
|
349
|
+
/**
|
|
350
|
+
* 统一收敛多栏序号,修复「半行续号」与「空行起始序号」两处独立计算导致的序号重复
|
|
351
|
+
* (如 5 条数据双栏:第三行第二列续号为 6,第四行空行起始又编出 6)。
|
|
352
|
+
* - 先给最后一个实数据行的右侧空格续号并写回(渲染侧 ensureRowSerialKeys 不再另行补号)
|
|
353
|
+
* - 空行序号以「全表已用最大序号 + 1」连续重编,与半行续号同源
|
|
354
|
+
* 幂等,重复执行结果不变;仅 fillIndex 开启时生效
|
|
355
|
+
*/
|
|
356
|
+
export const normalizeMultiSerials = (rows, colNumber, fillIndex) => {
|
|
357
|
+
if (!fillIndex || !rows?.length || colNumber < 1) return rows
|
|
358
|
+
const keys = getSerialKeys(colNumber)
|
|
359
|
+
const isFill = row => row && !row._isEmptyData && !isSpecialTableRow(row)
|
|
360
|
+
|
|
361
|
+
const result = rows.slice()
|
|
362
|
+
|
|
363
|
+
// 实数据行已用最大序号
|
|
364
|
+
let max = 0
|
|
365
|
+
result.forEach(row => {
|
|
366
|
+
if (!isFill(row)) return
|
|
367
|
+
keys.forEach(key => {
|
|
368
|
+
const n = toSerialNumber(row?.[key])
|
|
369
|
+
if (n != null && n > max) max = n
|
|
370
|
+
})
|
|
371
|
+
})
|
|
372
|
+
|
|
373
|
+
// 1. 最后一个实数据行的空格续号(写回数据,保证序号只有一处来源)
|
|
374
|
+
for (let i = result.length - 1; i >= 0; i--) {
|
|
375
|
+
if (!isFill(result[i])) continue
|
|
376
|
+
const next = { ...result[i] }
|
|
377
|
+
keys.forEach(key => {
|
|
378
|
+
if (!isFilledIndexValue(next[key])) {
|
|
379
|
+
max += 1
|
|
380
|
+
next[key] = max
|
|
381
|
+
}
|
|
382
|
+
})
|
|
383
|
+
result[i] = next
|
|
384
|
+
break
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 2. 空行从 max+1 连续重编,不会与实数据序号/半行续号撞号
|
|
388
|
+
result.forEach((row, i) => {
|
|
389
|
+
if (!row?._isEmptyData || isSpecialTableRow(row)) return
|
|
390
|
+
const next = { ...row }
|
|
391
|
+
keys.forEach(key => {
|
|
392
|
+
max += 1
|
|
393
|
+
next[key] = max
|
|
394
|
+
})
|
|
395
|
+
result[i] = next
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
return result
|
|
399
|
+
}
|
|
400
|
+
|
|
348
401
|
/** 最后一行右侧空单元格续编序号 */
|
|
349
402
|
export const fillPartialLastRow = (rows, colNumber, fillIndex) => {
|
|
350
403
|
if (!fillIndex || !rows?.length || colNumber <= 1) return rows
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import _ from 'lodash'
|
|
3
|
-
import { getDataKey, isMultiTable } from '../util'
|
|
3
|
+
import { getDataKey, isMultiTable, isMaskedValue, MASKED_VALUE } from '../util'
|
|
4
4
|
import Big from 'big.js'
|
|
5
5
|
import { observer } from 'mobx-react'
|
|
6
6
|
import { get } from 'mobx'
|
|
@@ -19,6 +19,8 @@ const regExp = text => {
|
|
|
19
19
|
* @returns {*|string}
|
|
20
20
|
*/
|
|
21
21
|
const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
|
|
22
|
+
// 任一值脱敏 '***' 则合计显 '***'(原逻辑 Big('***') 抛异常被 catch,合计显空串)
|
|
23
|
+
if (dataList.some(item => isMaskedValue(item[key]))) return MASKED_VALUE
|
|
22
24
|
let result
|
|
23
25
|
try {
|
|
24
26
|
result = dataList
|
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
|
}
|
|
@@ -132,7 +139,7 @@ class Printer extends React.Component {
|
|
|
132
139
|
printerStore.changeTableData()
|
|
133
140
|
printerStore.computedPages()
|
|
134
141
|
}
|
|
135
|
-
// 获取剩余空白高度,传到editor
|
|
142
|
+
// 获取剩余空白高度,传到 editor
|
|
136
143
|
getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
|
|
137
144
|
}
|
|
138
145
|
printerStore.setReady(true)
|
package/src/printer/store.js
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
getDataKey,
|
|
8
8
|
caclSingleDetailsPageHeight,
|
|
9
9
|
getArrayMid,
|
|
10
|
-
getOverallOrderTrHeight
|
|
10
|
+
getOverallOrderTrHeight,
|
|
11
|
+
isMaskedValue
|
|
11
12
|
} from '../util'
|
|
12
13
|
import {
|
|
13
14
|
isDetailOneRowSelectKey,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
detectColNumber,
|
|
24
25
|
ensureRowSerialKeys,
|
|
25
26
|
flattenHorizontalPackedRows,
|
|
27
|
+
normalizeMultiSerials,
|
|
26
28
|
repackVerticalTableByPageRanges,
|
|
27
29
|
packVerticalNewspaper,
|
|
28
30
|
packHorizontalRowMajor,
|
|
@@ -45,6 +47,8 @@ const canSplitRowDetails = (dataKey, row) => {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
const price = (n, f = 2) => {
|
|
50
|
+
// 脱敏值 '***' 原样返回(不能走 isNaN 判空,空单元格仍需显空)
|
|
51
|
+
if (isMaskedValue(n)) return n
|
|
48
52
|
if (isNaN(n)) return null
|
|
49
53
|
return Big(n || 0).toFixed(f)
|
|
50
54
|
}
|
|
@@ -64,7 +68,7 @@ class PrinterStore {
|
|
|
64
68
|
|
|
65
69
|
@observable pages = [] // [{type, index, begin, end}]
|
|
66
70
|
|
|
67
|
-
/**
|
|
71
|
+
/** 行数填充基准:填充表格最后一段所在页的剩余空白高度;无填充表格时为末页剩余 */
|
|
68
72
|
@observable remainPageHeight = 0
|
|
69
73
|
@observable isSave = false
|
|
70
74
|
/** data._table 非 observable,变更后递增以驱动预览重渲 */
|
|
@@ -323,6 +327,8 @@ class PrinterStore {
|
|
|
323
327
|
|
|
324
328
|
// 使用本地数组累积分页结果,避免循环中反复触发 observable 更新
|
|
325
329
|
const pages = []
|
|
330
|
+
// 各表格的行高数组(含明细拆分 splice 后的结果),供行数填充基准按同一口径复算
|
|
331
|
+
const splicedHeightsMap = {}
|
|
326
332
|
// 每页必有 页眉header, 页脚footer , 签名
|
|
327
333
|
const allPagesHaveThisHeight = heightMap.header + heightMap.footer
|
|
328
334
|
// 退出计算! 因为页眉 + 页脚 > currentPageHeight,页面装不下其他东西
|
|
@@ -358,43 +364,15 @@ class PrinterStore {
|
|
|
358
364
|
index++
|
|
359
365
|
continue
|
|
360
366
|
}
|
|
361
|
-
const {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
summaryConfig,
|
|
365
|
-
overallOrder,
|
|
366
|
-
diySubtotal
|
|
367
|
-
} = content
|
|
368
|
-
// 如果显示每页合计,那么table高度多预留一行高度
|
|
369
|
-
const subtotalTrHeight = subtotal.show ? getSumTrHeight(subtotal) : 0
|
|
370
|
-
// 如果显示整单合计,那么table高度多预留一行高度
|
|
371
|
-
const overallOrderTrHeight = overallOrder?.show
|
|
372
|
-
? getOverallOrderTrHeight(overallOrder)
|
|
373
|
-
: 0
|
|
374
|
-
// 如果每页合计(新的),那么table高度多预留一行高度
|
|
375
|
-
const pageSummaryTrHeight =
|
|
376
|
-
summaryConfig?.pageSummaryShow && !isMultiTable(dataKey) // 双栏table没有每页合计
|
|
377
|
-
? getSumTrHeight(summaryConfig)
|
|
378
|
-
: 0
|
|
379
|
-
|
|
380
|
-
// 如果显示自定义每页合计,那么table高度多预留一行高度
|
|
381
|
-
const diySubtotalTrHeight = diySubtotal?.show
|
|
382
|
-
? getOverallOrderTrHeight(diySubtotal) // 使用相同的计算方式
|
|
383
|
-
: 0
|
|
384
|
-
|
|
385
|
-
// 每个表格都具有的高度
|
|
386
|
-
const allTableHaveThisHeight =
|
|
387
|
-
table.head.height +
|
|
388
|
-
subtotalTrHeight +
|
|
389
|
-
pageSummaryTrHeight +
|
|
390
|
-
overallOrderTrHeight +
|
|
391
|
-
diySubtotalTrHeight
|
|
367
|
+
const { dataKey } = content
|
|
368
|
+
// 每个表格都具有的高度(表头 + 各类合计行),提取成方法供填充基准复用同一口径
|
|
369
|
+
const allTableHaveThisHeight = this.getTableAllHaveHeight(index)
|
|
392
370
|
|
|
393
371
|
/** 当前page页面的最小高度 */
|
|
394
372
|
const currentPageMinimumHeight =
|
|
395
373
|
allPagesHaveThisHeight + allTableHaveThisHeight
|
|
396
374
|
// 最后一项是表格时,末页仍要渲染签名:装行可用高度预留签名,避免空行顶进签名区
|
|
397
|
-
const isLastContent = index ===
|
|
375
|
+
const isLastContent = index === contentsLength - 1
|
|
398
376
|
const signReserve = isLastContent ? this.getSignHeight() : 0
|
|
399
377
|
/** 当前page可容纳的table高度 */
|
|
400
378
|
let pageAccomodateTableHeight = roundHeight(
|
|
@@ -404,6 +382,8 @@ class PrinterStore {
|
|
|
404
382
|
const heights = [
|
|
405
383
|
...this.getNormalTableBodyHeights(table.body.heights, dataKey)
|
|
406
384
|
]
|
|
385
|
+
// 保留引用:该数组会被明细拆分 splice,填充基准需要用拆分后的行高
|
|
386
|
+
splicedHeightsMap[index] = heights
|
|
407
387
|
const tableData = tableDataMap[dataKey] || []
|
|
408
388
|
// 表格行的索引,用于table.slice(begin, end), 分割到不同页面中
|
|
409
389
|
let begin = 0
|
|
@@ -486,7 +466,7 @@ class PrinterStore {
|
|
|
486
466
|
)
|
|
487
467
|
break
|
|
488
468
|
}
|
|
489
|
-
//
|
|
469
|
+
// 行无法拆分(普通长文本列)或拆分失败时,强制推进 end 防止死循环
|
|
490
470
|
if (end === begin) {
|
|
491
471
|
// 新一页可容纳的 table 高度(页高 - 页眉页脚)
|
|
492
472
|
const fullPageAccomodateTableHeight = roundHeight(
|
|
@@ -605,15 +585,127 @@ class PrinterStore {
|
|
|
605
585
|
currentPageHeight += this.getSignHeight()
|
|
606
586
|
}
|
|
607
587
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
588
|
+
// 行数填充基准:优先取「填充表格最后一段所在页」的剩余高度(表格底部与该页
|
|
589
|
+
// 可用底边之间的空白)。旧口径固定取末页剩余,当填充表格不在末页(下方内容
|
|
590
|
+
// 被挤到下一页)时,行数按末页空间换算会超出所在页容量:多出的空行被切到
|
|
591
|
+
// 下一页渲染成空表格,或把同页后续表格挤到下一页。
|
|
592
|
+
// 填充基准不做 Math.round 向上取整,避免整行边界多算 ≤1px 导致重分页时溢出
|
|
593
|
+
const fillRemainHeight = this.computeFillTableRemainHeight(
|
|
594
|
+
pages,
|
|
595
|
+
pageHeight,
|
|
596
|
+
heightMap,
|
|
597
|
+
splicedHeightsMap
|
|
611
598
|
)
|
|
599
|
+
this.remainPageHeight =
|
|
600
|
+
fillRemainHeight != null
|
|
601
|
+
? Math.max(0, fillRemainHeight)
|
|
602
|
+
: Math.max(0, Math.round(pageHeight - currentPageHeight))
|
|
612
603
|
this.isSave = false
|
|
613
604
|
this.config.isSave = false
|
|
614
605
|
this.repackVerticalMultiByPages()
|
|
615
606
|
}
|
|
616
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
|
+
|
|
617
709
|
getTablePageRanges(contentIndex, rows) {
|
|
618
710
|
const ranges = []
|
|
619
711
|
this.pages.forEach(page => {
|
|
@@ -1045,7 +1137,12 @@ class PrinterStore {
|
|
|
1045
1137
|
)
|
|
1046
1138
|
)
|
|
1047
1139
|
withPartial.push(...fillList)
|
|
1048
|
-
|
|
1140
|
+
// 半行续号与空行起始序号统一收敛,防止两处各自计算造成序号重复(如双栏 5 条出现两个 6)
|
|
1141
|
+
this.data._table[dataKey] = normalizeMultiSerials(
|
|
1142
|
+
withPartial,
|
|
1143
|
+
colNumber,
|
|
1144
|
+
this.fillIndex
|
|
1145
|
+
)
|
|
1049
1146
|
}
|
|
1050
1147
|
|
|
1051
1148
|
@action.bound
|
|
@@ -2,10 +2,9 @@ import React from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import _ from 'lodash'
|
|
4
4
|
// import Big from 'big.js'
|
|
5
|
-
import { coverDigit2Uppercase, getDataKey } from '../util'
|
|
5
|
+
import { coverDigit2Uppercase, getDataKey, maskedSum } from '../util'
|
|
6
6
|
import { observer } from 'mobx-react'
|
|
7
7
|
import classNames from 'classnames'
|
|
8
|
-
import Big from 'big.js'
|
|
9
8
|
|
|
10
9
|
const DiyOverallOrder = props => {
|
|
11
10
|
const {
|
|
@@ -15,20 +14,14 @@ const DiyOverallOrder = props => {
|
|
|
15
14
|
} = props
|
|
16
15
|
const tableData = printerStore.data._table[getDataKey(dataKey)] || []
|
|
17
16
|
|
|
18
|
-
//
|
|
17
|
+
// 计算合计:任一渲染结果脱敏 '***' 则合计显 '***'(整格判定假设同 table_diy_summary_tr)
|
|
19
18
|
const sumData = field => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.replace(/\(\)/g, '')
|
|
27
|
-
result = a.plus(+bRes || 0)
|
|
28
|
-
return result
|
|
29
|
-
},
|
|
30
|
-
Big(0)
|
|
31
|
-
).toFixed(2)
|
|
19
|
+
const values = _.map(tableData, (b, i) =>
|
|
20
|
+
printerStore
|
|
21
|
+
.templateTable(field, dataKey, i, pageIndex)
|
|
22
|
+
.replace(/\(\)/g, '')
|
|
23
|
+
)
|
|
24
|
+
return maskedSum(values)
|
|
32
25
|
}
|
|
33
26
|
|
|
34
27
|
if (!diyOverallOrder?.show || !printerStore?.ready) {
|