gm-printer 11.0.1 → 11.0.2-beta.2

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,85 @@
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import _ from 'lodash'
4
+ import { Flex } from '../components'
5
+ import { Gap, Title } from '../common/component'
6
+ import editStore from './store'
7
+ import { observer, inject } from 'mobx-react'
8
+ import EditorTitle from '../common/editor_title'
9
+ import EditorSelect from '../common/editor_select'
10
+ import EditorField from '../common/editor_edit_field'
11
+ import EditorAddField from '../common/editor_add_field'
12
+ import ContextMenu from './context_menu'
13
+ import i18next from '../../locales'
14
+ import withStore from '../common/hoc_with_store'
15
+
16
+ const tableDataKeyList = [
17
+ {
18
+ value: 'examiningDetail',
19
+ text: i18next.t('检测明细'),
20
+ hasSubtotalBtn: true
21
+ }
22
+ ]
23
+
24
+ @withStore(editStore)
25
+ @inject('editStore')
26
+ @observer
27
+ class Editor extends React.Component {
28
+ render() {
29
+ const { onSave, showEditor, addFields, menuConfig } = this.props
30
+
31
+ return (
32
+ <div className='gm-printer-edit'>
33
+ <Flex className='gm-printer-edit-title-fixed'>
34
+ <Title
35
+ title={i18next.t('模板预览')}
36
+ text={
37
+ <span className='gm-text-desc gm-padding-left-5'>
38
+ {i18next.t(
39
+ '说明:选中内容进行编辑,可拖动字段移动位置,右键使用更多功能'
40
+ )}
41
+ </span>
42
+ }
43
+ />
44
+ </Flex>
45
+
46
+ {showEditor && (
47
+ <div className='gm-printer-edit-zone'>
48
+ <EditorTitle onSave={onSave} />
49
+ <Gap height='10px' />
50
+ <EditorSelect />
51
+ <Gap height='5px' />
52
+ <EditorField tableDataKeyList={tableDataKeyList} />
53
+ <Gap height='5px' />
54
+ <EditorAddField addFields={addFields} />
55
+
56
+ <div id='gm-printer-tip' />
57
+ <div id='gm-printer-modal' />
58
+ </div>
59
+ )}
60
+
61
+ <div className='gm-printer-edit-wrap'>
62
+ <ContextMenu menuConfig={menuConfig} />
63
+ </div>
64
+ </div>
65
+ )
66
+ }
67
+ }
68
+
69
+ Editor.propTypes = {
70
+ config: PropTypes.object.isRequired,
71
+ onSave: PropTypes.func,
72
+ showEditor: PropTypes.bool,
73
+ mockData: PropTypes.object.isRequired,
74
+ addFields: PropTypes.object.isRequired,
75
+ menuConfig: PropTypes.oneOfType([
76
+ PropTypes.arrayOf(PropTypes.string),
77
+ PropTypes.object
78
+ ])
79
+ }
80
+
81
+ Editor.defaultProps = {
82
+ onSave: _.noop
83
+ }
84
+
85
+ export default Editor
@@ -0,0 +1,4 @@
1
+ import withShadowDom from '../common/hoc_with_shadow_dom'
2
+ import Editor from './editor'
3
+
4
+ export default withShadowDom(Editor)
@@ -0,0 +1,78 @@
1
+ import EditorStore from '../common/editor_store'
2
+ import { action, toJS } from 'mobx'
3
+ import i18next from '../../locales'
4
+
5
+ const DEFAULT_TABLE_COLUMNS = [
6
+ {
7
+ head: i18next.t('序号'),
8
+ text: i18next.t('{{列.序号}}'),
9
+ style: { textAlign: 'center' },
10
+ headStyle: { textAlign: 'center' }
11
+ },
12
+ {
13
+ head: i18next.t('样品名称'),
14
+ text: i18next.t('{{列.样品名称}}'),
15
+ style: { textAlign: 'center' },
16
+ headStyle: { textAlign: 'center' }
17
+ },
18
+ {
19
+ head: i18next.t('样品编码'),
20
+ text: i18next.t('{{列.样品编码}}'),
21
+ style: { textAlign: 'center' },
22
+ headStyle: { textAlign: 'center' }
23
+ },
24
+ {
25
+ head: i18next.t('检测结果'),
26
+ text: i18next.t('{{列.检测结果}}'),
27
+ style: { textAlign: 'center' },
28
+ headStyle: { textAlign: 'center' }
29
+ }
30
+ ]
31
+
32
+ class Store extends EditorStore {
33
+ constructor({ defaultTableDataKey }) {
34
+ super()
35
+ this.defaultTableDataKey = defaultTableDataKey
36
+ }
37
+
38
+ getDefaultTableConfig() {
39
+ return {
40
+ dataKey: this.defaultTableDataKey,
41
+ subtotal: { show: false },
42
+ columns: [
43
+ {
44
+ head: i18next.t('表头'),
45
+ text: i18next.t('{{列.表头}}'),
46
+ style: { textAlign: 'center' },
47
+ headStyle: { textAlign: 'center' }
48
+ }
49
+ ]
50
+ }
51
+ }
52
+
53
+ @action
54
+ init(config, data) {
55
+ super.init(config, data)
56
+ this.defaultTableDataKey = 'examiningDetail'
57
+ }
58
+
59
+ @action.bound
60
+ addContent(name, index, type, tableConfig = null) {
61
+ super.addContent(name, index, type, tableConfig)
62
+ this.config = toJS(this.config)
63
+ }
64
+
65
+ @action
66
+ changeTableDataKey(name, key, options = {}) {
67
+ super.changeTableDataKey(name, key, options)
68
+ this.config = toJS(this.config)
69
+ }
70
+
71
+ @action
72
+ removeContent(name) {
73
+ super.removeContent(name)
74
+ this.config = toJS(this.config)
75
+ }
76
+ }
77
+
78
+ export default new Store({ defaultTableDataKey: 'examiningDetail' })
package/src/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  // ‼️优先初始化语言设置(必须先初始化语言)
2
2
  import '../locales'
3
- import Editor from './editor'
3
+ import Editor, { Editor2 } from './editor'
4
+
4
5
  import EditorPurchase from './editor_purchase'
6
+ import EditorExaminingReport from './examining_report_editor'
5
7
  import EditorStockIn from './editor_stockin'
6
8
  import EditorStockOut from './editor_stockout'
7
9
  import EditorSettle from './editor_settle'
@@ -27,9 +29,11 @@ export { setLocale } from '../locales'
27
29
 
28
30
  export {
29
31
  Editor,
32
+ Editor2,
30
33
  EditorStockIn,
31
34
  EditorStockOut,
32
35
  EditorPurchase,
36
+ EditorExaminingReport,
33
37
  EditorSettle,
34
38
  EditorStatement,
35
39
  EditorAccoutStatement,
@@ -1,11 +1,6 @@
1
1
  import React from 'react'
2
2
  import _ from 'lodash'
3
- import {
4
- getDataKey,
5
- isMultiTable,
6
- formatSumWithPrecision,
7
- getHighPrecisionField
8
- } from '../util'
3
+ import { getDataKey, isMultiTable } from '../util'
9
4
  import Big from 'big.js'
10
5
  import { observer } from 'mobx-react'
11
6
  import { get } from 'mobx'
@@ -21,27 +16,17 @@ const regExp = text => {
21
16
  * @param key
22
17
  * @param dataList
23
18
  * @param summaryFieldsResultToNumber 需要转换为数字的汇总字段
24
- * @param formatter 精度格式化函数,由 stationv2 传入 AmountPrecisionUtil(precision_control)
25
- * @param highPrecisionMapping 高精度字段映射,优先用高精度字段求和
26
19
  * @returns {*|string}
27
20
  */
28
- const sumCol = (
29
- key,
30
- dataList,
31
- summaryFieldsResultToNumber = [],
32
- formatter,
33
- highPrecisionMapping
34
- ) => {
21
+ const sumCol = (key, dataList, summaryFieldsResultToNumber = []) => {
35
22
  let result
36
23
  try {
37
- // 优先使用高精度字段求和
38
- const sumKey = getHighPrecisionField(key, highPrecisionMapping)
39
- const sum = dataList.reduce((acc, item) => {
40
- const val = item[sumKey] ?? item._origin?.[sumKey] ?? 0
41
- acc = acc.plus(val)
42
- return acc
43
- }, Big(0))
44
- result = formatSumWithPrecision(sum, formatter)
24
+ result = dataList
25
+ .reduce((acc, item) => {
26
+ acc = acc.plus(item[key] || 0)
27
+ return acc
28
+ }, Big(0))
29
+ .toFixed(2)
45
30
 
46
31
  if (summaryFieldsResultToNumber.includes(key)) {
47
32
  result = Number(result)
@@ -81,8 +66,6 @@ const PageSummary = props => {
81
66
  regExp(item)
82
67
  )
83
68
  }
84
- const formatter = printerStore.config?.payAmountFormatter
85
- const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
86
69
  return (
87
70
  <tr>
88
71
  {_.map(columns, (col, index) => {
@@ -96,13 +79,7 @@ const PageSummary = props => {
96
79
  summaryConfig.summaryColumns
97
80
  .map(text => regExp(text))
98
81
  .includes(key) && key
99
- ? sumCol(
100
- key,
101
- currentPageTableData,
102
- summaryFieldsResultToNumber,
103
- formatter,
104
- highPrecisionMapping
105
- )
82
+ ? sumCol(key, currentPageTableData, summaryFieldsResultToNumber)
106
83
  : ' '
107
84
  }
108
85
 
@@ -103,10 +103,10 @@ class Printer extends React.Component {
103
103
  componentDidMount() {
104
104
  const { printerStore, config, getremainpageHeight } = this.props
105
105
  const batchPrintConfig = config.batchPrintConfig
106
- // 连续打印不需要计算
106
+ // didMount 代表第一次渲染完成
107
+ printerStore.setReady(true)
108
+ // 连续打印不需要分页计算
107
109
  if (batchPrintConfig !== 2) {
108
- // didMount 代表第一次渲染完成
109
- printerStore.setReady(true)
110
110
  printerStore.computedPages()
111
111
  if (config.autoFillConfig?.checked) {
112
112
  this.props.printerStore.setAutofillConfig(
@@ -1,5 +1,5 @@
1
1
  import i18next from '../../locales'
2
- import { action, observable, computed, toJS } from 'mobx'
2
+ import { action, observable, computed } from 'mobx'
3
3
  import {
4
4
  getSumTrHeight,
5
5
  isMultiTable,
@@ -530,7 +530,7 @@ class PrinterStore {
530
530
  })({
531
531
  ...this.data.common,
532
532
  [i18next.t('当前页码')]: pageIndex + 1,
533
- [i18next.t('页码总数')]: this.pages.length,
533
+ [i18next.t('页码总数')]: Math.max(1, this.pages.length),
534
534
  price: price
535
535
  })
536
536
  } catch (err) {
@@ -604,7 +604,7 @@ class PrinterStore {
604
604
 
605
605
  [i18next.t('列')]: list[index],
606
606
  [i18next.t('当前页码')]: pageIndex + 1,
607
- [i18next.t('页码总数')]: this.pages.length,
607
+ [i18next.t('页码总数')]: Math.max(1, this.pages.length),
608
608
  price: price // 提供一个价格处理函数
609
609
  })
610
610
  } catch (err) {
@@ -626,7 +626,7 @@ class PrinterStore {
626
626
  ...this.data.common,
627
627
  [i18next.t('列')]: list[index],
628
628
  [i18next.t('当前页码')]: pageIndex + 1,
629
- [i18next.t('页码总数')]: this.pages.length,
629
+ [i18next.t('页码总数')]: Math.max(1, this.pages.length),
630
630
  price: price // 提供一个价格处理函数
631
631
  })
632
632
  res =
@@ -2,11 +2,7 @@ import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import _ from 'lodash'
4
4
  // import Big from 'big.js'
5
- import {
6
- coverDigit2Uppercase,
7
- getDataKey,
8
- formatSumWithPrecision
9
- } from '../util'
5
+ import { coverDigit2Uppercase, getDataKey } from '../util'
10
6
  import { observer } from 'mobx-react'
11
7
  import classNames from 'classnames'
12
8
  import Big from 'big.js'
@@ -19,30 +15,20 @@ const DiyOverallOrder = props => {
19
15
  } = props
20
16
  const tableData = printerStore.data._table[getDataKey(dataKey)] || []
21
17
 
22
- const formatter = printerStore.config?.payAmountFormatter
23
- const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
24
-
25
18
  // 计算合计
26
19
  const sumData = field => {
27
- // 查找高精度字段,有则直接从原始数据取值,避免 templateTable 的精度损失
28
- const hpField = highPrecisionMapping?.[field]
29
- const sum = _.reduce(
20
+ return _.reduce(
30
21
  tableData,
31
22
  (a, b, i) => {
32
23
  let result = a
33
- if (hpField) {
34
- result = a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
35
- } else {
36
- const bRes = printerStore
37
- .templateTable(field, dataKey, i, pageIndex)
38
- .replace(/\(\)/g, '')
39
- result = a.plus(+bRes || 0)
40
- }
24
+ const bRes = printerStore
25
+ .templateTable(field, dataKey, i, pageIndex)
26
+ .replace(/\(\)/g, '')
27
+ result = a.plus(+bRes || 0)
41
28
  return result
42
29
  },
43
30
  Big(0)
44
- )
45
- return formatSumWithPrecision(sum, formatter)
31
+ ).toFixed(2)
46
32
  }
47
33
 
48
34
  if (!diyOverallOrder?.show || !printerStore?.ready) {
@@ -1,12 +1,7 @@
1
1
  import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import _ from 'lodash'
4
- import {
5
- coverDigit2Uppercase,
6
- getDataKey,
7
- isMultiTable,
8
- formatSumWithPrecision
9
- } from '../util'
4
+ import { coverDigit2Uppercase, getDataKey, isMultiTable } from '../util'
10
5
  import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
11
6
  import { observer } from 'mobx-react'
12
7
  import classNames from 'classnames'
@@ -48,20 +43,14 @@ const DiySummary = props => {
48
43
  // 判断是否是多栏表格
49
44
  const isMulti = isMultiTable(dataKey)
50
45
 
51
- const formatter = printerStore.config?.payAmountFormatter
52
- const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
53
-
54
46
  // 计算合计
55
47
  const sumData = field => {
56
- // 查找高精度字段,有则直接从原始数据取值,避免 templateTable 的精度损失
57
- const hpField = highPrecisionMapping?.[field]
58
-
59
48
  if (isMulti) {
60
- // 多栏表格暂不使用高精度字段,保持原有 templateTable 逻辑
61
- const sum = _.reduce(
49
+ return _.reduce(
62
50
  tableData,
63
51
  (a, b, i) => {
64
52
  let result = a
53
+ // 先通过 templateTable 获取原始字段的值
65
54
  const bRes = getRes(field, i)
66
55
  result = a.plus(+bRes || 0)
67
56
 
@@ -76,24 +65,10 @@ const DiySummary = props => {
76
65
  return result
77
66
  },
78
67
  Big(0)
79
- )
80
- return formatSumWithPrecision(sum, formatter)
81
- }
82
-
83
- // 单栏:有高精度字段则直接从原始数据取值
84
- if (hpField) {
85
- const sum = _.reduce(
86
- tableData,
87
- (a, b, i) => {
88
- return a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
89
- },
90
- Big(0)
91
- )
92
- return formatSumWithPrecision(sum, formatter)
68
+ ).toFixed(2)
93
69
  }
94
70
 
95
- // 兜底:无高精度字段,使用 templateTable
96
- const sum = _.reduce(
71
+ return _.reduce(
97
72
  tableData,
98
73
  (a, b, i) => {
99
74
  let result = a
@@ -102,8 +77,7 @@ const DiySummary = props => {
102
77
  return result
103
78
  },
104
79
  Big(0)
105
- )
106
- return formatSumWithPrecision(sum, formatter)
80
+ ).toFixed(2)
107
81
 
108
82
  function getRes(field, i) {
109
83
  return printerStore
@@ -4,11 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import _ from 'lodash'
5
5
  import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
6
6
  import Big from 'big.js'
7
- import {
8
- coverDigit2Uppercase,
9
- getDataKey,
10
- formatSumWithPrecision
11
- } from '../util'
7
+ import { coverDigit2Uppercase, getDataKey } from '../util'
12
8
  import { observer } from 'mobx-react'
13
9
  import { get } from 'mobx'
14
10
  import classNames from 'classnames'
@@ -49,47 +45,58 @@ const SubtotalTr = props => {
49
45
  isSomeSubtotalTr
50
46
  } = props
51
47
  const tableData = printerStore.data._table[getDataKey(dataKey, arrange)] || []
52
-
53
48
  // 计算合计
54
- const sumData2 = (list, field, formatter, highPrecisionMapping) => {
55
- // 在字段名转换前,查找是否有高精度字段
56
- const hpField = highPrecisionMapping?.[field]
49
+ const sumData = (list, field) => {
50
+ return _.reduce(
51
+ list,
52
+ (a, b) => {
53
+ let result = a
54
+
55
+ const _origin = b._origin || {}
56
+ const _origin2 = b['_origin' + MULTI_SUFFIX] || {}
57
+ const _origin3 = b['_origin' + MULTI_SUFFIX3] || {}
58
+
59
+ result = a.plus(_origin[field] || 0)
60
+ if (_origin2[field]) {
61
+ result = result.plus(_origin2[field])
62
+ }
63
+ if (_origin3[field]) {
64
+ result = result.plus(_origin3[field])
65
+ }
66
+ return result
67
+ },
68
+ Big(0)
69
+ ).toFixed(2)
70
+ }
57
71
 
72
+ // 计算合计
73
+ const sumData2 = (list, field) => {
58
74
  // 兼容之前
59
75
  if (field === 'total_item_price') field = '下单金额'
60
76
  if (field === 'real_item_price') field = '出库金额'
61
77
  if (field === 'settle_money2') field = '结算金额'
62
78
  if (field === 'total_money2') field = '金额'
63
-
64
- const sum = _.reduce(
79
+ return _.reduce(
65
80
  list,
66
81
  (a, b) => {
67
82
  let result = a
68
- // 优先使用高精度字段(从 _origin 中取原始数据)
69
- if (hpField) {
70
- result = a.plus(b._origin?.[hpField] ?? b[hpField] ?? 0)
71
- } else {
72
- result = a.plus(b[field] || 0)
73
- }
74
- if (!hpField && b?.[field + MULTI_SUFFIX]) {
83
+ result = a.plus(b[field] || 0)
84
+ if (b?.[field + MULTI_SUFFIX]) {
75
85
  result = result.plus(b?.[field + MULTI_SUFFIX])
76
86
  }
77
- if (!hpField && b?.[field + MULTI_SUFFIX3]) {
87
+ if (b?.[field + MULTI_SUFFIX3]) {
78
88
  result = result.plus(b?.[field + MULTI_SUFFIX3])
79
89
  }
80
90
  return result
81
91
  },
82
92
  Big(0)
83
- )
84
- return formatSumWithPrecision(sum, formatter)
93
+ ).toFixed(2)
85
94
  }
86
95
 
87
96
  const getData = field => {
88
97
  const data = printerStore.data.common
89
98
  return data?.[field] ?? ''
90
99
  }
91
- const formatter = printerStore.config?.payAmountFormatter
92
- const highPrecisionMapping = printerStore.config?.highPrecisionFieldMapping
93
100
  // 每页小计
94
101
  // show 是否展示小计,fields<Array> 合计的字段和展现的name,displayName 是否显示名字
95
102
  if (show && printerStore.ready) {
@@ -100,12 +107,7 @@ const SubtotalTr = props => {
100
107
  const sum = {}
101
108
 
102
109
  _.each(fields, v => {
103
- sum[v.name] = sumData2(
104
- list,
105
- v.valueField,
106
- formatter,
107
- highPrecisionMapping
108
- )
110
+ sum[v.name] = sumData2(list, v.valueField)
109
111
  })
110
112
  let subtotalStr = ''
111
113
  for (const name in sum) {
@@ -163,14 +165,9 @@ const SubtotalTr = props => {
163
165
  {item.type === 'useSummarize'
164
166
  ? getData(item.valueField)
165
167
  : index === 0
166
- ? sumData2(
167
- list,
168
- item.valueField,
169
- formatter,
170
- highPrecisionMapping
171
- )
168
+ ? sumData2(list, item.valueField)
172
169
  : ''}
173
- {/* {index === 0 ? sumData(list, item.valueField, formatter) : ''} */}
170
+ {/* {index === 0 ? sumData(list, item.valueField) : ''} */}
174
171
  </span>
175
172
  {subtotal?.needUpperCase && ( // 是否需要大写金额
176
173
  <span>
@@ -180,12 +177,7 @@ const SubtotalTr = props => {
180
177
  : index === 0
181
178
  ? '大写:' +
182
179
  coverDigit2Uppercase(
183
- sumData2(
184
- list,
185
- item.valueField,
186
- formatter,
187
- highPrecisionMapping
188
- )
180
+ sumData2(list, item.valueField)
189
181
  )
190
182
  : ''}
191
183
  </span>
package/src/util.js CHANGED
@@ -353,27 +353,6 @@ const collectGroups = (tableData, range, key = '_collect') => {
353
353
  }
354
354
  }
355
355
 
356
- /**
357
- * 使用精度格式化函数格式化 Big.js 求和结果,无格式化函数时兜底 toFixed(2)
358
- * @param {Big} sum - Big.js 实例
359
- * @param {Function} [formatter] - 可选的精度格式化函数
360
- * @returns {string}
361
- */
362
- const formatSumWithPrecision = (sum, formatter) => {
363
- return formatter ? formatter(sum).toFixed() : sum.toFixed(2)
364
- }
365
-
366
- /**
367
- * 根据高精度字段映射,获取求和时应使用的字段名
368
- * 如果字段有对应的高精度版本,返回高精度字段名,否则返回原字段名
369
- * @param {string} field - 原始字段名
370
- * @param {Object} mapping - 高精度字段映射,格式:{ normalField: 'high_precision_field' }
371
- * @returns {string}
372
- */
373
- const getHighPrecisionField = (field, mapping) => {
374
- return mapping?.[field] || field
375
- }
376
-
377
356
  export {
378
357
  collectGroups,
379
358
  getHeight,
@@ -394,7 +373,5 @@ export {
394
373
  caclSingleDetailsPageHeight,
395
374
  getArrayMid,
396
375
  getColSpanLength,
397
- getOverallOrderTrHeight,
398
- formatSumWithPrecision,
399
- getHighPrecisionField
376
+ getOverallOrderTrHeight
400
377
  }