gm-printer 10.28.2 → 10.28.4-beta.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.
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.28.2",
3
+ "version": "10.28.4-beta.4",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -2,13 +2,25 @@ import i18next from '../../locales'
2
2
  import { inject, observer } from 'mobx-react'
3
3
  import PropTypes from 'prop-types'
4
4
  import React from 'react'
5
- import { Flex, Switch } from '../components'
5
+ import { Flex, Switch, Select, Option } from '../components'
6
+ import _ from 'lodash'
7
+
8
+ const initOptionsList = [
9
+ { name: i18next.t('自适应'), value: 0 },
10
+ { name: i18next.t('20行'), value: 20 },
11
+ { name: i18next.t('30行'), value: 30 },
12
+ { name: i18next.t('40行'), value: 40 }
13
+ ]
6
14
 
7
15
  @inject('editStore')
8
16
  @observer
9
17
  class EditorCutomizedConfig extends React.Component {
10
18
  handleAutoFilling = value => {
11
19
  const { editStore } = this.props
20
+ editStore.setFillRowValue(0)
21
+ if (!value) {
22
+ editStore.setFillIndex(false)
23
+ }
12
24
  editStore.handleChangeTableData(value)
13
25
  }
14
26
 
@@ -17,10 +29,21 @@ class EditorCutomizedConfig extends React.Component {
17
29
  editStore.setMultiDigitDecimal(value)
18
30
  }
19
31
 
32
+ handleFillRowValue = value => {
33
+ const { editStore } = this.props
34
+ editStore.setFillRowValue(value)
35
+ editStore.handleChangeTableData(true)
36
+ }
37
+
38
+ handleFillIndex = value => {
39
+ const { editStore } = this.props
40
+ editStore.setFillIndex(value)
41
+ }
42
+
20
43
  render() {
21
44
  const {
22
45
  editStore,
23
- editStore: { isAutoFilling, isMultiDigitDecimal }
46
+ editStore: { isAutoFilling, isMultiDigitDecimal, fillRowValue, fillIndex }
24
47
  } = this.props
25
48
  // 是table
26
49
  if (editStore.computedRegionIsTable) {
@@ -29,7 +52,29 @@ class EditorCutomizedConfig extends React.Component {
29
52
  <Flex alignCenter className='gm-padding-top-5'>
30
53
  <div>{i18next.t('行数是否自动填充')}:</div>
31
54
  <Switch checked={isAutoFilling} onChange={this.handleAutoFilling} />
55
+ {isAutoFilling && (
56
+ <Select
57
+ value={fillRowValue}
58
+ onChange={this.handleFillRowValue}
59
+ options={initOptionsList}
60
+ >
61
+ {_.map(initOptionsList, (v, k) => (
62
+ <Option key={k} value={v.value}>
63
+ {v.name}
64
+ </Option>
65
+ ))}
66
+ </Select>
67
+ )}
68
+ </Flex>
69
+
70
+ <Flex className='gm-padding-top-5 '>
71
+ <div>{i18next.t('行数是否空白行是否填充序号')}:</div>
72
+ <Switch
73
+ checked={fillIndex || false}
74
+ onChange={this.handleFillIndex}
75
+ />
32
76
  </Flex>
77
+
33
78
  <Flex className='gm-padding-top-5 gm-text-red' column>
34
79
  {i18next.t('注意:填充仅支持单栏数据使用')}
35
80
  </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,12 @@ class EditorStore {
22
22
  @observable
23
23
  remainPageHeihgt = 0
24
24
 
25
+ @observable
26
+ fillRowValue = 0
27
+
28
+ @observable
29
+ fillIndex = 0
30
+
25
31
  // 初始模板
26
32
  originConfig = null
27
33
 
@@ -59,6 +65,44 @@ class EditorStore {
59
65
  // 默认table的dataKey
60
66
  setTableDataKeyEffect() {} // 改变dataKey后,做的副作用操作
61
67
 
68
+ @action
69
+ setFillRowValue(value) {
70
+ const { autoFillConfig } = this.config
71
+ if (!this.selectedRegion && !autoFillConfig?.checked) return
72
+ this.fillRowValue = value
73
+ const dataKey =
74
+ this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
75
+ set(this.config, {
76
+ autoFillConfig: {
77
+ region: this.selectedRegion || autoFillConfig?.region,
78
+ dataKey,
79
+ checked: this.isAutoFilling,
80
+ // 填充行数字段
81
+ fillRowValue: this.fillRowValue,
82
+ fillIndex: this.fillIndex
83
+ }
84
+ })
85
+ }
86
+
87
+ @action
88
+ setFillIndex(value) {
89
+ const { autoFillConfig } = this.config
90
+ if (!this.selectedRegion && !autoFillConfig?.checked) return
91
+ this.fillIndex = value
92
+ const dataKey =
93
+ this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
94
+ set(this.config, {
95
+ autoFillConfig: {
96
+ region: this.selectedRegion || autoFillConfig?.region,
97
+ dataKey,
98
+ checked: this.isAutoFilling,
99
+ // 填充行数字段
100
+ fillRowValue: this.fillRowValue,
101
+ fillIndex: value
102
+ }
103
+ })
104
+ }
105
+
62
106
  defaultTableSubtotal = { show: false }
63
107
 
64
108
  @action
@@ -165,9 +209,14 @@ class EditorStore {
165
209
  getFilledTableData(tableData) {
166
210
  const { autoFillConfig } = this.config
167
211
  if (!this.selectedRegion && !autoFillConfig?.checked) return []
168
- const tr_count = Math.floor(
169
- this.remainPageHeihgt / this.computedTableCustomerRowHeight
170
- )
212
+ let tr_count = 0
213
+ if (this.fillRowValue === 0) {
214
+ tr_count = Math.floor(
215
+ this.remainPageHeihgt / this.computedTableCustomerRowHeight
216
+ )
217
+ } else {
218
+ tr_count = this.fillRowValue
219
+ }
171
220
 
172
221
  const filledData = {
173
222
  _isEmptyData: true // 表示是填充的空白数据
@@ -184,20 +233,27 @@ class EditorStore {
184
233
  if (!this.selectedRegion && !autoFillConfig?.checked) return
185
234
  const dataKey =
186
235
  this.computedTableSpecialConfig?.dataKey || autoFillConfig?.dataKey
236
+ // 每次都更新一下?
187
237
  const table = this.mockData._table[dataKey]
238
+ // 赋值一下
188
239
  this.setAutoFillingConfig(isAutoFilling)
189
-
240
+ this.setFillRowValue(autoFillConfig?.fillRowValue || 0)
241
+ this.setFillIndex(autoFillConfig?.fillIndex || false)
190
242
  set(this.config, {
191
243
  autoFillConfig: {
192
244
  region: this.selectedRegion || autoFillConfig?.region,
193
245
  dataKey,
194
- checked: isAutoFilling
246
+ checked: isAutoFilling,
247
+ // 填充行数字段
248
+ fillRowValue: this.fillRowValue,
249
+ fillIndex: this.fillIndex
195
250
  }
196
251
  })
197
252
 
198
253
  const hasHadEmptyData = _.some(table, data => data?._isEmptyData)
199
254
 
200
255
  // 开关打开,且之前数组不包含空数据,再进行填充
256
+
201
257
  if (isAutoFilling && !hasHadEmptyData) {
202
258
  table.push(...this.getFilledTableData(table))
203
259
  }
@@ -227,6 +283,8 @@ class EditorStore {
227
283
  this.insertPanel = 'header'
228
284
  this.mockData = data
229
285
  this.isAutoFilling = false
286
+ this.fillRowValue = 0
287
+ this.fillIndex = false
230
288
  this.isMultiDigitDecimal = false
231
289
  }
232
290
 
@@ -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,4 @@
1
+ import RadioGroup from './RadioGroup'
2
+ import Radio from './Radio'
3
+
4
+ export { RadioGroup, Radio }
@@ -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,8 @@ class ContextMenu extends React.Component {
199
199
  selected={editStore.selected}
200
200
  selectedRegion={editStore.selectedRegion}
201
201
  isAutoFilling={editStore.isAutoFilling}
202
+ fillRowValue={editStore.fillRowValue}
203
+ fillIndex={editStore.fillIndex}
202
204
  lineheight={editStore.computedTableCustomerRowHeight}
203
205
  config={editStore.config}
204
206
  data={editStore.mockData}
@@ -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,26 @@ class Printer extends React.Component {
72
73
  if (nextProps.selectedRegion !== this.props.selectedRegion) {
73
74
  this.props.printerStore.setSelectedRegion(nextProps.selectedRegion)
74
75
  }
75
- if (nextProps.isAutoFilling !== this.props.isAutoFilling) {
76
+
77
+ if (
78
+ nextProps.isAutoFilling !== this.props.isAutoFilling ||
79
+ nextProps.fillRowValue !== this.props.printerStore.fillRowValue ||
80
+ nextProps.fillIndex !== this.props.printerStore.fillIndex
81
+ ) {
76
82
  await this.props.printerStore.setAutofillConfig(nextProps.isAutoFilling)
83
+ await this.props.printerStore.setFillRowValue(nextProps.fillRowValue)
84
+ await this.props.printerStore.setFillIndex(nextProps.fillIndex)
77
85
  await this.props.printerStore.setData(nextProps.data)
78
86
  await this.props.printerStore.setReady(true)
87
+ if (nextProps.fillRowValue === 0) {
88
+ // 自适应要先reset一下 在计算高度
89
+ await this.props.printerStore.resetTableData()
90
+ await this.props.printerStore.computedPages()
91
+ }
92
+ await this.props.printerStore.changeTableData()
79
93
  await this.props.printerStore.computedPages()
80
94
  }
95
+
81
96
  if (nextProps.lineheight !== this.props.lineheight) {
82
97
  await this.props.getremainpageHeight(
83
98
  this.props.printerStore.remainPageHeight
@@ -96,19 +111,30 @@ class Printer extends React.Component {
96
111
  // didMount 代表第一次渲染完成
97
112
  printerStore.setReady(true)
98
113
 
99
- // 开始计算,获取各种数据
100
- printerStore.computedPages()
101
-
102
114
  if (config.autoFillConfig?.checked) {
103
115
  this.props.printerStore.setAutofillConfig(
104
116
  config.autoFillConfig?.checked || false
105
117
  )
106
- this.props.printerStore.changeTableData()
118
+ this.props.printerStore.setFillRowValue(
119
+ config.autoFillConfig?.fillRowValue || 0
120
+ )
121
+ this.props.printerStore.setFillIndex(
122
+ config.autoFillConfig?.fillIndex || false
123
+ )
124
+ }
125
+ // 开始计算,获取各种数据
126
+ // 如果是自适应要先计算高度,在算出行数 不是自适应就先计算行数 在计算高度
127
+ if (config.autoFillConfig?.fillRowValue === 0) {
128
+ printerStore.computedPages()
129
+ printerStore.changeTableData()
130
+ } else {
131
+ printerStore.changeTableData()
132
+ printerStore.computedPages()
107
133
  }
108
-
109
134
  // 获取剩余空白高度,传到editor
110
135
  getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
111
136
  }
137
+
112
138
  // Printer 不是立马就呈现出最终样式,有个过程。这个过程需要时间,什么 ready,不太清楚,估借 setState 来获取过程结束时刻
113
139
  this.setState({}, () => {
114
140
  this.props.onReady()
@@ -220,16 +246,19 @@ class Printer extends React.Component {
220
246
 
221
247
  renderPage() {
222
248
  const { printerStore, isSomeSubtotalTr } = this.props
223
- const { config, remainPageHeight, isAutoFilling } = printerStore
249
+ const {
250
+ config,
251
+ remainPageHeight,
252
+ isAutoFilling,
253
+ fillRowValue
254
+ } = printerStore
224
255
  return (
225
256
  <>
226
257
  {_.map(printerStore.pages, (page, i) => {
227
258
  const isLastPage = i === printerStore.pages.length - 1
228
-
229
259
  return (
230
260
  <Page key={i}>
231
261
  <Header config={config.header} pageIndex={i} />
232
-
233
262
  {_.map(page, (panel, ii) => {
234
263
  const content = config.contents[panel.index]
235
264
  const autoFillConfig = config?.autoFillConfig || {}
@@ -237,15 +266,16 @@ class Printer extends React.Component {
237
266
  isLastPage &&
238
267
  isAutoFilling &&
239
268
  panel.end &&
240
- content?.dataKey === autoFillConfig?.dataKey
241
-
242
- const end = isAutofillConfig
243
- ? panel.end +
244
- Math.floor(
269
+ content?.dataKey === autoFillConfig?.dataKey &&
270
+ fillRowValue === 0
271
+ const endList = isAutofillConfig
272
+ ? Math.floor(
245
273
  remainPageHeight /
246
274
  printerStore.computedTableCustomerRowHeight
247
275
  )
248
- : panel.end
276
+ : 0
277
+ const end = +Big(panel?.end || 0).add(endList)
278
+
249
279
  switch (panel.type) {
250
280
  case 'table':
251
281
  return (
@@ -391,6 +421,8 @@ Printer.propTypes = {
391
421
  selected: PropTypes.string,
392
422
  selectedRegion: PropTypes.string,
393
423
  isAutoFilling: PropTypes.bool,
424
+ fillRowValue: PropTypes.number,
425
+ fillIndex: PropTypes.number,
394
426
  lineheight: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
395
427
  data: PropTypes.object.isRequired,
396
428
  config: PropTypes.object.isRequired,