gm-printer 10.39.4-beta.2 → 10.39.4-beta.21
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/build/demo.js +9 -9
- package/locales/en.json +3 -0
- package/locales/th.json +3 -0
- package/locales/zh-HK.json +3 -0
- package/package.json +1 -1
- package/src/common/common_context_menu.js +6 -4
- package/src/common/component.js +64 -8
- package/src/common/data_key_util.js +35 -0
- package/src/common/editor_edit_field.js +288 -167
- package/src/common/editor_store.js +230 -42
- package/src/common/hoc_with_store.js +9 -0
- package/src/common/style.lesss +43 -0
- package/src/common/util.js +58 -4
- package/src/editor/context_menu.js +17 -0
- package/src/editor/store.js +13 -0
- package/src/editor_purchase/editor.js +2 -1
- package/src/editor_purchase/editor_special_table.js +39 -17
- package/src/editor_purchase/editor_sum_table.js +5 -1
- package/src/editor_purchase/store.js +48 -45
- package/src/finance_voucher/components/table_subtotal_tr.js +12 -18
- package/src/index.js +6 -2
- package/src/printer/block.js +154 -4
- package/src/printer/compute_pages.js +122 -0
- package/src/printer/index.js +3 -1
- package/src/printer/long_print_table/index.js +14 -4
- package/src/printer/multi_column.js +1 -0
- package/src/printer/page_summary.js +3 -1
- package/src/printer/printer.js +23 -3
- package/src/printer/store.js +141 -91
- package/src/printer/table.js +11 -3
- package/src/printer/table_diy_overallOrder_tr.js +8 -15
- package/src/printer/table_diy_summary_tr.js +18 -35
- package/src/printer/table_overallOrder_tr.js +49 -37
- package/src/printer/table_special_tr.js +17 -2
- package/src/printer/table_subtotal_tr.js +100 -16
- package/src/util.js +34 -8
- package/yarn-error.log +372 -152
|
@@ -21,6 +21,7 @@ import withStore from '../common/hoc_with_store'
|
|
|
21
21
|
class Editor extends React.Component {
|
|
22
22
|
render() {
|
|
23
23
|
const { onSave, showEditor, addFields, isPurchase } = this.props
|
|
24
|
+
const editFieldConfig = addFields?.editFieldConfig
|
|
24
25
|
|
|
25
26
|
return (
|
|
26
27
|
<div className='gm-printer-edit'>
|
|
@@ -43,7 +44,7 @@ class Editor extends React.Component {
|
|
|
43
44
|
<Gap height='10px' />
|
|
44
45
|
<EditorSelect isPurchase={isPurchase} />
|
|
45
46
|
<Gap height='5px' />
|
|
46
|
-
<EditorField />
|
|
47
|
+
<EditorField editFieldConfig={editFieldConfig} />
|
|
47
48
|
<Gap height='5px' />
|
|
48
49
|
<EditorAddField addFields={addFields} />
|
|
49
50
|
<Gap height='5px' />
|
|
@@ -14,6 +14,11 @@ import {
|
|
|
14
14
|
} from '../common/component'
|
|
15
15
|
import _ from 'lodash'
|
|
16
16
|
import { inject, observer } from 'mobx-react'
|
|
17
|
+
import {
|
|
18
|
+
buildDataKey,
|
|
19
|
+
getDataKeyPrefix,
|
|
20
|
+
isDetailOneRowSelectKey,
|
|
21
|
+
} from '../common/data_key_util'
|
|
17
22
|
|
|
18
23
|
const dataKeyList = [
|
|
19
24
|
{ value: 'purchase_no_detail', text: i18next.t('不打印明细') },
|
|
@@ -57,8 +62,11 @@ const detailSortOptionsForMerchant = [
|
|
|
57
62
|
@observer
|
|
58
63
|
class TableDetailEditor extends React.Component {
|
|
59
64
|
handleDataKeyChange = dataKey => {
|
|
60
|
-
const { editStore } = this.props
|
|
61
|
-
editStore.setPurchaseTableKey(
|
|
65
|
+
const { editStore, addFields } = this.props
|
|
66
|
+
editStore.setPurchaseTableKey(
|
|
67
|
+
dataKey,
|
|
68
|
+
addFields.specialTableConfig
|
|
69
|
+
)
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
handlePurchaseSettingKeyChange = dataKey => {
|
|
@@ -74,28 +82,32 @@ class TableDetailEditor extends React.Component {
|
|
|
74
82
|
}
|
|
75
83
|
|
|
76
84
|
handleDetailAddField = ({ key, value }) => {
|
|
77
|
-
const { editStore, config } = this.props
|
|
78
|
-
if (editStore.computedDataKey
|
|
79
|
-
// 序号 {{列.序号}}
|
|
85
|
+
const { editStore, config, addFields } = this.props
|
|
86
|
+
if (isDetailOneRowSelectKey(editStore.computedDataKey)) {
|
|
80
87
|
const transform = str => {
|
|
81
88
|
return str
|
|
82
|
-
.replace(/{{\s*([^}]+)\s*}}/g, '{{$1}}')
|
|
89
|
+
.replace(/{{\s*([^}]+)\s*}}/g, '{{$1}}')
|
|
83
90
|
.replace(/{{([^.\s}]+)}}/g, '{{列.$1}}')
|
|
84
91
|
}
|
|
92
|
+
const prefix = getDataKeyPrefix(config.dataKey)
|
|
93
|
+
const rolSkuKey = buildDataKey(prefix, 'independent_rol_sku')
|
|
94
|
+
const rolAddressKey = buildDataKey(prefix, 'independent_rol_address')
|
|
85
95
|
if (
|
|
86
96
|
config.purchaseSettingKey === 'goods' &&
|
|
87
|
-
config.dataKey !==
|
|
97
|
+
config.dataKey !== rolSkuKey
|
|
88
98
|
) {
|
|
89
|
-
editStore.setPurchaseTableKey(
|
|
99
|
+
editStore.setPurchaseTableKey(rolSkuKey, addFields.specialTableConfig)
|
|
90
100
|
} else if (
|
|
91
101
|
config.purchaseSettingKey === 'merchant' &&
|
|
92
|
-
config.dataKey !==
|
|
102
|
+
config.dataKey !== rolAddressKey
|
|
93
103
|
) {
|
|
94
|
-
editStore.setPurchaseTableKey(
|
|
104
|
+
editStore.setPurchaseTableKey(
|
|
105
|
+
rolAddressKey,
|
|
106
|
+
addFields.specialTableConfig
|
|
107
|
+
)
|
|
95
108
|
}
|
|
96
109
|
|
|
97
110
|
editStore.addFieldToTable({ key, value: transform(value) })
|
|
98
|
-
|
|
99
111
|
return
|
|
100
112
|
}
|
|
101
113
|
editStore.specialTextAddField('*' + value)
|
|
@@ -113,7 +125,7 @@ class TableDetailEditor extends React.Component {
|
|
|
113
125
|
|
|
114
126
|
render() {
|
|
115
127
|
const {
|
|
116
|
-
addFields: { detailFields },
|
|
128
|
+
addFields: { detailFields, specialTableConfig = {} },
|
|
117
129
|
editStore
|
|
118
130
|
} = this.props
|
|
119
131
|
const {
|
|
@@ -123,18 +135,28 @@ class TableDetailEditor extends React.Component {
|
|
|
123
135
|
specialConfig: { template_text, style }
|
|
124
136
|
} = this.props.config
|
|
125
137
|
|
|
138
|
+
const title = specialTableConfig.title || i18next.t('设置采购明细')
|
|
139
|
+
const label = specialTableConfig.label || i18next.t('采购明细')
|
|
140
|
+
// 外部可整体覆盖下拉选项(dataKeyList),否则按 hideDataKeys 过滤默认列表
|
|
141
|
+
const baseDataKeyList = specialTableConfig.dataKeyList || dataKeyList
|
|
142
|
+
const hideDataKeys = specialTableConfig.hideDataKeys || []
|
|
143
|
+
const visibleDataKeyList = _.filter(
|
|
144
|
+
baseDataKeyList,
|
|
145
|
+
v => !hideDataKeys.includes(v.value)
|
|
146
|
+
)
|
|
147
|
+
|
|
126
148
|
return (
|
|
127
149
|
<div>
|
|
128
|
-
<Title title={
|
|
150
|
+
<Title title={title} />
|
|
129
151
|
<Gap />
|
|
130
152
|
<Flex alignCenter className='gm-padding-top-5'>
|
|
131
|
-
<div>{
|
|
153
|
+
<div>{label}:</div>
|
|
132
154
|
<Select
|
|
133
155
|
className='gm-printer-edit-select'
|
|
134
156
|
value={editStore.computedDataKey}
|
|
135
157
|
onChange={this.handleDataKeyChange}
|
|
136
158
|
>
|
|
137
|
-
{_.map(
|
|
159
|
+
{_.map(visibleDataKeyList, v => (
|
|
138
160
|
<Option key={v.value} value={v.value}>
|
|
139
161
|
{v.text}
|
|
140
162
|
</Option>
|
|
@@ -142,7 +164,7 @@ class TableDetailEditor extends React.Component {
|
|
|
142
164
|
</Select>
|
|
143
165
|
</Flex>
|
|
144
166
|
|
|
145
|
-
{editStore.computedDataKey
|
|
167
|
+
{isDetailOneRowSelectKey(editStore.computedDataKey) && (
|
|
146
168
|
<>
|
|
147
169
|
<Flex alignCenter className='gm-padding-top-5'>
|
|
148
170
|
<div>{i18next.t('打印设置')}:</div>
|
|
@@ -210,7 +232,7 @@ class TableDetailEditor extends React.Component {
|
|
|
210
232
|
</Flex>
|
|
211
233
|
</div>
|
|
212
234
|
|
|
213
|
-
{editStore.computedDataKey
|
|
235
|
+
{!isDetailOneRowSelectKey(editStore.computedDataKey) && (
|
|
214
236
|
<>
|
|
215
237
|
<div className='gm-padding-top-5'>
|
|
216
238
|
<div>{i18next.t('字段设置')}:</div>
|
|
@@ -16,10 +16,14 @@ class TableDetailEditor extends Component {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
render() {
|
|
19
|
-
const { editStore } = this.props
|
|
20
19
|
const {
|
|
21
20
|
addFields: { sumTableConfig }
|
|
22
21
|
} = this.props
|
|
22
|
+
// 业务侧可传 sumTableConfig.hide=true 隐藏「汇总表」开关;默认展示
|
|
23
|
+
if (sumTableConfig?.hide) {
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
const { editStore } = this.props
|
|
23
27
|
if (editStore.computedRegionIsTable) {
|
|
24
28
|
const arr = editStore.selectedRegion.split('.')
|
|
25
29
|
const tableConfig = editStore.config.contents[arr[2]]
|
|
@@ -1,55 +1,71 @@
|
|
|
1
1
|
import EditorStore from '../common/editor_store'
|
|
2
2
|
import { action, observable } from 'mobx'
|
|
3
3
|
import i18next from '../../locales'
|
|
4
|
+
import { getDataKeySuffix, isLastColDataKey } from '../common/data_key_util'
|
|
5
|
+
|
|
6
|
+
const getPurchaseDefaultDetailText = () =>
|
|
7
|
+
i18next.t('{{采购数量_采购单位}}{{采购单位}}*{{商户名}}*{{商品备注}}')
|
|
8
|
+
|
|
9
|
+
/** 创建/切换「单列-最后一列」时,明细列 text 应与 template_text 一致 */
|
|
10
|
+
const resolveDetailTemplateText = (tableConfig, specialTableConfig) => {
|
|
11
|
+
const existing = tableConfig.specialConfig?.template_text
|
|
12
|
+
if (existing) return existing
|
|
13
|
+
if (specialTableConfig && specialTableConfig.defaultDetailText !== undefined) {
|
|
14
|
+
return specialTableConfig.defaultDetailText
|
|
15
|
+
}
|
|
16
|
+
return getPurchaseDefaultDetailText()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const syncLastColColumnText = (tableConfig) => {
|
|
20
|
+
if (!isLastColDataKey(tableConfig.dataKey)) return
|
|
21
|
+
const templateText = tableConfig.specialConfig?.template_text
|
|
22
|
+
if (!templateText) return
|
|
23
|
+
const specialCol = tableConfig.columns?.find((o) => o.isSpecialColumn)
|
|
24
|
+
if (specialCol) specialCol.text = templateText
|
|
25
|
+
}
|
|
4
26
|
|
|
5
27
|
class Store extends EditorStore {
|
|
6
28
|
constructor({ defaultTableDataKey }) {
|
|
7
29
|
super()
|
|
8
|
-
this.defaultTableDataKey = defaultTableDataKey
|
|
30
|
+
this.defaultTableDataKey = defaultTableDataKey
|
|
9
31
|
}
|
|
10
32
|
|
|
11
33
|
@observable
|
|
12
34
|
customerTag = false
|
|
13
35
|
|
|
14
|
-
/* start---------设置采购明细相关--------- */
|
|
15
36
|
@action.bound
|
|
16
|
-
|
|
17
|
-
|
|
37
|
+
init(config, data) {
|
|
38
|
+
super.init(config, data)
|
|
39
|
+
config?.contents?.forEach((tableConfig) => {
|
|
40
|
+
if (tableConfig?.type === 'table') syncLastColColumnText(tableConfig)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@action.bound
|
|
45
|
+
setPurchaseTableKey(dataKey, specialTableConfig) {
|
|
18
46
|
this.selected = null
|
|
19
47
|
this.setTableDataKey(dataKey)
|
|
20
48
|
|
|
21
49
|
const arr = this.selectedRegion.split('.')
|
|
22
50
|
const tableConfig = this.config.contents[arr[2]]
|
|
23
51
|
|
|
24
|
-
|
|
25
|
-
const newCols = tableConfig.columns.filter(o => !o.isSpecialColumn)
|
|
52
|
+
const newCols = tableConfig.columns.filter((o) => !o.isSpecialColumn)
|
|
26
53
|
tableConfig.columns.replace(newCols)
|
|
27
54
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
dataKey === 'purchase_last_col' ||
|
|
31
|
-
dataKey === 'purchase_last_col_noLineBreak'
|
|
32
|
-
) {
|
|
55
|
+
if (isLastColDataKey(dataKey)) {
|
|
56
|
+
const templateText = resolveDetailTemplateText(tableConfig, specialTableConfig)
|
|
33
57
|
tableConfig.columns.push({
|
|
34
58
|
head: i18next.t('明细'),
|
|
35
59
|
headStyle: { textAlign: 'center' },
|
|
36
60
|
style: { textAlign: 'left' },
|
|
37
61
|
isSpecialColumn: true,
|
|
38
62
|
separator: '+',
|
|
39
|
-
// detailsType: 'purchase_last_col',
|
|
40
63
|
specialDetailsKey: '__details',
|
|
41
|
-
text:
|
|
42
|
-
'{{采购数量_采购单位}}{{采购单位}}*{{商户名}}*{{商品备注}}'
|
|
43
|
-
)
|
|
64
|
+
text: templateText,
|
|
44
65
|
})
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
?
|
|
48
|
-
tableConfig.columns.length - 1
|
|
49
|
-
].detailLastColType = 'purchase_last_col')
|
|
50
|
-
: (tableConfig.columns[
|
|
51
|
-
tableConfig.columns.length - 1
|
|
52
|
-
].detailLastColType = 'purchase_last_col_noLineBreak')
|
|
66
|
+
const suffix = getDataKeySuffix(dataKey)
|
|
67
|
+
tableConfig.columns[tableConfig.columns.length - 1].detailLastColType =
|
|
68
|
+
suffix === 'last_col' ? 'purchase_last_col' : 'purchase_last_col_noLineBreak'
|
|
53
69
|
}
|
|
54
70
|
}
|
|
55
71
|
|
|
@@ -59,13 +75,9 @@ class Store extends EditorStore {
|
|
|
59
75
|
const tableConfig = this.config.contents[arr[2]]
|
|
60
76
|
|
|
61
77
|
tableConfig.specialConfig.template_text = value
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
66
|
-
) {
|
|
67
|
-
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
68
|
-
specialCol.text = value
|
|
78
|
+
if (isLastColDataKey(tableConfig.dataKey)) {
|
|
79
|
+
const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
|
|
80
|
+
if (specialCol) specialCol.text = value
|
|
69
81
|
}
|
|
70
82
|
}
|
|
71
83
|
|
|
@@ -75,13 +87,9 @@ class Store extends EditorStore {
|
|
|
75
87
|
const tableConfig = this.config.contents[arr[2]]
|
|
76
88
|
|
|
77
89
|
tableConfig.specialConfig.style = value
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
82
|
-
) {
|
|
83
|
-
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
84
|
-
specialCol.style = value
|
|
90
|
+
if (isLastColDataKey(tableConfig.dataKey)) {
|
|
91
|
+
const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
|
|
92
|
+
if (specialCol) specialCol.style = value
|
|
85
93
|
}
|
|
86
94
|
}
|
|
87
95
|
|
|
@@ -91,17 +99,12 @@ class Store extends EditorStore {
|
|
|
91
99
|
const tableConfig = this.config.contents[arr[2]]
|
|
92
100
|
|
|
93
101
|
tableConfig.specialConfig.template_text += fieldText
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
tableConfig.dataKey === 'purchase_last_col_noLineBreak'
|
|
98
|
-
) {
|
|
99
|
-
const specialCol = tableConfig.columns.find(o => o.isSpecialColumn)
|
|
100
|
-
specialCol.text += fieldText
|
|
102
|
+
if (isLastColDataKey(tableConfig.dataKey)) {
|
|
103
|
+
const specialCol = tableConfig.columns.find((o) => o.isSpecialColumn)
|
|
104
|
+
if (specialCol) specialCol.text += fieldText
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
|
|
104
|
-
/* end---------设置采购明细相关--------- */
|
|
105
108
|
@action.bound
|
|
106
109
|
switchCustomerTag(val) {
|
|
107
110
|
const arr = this.selectedRegion.split('.')
|
|
@@ -3,8 +3,7 @@ import i18next from '../../../locales'
|
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
4
|
import _ from 'lodash'
|
|
5
5
|
import { MULTI_SUFFIX } from '../../config'
|
|
6
|
-
import
|
|
7
|
-
import { coverDigit2Uppercase, getDataKey } from '../../util'
|
|
6
|
+
import { coverDigit2Uppercase, getDataKey, maskedSum } from '../../util'
|
|
8
7
|
import { observer } from 'mobx-react'
|
|
9
8
|
import { get } from 'mobx'
|
|
10
9
|
|
|
@@ -47,22 +46,17 @@ const SubtotalTr = props => {
|
|
|
47
46
|
const tableData = printerStore.data._table[getDataKey(dataKey, arrange)] || []
|
|
48
47
|
// 计算合计
|
|
49
48
|
const sumData = (list, field) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
return result
|
|
63
|
-
},
|
|
64
|
-
Big(0)
|
|
65
|
-
).toFixed(2)
|
|
49
|
+
// 收集本列所有值(含多栏 _origin),任一脱敏 '***' 则合计显 '***',否则 Big('***') 会崩溃
|
|
50
|
+
const values = []
|
|
51
|
+
_.each(list, b => {
|
|
52
|
+
const _origin = b._origin || {}
|
|
53
|
+
const _origin2 = b['_origin' + MULTI_SUFFIX] || {}
|
|
54
|
+
values.push(_origin[field])
|
|
55
|
+
if (_origin2[field]) {
|
|
56
|
+
values.push(_origin2[field])
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
return maskedSum(values)
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
// 每页小计
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// ‼️优先初始化语言设置(必须先初始化语言)
|
|
2
2
|
import '../locales'
|
|
3
3
|
import Editor, { Editor2 } from './editor'
|
|
4
|
+
import { imageConfigDelivery } from './editor/store'
|
|
4
5
|
|
|
5
6
|
import EditorPurchase from './editor_purchase'
|
|
6
7
|
import EditorExaminingReport from './examining_report_editor'
|
|
@@ -20,7 +21,8 @@ import {
|
|
|
20
21
|
getCSS,
|
|
21
22
|
getPrintContainerHTML,
|
|
22
23
|
doBatchFinancePrint,
|
|
23
|
-
setPrintStyle
|
|
24
|
+
setPrintStyle,
|
|
25
|
+
computePages
|
|
24
26
|
} from './printer'
|
|
25
27
|
import { MULTI_SUFFIX, MULTI_SUFFIX3 } from './config'
|
|
26
28
|
|
|
@@ -30,6 +32,7 @@ export { setLocale } from '../locales'
|
|
|
30
32
|
export {
|
|
31
33
|
Editor,
|
|
32
34
|
Editor2,
|
|
35
|
+
imageConfigDelivery,
|
|
33
36
|
EditorStockIn,
|
|
34
37
|
EditorStockOut,
|
|
35
38
|
EditorPurchase,
|
|
@@ -49,5 +52,6 @@ export {
|
|
|
49
52
|
MULTI_SUFFIX3,
|
|
50
53
|
getPrintContainerHTML,
|
|
51
54
|
doBatchFinancePrint,
|
|
52
|
-
setPrintStyle
|
|
55
|
+
setPrintStyle,
|
|
56
|
+
computePages
|
|
53
57
|
}
|
package/src/printer/block.js
CHANGED
|
@@ -8,7 +8,12 @@ import BarCode from './barcode'
|
|
|
8
8
|
import QrCode from './qrcode'
|
|
9
9
|
import Tag from './tag'
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
// editStore 用函数形式注入:打印态(do_print 的 iframe)没有 editStore Provider,
|
|
12
|
+
// 字符串形式的 inject 会直接抛错,这里降级为 null 关闭编辑能力
|
|
13
|
+
@inject(({ printerStore, editStore }) => ({
|
|
14
|
+
printerStore,
|
|
15
|
+
editStore: editStore || null
|
|
16
|
+
}))
|
|
12
17
|
@observer
|
|
13
18
|
class Block extends React.Component {
|
|
14
19
|
constructor(props) {
|
|
@@ -16,8 +21,10 @@ class Block extends React.Component {
|
|
|
16
21
|
this.state = {
|
|
17
22
|
clientX: null,
|
|
18
23
|
clientY: null,
|
|
19
|
-
isEdit: false
|
|
24
|
+
isEdit: false,
|
|
25
|
+
isResizing: false
|
|
20
26
|
}
|
|
27
|
+
this.resizeState = null
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
componentDidMount() {
|
|
@@ -32,6 +39,7 @@ class Block extends React.Component {
|
|
|
32
39
|
'gm-printer-block-edit',
|
|
33
40
|
this.handleBlockEdit
|
|
34
41
|
)
|
|
42
|
+
this.teardownResize()
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
handleBlockEdit = e => {
|
|
@@ -112,6 +120,118 @@ class Block extends React.Component {
|
|
|
112
120
|
})
|
|
113
121
|
}
|
|
114
122
|
|
|
123
|
+
// 电子签章:图片四角等比例拖拽缩放
|
|
124
|
+
handleResizeStart = (direction, e) => {
|
|
125
|
+
// 阻止触发块的选中/拖动
|
|
126
|
+
e.stopPropagation()
|
|
127
|
+
e.preventDefault()
|
|
128
|
+
|
|
129
|
+
const {
|
|
130
|
+
config: { style, ratio }
|
|
131
|
+
} = this.props
|
|
132
|
+
|
|
133
|
+
const initW = parseFloat(style.width) || 0
|
|
134
|
+
const initH = parseFloat(style.height) || 0
|
|
135
|
+
// 旧模板无 ratio 时按当前显示宽高锁定;宽或高缺失(存量块无 width)时退回 1,
|
|
136
|
+
// 避免比例算出 0 导致高度 Infinity
|
|
137
|
+
const fallbackRatio = initW > 0 && initH > 0 ? initW / initH : 1
|
|
138
|
+
this.resizeState = {
|
|
139
|
+
direction,
|
|
140
|
+
startX: e.clientX,
|
|
141
|
+
startY: e.clientY,
|
|
142
|
+
initW,
|
|
143
|
+
initH,
|
|
144
|
+
initL: parseFloat(style.left) || 0,
|
|
145
|
+
initT: parseFloat(style.top) || 0,
|
|
146
|
+
// ratio = 原始宽/高
|
|
147
|
+
ratio: ratio || fallbackRatio,
|
|
148
|
+
baseStyle: style
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
this.setState({
|
|
152
|
+
isResizing: true
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
window.addEventListener('mousemove', this.handleResizeMove)
|
|
156
|
+
window.addEventListener('mouseup', this.handleResizeEnd)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
handleResizeMove = e => {
|
|
160
|
+
if (!this.resizeState) return
|
|
161
|
+
|
|
162
|
+
// rAF 节流,避免高频 mousemove 打爆渲染
|
|
163
|
+
if (this.resizePending) return
|
|
164
|
+
this.resizePending = e
|
|
165
|
+
window.requestAnimationFrame(() => {
|
|
166
|
+
const evt = this.resizePending
|
|
167
|
+
this.resizePending = null
|
|
168
|
+
if (!evt || !this.resizeState) return
|
|
169
|
+
this.doResize(evt)
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
doResize = e => {
|
|
174
|
+
const {
|
|
175
|
+
direction,
|
|
176
|
+
startX,
|
|
177
|
+
initW,
|
|
178
|
+
initH,
|
|
179
|
+
initL,
|
|
180
|
+
initT,
|
|
181
|
+
ratio,
|
|
182
|
+
baseStyle
|
|
183
|
+
} = this.resizeState
|
|
184
|
+
const dx = e.clientX - startX
|
|
185
|
+
|
|
186
|
+
// 右侧角向右放大,左侧角向左放大
|
|
187
|
+
let width =
|
|
188
|
+
direction === 'rb' || direction === 'rt' ? initW + dx : initW - dx
|
|
189
|
+
// 最小尺寸兜底,防止翻转
|
|
190
|
+
width = Math.max(width, 10)
|
|
191
|
+
const height = Math.round(width / ratio)
|
|
192
|
+
width = Math.round(width)
|
|
193
|
+
|
|
194
|
+
// 锚定对角:左向角拖拽时右/下边不动,上向角拖拽时下边不动
|
|
195
|
+
let left = initL
|
|
196
|
+
let top = initT
|
|
197
|
+
if (direction === 'lb' || direction === 'lt') {
|
|
198
|
+
left = initL + initW - width
|
|
199
|
+
}
|
|
200
|
+
if (direction === 'rt' || direction === 'lt') {
|
|
201
|
+
top = initT + initH - height
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
dispatchMsg('gm-printer-block-style-set', {
|
|
205
|
+
style: {
|
|
206
|
+
...baseStyle,
|
|
207
|
+
width: width + 'px',
|
|
208
|
+
height: height + 'px',
|
|
209
|
+
left: left + 'px',
|
|
210
|
+
top: top + 'px'
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
handleResizeEnd = () => {
|
|
216
|
+
// 先 flush 掉节流里排队中的最后一帧,避免松手回退
|
|
217
|
+
if (this.resizePending) {
|
|
218
|
+
const evt = this.resizePending
|
|
219
|
+
this.resizePending = null
|
|
220
|
+
this.doResize(evt)
|
|
221
|
+
}
|
|
222
|
+
this.teardownResize()
|
|
223
|
+
this.setState({
|
|
224
|
+
isResizing: false
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
teardownResize = () => {
|
|
229
|
+
window.removeEventListener('mousemove', this.handleResizeMove)
|
|
230
|
+
window.removeEventListener('mouseup', this.handleResizeEnd)
|
|
231
|
+
this.resizeState = null
|
|
232
|
+
this.resizePending = null
|
|
233
|
+
}
|
|
234
|
+
|
|
115
235
|
render() {
|
|
116
236
|
let {
|
|
117
237
|
name,
|
|
@@ -119,6 +239,7 @@ class Block extends React.Component {
|
|
|
119
239
|
pageIndex,
|
|
120
240
|
className,
|
|
121
241
|
printerStore,
|
|
242
|
+
editStore,
|
|
122
243
|
...rest
|
|
123
244
|
} = this.props
|
|
124
245
|
const { isEdit } = this.state
|
|
@@ -186,6 +307,14 @@ class Block extends React.Component {
|
|
|
186
307
|
}
|
|
187
308
|
|
|
188
309
|
const active = name === printerStore.selected
|
|
310
|
+
const { isResizing } = this.state
|
|
311
|
+
const showResizeHandles = !!(
|
|
312
|
+
active &&
|
|
313
|
+
type === 'image' &&
|
|
314
|
+
editStore &&
|
|
315
|
+
editStore.imageConfig &&
|
|
316
|
+
editStore.imageConfig.resizable
|
|
317
|
+
)
|
|
189
318
|
|
|
190
319
|
return (
|
|
191
320
|
<div
|
|
@@ -193,7 +322,7 @@ class Block extends React.Component {
|
|
|
193
322
|
className={classNames('gm-printer-block', className, {
|
|
194
323
|
active
|
|
195
324
|
})}
|
|
196
|
-
draggable
|
|
325
|
+
draggable={!isResizing}
|
|
197
326
|
onDragStart={this.handleDragStart}
|
|
198
327
|
onDragEnd={this.handleDragEnd}
|
|
199
328
|
onClick={this.handleClick}
|
|
@@ -221,6 +350,26 @@ class Block extends React.Component {
|
|
|
221
350
|
/>
|
|
222
351
|
)}
|
|
223
352
|
{content}
|
|
353
|
+
{showResizeHandles && (
|
|
354
|
+
<>
|
|
355
|
+
<div
|
|
356
|
+
className='gm-printer-resize-handle gm-printer-resize-lt'
|
|
357
|
+
onMouseDown={this.handleResizeStart.bind(this, 'lt')}
|
|
358
|
+
/>
|
|
359
|
+
<div
|
|
360
|
+
className='gm-printer-resize-handle gm-printer-resize-rt'
|
|
361
|
+
onMouseDown={this.handleResizeStart.bind(this, 'rt')}
|
|
362
|
+
/>
|
|
363
|
+
<div
|
|
364
|
+
className='gm-printer-resize-handle gm-printer-resize-lb'
|
|
365
|
+
onMouseDown={this.handleResizeStart.bind(this, 'lb')}
|
|
366
|
+
/>
|
|
367
|
+
<div
|
|
368
|
+
className='gm-printer-resize-handle gm-printer-resize-rb'
|
|
369
|
+
onMouseDown={this.handleResizeStart.bind(this, 'rb')}
|
|
370
|
+
/>
|
|
371
|
+
</>
|
|
372
|
+
)}
|
|
224
373
|
</div>
|
|
225
374
|
)
|
|
226
375
|
}
|
|
@@ -231,7 +380,8 @@ Block.propTypes = {
|
|
|
231
380
|
config: PropTypes.object.isRequired,
|
|
232
381
|
pageIndex: PropTypes.number.isRequired,
|
|
233
382
|
className: PropTypes.string,
|
|
234
|
-
printerStore: PropTypes.object
|
|
383
|
+
printerStore: PropTypes.object,
|
|
384
|
+
editStore: PropTypes.object
|
|
235
385
|
}
|
|
236
386
|
|
|
237
387
|
export default Block
|