gm-printer 10.33.8 → 10.33.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.33.8",
3
+ "version": "10.33.10",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -149,17 +149,6 @@ class CommonContextMenu extends React.Component {
149
149
  })
150
150
  }
151
151
 
152
- handleAddContentWithConfig = (diff, type, tableConfig) => {
153
- const { editStore } = this.props
154
- const { name } = this.state
155
-
156
- editStore.addContentByDiff(name, diff, type, tableConfig)
157
-
158
- this.setState({
159
- name: null
160
- })
161
- }
162
-
163
152
  handleInsertImage = imgURL => {
164
153
  this.handleInsertBlock('image', imgURL)
165
154
  }
@@ -251,6 +240,7 @@ class CommonContextMenu extends React.Component {
251
240
  <Hr />
252
241
  </>
253
242
  )}
243
+
254
244
  <div onClick={this.handleAddContent.bind(this, 0, '')}>
255
245
  {i18next.t('向上插入区域块')}
256
246
  </div>
@@ -306,7 +296,7 @@ class CommonContextMenu extends React.Component {
306
296
  }
307
297
 
308
298
  renderPanel = () => {
309
- let { insertBlockList, customTableConfigs } = this.props
299
+ let { insertBlockList } = this.props
310
300
  const { name } = this.state
311
301
  const arr = name.split('.')
312
302
  const type = arr[0]
@@ -338,21 +328,6 @@ class CommonContextMenu extends React.Component {
338
328
  )
339
329
  })}
340
330
 
341
- {customTableConfigs &&
342
- customTableConfigs.map(customConfig => (
343
- <div
344
- key={customConfig.label}
345
- onClick={this.handleAddContentWithConfig.bind(
346
- this,
347
- 1,
348
- 'table',
349
- customConfig.tableConfig
350
- )}
351
- >
352
- {customConfig.label}
353
- </div>
354
- ))}
355
-
356
331
  {arr[0] === 'contents' && (
357
332
  <>
358
333
  <Hr />
@@ -435,7 +410,6 @@ CommonContextMenu.propTypes = {
435
410
  editStore: PropTypes.object,
436
411
  insertBlockList: PropTypes.array.isRequired,
437
412
  renderTableAction: PropTypes.func,
438
- customTableConfigs: PropTypes.array,
439
413
  children: PropTypes.element.isRequired
440
414
  }
441
415
 
@@ -72,7 +72,7 @@ class Text extends React.Component {
72
72
  }
73
73
 
74
74
  render() {
75
- const { value, placeholder, style, className, ...rest } = this.props
75
+ const { value, placeholder, style, className } = this.props
76
76
  return (
77
77
  <input
78
78
  className={classNames('gm-printer-edit-input', className)}
@@ -81,7 +81,6 @@ class Text extends React.Component {
81
81
  placeholder={placeholder}
82
82
  onChange={this.handleChange}
83
83
  style={style}
84
- {...rest}
85
84
  />
86
85
  )
87
86
  }
@@ -132,6 +131,10 @@ Textarea.propTypes = {
132
131
  class TextPX extends React.Component {
133
132
  handleChange = value => {
134
133
  const { onChange } = this.props
134
+ // 理论上这里只会有字符串和 event 两种类型
135
+ if (Object.prototype.toString.call(value) === '[object Object]') {
136
+ value = value.target.value
137
+ }
135
138
  if (value === '') {
136
139
  onChange('')
137
140
  } else if (value.endsWith('%')) {
@@ -3,7 +3,6 @@ import { inject, observer } from 'mobx-react'
3
3
  import PropTypes from 'prop-types'
4
4
  import React from 'react'
5
5
  import { Flex, Switch } from '../components'
6
- import { Text } from './component'
7
6
 
8
7
  @inject('editStore')
9
8
  @observer
@@ -26,43 +25,10 @@ class EditorCutomizedConfig extends React.Component {
26
25
  editStore.setFillIndex(value)
27
26
  }
28
27
 
29
- handleTaxFreeProductRateDisplay = e => {
30
- const value = e.target.value
31
-
32
- const { editStore } = this.props
33
- // 限制10位以内,如果超过则截断
34
- const trimmedValue = value.length > 10 ? value.slice(0, 10) : value
35
- editStore.setTaxFreeProductRateDisplay(trimmedValue)
36
-
37
- // 如果选中了表格,同时更新表格配置
38
- if (editStore.selectedRegion && editStore.computedRegionIsTable) {
39
- const arr = editStore.selectedRegion.split('.')
40
- const tableConfig = editStore.config.contents[arr[2]]
41
-
42
- const dataKey = tableConfig.dataKey
43
- const tableData = editStore.mockData._table[dataKey]
44
-
45
- if (dataKey === 'taxRateSales' && tableData?.length) {
46
- const list = tableData.map(item => {
47
- if (item._origin && !Number(item._origin?.tax_rate)) {
48
- item['税率'] = value
49
- }
50
- return item
51
- })
52
- editStore.updateTableData(dataKey, list)
53
- }
54
- }
55
- }
56
-
57
28
  render() {
58
29
  const {
59
30
  editStore,
60
- editStore: {
61
- isAutoFilling,
62
- isMultiDigitDecimal,
63
- fillIndex,
64
- taxFreeProductRateDisplay
65
- }
31
+ editStore: { isAutoFilling, isMultiDigitDecimal, fillIndex }
66
32
  } = this.props
67
33
  // 是table
68
34
  if (editStore.computedRegionIsTable) {
@@ -92,15 +58,6 @@ class EditorCutomizedConfig extends React.Component {
92
58
  onChange={this.handleMultiDigitDecimal}
93
59
  />
94
60
  </Flex>
95
- <Flex alignCenter className='gm-padding-top-5'>
96
- <div>{i18next.t('免税产品税率显示')}:</div>
97
- <Text
98
- value={taxFreeProductRateDisplay || ''}
99
- onChange={this.handleTaxFreeProductRateDisplay}
100
- placeholder={i18next.t('请输入')}
101
- maxLength={10}
102
- />
103
- </Flex>
104
61
  </>
105
62
  )
106
63
  } else {
@@ -57,10 +57,6 @@ class EditorStore {
57
57
  @observable
58
58
  isMultiDigitDecimal = false
59
59
 
60
- /** 免税产品税率显示 */
61
- @observable
62
- taxFreeProductRateDisplay = ''
63
-
64
60
  defaultTableDataKey = 'orders'
65
61
 
66
62
  // 默认table的dataKey
@@ -105,23 +101,11 @@ class EditorStore {
105
101
  this.isMultiDigitDecimal = bool
106
102
  set(this.config, {
107
103
  specialControlConfig: {
108
- ...this.config.specialControlConfig,
109
104
  multiDigitDecimal: bool
110
105
  }
111
106
  })
112
107
  }
113
108
 
114
- @action
115
- setTaxFreeProductRateDisplay(value) {
116
- this.taxFreeProductRateDisplay = value
117
- set(this.config, {
118
- specialControlConfig: {
119
- ...this.config.specialControlConfig,
120
- taxFreeProductRateDisplay: value
121
- }
122
- })
123
- }
124
-
125
109
  @observable
126
110
  overallOrderShow = false
127
111
 
@@ -273,9 +257,6 @@ class EditorStore {
273
257
  this.isAutoFilling = false
274
258
  this.fillIndex = false
275
259
  this.isMultiDigitDecimal = false
276
-
277
- this.taxFreeProductRateDisplay =
278
- config?.specialControlConfig?.taxFreeProductRateDisplay || ''
279
260
  }
280
261
 
281
262
  @action
@@ -498,11 +479,6 @@ class EditorStore {
498
479
  }
499
480
  }
500
481
 
501
- @action.bound
502
- updateTableData(dataKey, tableData) {
503
- this.mockData._table[dataKey] = tableData
504
- }
505
-
506
482
  @action
507
483
  clearAllTableEmptyData() {
508
484
  const tableData = this.mockData._table
@@ -1040,20 +1016,17 @@ class EditorStore {
1040
1016
  }
1041
1017
 
1042
1018
  @action
1043
- addContentByDiff(name, diff, type, tableConfig = null) {
1019
+ addContentByDiff(name, diff, type) {
1044
1020
  const arr = name.split('.')
1045
-
1046
1021
  if (arr.length === 3 && arr[0] === 'contents') {
1047
- this.addContent(name, ~~arr[2] + diff, type, tableConfig)
1022
+ this.addContent(name, ~~arr[2] + diff, type)
1048
1023
  } else if (arr.length === 5 && arr[3] === 'column') {
1049
- this.addContent(name, ~~arr[2] + diff, type, tableConfig)
1050
- } else {
1051
- console.warn('addContentByDiff: Invalid name format', name)
1024
+ this.addContent(name, ~~arr[2] + diff, type)
1052
1025
  }
1053
1026
  }
1054
1027
 
1055
1028
  @action.bound
1056
- addContent(name, index, type, tableConfig = null) {
1029
+ addContent(name, index, type) {
1057
1030
  const defaultTableDataKey = this.defaultTableDataKey
1058
1031
  const defaultTableSubtotal = this.defaultTableSubtotal
1059
1032
 
@@ -1063,89 +1036,27 @@ class EditorStore {
1063
1036
  if ((arr.length === 3 || arr.length === 5) && arr[0] === 'contents') {
1064
1037
  if (index >= 0 && index <= this.config.contents.length) {
1065
1038
  if (type === 'table') {
1066
- // 如果传入了自定义表格配置,使用自定义配置,否则使用默认配置
1067
- const finalTableConfig = tableConfig
1068
- ? {
1069
- // 先展开自定义配置,支持传入其他配置项
1070
- ...tableConfig,
1071
- // 然后设置必需的属性,确保都有值
1072
- type: 'table',
1073
- className: tableConfig.className || '',
1074
- specialConfig: tableConfig.specialConfig || {
1075
- style: {}
1039
+ this.config.contents.splice(index, 0, {
1040
+ type: 'table',
1041
+ className: '',
1042
+ specialConfig: { style: {} },
1043
+ dataKey: defaultTableDataKey, // 默认
1044
+ subtotal: defaultTableSubtotal, // 默认的每页合计配置
1045
+ customerTag: false, // 特殊标记,用于提供用户干预功能标记
1046
+ columns: [
1047
+ {
1048
+ head: i18next.t('表头'),
1049
+ headStyle: {
1050
+ textAlign: 'center',
1051
+ minWidth: '30px'
1076
1052
  },
1077
- dataKey: tableConfig.dataKey || defaultTableDataKey,
1078
- subtotal:
1079
- tableConfig.subtotal !== undefined
1080
- ? tableConfig.subtotal
1081
- : defaultTableSubtotal,
1082
- customerTag:
1083
- tableConfig.customerTag !== undefined
1084
- ? tableConfig.customerTag
1085
- : false,
1086
- columns: tableConfig.columns || [
1087
- {
1088
- head: i18next.t('表头'),
1089
- headStyle: {
1090
- textAlign: 'center',
1091
- minWidth: '30px'
1092
- },
1093
- text: i18next.t('内容'),
1094
- style: {
1095
- textAlign: 'center'
1096
- }
1097
- }
1098
- ]
1099
- }
1100
- : {
1101
- type: 'table',
1102
- className: '',
1103
- specialConfig: { style: {} },
1104
- dataKey: defaultTableDataKey, // 默认
1105
- subtotal: defaultTableSubtotal, // 默认的每页合计配置
1106
- customerTag: false, // 特殊标记,用于提供用户干预功能标记
1107
- columns: [
1108
- {
1109
- head: i18next.t('表头'),
1110
- headStyle: {
1111
- textAlign: 'center',
1112
- minWidth: '30px'
1113
- },
1114
- text: i18next.t('内容'),
1115
- style: {
1116
- textAlign: 'center'
1117
- }
1118
- }
1119
- ]
1120
- }
1121
-
1122
- // 确保数据源存在,如果不存在则初始化为空数组
1123
- const dataKey = finalTableConfig.dataKey
1124
- if (!this.mockData._table) {
1125
- this.mockData._table = {}
1126
- }
1127
- if (!this.mockData._table[dataKey]) {
1128
- this.mockData._table[dataKey] = []
1129
- }
1130
-
1131
- // 如果 dataKey 是 taxRateSales,并且有 head 为 custom_filed 的列,修改其 text
1132
- if (
1133
- finalTableConfig.dataKey === 'taxRateSales' &&
1134
- finalTableConfig.columns &&
1135
- this.mockData._table[dataKey] &&
1136
- this.mockData._table[dataKey].length > 0
1137
- ) {
1138
- const firstRowData = this.mockData._table[dataKey][0]
1139
-
1140
- finalTableConfig.columns.forEach(column => {
1141
- if (column.head === 'custom_filed' && firstRowData.custom_filed) {
1142
- // 将 text 设置为第一行的 custom_filed 值
1143
- column.text = firstRowData.custom_filed
1053
+ text: i18next.t('内容'),
1054
+ style: {
1055
+ textAlign: 'center'
1056
+ }
1144
1057
  }
1145
- })
1146
- }
1147
-
1148
- this.config.contents.splice(index, 0, finalTableConfig)
1058
+ ]
1059
+ })
1149
1060
  } else {
1150
1061
  this.config.contents.splice(index, 0, {
1151
1062
  blocks: [],
@@ -44,12 +44,6 @@ class ContextMenu extends React.Component {
44
44
  // 多位小数
45
45
  editStore.setMultiDigitDecimal(specialControlConfig?.multiDigitDecimal)
46
46
  }
47
- if (specialControlConfig?.taxFreeProductRateDisplay !== undefined) {
48
- // 免税产品税率显示
49
- editStore.setTaxFreeProductRateDisplay(
50
- specialControlConfig?.taxFreeProductRateDisplay || ''
51
- )
52
- }
53
47
  }
54
48
 
55
49
  /**
@@ -202,12 +196,11 @@ class ContextMenu extends React.Component {
202
196
  }
203
197
 
204
198
  render() {
205
- const { editStore, customTableConfigs } = this.props
199
+ const { editStore } = this.props
206
200
  return (
207
201
  <CommonContextMenu
208
202
  renderTableAction={this.renderOrderActionBtn}
209
203
  insertBlockList={blockTypeList}
210
- customTableConfigs={customTableConfigs}
211
204
  >
212
205
  <Printer
213
206
  key={editStore.computedPrinterKey}
@@ -227,7 +220,6 @@ class ContextMenu extends React.Component {
227
220
  }
228
221
  ContextMenu.propTypes = {
229
222
  editStore: PropTypes.object,
230
- mockData: PropTypes.object,
231
- customTableConfigs: PropTypes.array
223
+ mockData: PropTypes.object
232
224
  }
233
225
  export default ContextMenu
@@ -47,8 +47,7 @@ class Editor extends React.Component {
47
47
  addFields,
48
48
  showNewDate,
49
49
  mockData,
50
- mergeClassificationAndLabel,
51
- customTableConfigs
50
+ mergeClassificationAndLabel
52
51
  } = this.props
53
52
 
54
53
  return (
@@ -107,7 +106,7 @@ class Editor extends React.Component {
107
106
  )}
108
107
 
109
108
  <div className='gm-printer-edit-wrap'>
110
- <ContextMenu customTableConfigs={customTableConfigs} />
109
+ <ContextMenu />
111
110
  </div>
112
111
  </div>
113
112
  )
@@ -121,8 +120,7 @@ Editor.propTypes = {
121
120
  mockData: PropTypes.object.isRequired,
122
121
  addFields: PropTypes.object.isRequired,
123
122
  showNewDate: PropTypes.bool,
124
- mergeClassificationAndLabel: PropTypes.bool,
125
- customTableConfigs: PropTypes.array
123
+ mergeClassificationAndLabel: PropTypes.bool
126
124
  }
127
125
 
128
126
  Editor.defaultProps = {
@@ -15,10 +15,9 @@ const regExp = text => {
15
15
  * 每列统计
16
16
  * @param key
17
17
  * @param dataList
18
- * @param summaryFieldsResultToNumber 需要转换为数字的汇总字段
19
18
  * @returns {*|string}
20
19
  */
21
- const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
20
+ const sumCol = (key, dataList) => {
22
21
  let result
23
22
  try {
24
23
  result = dataList
@@ -27,10 +26,6 @@ const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
27
26
  return acc
28
27
  }, Big(0))
29
28
  .toFixed(2)
30
-
31
- if (summaryFieldsResultToNumber.includes(key)) {
32
- result = Number(result)
33
- }
34
29
  } catch (e) {
35
30
  result = ''
36
31
  }
@@ -58,14 +53,6 @@ const PageSummary = props => {
58
53
  const tableData = printerStore.data._table[_dataKey] || []
59
54
  const currentPageTableData = tableData.slice(range.begin, range.end)
60
55
 
61
- // 需要转换为数字的汇总字段
62
- let summaryFieldsResultToNumber =
63
- printerStore.config?.summaryFieldsResultToNumber
64
- if (summaryFieldsResultToNumber) {
65
- summaryFieldsResultToNumber = summaryFieldsResultToNumber.map(item =>
66
- regExp(item)
67
- )
68
- }
69
56
  return (
70
57
  <tr>
71
58
  {_.map(columns, (col, index) => {
@@ -79,7 +66,7 @@ const PageSummary = props => {
79
66
  summaryConfig.summaryColumns
80
67
  .map(text => regExp(text))
81
68
  .includes(key) && key
82
- ? sumCol(key, currentPageTableData, summaryFieldsResultToNumber)
69
+ ? sumCol(key, currentPageTableData)
83
70
  : ' '
84
71
  }
85
72
 
@@ -537,8 +537,7 @@ class PrinterStore {
537
537
  if (
538
538
  dataKey !== 'purchase_detail_one_row' &&
539
539
  dataKey !== 'purchase_independent_rol_sku' &&
540
- dataKey !== 'purchase_independent_rol_address' &&
541
- dataKey !== 'taxRateSales'
540
+ dataKey !== 'purchase_independent_rol_address'
542
541
  ) {
543
542
  return null
544
543
  }
@@ -546,7 +545,6 @@ class PrinterStore {
546
545
 
547
546
  const interpolate = /{{([\s\S]+?)}}/g
548
547
  const match = interpolate.exec(text)
549
- if (!match) return null
550
548
  // 显示在表格上的 th 名
551
549
  const showFiledText = match[1].split('.')[1]
552
550
 
@@ -557,7 +555,7 @@ class PrinterStore {
557
555
  let newPageCellRowSpan = 1
558
556
  for (let i = index - 1; i < list.length; i--) {
559
557
  const record = list[i]
560
- if (record && record._origin && record._origin.rowSpan > 1) {
558
+ if (record._origin.rowSpan > 1) {
561
559
  newPageCellRowSpan = record._origin.rowSpan - (index - i)
562
560
  break
563
561
  }
@@ -224,16 +224,6 @@ class Table extends React.Component {
224
224
  }
225
225
  return tdStyle
226
226
  }
227
-
228
- const headText = col => {
229
- if (dataKey === 'taxRateSales') {
230
- return col.head === 'custom_field'
231
- ? tableData?.[0]?.custom_field || ''
232
- : col.headAlias
233
- }
234
- return col.head
235
- }
236
-
237
227
  return (
238
228
  <table
239
229
  style={{
@@ -264,7 +254,7 @@ class Table extends React.Component {
264
254
  onDrop={this.handleDrop}
265
255
  onDragOver={this.handleDragOver}
266
256
  >
267
- {headText(col)}
257
+ {col.head}
268
258
  </th>
269
259
  ))}
270
260
  </tr>
@@ -274,17 +264,10 @@ class Table extends React.Component {
274
264
  {_.map(_.range(range.begin, range.end), i => {
275
265
  const _special = tableData[i] && tableData[i]._special
276
266
  const _specialText = tableData[i] && tableData[i]._specialText
277
- const _customTr = tableData[i] && tableData[i]._customTr
278
-
279
267
  if (_specialText)
280
268
  return <CategoryTr key={i} config={config} data={_specialText} />
281
269
  if (_special)
282
270
  return <SpecialTr key={i} config={config} data={_special} />
283
-
284
- if (_customTr) {
285
- return <tr dangerouslySetInnerHTML={{ __html: _customTr }} />
286
- }
287
-
288
271
  // 如果项为空对象展现一个占满一行的td
289
272
  const isItemNone = !_.keys(tableData[i]).length
290
273
  return (
@@ -325,9 +308,7 @@ class Table extends React.Component {
325
308
  ...getTdStyle(j, col.style),
326
309
  ...col.style
327
310
  }}
328
- {...(rowSpan > 1 && {
329
- rowSpan: rowSpan
330
- })}
311
+ {...(rowSpan > 1 && { rowSpan: rowSpan })}
331
312
  className={classNames({
332
313
  active:
333
314
  getTableColumnName(name, col.index) ===