gm-printer 10.28.5 → 10.28.6
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/.github/workflows/release.yml +5 -4
- package/build/demo.js +54 -0
- package/build/index.html +1 -0
- package/package.json +1 -1
- package/src/common/editor_customize_config.js +19 -1
- package/src/common/editor_select.js +1 -2
- package/src/common/editor_store.js +32 -3
- package/src/components/index.js +3 -0
- package/src/components/radio/Radio.js +76 -0
- package/src/components/radio/RadioGroup.js +52 -0
- package/src/components/radio/index.js +4 -0
- package/src/components/radio/style.less +63 -0
- package/src/editor/context_menu.js +1 -0
- package/src/printer/printer.js +22 -13
- package/src/printer/store.js +38 -15
- package/src/printer/table.js +8 -6
package/build/index.html
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!doctype html><html><head></head><body><div id="appContainer"></div><script src="/demo.js"></script><script src="/demo.js"></script></body></html>
|
package/package.json
CHANGED
|
@@ -9,6 +9,9 @@ import { Flex, Switch } from '../components'
|
|
|
9
9
|
class EditorCutomizedConfig extends React.Component {
|
|
10
10
|
handleAutoFilling = value => {
|
|
11
11
|
const { editStore } = this.props
|
|
12
|
+
if (!value) {
|
|
13
|
+
editStore.setFillIndex(false)
|
|
14
|
+
}
|
|
12
15
|
editStore.handleChangeTableData(value)
|
|
13
16
|
}
|
|
14
17
|
|
|
@@ -17,10 +20,15 @@ class EditorCutomizedConfig extends React.Component {
|
|
|
17
20
|
editStore.setMultiDigitDecimal(value)
|
|
18
21
|
}
|
|
19
22
|
|
|
23
|
+
handleFillIndex = value => {
|
|
24
|
+
const { editStore } = this.props
|
|
25
|
+
editStore.setFillIndex(value)
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
render() {
|
|
21
29
|
const {
|
|
22
30
|
editStore,
|
|
23
|
-
editStore: { isAutoFilling, isMultiDigitDecimal }
|
|
31
|
+
editStore: { isAutoFilling, isMultiDigitDecimal, fillIndex }
|
|
24
32
|
} = this.props
|
|
25
33
|
// 是table
|
|
26
34
|
if (editStore.computedRegionIsTable) {
|
|
@@ -30,6 +38,16 @@ class EditorCutomizedConfig extends React.Component {
|
|
|
30
38
|
<div>{i18next.t('行数是否自动填充')}:</div>
|
|
31
39
|
<Switch checked={isAutoFilling} onChange={this.handleAutoFilling} />
|
|
32
40
|
</Flex>
|
|
41
|
+
|
|
42
|
+
{isAutoFilling && (
|
|
43
|
+
<Flex className='gm-padding-top-5 '>
|
|
44
|
+
<div>{i18next.t('空白行是否填充序号')}:</div>
|
|
45
|
+
<Switch
|
|
46
|
+
checked={fillIndex || false}
|
|
47
|
+
onChange={this.handleFillIndex}
|
|
48
|
+
/>
|
|
49
|
+
</Flex>
|
|
50
|
+
)}
|
|
33
51
|
<Flex className='gm-padding-top-5 gm-text-red' column>
|
|
34
52
|
{i18next.t('注意:填充仅支持单栏数据使用')}
|
|
35
53
|
</Flex>
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { observer, inject } from 'mobx-react'
|
|
4
|
-
import { Flex, Option, Select } from '../components'
|
|
5
|
-
import { RadioGroup, Radio } from '@gmfe/react'
|
|
4
|
+
import { Flex, Option, Select, RadioGroup, Radio } from '../components'
|
|
6
5
|
import { InputWithUnit } from '../common/component'
|
|
7
6
|
import { pageTypeMap, printDirectionList, LONG_PRINT } from '../config'
|
|
8
7
|
import _ from 'lodash'
|
|
@@ -22,6 +22,9 @@ class EditorStore {
|
|
|
22
22
|
@observable
|
|
23
23
|
remainPageHeihgt = 0
|
|
24
24
|
|
|
25
|
+
@observable
|
|
26
|
+
fillIndex = 0
|
|
27
|
+
|
|
25
28
|
// 初始模板
|
|
26
29
|
originConfig = null
|
|
27
30
|
|
|
@@ -59,6 +62,24 @@ class EditorStore {
|
|
|
59
62
|
// 默认table的dataKey
|
|
60
63
|
setTableDataKeyEffect() {} // 改变dataKey后,做的副作用操作
|
|
61
64
|
|
|
65
|
+
@action
|
|
66
|
+
setFillIndex(value) {
|
|
67
|
+
const { autoFillConfig } = this.config
|
|
68
|
+
if (!this.selectedRegion && !autoFillConfig?.checked) return
|
|
69
|
+
this.fillIndex = value
|
|
70
|
+
const dataKey =
|
|
71
|
+
this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
|
|
72
|
+
set(this.config, {
|
|
73
|
+
autoFillConfig: {
|
|
74
|
+
region: this.selectedRegion || autoFillConfig?.region,
|
|
75
|
+
dataKey,
|
|
76
|
+
checked: this.isAutoFilling,
|
|
77
|
+
// 填充行数字段
|
|
78
|
+
fillIndex: value
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
defaultTableSubtotal = { show: false }
|
|
63
84
|
|
|
64
85
|
@action
|
|
@@ -165,7 +186,9 @@ class EditorStore {
|
|
|
165
186
|
getFilledTableData(tableData) {
|
|
166
187
|
const { autoFillConfig } = this.config
|
|
167
188
|
if (!this.selectedRegion && !autoFillConfig?.checked) return []
|
|
168
|
-
|
|
189
|
+
let tr_count = 0
|
|
190
|
+
|
|
191
|
+
tr_count = Math.floor(
|
|
169
192
|
this.remainPageHeihgt / this.computedTableCustomerRowHeight
|
|
170
193
|
)
|
|
171
194
|
|
|
@@ -184,20 +207,25 @@ class EditorStore {
|
|
|
184
207
|
if (!this.selectedRegion && !autoFillConfig?.checked) return
|
|
185
208
|
const dataKey =
|
|
186
209
|
this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
|
|
210
|
+
// 每次都更新一下?
|
|
187
211
|
const table = this.mockData._table[dataKey]
|
|
212
|
+
// 赋值一下
|
|
188
213
|
this.setAutoFillingConfig(isAutoFilling)
|
|
189
|
-
|
|
214
|
+
this.setFillIndex(autoFillConfig?.fillIndex || false)
|
|
190
215
|
set(this.config, {
|
|
191
216
|
autoFillConfig: {
|
|
192
217
|
region: this.selectedRegion || autoFillConfig?.region,
|
|
193
218
|
dataKey,
|
|
194
|
-
checked: isAutoFilling
|
|
219
|
+
checked: isAutoFilling,
|
|
220
|
+
// 填充行数字段
|
|
221
|
+
fillIndex: this.fillIndex
|
|
195
222
|
}
|
|
196
223
|
})
|
|
197
224
|
|
|
198
225
|
const hasHadEmptyData = _.some(table, data => data?._isEmptyData)
|
|
199
226
|
|
|
200
227
|
// 开关打开,且之前数组不包含空数据,再进行填充
|
|
228
|
+
|
|
201
229
|
if (isAutoFilling && !hasHadEmptyData) {
|
|
202
230
|
table.push(...this.getFilledTableData(table))
|
|
203
231
|
}
|
|
@@ -227,6 +255,7 @@ class EditorStore {
|
|
|
227
255
|
this.insertPanel = 'header'
|
|
228
256
|
this.mockData = data
|
|
229
257
|
this.isAutoFilling = false
|
|
258
|
+
this.fillIndex = false
|
|
230
259
|
this.isMultiDigitDecimal = false
|
|
231
260
|
}
|
|
232
261
|
|
package/src/components/index.js
CHANGED
|
@@ -5,9 +5,12 @@ import { DropDown, DropDownItem, DropDownItems } from './dropdown'
|
|
|
5
5
|
import Dialog from './dialog'
|
|
6
6
|
import Switch from './switch'
|
|
7
7
|
import ToolTip from './tooltip'
|
|
8
|
+
import { RadioGroup, Radio } from './radio'
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
Flex,
|
|
12
|
+
RadioGroup,
|
|
13
|
+
Radio,
|
|
11
14
|
Select,
|
|
12
15
|
Option,
|
|
13
16
|
Tip,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import _ from 'lodash'
|
|
4
|
+
import classNames from 'classnames'
|
|
5
|
+
import './style.less'
|
|
6
|
+
class Radio extends React.Component {
|
|
7
|
+
render() {
|
|
8
|
+
const {
|
|
9
|
+
value,
|
|
10
|
+
checked,
|
|
11
|
+
onChange,
|
|
12
|
+
onClick,
|
|
13
|
+
children,
|
|
14
|
+
inline,
|
|
15
|
+
block,
|
|
16
|
+
name,
|
|
17
|
+
disabled,
|
|
18
|
+
className,
|
|
19
|
+
...rest
|
|
20
|
+
} = this.props
|
|
21
|
+
|
|
22
|
+
const inner = (
|
|
23
|
+
<label
|
|
24
|
+
{...rest}
|
|
25
|
+
className={classNames(
|
|
26
|
+
'gm-radio',
|
|
27
|
+
{
|
|
28
|
+
'gm-radio-inline': inline,
|
|
29
|
+
'gm-radio-block': block,
|
|
30
|
+
disabled
|
|
31
|
+
},
|
|
32
|
+
className
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
<input
|
|
36
|
+
type='radio'
|
|
37
|
+
className='gm-radio-input'
|
|
38
|
+
name={name}
|
|
39
|
+
value={value}
|
|
40
|
+
checked={checked || false}
|
|
41
|
+
onChange={onChange}
|
|
42
|
+
onClick={onClick}
|
|
43
|
+
disabled={disabled}
|
|
44
|
+
/>
|
|
45
|
+
<span className='gm-radio-span' />
|
|
46
|
+
{children}
|
|
47
|
+
</label>
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
if (!inline) {
|
|
51
|
+
return <div>{inner}</div>
|
|
52
|
+
}
|
|
53
|
+
return inner
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Radio.propTypes = {
|
|
58
|
+
checked: PropTypes.bool,
|
|
59
|
+
onChange: PropTypes.func,
|
|
60
|
+
value: PropTypes.any,
|
|
61
|
+
children: PropTypes.any,
|
|
62
|
+
disabled: PropTypes.bool,
|
|
63
|
+
inline: PropTypes.bool,
|
|
64
|
+
block: PropTypes.bool,
|
|
65
|
+
name: PropTypes.string,
|
|
66
|
+
onClick: PropTypes.func,
|
|
67
|
+
className: PropTypes.string,
|
|
68
|
+
style: PropTypes.object
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
Radio.defaultProps = {
|
|
72
|
+
onChange: _.noop,
|
|
73
|
+
onClick: _.noop
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default Radio
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types'
|
|
3
|
+
import classNames from 'classnames'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
import './style.less'
|
|
6
|
+
|
|
7
|
+
class RadioGroup extends React.Component {
|
|
8
|
+
render() {
|
|
9
|
+
const {
|
|
10
|
+
onChange,
|
|
11
|
+
value,
|
|
12
|
+
inline,
|
|
13
|
+
className,
|
|
14
|
+
children,
|
|
15
|
+
name,
|
|
16
|
+
...rest
|
|
17
|
+
} = this.props
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div {...rest} className={classNames('gm-radio-group', className)}>
|
|
21
|
+
{_.map(React.Children.toArray(children), (child, i) => {
|
|
22
|
+
return React.cloneElement(child, {
|
|
23
|
+
key: i,
|
|
24
|
+
index: i,
|
|
25
|
+
checked: child.props.value === value,
|
|
26
|
+
inline,
|
|
27
|
+
onChange: () => {
|
|
28
|
+
onChange(child.props.value)
|
|
29
|
+
},
|
|
30
|
+
name
|
|
31
|
+
})
|
|
32
|
+
})}
|
|
33
|
+
</div>
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
RadioGroup.propTypes = {
|
|
39
|
+
name: PropTypes.string.isRequired,
|
|
40
|
+
value: PropTypes.any,
|
|
41
|
+
onChange: PropTypes.func,
|
|
42
|
+
inline: PropTypes.bool,
|
|
43
|
+
children: PropTypes.any,
|
|
44
|
+
className: PropTypes.string,
|
|
45
|
+
style: PropTypes.object
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
RadioGroup.defaultProps = {
|
|
49
|
+
onChange: _.noop
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default RadioGroup
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//cover bootstrap.style for radio
|
|
2
|
+
.gm-radio {
|
|
3
|
+
cursor: pointer;
|
|
4
|
+
margin: 0;
|
|
5
|
+
|
|
6
|
+
&.gm-radio-block {
|
|
7
|
+
display: block;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
&.gm-radio-inline {
|
|
11
|
+
display: inline-block;
|
|
12
|
+
padding-right: 10px;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.gm-radio-input {
|
|
16
|
+
display: none;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.disabled {
|
|
20
|
+
cursor: not-allowed;
|
|
21
|
+
|
|
22
|
+
.gm-radio-input + .gm-radio-span {
|
|
23
|
+
cursor: not-allowed;
|
|
24
|
+
border: 1px solid #d4d8d8;
|
|
25
|
+
background: #eee;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.gm-radio-input:checked + .gm-radio-span {
|
|
29
|
+
border: 1px solid #d4d8d8;
|
|
30
|
+
|
|
31
|
+
&::after {
|
|
32
|
+
border: 3px solid #d4d8d8;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.gm-radio-input + .gm-radio-span {
|
|
38
|
+
margin-right: 5px;
|
|
39
|
+
top: 2px;
|
|
40
|
+
-webkit-appearance: none;
|
|
41
|
+
border: 1px solid #d4d8d8;
|
|
42
|
+
border-radius: 7px;
|
|
43
|
+
display: inline-block;
|
|
44
|
+
position: relative;
|
|
45
|
+
width: 14px;
|
|
46
|
+
height: 14px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.gm-radio-input:checked + .gm-radio-span {
|
|
50
|
+
border: 1px solid #56a3f2;
|
|
51
|
+
|
|
52
|
+
&::after {
|
|
53
|
+
content: '';
|
|
54
|
+
position: absolute;
|
|
55
|
+
width: 0;
|
|
56
|
+
height: 0;
|
|
57
|
+
top: 2px;
|
|
58
|
+
left: 2px;
|
|
59
|
+
border-radius: 4px;
|
|
60
|
+
border: 4px solid #56a3f2;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -199,6 +199,7 @@ class ContextMenu extends React.Component {
|
|
|
199
199
|
selected={editStore.selected}
|
|
200
200
|
selectedRegion={editStore.selectedRegion}
|
|
201
201
|
isAutoFilling={editStore.isAutoFilling}
|
|
202
|
+
fillIndex={editStore.fillIndex}
|
|
202
203
|
lineheight={editStore.computedTableCustomerRowHeight}
|
|
203
204
|
config={editStore.config}
|
|
204
205
|
data={editStore.mockData}
|
package/src/printer/printer.js
CHANGED
|
@@ -11,6 +11,7 @@ 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 Big from 'big.js'
|
|
14
15
|
|
|
15
16
|
// Header Sign Footer 相对特殊,要单独处理
|
|
16
17
|
const Header = props => (
|
|
@@ -72,12 +73,19 @@ class Printer extends React.Component {
|
|
|
72
73
|
if (nextProps.selectedRegion !== this.props.selectedRegion) {
|
|
73
74
|
this.props.printerStore.setSelectedRegion(nextProps.selectedRegion)
|
|
74
75
|
}
|
|
75
|
-
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
nextProps.isAutoFilling !== this.props.isAutoFilling ||
|
|
79
|
+
nextProps.fillIndex !== this.props.printerStore.fillIndex
|
|
80
|
+
) {
|
|
76
81
|
await this.props.printerStore.setAutofillConfig(nextProps.isAutoFilling)
|
|
82
|
+
await this.props.printerStore.setFillIndex(nextProps.fillIndex)
|
|
77
83
|
await this.props.printerStore.setData(nextProps.data)
|
|
78
84
|
await this.props.printerStore.setReady(true)
|
|
85
|
+
await this.props.printerStore.changeTableData()
|
|
79
86
|
await this.props.printerStore.computedPages()
|
|
80
87
|
}
|
|
88
|
+
|
|
81
89
|
if (nextProps.lineheight !== this.props.lineheight) {
|
|
82
90
|
await this.props.getremainpageHeight(
|
|
83
91
|
this.props.printerStore.remainPageHeight
|
|
@@ -95,20 +103,22 @@ class Printer extends React.Component {
|
|
|
95
103
|
if (batchPrintConfig !== 2) {
|
|
96
104
|
// didMount 代表第一次渲染完成
|
|
97
105
|
printerStore.setReady(true)
|
|
98
|
-
|
|
99
|
-
// 开始计算,获取各种数据
|
|
100
106
|
printerStore.computedPages()
|
|
101
|
-
|
|
102
107
|
if (config.autoFillConfig?.checked) {
|
|
103
108
|
this.props.printerStore.setAutofillConfig(
|
|
104
109
|
config.autoFillConfig?.checked || false
|
|
105
110
|
)
|
|
106
|
-
this.props.printerStore.
|
|
111
|
+
this.props.printerStore.setFillIndex(
|
|
112
|
+
config.autoFillConfig?.fillIndex || false
|
|
113
|
+
)
|
|
114
|
+
printerStore.changeTableData()
|
|
107
115
|
}
|
|
108
|
-
|
|
116
|
+
// 开始计算,获取各种数据
|
|
117
|
+
// 如果是自适应要先计算高度,在算出行数 不是自适应就先计算行数 在计算高度
|
|
109
118
|
// 获取剩余空白高度,传到editor
|
|
110
119
|
getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
|
|
111
120
|
}
|
|
121
|
+
|
|
112
122
|
// Printer 不是立马就呈现出最终样式,有个过程。这个过程需要时间,什么 ready,不太清楚,估借 setState 来获取过程结束时刻
|
|
113
123
|
this.setState({}, () => {
|
|
114
124
|
this.props.onReady()
|
|
@@ -225,11 +235,9 @@ class Printer extends React.Component {
|
|
|
225
235
|
<>
|
|
226
236
|
{_.map(printerStore.pages, (page, i) => {
|
|
227
237
|
const isLastPage = i === printerStore.pages.length - 1
|
|
228
|
-
|
|
229
238
|
return (
|
|
230
239
|
<Page key={i}>
|
|
231
240
|
<Header config={config.header} pageIndex={i} />
|
|
232
|
-
|
|
233
241
|
{_.map(page, (panel, ii) => {
|
|
234
242
|
const content = config.contents[panel.index]
|
|
235
243
|
const autoFillConfig = config?.autoFillConfig || {}
|
|
@@ -238,14 +246,14 @@ class Printer extends React.Component {
|
|
|
238
246
|
isAutoFilling &&
|
|
239
247
|
panel.end &&
|
|
240
248
|
content?.dataKey === autoFillConfig?.dataKey
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
? panel.end +
|
|
244
|
-
Math.floor(
|
|
249
|
+
const endList = isAutofillConfig
|
|
250
|
+
? Math.floor(
|
|
245
251
|
remainPageHeight /
|
|
246
252
|
printerStore.computedTableCustomerRowHeight
|
|
247
253
|
)
|
|
248
|
-
:
|
|
254
|
+
: 0
|
|
255
|
+
const end = +Big(panel?.end || 0).add(endList)
|
|
256
|
+
|
|
249
257
|
switch (panel.type) {
|
|
250
258
|
case 'table':
|
|
251
259
|
return (
|
|
@@ -391,6 +399,7 @@ Printer.propTypes = {
|
|
|
391
399
|
selected: PropTypes.string,
|
|
392
400
|
selectedRegion: PropTypes.string,
|
|
393
401
|
isAutoFilling: PropTypes.bool,
|
|
402
|
+
fillIndex: PropTypes.number,
|
|
394
403
|
lineheight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
395
404
|
data: PropTypes.object.isRequired,
|
|
396
405
|
config: PropTypes.object.isRequired,
|
package/src/printer/store.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import i18next from '../../locales'
|
|
2
|
-
import { action, observable, computed } from 'mobx'
|
|
2
|
+
import { action, observable, computed, toJS } from 'mobx'
|
|
3
3
|
import {
|
|
4
4
|
getSumTrHeight,
|
|
5
5
|
isMultiTable,
|
|
@@ -48,6 +48,10 @@ class PrinterStore {
|
|
|
48
48
|
@observable
|
|
49
49
|
isAutoFilling = false
|
|
50
50
|
|
|
51
|
+
// 是否自动行数填充
|
|
52
|
+
@observable
|
|
53
|
+
fillIndex = false
|
|
54
|
+
|
|
51
55
|
/** 是否开启多位小数,默认不开启,取两位 */
|
|
52
56
|
@observable
|
|
53
57
|
isMultiDigitDecimal = false
|
|
@@ -72,6 +76,14 @@ class PrinterStore {
|
|
|
72
76
|
@action
|
|
73
77
|
setAutofillConfig(bol) {
|
|
74
78
|
this.isAutoFilling = bol
|
|
79
|
+
if (!bol) {
|
|
80
|
+
this.fillIndex = false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@action
|
|
85
|
+
setFillIndex(value) {
|
|
86
|
+
this.fillIndex = value
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
@action
|
|
@@ -110,11 +122,11 @@ class PrinterStore {
|
|
|
110
122
|
return tableConfig
|
|
111
123
|
}
|
|
112
124
|
|
|
125
|
+
@computed
|
|
113
126
|
get tableData() {
|
|
114
127
|
if (!this.tableConfig) return []
|
|
115
128
|
const { autoFillConfig } = this.config
|
|
116
129
|
const { dataKey } = this.tableConfig
|
|
117
|
-
|
|
118
130
|
if (autoFillConfig?.region) {
|
|
119
131
|
/** 当前数据 */
|
|
120
132
|
return this.data._table[dataKey] || []
|
|
@@ -125,7 +137,7 @@ class PrinterStore {
|
|
|
125
137
|
return this.data._table[dataKey] || []
|
|
126
138
|
}
|
|
127
139
|
|
|
128
|
-
// 空数据的长度
|
|
140
|
+
@computed // 空数据的长度
|
|
129
141
|
get filledTableLen() {
|
|
130
142
|
const filledData = this.tableData.filter(x => x._isEmptyData)
|
|
131
143
|
return filledData.length
|
|
@@ -158,15 +170,12 @@ class PrinterStore {
|
|
|
158
170
|
|
|
159
171
|
getNormalTableBodyHeights(heights, dataKey) {
|
|
160
172
|
if (!this.tableConfig) return heights
|
|
161
|
-
|
|
162
173
|
const len = this.tableData.length
|
|
163
174
|
// 如果是已经开了填充配置,回显的heights包括了填充的表格部分,关闭配置时,这种情况就要去掉填充的
|
|
164
175
|
if (_.gt(heights.length, len)) return heights.slice(0, len)
|
|
165
|
-
|
|
166
176
|
const hasEmptyData = this.tableData.some(x => x._isEmptyData)
|
|
167
177
|
const isOrderCategroy = dataKey === this.config?.autoFillConfig?.dataKey
|
|
168
178
|
const { customerRowHeight = TR_BASE_HEIGHT } = this.tableConfig
|
|
169
|
-
|
|
170
179
|
if (hasEmptyData && !this.isAutoFilling && isOrderCategroy) {
|
|
171
180
|
// 如果tableData有填充的空数据, 则去掉
|
|
172
181
|
return heights.slice(0, -this.filledTableLen)
|
|
@@ -194,7 +203,6 @@ class PrinterStore {
|
|
|
194
203
|
computedData(dataKey, table, end, currentRemainTableHeight) {
|
|
195
204
|
/** 当前数据 */
|
|
196
205
|
const tableData = this.data._table[dataKey] || []
|
|
197
|
-
|
|
198
206
|
let count = 0
|
|
199
207
|
_.forEach(Array(end).fill(1), (val, i) => {
|
|
200
208
|
const details = tableData[i]?.__details || []
|
|
@@ -238,11 +246,9 @@ class PrinterStore {
|
|
|
238
246
|
return _tableData
|
|
239
247
|
}
|
|
240
248
|
)
|
|
241
|
-
|
|
242
249
|
// 插入原table数据中
|
|
243
250
|
tableData.splice(end, 1, ...splitTableData)
|
|
244
251
|
this.data._table[dataKey] = tableData
|
|
245
|
-
|
|
246
252
|
return detailsPageHeight
|
|
247
253
|
}
|
|
248
254
|
|
|
@@ -300,7 +306,6 @@ class PrinterStore {
|
|
|
300
306
|
let pageAccomodateTableHeight = +new Big(this.pageHeight)
|
|
301
307
|
.minus(currentPageHeight)
|
|
302
308
|
.toFixed(2)
|
|
303
|
-
|
|
304
309
|
const heights = this.getNormalTableBodyHeights(
|
|
305
310
|
table.body.heights,
|
|
306
311
|
dataKey
|
|
@@ -320,7 +325,6 @@ class PrinterStore {
|
|
|
320
325
|
let currentRemainTableHeight = 0
|
|
321
326
|
/** 去最小的tr高度,用于下面的计算compare,(避免特殊情况:一般来说最小tr——height = 23, 比23还小的不考虑计算) */
|
|
322
327
|
const minHeight = Math.max(getArrayMid(heights), 23)
|
|
323
|
-
|
|
324
328
|
/* 遍历表格每一行,填充表格内容 */
|
|
325
329
|
while (end < heights.length) {
|
|
326
330
|
currentTableHeight += heights[end]
|
|
@@ -416,6 +420,7 @@ class PrinterStore {
|
|
|
416
420
|
if (index === this.config.contents.length - 1) {
|
|
417
421
|
currentPageHeight += this.height?.sign
|
|
418
422
|
}
|
|
423
|
+
|
|
419
424
|
if (currentPageHeight <= this.pageHeight) {
|
|
420
425
|
// 空间充足,把信息加入 page,并轮下一个contents
|
|
421
426
|
page.push({
|
|
@@ -435,7 +440,6 @@ class PrinterStore {
|
|
|
435
440
|
}
|
|
436
441
|
}
|
|
437
442
|
this.pages.push(page)
|
|
438
|
-
|
|
439
443
|
this.remainPageHeight = +Big(this.pageHeight - currentPageHeight).toFixed(0)
|
|
440
444
|
}
|
|
441
445
|
|
|
@@ -499,14 +503,17 @@ class PrinterStore {
|
|
|
499
503
|
// 做好保护,出错就返回 text
|
|
500
504
|
try {
|
|
501
505
|
let list = this.data._table[dataKey] || this.data._table.orders
|
|
506
|
+
|
|
502
507
|
// 采购任务打印存在两个表格,第二表格没有明细,数据需要做去重
|
|
503
508
|
if (dataKey === 'purchase_no_detail') {
|
|
504
509
|
list = _.uniqBy(list, '序号')
|
|
505
510
|
}
|
|
511
|
+
|
|
506
512
|
return _.template(text, {
|
|
507
513
|
interpolate: /{{([\s\S]+?)}}/g
|
|
508
514
|
})({
|
|
509
515
|
...this.data.common,
|
|
516
|
+
|
|
510
517
|
[i18next.t('列')]: list[index],
|
|
511
518
|
[i18next.t('当前页码')]: pageIndex + 1,
|
|
512
519
|
[i18next.t('页码总数')]: this.pages.length,
|
|
@@ -590,6 +597,8 @@ class PrinterStore {
|
|
|
590
597
|
_.map(tableData[0], (val, key) => {
|
|
591
598
|
filledData[key] = ''
|
|
592
599
|
})
|
|
600
|
+
console.log(tr_count, 'tr_count')
|
|
601
|
+
|
|
593
602
|
return Array(tr_count).fill(filledData)
|
|
594
603
|
}
|
|
595
604
|
|
|
@@ -598,9 +607,23 @@ class PrinterStore {
|
|
|
598
607
|
const { autoFillConfig } = this.config
|
|
599
608
|
if (!this.isAutoFilling) return
|
|
600
609
|
const dataKey = autoFillConfig?.dataKey
|
|
601
|
-
const table = this.data._table[dataKey]
|
|
602
|
-
|
|
603
|
-
|
|
610
|
+
const table = this.data._table[dataKey]?.filter(item => !item._isEmptyData)
|
|
611
|
+
const emptyTable = this.data._table[dataKey]?.filter(
|
|
612
|
+
item => item._isEmptyData
|
|
613
|
+
)
|
|
614
|
+
const lastKey = _.findLast(table, item => item?.序号)?.序号 + 1
|
|
615
|
+
const fillList = _.map(
|
|
616
|
+
emptyTable?.length === 0 ? this.getFilledTableData(table) : emptyTable,
|
|
617
|
+
(item, index) => {
|
|
618
|
+
if (this.fillIndex) {
|
|
619
|
+
return { ...item, 序号: index + lastKey }
|
|
620
|
+
} else {
|
|
621
|
+
return { ...item, 序号: '' }
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
)
|
|
625
|
+
console.log(fillList, 'fillList')
|
|
626
|
+
table.push(...fillList)
|
|
604
627
|
this.data._table[dataKey] = table
|
|
605
628
|
}
|
|
606
629
|
}
|
package/src/printer/table.js
CHANGED
|
@@ -19,6 +19,7 @@ import SubtotalTr from './table_subtotal_tr'
|
|
|
19
19
|
import PageSummary from './page_summary'
|
|
20
20
|
import OverallOrder from './table_overallOrder_tr'
|
|
21
21
|
import DiyOverallOrder from './table_diy_overallOrder_tr'
|
|
22
|
+
import { toJS } from 'mobx'
|
|
22
23
|
|
|
23
24
|
@inject('printerStore')
|
|
24
25
|
@observer
|
|
@@ -40,7 +41,7 @@ class Table extends React.Component {
|
|
|
40
41
|
const ths = tHead.querySelectorAll('th') || []
|
|
41
42
|
const trs = $table.querySelectorAll('tbody tr') || []
|
|
42
43
|
const detailsDiv = $table.querySelectorAll('tr td .b-table-details')
|
|
43
|
-
|
|
44
|
+
// 问题出现在这里
|
|
44
45
|
printerStore.setHeight(name, getHeight($table))
|
|
45
46
|
|
|
46
47
|
printerStore.setTable(name, {
|
|
@@ -168,11 +169,9 @@ class Table extends React.Component {
|
|
|
168
169
|
printerStore,
|
|
169
170
|
isSomeSubtotalTr
|
|
170
171
|
} = this.props
|
|
171
|
-
|
|
172
172
|
// 数据
|
|
173
173
|
dataKey = getDataKey(dataKey, arrange)
|
|
174
174
|
const tableData = printerStore.data._table[dataKey] || []
|
|
175
|
-
|
|
176
175
|
// 列
|
|
177
176
|
const columns = this.getColumns()
|
|
178
177
|
// 列宽固定(避免跳页bug)
|
|
@@ -225,7 +224,6 @@ class Table extends React.Component {
|
|
|
225
224
|
}
|
|
226
225
|
return tdStyle
|
|
227
226
|
}
|
|
228
|
-
|
|
229
227
|
return (
|
|
230
228
|
<table
|
|
231
229
|
style={{
|
|
@@ -261,6 +259,7 @@ class Table extends React.Component {
|
|
|
261
259
|
))}
|
|
262
260
|
</tr>
|
|
263
261
|
</thead>
|
|
262
|
+
|
|
264
263
|
<tbody>
|
|
265
264
|
{_.map(_.range(range.begin, range.end), i => {
|
|
266
265
|
const _special = tableData[i] && tableData[i]._special
|
|
@@ -271,11 +270,14 @@ class Table extends React.Component {
|
|
|
271
270
|
return <SpecialTr key={i} config={config} data={_special} />
|
|
272
271
|
// 如果项为空对象展现一个占满一行的td
|
|
273
272
|
const isItemNone = !_.keys(tableData[i]).length
|
|
274
|
-
|
|
275
273
|
return (
|
|
276
274
|
<tr style={{ height: `${customerRowHeight}px` }} key={i}>
|
|
277
275
|
{isItemNone ? (
|
|
278
|
-
|
|
276
|
+
!printerStore?.isAutoFilling ? (
|
|
277
|
+
<td colSpan='99' />
|
|
278
|
+
) : (
|
|
279
|
+
<></>
|
|
280
|
+
)
|
|
279
281
|
) : (
|
|
280
282
|
_.map(columns, (col, j) => {
|
|
281
283
|
return (
|