gm-printer 10.37.2 → 10.37.3-beta.1

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.37.2",
3
+ "version": "10.37.3-beta.1",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -94,13 +94,45 @@ class EditorStore {
94
94
 
95
95
  @action
96
96
  setSubtotalFieldsCol(arr) {
97
- // this.overallOrderShow = !this.overallOrderShow
98
- // 重新计算每页合计的单元格
99
97
  const table = this.config.contents[arr[2]]
98
+ if (!table?.subtotal?.show) return
99
+
100
+ const colSpanLength = getColSpanLength(table)
101
+ if (!table.subtotal.fields?.length) {
102
+ set(table.subtotal, {
103
+ fields: [
104
+ {
105
+ name: '每页合计:',
106
+ valueField: 'real_item_price',
107
+ colSpan: colSpanLength
108
+ }
109
+ ]
110
+ })
111
+ return
112
+ }
113
+
100
114
  const subtotalLength = table.subtotal.fields.length
101
115
  table.subtotal.fields[subtotalLength - 1].colSpan += 1
102
116
  }
103
117
 
118
+ @action
119
+ updateSelectedRegionAfterContentInsert(insertIndex) {
120
+ const updateNameIndex = name => {
121
+ if (!name) return name
122
+ const parts = name.split('.')
123
+ if (parts[0] !== 'contents') return name
124
+ const regionIndex = ~~parts[2]
125
+ if (regionIndex >= insertIndex) {
126
+ parts[2] = String(regionIndex + 1)
127
+ return parts.join('.')
128
+ }
129
+ return name
130
+ }
131
+
132
+ this.selectedRegion = updateNameIndex(this.selectedRegion)
133
+ this.selected = updateNameIndex(this.selected)
134
+ }
135
+
104
136
  @action
105
137
  setMultiDigitDecimal(bool) {
106
138
  this.isMultiDigitDecimal = bool
@@ -266,6 +298,7 @@ class EditorStore {
266
298
  { batchPrintConfig: 1, isFixLastFooter: true },
267
299
  config
268
300
  )
301
+ this.defaultTableDataKey = config.defaultTableDataKey || 'orders'
269
302
  this.originConfig = config
270
303
  this.selected = null
271
304
  this.selectedRegion = null
@@ -1205,6 +1238,8 @@ class EditorStore {
1205
1238
  }
1206
1239
  })
1207
1240
  }
1241
+ this.updateSelectedRegionAfterContentInsert(index)
1242
+ this.config = toJS(this.config)
1208
1243
  }
1209
1244
  }
1210
1245
  }
@@ -72,15 +72,13 @@ class EditorTitle extends React.Component {
72
72
  }
73
73
 
74
74
  handleTestPrint = () => {
75
- // 新增结款单每页合计标识,测试打印时原样透传到打印入口
76
- const { mockData, editStore, isSomeSubtotalTr } = this.props
75
+ const { mockData, editStore } = this.props
77
76
  doPrint(
78
77
  {
79
78
  config: toJS(editStore.config),
80
79
  data: mockData
81
80
  },
82
- true,
83
- isSomeSubtotalTr
81
+ true
84
82
  )
85
83
  }
86
84
 
@@ -142,14 +140,10 @@ class EditorTitle extends React.Component {
142
140
  EditorTitle.propTypes = {
143
141
  onSave: PropTypes.func.isRequired,
144
142
  isPurchase: PropTypes.bool,
145
- editStore: PropTypes.object,
146
- // 标识是否为结款单每页合计场景
147
- isSomeSubtotalTr: PropTypes.bool
143
+ editStore: PropTypes.object
148
144
  }
149
145
  EditorTitle.defaultProps = {
150
- isPurchase: false,
151
- // 默认按非结款单每页合计场景处理
152
- isSomeSubtotalTr: false
146
+ isPurchase: false
153
147
  }
154
148
 
155
149
  EditorTitle.wrappedComponent.propTypes = {
@@ -13,7 +13,7 @@ import EditorField from '../common/editor_edit_field'
13
13
  import EditorAddField from '../common/editor_add_field'
14
14
  import EditorPageSummary from '../common/editor_page_summary'
15
15
  import EditorCutomizedConfig from '../common/editor_customize_config'
16
- import ContextMenu from './context_menu2'
16
+ import ContextMenu from './context_menu_config'
17
17
  import i18next from '../../locales'
18
18
  import withStore from '../common/hoc_with_store'
19
19
 
@@ -51,7 +51,6 @@ class Editor extends React.Component {
51
51
  customTableConfigs,
52
52
  menuConfig
53
53
  } = this.props
54
- console.log('menuConfig', menuConfig)
55
54
  return (
56
55
  <div className='gm-printer-edit'>
57
56
  <Flex className='gm-printer-edit-title-fixed'>
@@ -1,6 +1,6 @@
1
1
  import withShadowDom from '../common/hoc_with_shadow_dom'
2
2
  import Editor from './editor'
3
- import Editor22 from './editor2'
3
+ import EditorMenuConfig from './editor_menu_config'
4
4
 
5
5
  export default withShadowDom(Editor)
6
- export const Editor2 = withShadowDom(Editor22)
6
+ export const Editor2 = withShadowDom(EditorMenuConfig)
@@ -42,8 +42,7 @@ class Editor extends React.Component {
42
42
 
43
43
  {showEditor && (
44
44
  <div className='gm-printer-edit-zone'>
45
- {/* 透传结款单每页合计标识给标题区,用于测试打印时走对应逻辑 */}
46
- <EditorTitle onSave={onSave} isSomeSubtotalTr={isSomeSubtotalTr} />
45
+ <EditorTitle onSave={onSave} />
47
46
  <Gap height='10px' />
48
47
  <EditorSelect />
49
48
  <Gap height='5px' />
@@ -0,0 +1,94 @@
1
+ import i18next from '../../locales'
2
+ import React from 'react'
3
+ import PropTypes from 'prop-types'
4
+ import CommonContextMenu from '../common/common_context_menu'
5
+ import { inject, observer } from 'mobx-react'
6
+ import _ from 'lodash'
7
+ import { Printer } from '../printer'
8
+
9
+ const blockTypeList = [
10
+ { value: '', text: i18next.t('插入文本') },
11
+ { value: 'line', text: i18next.t('插入线条') },
12
+ { value: 'image', text: i18next.t('插入图片') }
13
+ ]
14
+
15
+ @inject(stores => ({
16
+ editStore: stores.editStore,
17
+ mockData: stores.mockData
18
+ }))
19
+ @observer
20
+ class ContextMenu extends React.Component {
21
+ isMenuItemEnabled = key => {
22
+ const { menuConfig } = this.props
23
+ if (!menuConfig) return true
24
+ if (Array.isArray(menuConfig)) return menuConfig.includes(key)
25
+ if (typeof menuConfig === 'object') return !!menuConfig[key]
26
+ return true
27
+ }
28
+
29
+ hasSubtotalBtn = name => {
30
+ if (!name) return false
31
+ const arr = name.split('.')
32
+ if (!_.includes(arr, 'table')) return false
33
+ const dataKey = this.props.editStore.config.contents[arr[2]].dataKey
34
+ return dataKey === 'examiningDetail' || dataKey.startsWith('examiningDetail_')
35
+ }
36
+
37
+ handleChangeTableDataKey = (key, name) => {
38
+ const { editStore } = this.props
39
+ editStore.changeTableDataKey(name, key)
40
+ }
41
+
42
+ renderTableAction = name => {
43
+ if (!this.hasSubtotalBtn(name)) {
44
+ return null
45
+ }
46
+
47
+ const arr = name.split('.')
48
+ const { dataKey } = this.props.editStore.config.contents[arr[2]]
49
+ const keyArr = dataKey.split('_')
50
+ const isMultiActive = keyArr.includes('multi')
51
+
52
+ return (
53
+ <>
54
+ {this.isMenuItemEnabled('multi') && (
55
+ <div
56
+ onClick={this.handleChangeTableDataKey.bind(this, 'multi', name)}
57
+ className={isMultiActive ? 'active' : ''}
58
+ >
59
+ {i18next.t('双栏商品')}
60
+ </div>
61
+ )}
62
+ </>
63
+ )
64
+ }
65
+
66
+ render() {
67
+ const { editStore, mockData } = this.props
68
+ return (
69
+ <CommonContextMenu
70
+ renderTableAction={this.renderTableAction}
71
+ insertBlockList={blockTypeList}
72
+ >
73
+ <Printer
74
+ key={editStore.computedPrinterKey}
75
+ selected={editStore.selected}
76
+ selectedRegion={editStore.selectedRegion}
77
+ config={editStore.config}
78
+ data={mockData}
79
+ />
80
+ </CommonContextMenu>
81
+ )
82
+ }
83
+ }
84
+
85
+ ContextMenu.propTypes = {
86
+ editStore: PropTypes.object,
87
+ mockData: PropTypes.object,
88
+ menuConfig: PropTypes.oneOfType([
89
+ PropTypes.arrayOf(PropTypes.string),
90
+ PropTypes.object
91
+ ])
92
+ }
93
+
94
+ export default ContextMenu
@@ -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,79 @@
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
+ console.log('getDefaultTableConfig--->')
40
+ return {
41
+ dataKey: this.defaultTableDataKey,
42
+ subtotal: { show: false },
43
+ columns: [
44
+ {
45
+ head: i18next.t('表头'),
46
+ text: i18next.t('{{列.表头}}'),
47
+ style: { textAlign: 'center' },
48
+ headStyle: { textAlign: 'center' }
49
+ }
50
+ ]
51
+ }
52
+ }
53
+
54
+ @action
55
+ init(config, data) {
56
+ super.init(config, data)
57
+ this.defaultTableDataKey = 'examiningDetail'
58
+ }
59
+
60
+ @action.bound
61
+ addContent(name, index, type, tableConfig = null) {
62
+ super.addContent(name, index, type, tableConfig)
63
+ this.config = toJS(this.config)
64
+ }
65
+
66
+ @action
67
+ changeTableDataKey(name, key, options = {}) {
68
+ super.changeTableDataKey(name, key, options)
69
+ this.config = toJS(this.config)
70
+ }
71
+
72
+ @action
73
+ removeContent(name) {
74
+ super.removeContent(name)
75
+ this.config = toJS(this.config)
76
+ }
77
+ }
78
+
79
+ export default new Store({ defaultTableDataKey: 'examiningDetail' })
package/src/index.js CHANGED
@@ -3,6 +3,7 @@ import '../locales'
3
3
  import Editor, { Editor2 } from './editor'
4
4
 
5
5
  import EditorPurchase from './editor_purchase'
6
+ import EditorExaminingReport from './examining_report_editor'
6
7
  import EditorStockIn from './editor_stockin'
7
8
  import EditorStockOut from './editor_stockout'
8
9
  import EditorSettle from './editor_settle'
@@ -32,6 +33,7 @@ export {
32
33
  EditorStockIn,
33
34
  EditorStockOut,
34
35
  EditorPurchase,
36
+ EditorExaminingReport,
35
37
  EditorSettle,
36
38
  EditorStatement,
37
39
  EditorAccoutStatement,
@@ -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(