gm-printer 10.13.2-alpha.4 → 10.13.4
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/.eslintcache +1 -1
- package/package.json +1 -1
- package/src/common/editor_add_field.js +1 -1
- package/src/common/editor_page_summary.js +1 -1
- package/src/common/editor_special_field.js +2 -0
- package/src/common/editor_store.js +40 -124
- package/src/common/editor_title.js +2 -2
- package/src/common/hoc_with_shadow_dom.js +5 -5
- package/src/common/hoc_with_store.js +25 -65
- package/src/editor/context_menu.js +8 -27
- package/src/editor/editor.js +1 -3
- package/src/editor_account/context_menu.js +2 -25
- package/src/editor_account/editor.js +1 -3
- package/src/printer/do_print.js +0 -1
- package/src/printer/printer.js +9 -18
- package/src/printer/store.js +91 -109
- package/src/printer/table.js +1 -0
- package/src/util.js +17 -27
- package/src/common/editor_customize_config.js +0 -47
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js":"1","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js":"2","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js":"3","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js":"4","/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js":"5","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js":"6","/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js":"7","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js":"8","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js":"9","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js":"10","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_store.js":"11","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js":"12","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js":"13","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js":"14","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js":"15","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js":"16","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js":"17","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js":"18"},{"size":8813,"mtime":1635407151058,"results":"19","hashOfConfig":"20"},{"size":
|
|
1
|
+
[{"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js":"1","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js":"2","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js":"3","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js":"4","/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js":"5","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js":"6","/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js":"7","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js":"8","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js":"9","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js":"10","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_store.js":"11","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js":"12","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js":"13","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js":"14","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js":"15","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js":"16","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js":"17","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js":"18"},{"size":8813,"mtime":1635407151058,"results":"19","hashOfConfig":"20"},{"size":11655,"mtime":1636081549102,"results":"21","hashOfConfig":"20"},{"size":4244,"mtime":1635494969691,"results":"22","hashOfConfig":"20"},{"size":3683,"mtime":1635851060224,"results":"23","hashOfConfig":"20"},{"size":616,"mtime":1621235314060,"results":"24","hashOfConfig":"25"},{"size":9693,"mtime":1621242097206,"results":"26","hashOfConfig":"25"},{"size":5923,"mtime":1636025210364,"results":"27","hashOfConfig":"20"},{"size":8733,"mtime":1635931829112,"results":"28","hashOfConfig":"20"},{"size":3119,"mtime":1634191808754,"results":"29","hashOfConfig":"20"},{"size":1113,"mtime":1635407660514,"results":"30","hashOfConfig":"20"},{"size":3905,"mtime":1635304242763},{"size":861,"mtime":1635246075403,"results":"31","hashOfConfig":"20"},{"size":3260,"mtime":1635334661529,"results":"32","hashOfConfig":"20"},{"size":24504,"mtime":1635908548975,"results":"33","hashOfConfig":"20"},{"size":1907,"mtime":1635492860490,"results":"34","hashOfConfig":"20"},{"size":3548,"mtime":1635409410379,"results":"35","hashOfConfig":"20"},{"size":2989,"mtime":1635495718901,"results":"36","hashOfConfig":"20"},{"size":3465,"mtime":1635495798948,"results":"37","hashOfConfig":"20"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1j0d8vf",{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"175njjo",{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":13,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"62","messages":"63","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"68","messages":"69","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","errorCount":2,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js",["72","73","74","75","76","77","78","79","80","81","82","83","84"],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js",["85","86"],{"ruleId":"87","severity":2,"message":"88","line":47,"column":13,"nodeType":"89","messageId":"90","endLine":47,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":48,"column":30,"nodeType":"92","messageId":"90","endLine":48,"endColumn":36},{"ruleId":"87","severity":2,"message":"93","line":49,"column":31,"nodeType":"92","messageId":"90","endLine":49,"endColumn":47},{"ruleId":"87","severity":2,"message":"93","line":50,"column":21,"nodeType":"92","messageId":"90","endLine":50,"endColumn":37},{"ruleId":"87","severity":2,"message":"88","line":56,"column":13,"nodeType":"89","messageId":"90","endLine":56,"endColumn":22},{"ruleId":"87","severity":2,"message":"94","line":59,"column":20,"nodeType":"92","messageId":"90","endLine":59,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":61,"column":23,"nodeType":"92","messageId":"90","endLine":61,"endColumn":29},{"ruleId":"87","severity":2,"message":"95","line":61,"column":30,"nodeType":"92","messageId":"90","endLine":61,"endColumn":34},{"ruleId":"87","severity":2,"message":"96","line":63,"column":15,"nodeType":"92","messageId":"90","endLine":63,"endColumn":19},{"ruleId":"87","severity":2,"message":"88","line":67,"column":23,"nodeType":"89","messageId":"90","endLine":67,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":70,"column":32,"nodeType":"92","messageId":"90","endLine":70,"endColumn":38},{"ruleId":"87","severity":2,"message":"88","line":78,"column":13,"nodeType":"89","messageId":"90","endLine":78,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":84,"column":42,"nodeType":"92","messageId":"90","endLine":84,"endColumn":48},{"ruleId":"97","severity":2,"message":"98","line":64,"column":11,"nodeType":"92","endLine":64,"endColumn":17},{"ruleId":"97","severity":2,"message":"99","line":102,"column":24,"nodeType":"92","endLine":102,"endColumn":32},"react/prop-types","'editStore' is missing in props validation","Property","missingPropType","'editStore.config' is missing in props validation","Identifier","'editStore.config.batchPrintConfig' is missing in props validation","'editStore.originConfig' is missing in props validation","'editStore.config.name' is missing in props validation","'editStore.init' is missing in props validation","no-unused-vars","'keyArr' is assigned a value but never used.","'mockData' is assigned a value but never used."]
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
2
|
import React, { Fragment } from 'react'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
|
-
import { Gap, SubTitle, Title, FieldBtn } from '../common/component'
|
|
5
4
|
import { Flex } from '../components'
|
|
5
|
+
import { Gap, SubTitle, Title, FieldBtn } from '../common/component'
|
|
6
6
|
import _ from 'lodash'
|
|
7
7
|
import { observer, inject } from 'mobx-react'
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ class SummarySetting extends React.Component {
|
|
|
25
25
|
handlePageSummaryColumns = e => {
|
|
26
26
|
const { editStore } = this.props
|
|
27
27
|
const { summaryConfig } = editStore.computedTableSpecialConfig
|
|
28
|
-
//
|
|
28
|
+
// 由于初始末班没有summary 这个object,为了UI响应数据,只能这么写了
|
|
29
29
|
const hasSummaryConfig = has(
|
|
30
30
|
editStore.computedTableSpecialConfig,
|
|
31
31
|
'summaryConfig'
|
|
@@ -33,6 +33,8 @@ class SpecialField extends React.Component {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
SpecialField.propTypes = {
|
|
36
|
+
fields: PropTypes.object.isRequired,
|
|
37
|
+
handleAddField: PropTypes.func,
|
|
36
38
|
addFields: PropTypes.object.isRequired,
|
|
37
39
|
editStore: PropTypes.object,
|
|
38
40
|
mockData: PropTypes.object.isRequired
|
|
@@ -4,54 +4,20 @@ import { pageTypeMap } from '../config'
|
|
|
4
4
|
import _ from 'lodash'
|
|
5
5
|
import { dispatchMsg, getBlockName, exchange } from '../util'
|
|
6
6
|
|
|
7
|
-
/** 默认填充的tr高度为23px */
|
|
8
|
-
const TR_HEIGHT = 23
|
|
9
7
|
class EditorStore {
|
|
10
8
|
@observable
|
|
11
9
|
tableCustomStyle = 'default'
|
|
12
10
|
|
|
13
|
-
@
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
remainPageHeihgt = 0
|
|
24
|
-
|
|
25
|
-
// 初始模板
|
|
26
|
-
originConfig = null
|
|
27
|
-
|
|
28
|
-
// 一个能唯一标识某个东西的字符串
|
|
29
|
-
// header
|
|
30
|
-
// header.block.1
|
|
31
|
-
// contents.panel.1.block.1
|
|
32
|
-
// contents.table.2.column.1
|
|
33
|
-
@observable
|
|
34
|
-
selected = null
|
|
35
|
-
|
|
36
|
-
/* 选择中区域, 区域唯一标识字符串
|
|
37
|
-
header
|
|
38
|
-
footer
|
|
39
|
-
sign
|
|
40
|
-
contents.panel.n
|
|
41
|
-
contents.table.n
|
|
42
|
-
*/
|
|
43
|
-
@observable
|
|
44
|
-
selectedRegion = null
|
|
45
|
-
|
|
46
|
-
@observable
|
|
47
|
-
insertPanel = 'header'
|
|
48
|
-
|
|
49
|
-
defaultTableDataKey = 'orders'
|
|
50
|
-
|
|
51
|
-
// 默认table的dataKey
|
|
52
|
-
setTableDataKeyEffect() {} // 改变dataKey后,做的副作用操作
|
|
53
|
-
|
|
54
|
-
defaultTableSubtotal = { show: false }
|
|
11
|
+
@action.bound
|
|
12
|
+
changeTableCustomStyle(v) {
|
|
13
|
+
if (this.selectedRegion) {
|
|
14
|
+
const arr = this.selectedRegion.split('.')
|
|
15
|
+
if (arr.includes('table')) {
|
|
16
|
+
this.config.contents[arr[2]].className = v
|
|
17
|
+
this.tableCustomStyle = v
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
55
21
|
|
|
56
22
|
@computed
|
|
57
23
|
get computedPrinterKey() {
|
|
@@ -82,71 +48,48 @@ class EditorStore {
|
|
|
82
48
|
}).join('_')
|
|
83
49
|
}
|
|
84
50
|
|
|
85
|
-
@
|
|
86
|
-
|
|
87
|
-
if (this.selectedRegion) {
|
|
88
|
-
const arr = this.selectedRegion.split('.')
|
|
89
|
-
if (arr.includes('table')) {
|
|
90
|
-
this.config.contents[arr[2]].className = v
|
|
91
|
-
this.tableCustomStyle = v
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
51
|
+
@observable
|
|
52
|
+
config = null
|
|
95
53
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
this.remainPageHeihgt = remainHeight
|
|
99
|
-
}
|
|
54
|
+
// 初始模板
|
|
55
|
+
originConfig = null
|
|
100
56
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
})
|
|
109
|
-
return Array(tr_count).fill(filledData)
|
|
110
|
-
}
|
|
57
|
+
// 一个能唯一标识某个东西的字符串
|
|
58
|
+
// header
|
|
59
|
+
// header.block.1
|
|
60
|
+
// contents.panel.1.block.1
|
|
61
|
+
// contents.table.2.column.1
|
|
62
|
+
@observable
|
|
63
|
+
selected = null
|
|
111
64
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
this.clearExtraTableData(dataKey)
|
|
122
|
-
this.setAutoFillRemainPage({ isAutoFilling: isAutoFilling })
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
this.setAutoFillRemainPage({ isAutoFilling: isAutoFilling })
|
|
126
|
-
this.mockData._table[dataKey] = table
|
|
127
|
-
// this.mockData = Object.assign({}, this.mockData)
|
|
128
|
-
}
|
|
65
|
+
/* 选择中区域, 区域唯一标识字符串
|
|
66
|
+
header
|
|
67
|
+
footer
|
|
68
|
+
sign
|
|
69
|
+
contents.panel.n
|
|
70
|
+
contents.table.n
|
|
71
|
+
*/
|
|
72
|
+
@observable
|
|
73
|
+
selectedRegion = null
|
|
129
74
|
|
|
130
|
-
@
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
75
|
+
@observable
|
|
76
|
+
insertPanel = 'header'
|
|
77
|
+
|
|
78
|
+
defaultTableDataKey = 'orders'
|
|
79
|
+
|
|
80
|
+
// 默认table的dataKey
|
|
81
|
+
setTableDataKeyEffect() {} // 改变dataKey后,做的副作用操作
|
|
82
|
+
|
|
83
|
+
defaultTableSubtotal = { show: false }
|
|
140
84
|
|
|
141
85
|
@action
|
|
142
|
-
init(config
|
|
86
|
+
init(config) {
|
|
143
87
|
// batchPrintConfig: 1 不连续打印(一张采购单不出现多供应商)2 连续打印(一张采购单可能出现多个供应商)
|
|
144
88
|
this.config = Object.assign({ batchPrintConfig: 1 }, config)
|
|
145
89
|
this.originConfig = config
|
|
146
90
|
this.selected = null
|
|
147
91
|
this.selectedRegion = null
|
|
148
92
|
this.insertPanel = 'header'
|
|
149
|
-
this.mockData = data
|
|
150
93
|
}
|
|
151
94
|
|
|
152
95
|
@action
|
|
@@ -459,9 +402,6 @@ class EditorStore {
|
|
|
459
402
|
setSubtotalShow(name) {
|
|
460
403
|
const arr = name.split('.')
|
|
461
404
|
const table = this.config.contents[arr[2]]
|
|
462
|
-
|
|
463
|
-
// 切换的时候,要把对应table的多余空数据清掉
|
|
464
|
-
this.clearExtraTableData(table.dataKey)
|
|
465
405
|
table.subtotal.show = !table.subtotal.show
|
|
466
406
|
}
|
|
467
407
|
|
|
@@ -492,8 +432,6 @@ class EditorStore {
|
|
|
492
432
|
o => o === 'category',
|
|
493
433
|
o => o === 'orders'
|
|
494
434
|
])
|
|
495
|
-
// 切换的时候,要把对应table的多余空数据清掉
|
|
496
|
-
this.clearExtraTableData(dataKey)
|
|
497
435
|
|
|
498
436
|
this.config.contents[arr[2]].dataKey = newDataKey.join('_')
|
|
499
437
|
}
|
|
@@ -928,22 +866,6 @@ class EditorStore {
|
|
|
928
866
|
}
|
|
929
867
|
}
|
|
930
868
|
|
|
931
|
-
// 设置是否自动填充空白
|
|
932
|
-
@action.bound
|
|
933
|
-
setAutoFillRemainPage(modify) {
|
|
934
|
-
if (this.computedRegionIsTable) {
|
|
935
|
-
const tableConfig = this.computedTableSpecialConfig
|
|
936
|
-
const extraSpecialConfig = tableConfig.extraSpecialConfig
|
|
937
|
-
if (extraSpecialConfig) {
|
|
938
|
-
set(extraSpecialConfig, modify)
|
|
939
|
-
} else {
|
|
940
|
-
set(tableConfig, { extraSpecialConfig: { ...modify } })
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
// 这么写才会触发子组件的更新
|
|
944
|
-
this.config = Object.assign({}, this.config)
|
|
945
|
-
}
|
|
946
|
-
|
|
947
869
|
@action.bound
|
|
948
870
|
setSummaryConfig(modify) {
|
|
949
871
|
if (this.selectedRegion) {
|
|
@@ -961,12 +883,6 @@ class EditorStore {
|
|
|
961
883
|
}
|
|
962
884
|
set(config, { summaryConfig: { ...init, ...modify } })
|
|
963
885
|
}
|
|
964
|
-
|
|
965
|
-
if ('pageSummaryShow' in modify || 'totalSummaryShow' in modify) {
|
|
966
|
-
// 切换的时候,要把对应table的多余空数据清掉
|
|
967
|
-
this.clearExtraTableData(config.dataKey)
|
|
968
|
-
}
|
|
969
|
-
|
|
970
886
|
this.config = toJS(this.config)
|
|
971
887
|
}
|
|
972
888
|
}
|
|
@@ -53,14 +53,14 @@ class EditorTitle extends React.Component {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
handleReset = () => {
|
|
56
|
-
const { editStore
|
|
56
|
+
const { editStore } = this.props
|
|
57
57
|
// 重置模板配置,但是保留原来模板名字
|
|
58
58
|
const config = {
|
|
59
59
|
...editStore.originConfig,
|
|
60
60
|
__key__: Date.now(), // 时间戳的key,直接让页面重新渲染!
|
|
61
61
|
name: editStore.config.name
|
|
62
62
|
}
|
|
63
|
-
editStore.init(config
|
|
63
|
+
editStore.init(config)
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
handleTestPrint = () => {
|
|
@@ -8,21 +8,21 @@ const withShadowDom = WrapCom => {
|
|
|
8
8
|
return class extends React.Component {
|
|
9
9
|
ref = React.createRef()
|
|
10
10
|
|
|
11
|
-
componentDidMount() {
|
|
11
|
+
componentDidMount () {
|
|
12
12
|
const shadowRoot = this.ref.current.attachShadow({ mode: 'open' })
|
|
13
13
|
// 在window下挂 shadow root
|
|
14
14
|
window.shadowRoot = shadowRoot
|
|
15
|
-
ReactDOM.render(<WrapCom {...this.props}
|
|
15
|
+
ReactDOM.render(<WrapCom {...this.props}/>, shadowRoot)
|
|
16
16
|
insertCSS(getPrinterCSS() + getEditorCSS(), shadowRoot)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
componentWillUnmount() {
|
|
19
|
+
componentWillUnmount () {
|
|
20
20
|
// 移除示例,不然很多意想不到的事情发生
|
|
21
21
|
ReactDOM.unmountComponentAtNode(window.shadowRoot)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
render() {
|
|
25
|
-
return <div id='shadowroot' ref={this.ref}
|
|
24
|
+
render () {
|
|
25
|
+
return <div id='shadowroot' ref={this.ref}/>
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
}
|
|
@@ -4,65 +4,29 @@ import { getStyleWithDiff } from '../util'
|
|
|
4
4
|
|
|
5
5
|
const withStore = store => WrapComponent =>
|
|
6
6
|
class extends React.Component {
|
|
7
|
-
constructor(props) {
|
|
7
|
+
constructor (props) {
|
|
8
8
|
super(props)
|
|
9
9
|
this.store = store
|
|
10
|
-
this.store.init(props.config
|
|
10
|
+
this.store.init(props.config)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
componentDidMount() {
|
|
14
|
-
window.document.addEventListener(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
)
|
|
18
|
-
window.document.addEventListener(
|
|
19
|
-
|
|
20
|
-
this.handleSelectedRegion
|
|
21
|
-
)
|
|
22
|
-
window.document.addEventListener(
|
|
23
|
-
'gm-printer-panel-style-set',
|
|
24
|
-
this.handlePrinterPanelStyleSet
|
|
25
|
-
)
|
|
26
|
-
window.document.addEventListener(
|
|
27
|
-
'gm-printer-block-style-set',
|
|
28
|
-
this.handlePrinterBlockStyleSet
|
|
29
|
-
)
|
|
30
|
-
window.document.addEventListener(
|
|
31
|
-
'gm-printer-block-text-set',
|
|
32
|
-
this.handlePrinterBlockTextSet
|
|
33
|
-
)
|
|
34
|
-
window.document.addEventListener(
|
|
35
|
-
'gm-printer-table-drag',
|
|
36
|
-
this.handlePrinterTableDrag
|
|
37
|
-
)
|
|
13
|
+
componentDidMount () {
|
|
14
|
+
window.document.addEventListener('gm-printer-select', this.handlePrinterSelect)
|
|
15
|
+
window.document.addEventListener('gm-printer-select-region', this.handleSelectedRegion)
|
|
16
|
+
window.document.addEventListener('gm-printer-panel-style-set', this.handlePrinterPanelStyleSet)
|
|
17
|
+
window.document.addEventListener('gm-printer-block-style-set', this.handlePrinterBlockStyleSet)
|
|
18
|
+
window.document.addEventListener('gm-printer-block-text-set', this.handlePrinterBlockTextSet)
|
|
19
|
+
window.document.addEventListener('gm-printer-table-drag', this.handlePrinterTableDrag)
|
|
38
20
|
window.document.addEventListener('keydown', this.handleKeyDown)
|
|
39
21
|
}
|
|
40
22
|
|
|
41
|
-
componentWillUnmount() {
|
|
42
|
-
window.document.removeEventListener(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
)
|
|
46
|
-
window.document.removeEventListener(
|
|
47
|
-
|
|
48
|
-
this.handleSelectedRegion
|
|
49
|
-
)
|
|
50
|
-
window.document.removeEventListener(
|
|
51
|
-
'gm-printer-panel-style-set',
|
|
52
|
-
this.handlePrinterPanelStyleSet
|
|
53
|
-
)
|
|
54
|
-
window.document.removeEventListener(
|
|
55
|
-
'gm-printer-block-style-set',
|
|
56
|
-
this.handlePrinterBlockStyleSet
|
|
57
|
-
)
|
|
58
|
-
window.document.removeEventListener(
|
|
59
|
-
'gm-printer-block-text-set',
|
|
60
|
-
this.handlePrinterBlockTextSet
|
|
61
|
-
)
|
|
62
|
-
window.document.removeEventListener(
|
|
63
|
-
'gm-printer-table-drag',
|
|
64
|
-
this.handlePrinterTableDrag
|
|
65
|
-
)
|
|
23
|
+
componentWillUnmount () {
|
|
24
|
+
window.document.removeEventListener('gm-printer-select', this.handlePrinterSelect)
|
|
25
|
+
window.document.removeEventListener('gm-printer-select-region', this.handleSelectedRegion)
|
|
26
|
+
window.document.removeEventListener('gm-printer-panel-style-set', this.handlePrinterPanelStyleSet)
|
|
27
|
+
window.document.removeEventListener('gm-printer-block-style-set', this.handlePrinterBlockStyleSet)
|
|
28
|
+
window.document.removeEventListener('gm-printer-block-text-set', this.handlePrinterBlockTextSet)
|
|
29
|
+
window.document.removeEventListener('gm-printer-table-drag', this.handlePrinterTableDrag)
|
|
66
30
|
window.document.removeEventListener('keydown', this.handleKeyDown)
|
|
67
31
|
}
|
|
68
32
|
|
|
@@ -71,31 +35,31 @@ const withStore = store => WrapComponent =>
|
|
|
71
35
|
this.store.setSelectedRegion(selected)
|
|
72
36
|
}
|
|
73
37
|
|
|
74
|
-
handlePrinterSelect = e => {
|
|
38
|
+
handlePrinterSelect = (e) => {
|
|
75
39
|
const { selected } = e.detail
|
|
76
40
|
this.store.setSelected(selected)
|
|
77
41
|
}
|
|
78
42
|
|
|
79
|
-
handlePrinterPanelStyleSet = e => {
|
|
43
|
+
handlePrinterPanelStyleSet = (e) => {
|
|
80
44
|
const { name, style } = e.detail
|
|
81
45
|
this.store.setConfigPanelStyle(name, style)
|
|
82
46
|
}
|
|
83
47
|
|
|
84
|
-
handlePrinterBlockStyleSet = e => {
|
|
48
|
+
handlePrinterBlockStyleSet = (e) => {
|
|
85
49
|
const { style } = e.detail
|
|
86
50
|
this.store.setConfigBlockBy('style', style)
|
|
87
51
|
}
|
|
88
52
|
|
|
89
|
-
handlePrinterBlockTextSet = e => {
|
|
53
|
+
handlePrinterBlockTextSet = (e) => {
|
|
90
54
|
const { text } = e.detail
|
|
91
55
|
this.store.setConfigBlockBy('text', text)
|
|
92
56
|
}
|
|
93
57
|
|
|
94
|
-
handlePrinterTableDrag = e => {
|
|
58
|
+
handlePrinterTableDrag = (e) => {
|
|
95
59
|
this.store.exchangeTableColumn(e.detail.target, e.detail.source)
|
|
96
60
|
}
|
|
97
61
|
|
|
98
|
-
handleKeyDown = e => {
|
|
62
|
+
handleKeyDown = (e) => {
|
|
99
63
|
if (e.target !== window.document.body) {
|
|
100
64
|
return
|
|
101
65
|
}
|
|
@@ -117,11 +81,7 @@ const withStore = store => WrapComponent =>
|
|
|
117
81
|
diffY += 1
|
|
118
82
|
}
|
|
119
83
|
|
|
120
|
-
const newStyle = getStyleWithDiff(
|
|
121
|
-
this.store.computedSelectedInfo.style,
|
|
122
|
-
diffX,
|
|
123
|
-
diffY
|
|
124
|
-
)
|
|
84
|
+
const newStyle = getStyleWithDiff(this.store.computedSelectedInfo.style, diffX, diffY)
|
|
125
85
|
|
|
126
86
|
this.store.setConfigBlockBy('style', newStyle)
|
|
127
87
|
} else if (this.store.computedIsSelectTable) {
|
|
@@ -140,10 +100,10 @@ const withStore = store => WrapComponent =>
|
|
|
140
100
|
}
|
|
141
101
|
}
|
|
142
102
|
|
|
143
|
-
render() {
|
|
103
|
+
render () {
|
|
144
104
|
return (
|
|
145
105
|
<Provider editStore={this.store} mockData={this.props.mockData}>
|
|
146
|
-
<WrapComponent {...this.props}
|
|
106
|
+
<WrapComponent {...this.props}/>
|
|
147
107
|
</Provider>
|
|
148
108
|
)
|
|
149
109
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
3
|
import CommonContextMenu from '../common/common_context_menu'
|
|
5
4
|
import { inject, observer } from 'mobx-react'
|
|
6
5
|
import _ from 'lodash'
|
|
7
6
|
import { Printer } from '../printer'
|
|
7
|
+
import { noSubtotalBtnTableDataKeySet } from './editor'
|
|
8
8
|
|
|
9
9
|
const blockTypeList = [
|
|
10
10
|
{ value: '', text: i18next.t('插入文本') },
|
|
@@ -19,7 +19,10 @@ const blockTypeList = [
|
|
|
19
19
|
}
|
|
20
20
|
]
|
|
21
21
|
|
|
22
|
-
@inject(
|
|
22
|
+
@inject(stores => ({
|
|
23
|
+
editStore: stores.editStore,
|
|
24
|
+
mockData: stores.mockData
|
|
25
|
+
}))
|
|
23
26
|
@observer
|
|
24
27
|
class ContextMenu extends React.Component {
|
|
25
28
|
/**
|
|
@@ -49,28 +52,18 @@ class ContextMenu extends React.Component {
|
|
|
49
52
|
editStore.setSubtotalShow(name)
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
handleChangeTableData = isAutoFilling => {
|
|
53
|
-
const { editStore } = this.props
|
|
54
|
-
editStore.handleChangeTableData(isAutoFilling)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
55
|
renderOrderActionBtn = name => {
|
|
58
56
|
if (!this.hasSubtotalBtn(name)) {
|
|
59
57
|
return null
|
|
60
58
|
}
|
|
61
59
|
|
|
62
60
|
const arr = name.split('.')
|
|
63
|
-
const {
|
|
64
|
-
dataKey,
|
|
65
|
-
subtotal,
|
|
66
|
-
extraSpecialConfig
|
|
67
|
-
} = this.props.editStore.config.contents[arr[2]]
|
|
61
|
+
const { dataKey, subtotal } = this.props.editStore.config.contents[arr[2]]
|
|
68
62
|
const keyArr = dataKey.split('_')
|
|
69
63
|
|
|
70
64
|
const isMultiActive = keyArr.includes('multi')
|
|
71
65
|
const isCategoryActive = keyArr.includes('category')
|
|
72
66
|
const isSubtotalActive = subtotal.show
|
|
73
|
-
const isAutoFilling = extraSpecialConfig?.isAutoFilling
|
|
74
67
|
|
|
75
68
|
return (
|
|
76
69
|
<>
|
|
@@ -92,18 +85,12 @@ class ContextMenu extends React.Component {
|
|
|
92
85
|
>
|
|
93
86
|
{i18next.t('每页合计')}
|
|
94
87
|
</div>
|
|
95
|
-
<div
|
|
96
|
-
onClick={this.handleChangeTableData.bind(this, !isAutoFilling)}
|
|
97
|
-
className={isAutoFilling ? 'active' : ''}
|
|
98
|
-
>
|
|
99
|
-
{i18next.t('行数填充')}
|
|
100
|
-
</div>
|
|
101
88
|
</>
|
|
102
89
|
)
|
|
103
90
|
}
|
|
104
91
|
|
|
105
92
|
render() {
|
|
106
|
-
const { editStore } = this.props
|
|
93
|
+
const { editStore, mockData } = this.props
|
|
107
94
|
return (
|
|
108
95
|
<CommonContextMenu
|
|
109
96
|
renderTableAction={this.renderOrderActionBtn}
|
|
@@ -114,17 +101,11 @@ class ContextMenu extends React.Component {
|
|
|
114
101
|
selected={editStore.selected}
|
|
115
102
|
selectedRegion={editStore.selectedRegion}
|
|
116
103
|
config={editStore.config}
|
|
117
|
-
data={
|
|
118
|
-
getremainpageheight={editStore.setRemainPageHeight}
|
|
104
|
+
data={mockData}
|
|
119
105
|
/>
|
|
120
106
|
</CommonContextMenu>
|
|
121
107
|
)
|
|
122
108
|
}
|
|
123
109
|
}
|
|
124
110
|
|
|
125
|
-
ContextMenu.propTypes = {
|
|
126
|
-
editStore: PropTypes.object,
|
|
127
|
-
mockData: PropTypes.object
|
|
128
|
-
}
|
|
129
|
-
|
|
130
111
|
export default ContextMenu
|
package/src/editor/editor.js
CHANGED
|
@@ -11,7 +11,6 @@ import SpecialField from '../common/editor_special_field'
|
|
|
11
11
|
import EditorField from '../common/editor_edit_field'
|
|
12
12
|
import EditorAddField from '../common/editor_add_field'
|
|
13
13
|
import EditorPageSummary from '../common/editor_page_summary'
|
|
14
|
-
import EditorCutomizedConfig from '../common/editor_customize_config'
|
|
15
14
|
import ContextMenu from './context_menu'
|
|
16
15
|
import i18next from '../../locales'
|
|
17
16
|
import withStore from '../common/hoc_with_store'
|
|
@@ -78,14 +77,13 @@ class Editor extends React.Component {
|
|
|
78
77
|
<EditorSelect />
|
|
79
78
|
<Gap height='5px' />
|
|
80
79
|
<SpecialField addFields={addFields} mockData={mockData} />
|
|
81
|
-
<EditorCutomizedConfig />
|
|
82
80
|
<Gap height='5px' />
|
|
83
81
|
<EditorField
|
|
84
82
|
tableDataKeyList={tableDataKeyList}
|
|
85
83
|
showNewDate={showNewDate}
|
|
86
84
|
/>
|
|
87
85
|
<Gap height='5px' />
|
|
88
|
-
<EditorAddField addFields={addFields} />
|
|
86
|
+
<EditorAddField addFields={addFields} mockData={mockData} />
|
|
89
87
|
<Gap height='5px' />
|
|
90
88
|
<EditorPageSummary summaryFields={addFields.summaryFields} />
|
|
91
89
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
2
|
import React from 'react'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
3
|
import CommonContextMenu from '../common/common_context_menu'
|
|
5
4
|
import { inject, observer } from 'mobx-react'
|
|
6
5
|
import _ from 'lodash'
|
|
@@ -45,28 +44,18 @@ class ContextMenu extends React.Component {
|
|
|
45
44
|
editStore.setSubtotalShow(name)
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
handleChangeTableData = isAutoFilling => {
|
|
49
|
-
const { editStore } = this.props
|
|
50
|
-
editStore.handleChangeTableData(isAutoFilling)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
47
|
renderOrderActionBtn = name => {
|
|
54
48
|
if (!this.hasSubtotalBtn(name)) {
|
|
55
49
|
return null
|
|
56
50
|
}
|
|
57
51
|
|
|
58
52
|
const arr = name.split('.')
|
|
59
|
-
const {
|
|
60
|
-
dataKey,
|
|
61
|
-
subtotal,
|
|
62
|
-
extraSpecialConfig
|
|
63
|
-
} = this.props.editStore.config.contents[arr[2]]
|
|
53
|
+
const { dataKey, subtotal } = this.props.editStore.config.contents[arr[2]]
|
|
64
54
|
const keyArr = dataKey.split('_')
|
|
65
55
|
|
|
66
56
|
// const isMultiActive = keyArr.includes('multi')
|
|
67
57
|
// const isCategoryActive = keyArr.includes('category')
|
|
68
58
|
const isSubtotalActive = subtotal.show
|
|
69
|
-
const isAutoFilling = extraSpecialConfig?.isAutoFilling
|
|
70
59
|
|
|
71
60
|
return (
|
|
72
61
|
<>
|
|
@@ -88,12 +77,6 @@ class ContextMenu extends React.Component {
|
|
|
88
77
|
>
|
|
89
78
|
{i18next.t('每页合计')}
|
|
90
79
|
</div>
|
|
91
|
-
<div
|
|
92
|
-
onClick={this.handleChangeTableData.bind(this, !isAutoFilling)}
|
|
93
|
-
className={isAutoFilling ? 'active' : ''}
|
|
94
|
-
>
|
|
95
|
-
{i18next.t('行数填充')}
|
|
96
|
-
</div>
|
|
97
80
|
</>
|
|
98
81
|
)
|
|
99
82
|
}
|
|
@@ -110,17 +93,11 @@ class ContextMenu extends React.Component {
|
|
|
110
93
|
selected={editStore.selected}
|
|
111
94
|
selectedRegion={editStore.selectedRegion}
|
|
112
95
|
config={editStore.config}
|
|
113
|
-
data={
|
|
114
|
-
getremainpageheight={editStore.setRemainPageHeight}
|
|
96
|
+
data={mockData}
|
|
115
97
|
/>
|
|
116
98
|
</CommonContextMenu>
|
|
117
99
|
)
|
|
118
100
|
}
|
|
119
101
|
}
|
|
120
102
|
|
|
121
|
-
ContextMenu.propTypes = {
|
|
122
|
-
editStore: PropTypes.object,
|
|
123
|
-
mockData: PropTypes.object
|
|
124
|
-
}
|
|
125
|
-
|
|
126
103
|
export default ContextMenu
|
|
@@ -9,7 +9,6 @@ import EditorTitle from '../common/editor_title'
|
|
|
9
9
|
import EditorSelect from '../common/editor_select'
|
|
10
10
|
import EditorField from '../common/editor_edit_field'
|
|
11
11
|
import EditorAddField from '../common/editor_add_field'
|
|
12
|
-
import EditorCutomizedConfig from '../common/editor_customize_config'
|
|
13
12
|
import ContextMenu from './context_menu'
|
|
14
13
|
import i18next from '../../locales'
|
|
15
14
|
import withStore from '../common/hoc_with_store'
|
|
@@ -20,6 +19,7 @@ import withStore from '../common/hoc_with_store'
|
|
|
20
19
|
class Editor extends React.Component {
|
|
21
20
|
render() {
|
|
22
21
|
const { onSave, showEditor, addFields, showNewDate } = this.props
|
|
22
|
+
|
|
23
23
|
return (
|
|
24
24
|
<div className='gm-printer-edit'>
|
|
25
25
|
<Flex className='gm-printer-edit-title-fixed'>
|
|
@@ -55,8 +55,6 @@ class Editor extends React.Component {
|
|
|
55
55
|
<Gap height='10px' />
|
|
56
56
|
<EditorSelect />
|
|
57
57
|
<Gap height='5px' />
|
|
58
|
-
<EditorCutomizedConfig />
|
|
59
|
-
<Gap height='5px' />
|
|
60
58
|
<EditorField showNewDate={showNewDate} />
|
|
61
59
|
<Gap height='5px' />
|
|
62
60
|
<EditorAddField addFields={addFields} />
|
package/src/printer/do_print.js
CHANGED
package/src/printer/printer.js
CHANGED
|
@@ -3,7 +3,7 @@ import React from 'react'
|
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { inject, observer, Provider } from 'mobx-react'
|
|
5
5
|
import PropTypes from 'prop-types'
|
|
6
|
-
import PrinterStore
|
|
6
|
+
import PrinterStore from './store'
|
|
7
7
|
import Page from './page'
|
|
8
8
|
import _ from 'lodash'
|
|
9
9
|
import Panel from './panel'
|
|
@@ -60,6 +60,7 @@ class Printer extends React.Component {
|
|
|
60
60
|
|
|
61
61
|
// 无实际意义,辅助 onReady,见 didMount
|
|
62
62
|
this.state = {}
|
|
63
|
+
|
|
63
64
|
props.printerStore.init(props.config, props.data)
|
|
64
65
|
props.printerStore.setSelected(props.selected)
|
|
65
66
|
props.printerStore.setSelectedRegion(props.selectedRegion)
|
|
@@ -75,8 +76,9 @@ class Printer extends React.Component {
|
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
componentDidMount() {
|
|
78
|
-
const { printerStore, config
|
|
79
|
+
const { printerStore, config } = this.props
|
|
79
80
|
const batchPrintConfig = config.batchPrintConfig
|
|
81
|
+
|
|
80
82
|
// 连续打印不需要计算
|
|
81
83
|
if (batchPrintConfig !== 2) {
|
|
82
84
|
// didMount 代表第一次渲染完成
|
|
@@ -84,12 +86,6 @@ class Printer extends React.Component {
|
|
|
84
86
|
|
|
85
87
|
// 开始计算,获取各种数据
|
|
86
88
|
printerStore.computedPages()
|
|
87
|
-
|
|
88
|
-
// 计算是否填充空白数据
|
|
89
|
-
printerStore.fillEmptyPage()
|
|
90
|
-
|
|
91
|
-
// 获取剩余空白高度,传到editor
|
|
92
|
-
getremainpageheight && getremainpageheight(printerStore.remainPageHeight)
|
|
93
89
|
}
|
|
94
90
|
// Printer 不是立马就呈现出最终样式,有个过程。这个过程需要时间,什么 ready,不太清楚,估借 setState 来获取过程结束时刻
|
|
95
91
|
this.setState({}, () => {
|
|
@@ -140,7 +136,8 @@ class Printer extends React.Component {
|
|
|
140
136
|
|
|
141
137
|
renderPage() {
|
|
142
138
|
const { printerStore } = this.props
|
|
143
|
-
const { config
|
|
139
|
+
const { config } = printerStore
|
|
140
|
+
|
|
144
141
|
return (
|
|
145
142
|
<>
|
|
146
143
|
{_.map(printerStore.pages, (page, i) => {
|
|
@@ -151,12 +148,6 @@ class Printer extends React.Component {
|
|
|
151
148
|
<Header config={config.header} pageIndex={i} />
|
|
152
149
|
|
|
153
150
|
{_.map(page, (panel, ii) => {
|
|
154
|
-
const { extraSpecialConfig } = config.contents[panel.index]
|
|
155
|
-
const end =
|
|
156
|
-
isLastPage && extraSpecialConfig?.isAutoFilling
|
|
157
|
-
? panel.end + Math.floor(remainPageHeight / TR_BASE_HEIGHT)
|
|
158
|
-
: panel.end
|
|
159
|
-
|
|
160
151
|
switch (panel.type) {
|
|
161
152
|
case 'table':
|
|
162
153
|
return (
|
|
@@ -166,7 +157,7 @@ class Printer extends React.Component {
|
|
|
166
157
|
config={config.contents[panel.index]}
|
|
167
158
|
range={{
|
|
168
159
|
begin: panel.begin,
|
|
169
|
-
end: end
|
|
160
|
+
end: panel.end
|
|
170
161
|
}}
|
|
171
162
|
placeholder={`${i18next.t('区域')} ${panel.index}`}
|
|
172
163
|
pageIndex={i}
|
|
@@ -257,6 +248,7 @@ class Printer extends React.Component {
|
|
|
257
248
|
render() {
|
|
258
249
|
const {
|
|
259
250
|
selected,
|
|
251
|
+
data,
|
|
260
252
|
config,
|
|
261
253
|
onReady,
|
|
262
254
|
selectedRegion,
|
|
@@ -294,8 +286,7 @@ Printer.propTypes = {
|
|
|
294
286
|
selectedRegion: PropTypes.string,
|
|
295
287
|
data: PropTypes.object.isRequired,
|
|
296
288
|
config: PropTypes.object.isRequired,
|
|
297
|
-
onReady: PropTypes.func
|
|
298
|
-
getremainpageheight: PropTypes.func
|
|
289
|
+
onReady: PropTypes.func
|
|
299
290
|
}
|
|
300
291
|
|
|
301
292
|
Printer.defaultProps = {
|
package/src/printer/store.js
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
import _ from 'lodash'
|
|
9
9
|
import Big from 'big.js'
|
|
10
10
|
|
|
11
|
-
export const TR_BASE_HEIGHT = 23
|
|
12
11
|
const price = (n, f = 2) => Big(n || 0).toFixed(f)
|
|
13
12
|
class PrinterStore {
|
|
14
13
|
@observable ready = false
|
|
@@ -26,9 +25,6 @@ class PrinterStore {
|
|
|
26
25
|
|
|
27
26
|
@observable pages = [] // [{type, index, begin, end}]
|
|
28
27
|
|
|
29
|
-
/** 当前页剩余空白高度 */
|
|
30
|
-
@observable remainPageHeight = 0
|
|
31
|
-
|
|
32
28
|
data = {}
|
|
33
29
|
|
|
34
30
|
// 选中某个东西,具体见 edit/store.js 定义
|
|
@@ -81,6 +77,32 @@ class PrinterStore {
|
|
|
81
77
|
this.selectedRegion = selected || null
|
|
82
78
|
}
|
|
83
79
|
|
|
80
|
+
@action
|
|
81
|
+
computedData(dataKey, table, end, currentRemainTableHeight) {
|
|
82
|
+
/** 当前数据 */
|
|
83
|
+
const tableData = this.data._table[dataKey] || []
|
|
84
|
+
/** 明细data */
|
|
85
|
+
const detailsData = tableData[end]?.__details || []
|
|
86
|
+
const { ranges, detailsPageHeight } = caclSingleDetailsPageHeight(
|
|
87
|
+
table,
|
|
88
|
+
detailsData,
|
|
89
|
+
currentRemainTableHeight
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
// 分局明细拆分后的数据
|
|
93
|
+
const splitTableData = _.map(ranges, range => {
|
|
94
|
+
const _tableData = Object.assign({}, tableData[end])
|
|
95
|
+
_tableData.__details = detailsData.slice(...range)
|
|
96
|
+
return _tableData
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// 插入原table数据中
|
|
100
|
+
tableData.splice(end, 1, ...splitTableData)
|
|
101
|
+
this.data._table[dataKey] = tableData
|
|
102
|
+
|
|
103
|
+
return detailsPageHeight
|
|
104
|
+
}
|
|
105
|
+
|
|
84
106
|
@action
|
|
85
107
|
computedPages() {
|
|
86
108
|
// 每页必有 页眉header, 页脚footer
|
|
@@ -90,15 +112,13 @@ class PrinterStore {
|
|
|
90
112
|
return
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
|
|
115
|
+
/** 某一page的累积已填充的高度 */
|
|
94
116
|
let currentPageHeight = allPagesHaveThisHeight
|
|
95
|
-
/** 区域1的高度 */
|
|
96
|
-
let firstPagePanel0Height = 0
|
|
97
117
|
// 当前在处理 contents 的索引
|
|
98
118
|
let index = 0
|
|
99
|
-
|
|
119
|
+
/** 一页承载的内容. [object, object, ...] */
|
|
100
120
|
let page = []
|
|
101
|
-
|
|
121
|
+
/** 处理配送单有多个表格的情况 */
|
|
102
122
|
let tableCount = 0
|
|
103
123
|
/* --- 遍历 contents,将内容动态分配到page --- */
|
|
104
124
|
while (index < this.config.contents.length) {
|
|
@@ -122,12 +142,13 @@ class PrinterStore {
|
|
|
122
142
|
// 每个表格都具有的高度
|
|
123
143
|
const allTableHaveThisHeight =
|
|
124
144
|
table.head.height + subtotalTrHeight + pageSummaryTrHeight
|
|
125
|
-
|
|
145
|
+
/** 当前page页面的最小高度 */
|
|
126
146
|
const currentPageMinimumHeight =
|
|
127
147
|
allPagesHaveThisHeight + allTableHaveThisHeight
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
148
|
+
/** 当前page可容纳的table高度 */
|
|
149
|
+
let pageAccomodateTableHeight = +new Big(this.pageHeight)
|
|
150
|
+
.minus(currentPageHeight)
|
|
151
|
+
.toFixed(2)
|
|
131
152
|
|
|
132
153
|
// 表格行的索引,用于table.slice(begin, end), 分割到不同页面中
|
|
133
154
|
let begin = 0
|
|
@@ -137,18 +158,47 @@ class PrinterStore {
|
|
|
137
158
|
if (table.body.heights.length === 0) {
|
|
138
159
|
index++
|
|
139
160
|
} else {
|
|
161
|
+
/** 仅计算当前页table的累积高度 */
|
|
162
|
+
let currentTableHeight = allTableHaveThisHeight
|
|
140
163
|
// 表格有数据,添加[每个表格都具有的高度]
|
|
141
164
|
currentPageHeight += allTableHaveThisHeight
|
|
165
|
+
/** 当前table剩余的高度 */
|
|
166
|
+
let currentRemainTableHeight = 0
|
|
167
|
+
/** 去最小的tr高度,用于下面的计算compare */
|
|
168
|
+
const minHeight = Math.min(...table.body.heights)
|
|
142
169
|
|
|
143
|
-
/*
|
|
170
|
+
/* 遍历表格每一行,填充表格内容 */
|
|
144
171
|
while (end < table.body.heights.length) {
|
|
172
|
+
currentTableHeight += table.body.heights[end]
|
|
173
|
+
// 用于计算最后一页有footer情况的高度
|
|
145
174
|
currentPageHeight += table.body.heights[end]
|
|
146
|
-
|
|
147
175
|
// 当前页没有多余空间
|
|
148
|
-
if (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
176
|
+
if (currentTableHeight > pageAccomodateTableHeight) {
|
|
177
|
+
currentRemainTableHeight = +Big(pageAccomodateTableHeight)
|
|
178
|
+
.minus(currentTableHeight)
|
|
179
|
+
.plus(table.body.heights[end])
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 说明: 1. currentRemainTableHeight > minHeight 要比最小度高高,不然每次到这都进入if
|
|
183
|
+
* 2. table.body.heights[end]至少要是currentRemainTableHeight的 2倍,怕出现打印时最后一行文字显示一半的情况
|
|
184
|
+
* 3. table.body.heights[end] 高度超过了 pageAccomodateTableHeight
|
|
185
|
+
*/
|
|
186
|
+
if (
|
|
187
|
+
(currentRemainTableHeight > minHeight &&
|
|
188
|
+
table.body.heights[end] / minHeight > 2) ||
|
|
189
|
+
table.body.heights[end] > pageAccomodateTableHeight
|
|
190
|
+
) {
|
|
191
|
+
const detailsPageHeight = this.computedData(
|
|
192
|
+
dataKey,
|
|
193
|
+
table,
|
|
194
|
+
end,
|
|
195
|
+
currentRemainTableHeight
|
|
196
|
+
)
|
|
197
|
+
// 拆分明细后,同时也要更新body.heights 不能影响后续计算
|
|
198
|
+
table.body.heights.splice(end, 1, ...detailsPageHeight)
|
|
199
|
+
end++
|
|
200
|
+
}
|
|
201
|
+
// 第一条极端会有问题
|
|
152
202
|
if (end !== 0) {
|
|
153
203
|
page.push({
|
|
154
204
|
type: 'table',
|
|
@@ -167,55 +217,12 @@ class PrinterStore {
|
|
|
167
217
|
page = []
|
|
168
218
|
}
|
|
169
219
|
|
|
170
|
-
// ‼️‼️‼️ 极端情况: 如果一行的高度 大于 页面高度, 那么就对明细进行分页
|
|
171
|
-
if (
|
|
172
|
-
table.body.heights[end] + currentPageMinimumHeight >
|
|
173
|
-
this.pageHeight
|
|
174
|
-
) {
|
|
175
|
-
/** 明细data */
|
|
176
|
-
const detailsData = tableData[end]?.__details || []
|
|
177
|
-
const heightParams = {
|
|
178
|
-
currentPageMinimumHeight: currentPageMinimumHeight,
|
|
179
|
-
calcHeight: calcHeight,
|
|
180
|
-
pageHeight: this.pageHeight
|
|
181
|
-
}
|
|
182
|
-
const {
|
|
183
|
-
ranges,
|
|
184
|
-
detailsPageHeight
|
|
185
|
-
} = caclSingleDetailsPageHeight(
|
|
186
|
-
end,
|
|
187
|
-
table,
|
|
188
|
-
detailsData,
|
|
189
|
-
heightParams
|
|
190
|
-
)
|
|
191
|
-
// 分局明细拆分后的数据
|
|
192
|
-
const splitTableData = _.map(ranges, range => {
|
|
193
|
-
// 当前行的table数据
|
|
194
|
-
const _tableData = Object.assign({}, tableData[end])
|
|
195
|
-
_tableData.__details = detailsData.slice(...range)
|
|
196
|
-
return _tableData
|
|
197
|
-
})
|
|
198
|
-
// 插入原table数据中
|
|
199
|
-
tableData.splice(end, 1, ...splitTableData)
|
|
200
|
-
// 更新
|
|
201
|
-
this.data._table[dataKey] = tableData
|
|
202
|
-
|
|
203
|
-
// 同时也要更新body.heights 不能影响后续计算
|
|
204
|
-
table.body.heights.splice(end, 1, ...detailsPageHeight)
|
|
205
|
-
|
|
206
|
-
page.push({
|
|
207
|
-
type: 'table',
|
|
208
|
-
index,
|
|
209
|
-
begin: end,
|
|
210
|
-
end: ++end
|
|
211
|
-
})
|
|
212
|
-
// 此页完成任务
|
|
213
|
-
this.pages.push(page)
|
|
214
|
-
page = []
|
|
215
|
-
}
|
|
216
|
-
|
|
217
220
|
begin = end
|
|
218
221
|
// 开启新一页,重置页面高度
|
|
222
|
+
pageAccomodateTableHeight = +new Big(this.pageHeight).minus(
|
|
223
|
+
currentPageMinimumHeight
|
|
224
|
+
)
|
|
225
|
+
currentTableHeight = allTableHaveThisHeight
|
|
219
226
|
currentPageHeight = currentPageMinimumHeight
|
|
220
227
|
} else {
|
|
221
228
|
// 有空间,继续做下行
|
|
@@ -243,11 +250,6 @@ class PrinterStore {
|
|
|
243
250
|
break
|
|
244
251
|
}
|
|
245
252
|
|
|
246
|
-
if (index === 0) {
|
|
247
|
-
// 针对极端情况下,保存区域1的高度
|
|
248
|
-
firstPagePanel0Height = panelHeight
|
|
249
|
-
}
|
|
250
|
-
|
|
251
253
|
if (currentPageHeight <= this.pageHeight) {
|
|
252
254
|
// 空间充足,把信息加入 page,并轮下一个contents
|
|
253
255
|
page.push({
|
|
@@ -267,44 +269,6 @@ class PrinterStore {
|
|
|
267
269
|
}
|
|
268
270
|
}
|
|
269
271
|
this.pages.push(page)
|
|
270
|
-
this.remainPageHeight = +Big(this.pageHeight - currentPageHeight).toFixed(0)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
// 计算初始化是否填充tableData
|
|
274
|
-
@action.bound
|
|
275
|
-
fillEmptyPage() {
|
|
276
|
-
const { contents } = this.config
|
|
277
|
-
// 或许存在多个table
|
|
278
|
-
const tableConfigs = _.find(contents, item => {
|
|
279
|
-
if (item.extraSpecialConfig) return item
|
|
280
|
-
})
|
|
281
|
-
// 兼容没有extraSpecialConfig配置的
|
|
282
|
-
if (!tableConfigs) return
|
|
283
|
-
|
|
284
|
-
const { extraSpecialConfig, dataKey } = tableConfigs
|
|
285
|
-
let table = this.data._table[dataKey]
|
|
286
|
-
|
|
287
|
-
if (tableConfigs?.extraSpecialConfig?.isAutoFilling) {
|
|
288
|
-
if (extraSpecialConfig.isAutoFilling) {
|
|
289
|
-
table.push(...this.getFilledTableData(table))
|
|
290
|
-
} else {
|
|
291
|
-
const len = this.getFilledTableData(table).length
|
|
292
|
-
const newTable = this.data._table[dataKey].slice(0, -len)
|
|
293
|
-
table = newTable
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
this.data._table[dataKey] = table
|
|
297
|
-
this.data = Object.assign({}, this.data)
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
@action.bound
|
|
301
|
-
getFilledTableData(tableData) {
|
|
302
|
-
const tr_count = Math.floor(this.remainPageHeight / TR_BASE_HEIGHT)
|
|
303
|
-
const filledData = {}
|
|
304
|
-
_.map(tableData[0], (val, key) => {
|
|
305
|
-
filledData[key] = ''
|
|
306
|
-
})
|
|
307
|
-
return Array(tr_count).fill(filledData)
|
|
308
272
|
}
|
|
309
273
|
|
|
310
274
|
template(text, pageIndex) {
|
|
@@ -366,6 +330,24 @@ class PrinterStore {
|
|
|
366
330
|
? filterList(detailsList)
|
|
367
331
|
: filterList(detailsList, 'noLineBreak')
|
|
368
332
|
|
|
333
|
+
// 兼容之前已经添加上最后一列的模板
|
|
334
|
+
// if (!detailLastColType) {
|
|
335
|
+
// detailsList = detailsList
|
|
336
|
+
// ? detailsList.map(d => `<div> ${compiled(d)} </div>`).join('')
|
|
337
|
+
// : []
|
|
338
|
+
// } else {
|
|
339
|
+
// // 多栏商品时,同一行仅有一个商品,后面空余部分显示空白
|
|
340
|
+
// if (detailsList) {
|
|
341
|
+
// // detailLastColType ---> 区分采购明细单列——最后一列是否换行
|
|
342
|
+
// detailsList =
|
|
343
|
+
// detailLastColType === 'purchase_last_col'
|
|
344
|
+
// ? detailsList.map(d => `<div> ${compiled(d)} </div>`).join('')
|
|
345
|
+
// : detailsList.map(d => `${compiled(d)}`).join(separator)
|
|
346
|
+
// } else {
|
|
347
|
+
// detailsList = []
|
|
348
|
+
// }
|
|
349
|
+
// }
|
|
350
|
+
|
|
369
351
|
return detailsList
|
|
370
352
|
} catch (err) {
|
|
371
353
|
return text
|
package/src/printer/table.js
CHANGED
package/src/util.js
CHANGED
|
@@ -181,47 +181,37 @@ const getDataKey = (dataKey, arrange) =>
|
|
|
181
181
|
/**
|
|
182
182
|
* @param {*} table 当前单据的高度信息
|
|
183
183
|
* @param {*} detailsData 当前所有tablelist
|
|
184
|
-
* @param {*}
|
|
185
|
-
* @param {*} pageHeight page的高度
|
|
184
|
+
* @param {*} curRemainPageHeight 可容纳table的总高度
|
|
186
185
|
* @returns {ranges, detailsPageHeight} detailsPageHeight 每页高度合集
|
|
187
186
|
*/
|
|
188
187
|
const caclSingleDetailsPageHeight = (
|
|
189
|
-
indexEnd,
|
|
190
188
|
table,
|
|
191
189
|
detailsData,
|
|
192
|
-
|
|
190
|
+
curRemainPageHeight
|
|
193
191
|
) => {
|
|
194
|
-
let end = 0
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
let currentDetailsMiniHeight =
|
|
192
|
+
let [end, deadline] = [0, 0]
|
|
193
|
+
const begin = 0
|
|
194
|
+
/** 当前明细高度,默认为tr的border+padding的height */
|
|
195
|
+
let currentDetailsMiniHeight = 5
|
|
198
196
|
const ranges = []
|
|
199
197
|
const detailsPageHeight = []
|
|
200
|
-
|
|
198
|
+
/** 未进行计算的高度,留到下一次, 默认为tr的border+padding的height */
|
|
199
|
+
let remainDetailsHeight = 5
|
|
201
200
|
|
|
201
|
+
// 如果当前累计高度高于当前剩余高度,则跳出返回
|
|
202
202
|
while (end < detailsData.length) {
|
|
203
|
-
currentDetailsMiniHeight
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// 如果当前明细高度综合大于页面高度,到此为止进行分页
|
|
207
|
-
if (currentDetailsMiniHeight + currentPageMinimumHeight > _calcHeight) {
|
|
208
|
-
detailsPageHeight.push(
|
|
209
|
-
currentDetailsMiniHeight - table.body.children[end]
|
|
210
|
-
)
|
|
211
|
-
ranges.push([begin, end])
|
|
212
|
-
end++
|
|
213
|
-
index++
|
|
214
|
-
begin = end
|
|
215
|
-
currentDetailsMiniHeight = 0
|
|
203
|
+
if (currentDetailsMiniHeight < curRemainPageHeight) {
|
|
204
|
+
currentDetailsMiniHeight += table.body.children[end]
|
|
205
|
+
deadline = end
|
|
216
206
|
} else {
|
|
217
|
-
end
|
|
218
|
-
if (end === detailsData.length) {
|
|
219
|
-
ranges.push([begin, end])
|
|
220
|
-
detailsPageHeight.push(currentDetailsMiniHeight)
|
|
221
|
-
}
|
|
207
|
+
remainDetailsHeight += table.body.children[end]
|
|
222
208
|
}
|
|
209
|
+
end++
|
|
223
210
|
}
|
|
224
211
|
|
|
212
|
+
ranges.push([begin, deadline], [deadline, end])
|
|
213
|
+
detailsPageHeight.push(currentDetailsMiniHeight, remainDetailsHeight)
|
|
214
|
+
|
|
225
215
|
return {
|
|
226
216
|
ranges,
|
|
227
217
|
detailsPageHeight
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import i18next from '../../locales'
|
|
2
|
-
import { inject, observer } from 'mobx-react'
|
|
3
|
-
import PropTypes from 'prop-types'
|
|
4
|
-
import React from 'react'
|
|
5
|
-
import { Flex, Switch } from '../components'
|
|
6
|
-
|
|
7
|
-
@inject('editStore')
|
|
8
|
-
@observer
|
|
9
|
-
class EditorCutomizedConfig extends React.Component {
|
|
10
|
-
handleAutoFilling = value => {
|
|
11
|
-
const { editStore } = this.props
|
|
12
|
-
editStore.handleChangeTableData(value)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
render() {
|
|
16
|
-
/** !!!注: 不要删除config, 否则会影响mobx的动态监听(PS: 感觉像是mobx的bug?) */
|
|
17
|
-
const {
|
|
18
|
-
editStore,
|
|
19
|
-
editStore: { config }
|
|
20
|
-
} = this.props
|
|
21
|
-
const {
|
|
22
|
-
extraSpecialConfig,
|
|
23
|
-
specialConfig
|
|
24
|
-
} = editStore.computedTableSpecialConfig
|
|
25
|
-
// 是table且具有specialConfig的附属table
|
|
26
|
-
if (editStore.computedRegionIsTable && !specialConfig) {
|
|
27
|
-
return (
|
|
28
|
-
<Flex alignCenter className='gm-padding-top-5'>
|
|
29
|
-
<div>{i18next.t('行数是否自动填充')}:</div>
|
|
30
|
-
<Switch
|
|
31
|
-
checked={extraSpecialConfig?.isAutoFilling}
|
|
32
|
-
onChange={this.handleAutoFilling}
|
|
33
|
-
/>
|
|
34
|
-
</Flex>
|
|
35
|
-
)
|
|
36
|
-
} else {
|
|
37
|
-
return null
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
EditorCutomizedConfig.propTypes = {
|
|
43
|
-
editStore: PropTypes.object,
|
|
44
|
-
extraSpecialConfig: PropTypes.object
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export default EditorCutomizedConfig
|