gm-printer-label 3.1.0-beta.8 → 3.1.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/.eslintcache +1 -1
- package/package.json +1 -1
- package/src/common/editor_compoents/edit.js +13 -12
- package/src/common/editor_compoents/edit_modify_filed.js +3 -1
- package/src/common/editor_compoents/edit_select.js +37 -15
- package/src/common/editor_compoents/store.js +17 -4
- package/src/common/editor_compoents/style.lesss +3 -0
- package/src/printer/barcode.js +12 -2
- package/src/printer/block.js +67 -18
- package/src/printer/printer.js +8 -12
- package/src/util.js +11 -12
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/
|
|
1
|
+
[{"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/util.js":"1","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/edit_select.js":"2","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/edit.js":"3","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/component.js":"4","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/qrcode.js":"5","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/printer.js":"6","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/index.js":"7","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/block.js":"8","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/batch_printer.js":"9","/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/barcode.js":"10"},{"size":1934,"mtime":1642494468444,"results":"11","hashOfConfig":"12"},{"size":5505,"mtime":1635767717933,"results":"13","hashOfConfig":"12"},{"size":2694,"mtime":1635767728834,"results":"14","hashOfConfig":"12"},{"size":11621,"mtime":1635767876018,"results":"15","hashOfConfig":"12"},{"size":394,"mtime":1642488443965},{"size":1594,"mtime":1642499397285},{"size":3064,"mtime":1642499124287},{"size":11929,"mtime":1664163468352,"results":"16","hashOfConfig":"12"},{"size":825,"mtime":1642499158040},{"size":548,"mtime":1643102755561},{"filePath":"17","messages":"18","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"18d3ysg",{"filePath":"19","messages":"20","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"21","messages":"22","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"23","messages":"24","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/util.js",[],"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/edit_select.js",[],"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/edit.js",[],"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/common/editor_compoents/component.js",[],"/Users/min/Documents/GMFE/gm-util/gm-printer-label/src/printer/block.js",[]]
|
package/package.json
CHANGED
|
@@ -21,7 +21,7 @@ class Edit extends React.Component {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
render() {
|
|
24
|
+
render () {
|
|
25
25
|
const {
|
|
26
26
|
data,
|
|
27
27
|
initDefaultTemp,
|
|
@@ -31,7 +31,8 @@ class Edit extends React.Component {
|
|
|
31
31
|
editStore,
|
|
32
32
|
insertBlocksConfig,
|
|
33
33
|
uploadQiniuImage,
|
|
34
|
-
|
|
34
|
+
showDoublePage,
|
|
35
|
+
doublePageType
|
|
35
36
|
} = this.props
|
|
36
37
|
return (
|
|
37
38
|
<div className='gm-printer-label-edit'>
|
|
@@ -49,21 +50,22 @@ class Edit extends React.Component {
|
|
|
49
50
|
</Flex>
|
|
50
51
|
|
|
51
52
|
<div className='gm-printer-label-edit-header'>
|
|
52
|
-
<EditTitle onSave={onSave} initDefaultTemp={initDefaultTemp}
|
|
53
|
-
<Gap height='10px'
|
|
53
|
+
<EditTitle onSave={onSave} initDefaultTemp={initDefaultTemp}/>
|
|
54
|
+
<Gap height='10px'/>
|
|
54
55
|
<EditSelect
|
|
55
56
|
insertBlocksConfig={insertBlocksConfig}
|
|
56
57
|
initDefaultTemp={initDefaultTemp}
|
|
57
58
|
defaultTempList={defaultTempList}
|
|
58
59
|
uploadQiniuImage={uploadQiniuImage}
|
|
60
|
+
showDoublePage={showDoublePage}
|
|
59
61
|
/>
|
|
60
|
-
<Gap height='5px'
|
|
61
|
-
<EditModifyFiled
|
|
62
|
-
<Gap height='5px'
|
|
63
|
-
<EditAddFiled data={addFields}
|
|
62
|
+
<Gap height='5px'/>
|
|
63
|
+
<EditModifyFiled/>
|
|
64
|
+
<Gap height='5px'/>
|
|
65
|
+
<EditAddFiled data={addFields}/>
|
|
64
66
|
|
|
65
67
|
{/* 挂载shadow down中的Dialog组件 */}
|
|
66
|
-
<div id='gm-printer-label-modal'
|
|
68
|
+
<div id='gm-printer-label-modal'/>
|
|
67
69
|
</div>
|
|
68
70
|
|
|
69
71
|
<div
|
|
@@ -94,12 +96,11 @@ Edit.propTypes = {
|
|
|
94
96
|
defaultTempList: PropTypes.object,
|
|
95
97
|
addFields: PropTypes.object.isRequired,
|
|
96
98
|
insertBlocksConfig: PropTypes.array.isRequired,
|
|
97
|
-
|
|
98
|
-
doublePageType: PropTypes.bool,
|
|
99
|
+
showDoublePage: PropTypes.bool
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
Edit.deaultProps = {
|
|
102
|
-
onSave: _.noop
|
|
103
|
+
onSave: _.noop
|
|
103
104
|
}
|
|
104
105
|
|
|
105
106
|
export default Edit
|
|
@@ -84,7 +84,9 @@ class EditModifyFiled extends React.Component {
|
|
|
84
84
|
{(type === 'qrcode' ||
|
|
85
85
|
type === 'order_qrcode' ||
|
|
86
86
|
type === 'package_id_qrcode' ||
|
|
87
|
-
type === 'image'
|
|
87
|
+
type === 'image' ||
|
|
88
|
+
type === 'rack_barcode' ||
|
|
89
|
+
type === 'merchandise_trace_qrcode') && (
|
|
88
90
|
<div>
|
|
89
91
|
<Size
|
|
90
92
|
style={style}
|
|
@@ -57,12 +57,17 @@ class EditSelect extends React.Component {
|
|
|
57
57
|
|
|
58
58
|
handleChangeCustomizeSize = (name, value) => {
|
|
59
59
|
const { editStore } = this.props
|
|
60
|
-
|
|
61
60
|
editStore.setCustomizePageSize(name, value)
|
|
62
61
|
}
|
|
63
62
|
|
|
64
63
|
render () {
|
|
65
|
-
const {
|
|
64
|
+
const {
|
|
65
|
+
defaultTempList,
|
|
66
|
+
editStore,
|
|
67
|
+
insertBlocksConfig,
|
|
68
|
+
uploadQiniuImage,
|
|
69
|
+
showDoublePage
|
|
70
|
+
} = this.props
|
|
66
71
|
const {
|
|
67
72
|
tempKey,
|
|
68
73
|
config: { name, page }
|
|
@@ -113,7 +118,9 @@ class EditSelect extends React.Component {
|
|
|
113
118
|
</Option>
|
|
114
119
|
))}
|
|
115
120
|
{/* 格式不同,单独处理 */}
|
|
116
|
-
<Option key='-1' value='-1'>
|
|
121
|
+
<Option key='-1' value='-1'>
|
|
122
|
+
{i18next.t('自定义尺寸')}
|
|
123
|
+
</Option>
|
|
117
124
|
</Select>
|
|
118
125
|
</Flex>
|
|
119
126
|
{page.type === '-1' && (
|
|
@@ -122,27 +129,41 @@ class EditSelect extends React.Component {
|
|
|
122
129
|
<div>{i18next.t('宽度')}:</div>
|
|
123
130
|
<InputNumber
|
|
124
131
|
className='gm-printer-label-edit-input-custom'
|
|
125
|
-
value={
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
value={page.customizeWidth}
|
|
133
|
+
onChange={this.handleChangeCustomizeSize.bind(
|
|
134
|
+
this,
|
|
135
|
+
'customizeWidth'
|
|
136
|
+
)}
|
|
130
137
|
/>
|
|
131
138
|
</Flex>
|
|
132
139
|
<Flex alignCenter className='gm-padding-top-5'>
|
|
133
140
|
<div>{i18next.t('高度')}:</div>
|
|
134
141
|
<InputNumber
|
|
135
142
|
className='gm-printer-label-edit-input-custom'
|
|
136
|
-
value={
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
value={page.customizeHeight}
|
|
144
|
+
onChange={this.handleChangeCustomizeSize.bind(
|
|
145
|
+
this,
|
|
146
|
+
'customizeHeight'
|
|
147
|
+
)}
|
|
141
148
|
/>
|
|
142
149
|
</Flex>
|
|
143
150
|
</Flex>
|
|
144
151
|
)}
|
|
145
|
-
|
|
152
|
+
{showDoublePage && (
|
|
153
|
+
<Flex alignCenter className='gm-padding-top-5'>
|
|
154
|
+
<div>{i18next.t('预览区域放大展示')}:</div>
|
|
155
|
+
<input
|
|
156
|
+
type='checkbox'
|
|
157
|
+
checked={page.doublePage === true}
|
|
158
|
+
onChange={(v) =>
|
|
159
|
+
this.handleChangeCustomizeSize.bind(
|
|
160
|
+
this,
|
|
161
|
+
'doublePage'
|
|
162
|
+
)(v.target.checked)
|
|
163
|
+
}
|
|
164
|
+
/>
|
|
165
|
+
</Flex>
|
|
166
|
+
)}
|
|
146
167
|
<Gap height='10px'/>
|
|
147
168
|
|
|
148
169
|
<Flex alignCenter style={{ flexWrap: 'wrap' }}>
|
|
@@ -184,7 +205,8 @@ EditSelect.propTypes = {
|
|
|
184
205
|
editStore: PropTypes.object,
|
|
185
206
|
initDefaultTemp: PropTypes.string,
|
|
186
207
|
defaultTempList: PropTypes.object,
|
|
187
|
-
insertBlocksConfig: PropTypes.array.isRequired
|
|
208
|
+
insertBlocksConfig: PropTypes.array.isRequired,
|
|
209
|
+
showDoublePage: PropTypes.bool
|
|
188
210
|
}
|
|
189
211
|
|
|
190
212
|
export default EditSelect
|
|
@@ -114,8 +114,8 @@ class EditStore {
|
|
|
114
114
|
position: 'absolute',
|
|
115
115
|
left: '0px',
|
|
116
116
|
top: '0px',
|
|
117
|
-
width: '
|
|
118
|
-
height: '
|
|
117
|
+
width: '50px',
|
|
118
|
+
height: '50px'
|
|
119
119
|
}
|
|
120
120
|
})
|
|
121
121
|
break
|
|
@@ -224,6 +224,19 @@ class EditStore {
|
|
|
224
224
|
}
|
|
225
225
|
})
|
|
226
226
|
break
|
|
227
|
+
case 'rack_barcode':
|
|
228
|
+
this.config.blocks.push({
|
|
229
|
+
type,
|
|
230
|
+
rack_barcode: i18next.t('{{货位条形码}}'),
|
|
231
|
+
style: {
|
|
232
|
+
position: 'absolute',
|
|
233
|
+
left: '0px',
|
|
234
|
+
top: '0px',
|
|
235
|
+
height: '30px',
|
|
236
|
+
width: '165px'
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
break
|
|
227
240
|
default:
|
|
228
241
|
window.alert(i18next.t('出错啦,未识别类型,此信息不应该出现'))
|
|
229
242
|
break
|
|
@@ -289,11 +302,11 @@ class EditStore {
|
|
|
289
302
|
getHandledConfig (config) {
|
|
290
303
|
const result = _.cloneDeep(config)
|
|
291
304
|
// 添加自定义尺寸字段
|
|
292
|
-
|
|
293
305
|
result.page = {
|
|
294
306
|
...result.page,
|
|
295
307
|
customizeWidth: result.page.customizeWidth || 100, // 若没有则默认为100
|
|
296
|
-
customizeHeight: result.page.customizeHeight || 100
|
|
308
|
+
customizeHeight: result.page.customizeHeight || 100,
|
|
309
|
+
doublePage: result.page.doublePage || false
|
|
297
310
|
}
|
|
298
311
|
|
|
299
312
|
return result
|
package/src/printer/barcode.js
CHANGED
|
@@ -8,14 +8,24 @@ class BarCode extends React.Component {
|
|
|
8
8
|
componentDidMount () {
|
|
9
9
|
const { value, ...rest } = this.props
|
|
10
10
|
if (!value) return
|
|
11
|
+
/** jsBarCode的具体options前往:
|
|
12
|
+
* https://blog.csdn.net/shencailing/article/details/122101956
|
|
13
|
+
*/
|
|
11
14
|
jsBarcode(this.barcode.current, value, {
|
|
12
15
|
...rest
|
|
13
16
|
})
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
render () {
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
// 可设置条形码的宽高
|
|
21
|
+
const { dataName, height = '', svgWidth } = this.props
|
|
22
|
+
return <svg
|
|
23
|
+
data-name={dataName}
|
|
24
|
+
ref={this.barcode}
|
|
25
|
+
style={{
|
|
26
|
+
width: svgWidth, height: height + 'px'
|
|
27
|
+
}}
|
|
28
|
+
/>
|
|
19
29
|
}
|
|
20
30
|
}
|
|
21
31
|
|
package/src/printer/block.js
CHANGED
|
@@ -10,12 +10,14 @@ import _ from 'lodash'
|
|
|
10
10
|
|
|
11
11
|
@observer
|
|
12
12
|
class Block extends React.Component {
|
|
13
|
-
|
|
13
|
+
dragBlock = React.createRef(null)
|
|
14
|
+
handleChangeDebounce = null
|
|
15
|
+
constructor (props) {
|
|
14
16
|
super(props)
|
|
15
17
|
this.state = {
|
|
16
18
|
clientX: null,
|
|
17
19
|
clientY: null,
|
|
18
|
-
isEdit: false
|
|
20
|
+
isEdit: false
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
@@ -24,14 +26,14 @@ class Block extends React.Component {
|
|
|
24
26
|
|
|
25
27
|
this.setState({
|
|
26
28
|
clientX,
|
|
27
|
-
clientY
|
|
29
|
+
clientY
|
|
28
30
|
})
|
|
29
31
|
|
|
30
32
|
window.document.dispatchEvent(
|
|
31
33
|
new window.CustomEvent('gm-printer-label-select', {
|
|
32
34
|
detail: {
|
|
33
|
-
selected: index
|
|
34
|
-
}
|
|
35
|
+
selected: index
|
|
36
|
+
}
|
|
35
37
|
})
|
|
36
38
|
)
|
|
37
39
|
}
|
|
@@ -44,7 +46,7 @@ class Block extends React.Component {
|
|
|
44
46
|
const style = getStyleWithDiff(config.style, diffX, diffY)
|
|
45
47
|
|
|
46
48
|
dispatchMsg('gm-printer-label-block-style-set', {
|
|
47
|
-
style
|
|
49
|
+
style
|
|
48
50
|
})
|
|
49
51
|
}
|
|
50
52
|
|
|
@@ -52,18 +54,18 @@ class Block extends React.Component {
|
|
|
52
54
|
const { index } = this.props
|
|
53
55
|
|
|
54
56
|
dispatchMsg('gm-printer-label-select', {
|
|
55
|
-
selected: index
|
|
57
|
+
selected: index
|
|
56
58
|
})
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
handleDoubleClick = () => {
|
|
60
62
|
const {
|
|
61
|
-
config: { type }
|
|
63
|
+
config: { type }
|
|
62
64
|
} = this.props
|
|
63
65
|
if (!type || type === 'text') {
|
|
64
66
|
this.setState(
|
|
65
67
|
{
|
|
66
|
-
isEdit: true
|
|
68
|
+
isEdit: true
|
|
67
69
|
},
|
|
68
70
|
() => {
|
|
69
71
|
this.refEdit.focus()
|
|
@@ -74,17 +76,43 @@ class Block extends React.Component {
|
|
|
74
76
|
|
|
75
77
|
handleEditBlur = () => {
|
|
76
78
|
this.setState({
|
|
77
|
-
isEdit: false
|
|
79
|
+
isEdit: false
|
|
78
80
|
})
|
|
79
81
|
}
|
|
80
82
|
|
|
81
83
|
handleText = (e) => {
|
|
82
84
|
dispatchMsg('gm-printer-label-block-text-set', {
|
|
83
|
-
text: e.target.value
|
|
85
|
+
text: e.target.value
|
|
84
86
|
})
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
/** TODO: 鼠标移动事件 */
|
|
90
|
+
handleMouseMove = (e) => {
|
|
91
|
+
e.persist()
|
|
92
|
+
if (!this.handleChangeDebounce) {
|
|
93
|
+
this.handleChangeDebounce = _.debounce(this.handleChange, 200)
|
|
94
|
+
}
|
|
95
|
+
this.handleChangeDebounce(e)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** TODO: 拖拉设置条形码宽高 */
|
|
99
|
+
handleChange = (e) => {
|
|
100
|
+
const ref = this.dragBlock.current
|
|
101
|
+
const rect = ref.getBoundingClientRect()
|
|
102
|
+
const diffX_r = Math.abs(e.nativeEvent.clientX - rect.right)
|
|
103
|
+
const isActive = ref.classList.contains('gm-printer-resize-active')
|
|
104
|
+
console.log('diffX_r', diffX_r, ref.classList)
|
|
105
|
+
if (diffX_r < 20 && !isActive) {
|
|
106
|
+
ref.classList.add('gm-printer-resize-active')
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (isActive) {
|
|
111
|
+
ref.classList.remove('gm-printer-resize-active')
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
render () {
|
|
88
116
|
const {
|
|
89
117
|
index,
|
|
90
118
|
selected,
|
|
@@ -103,6 +131,7 @@ class Block extends React.Component {
|
|
|
103
131
|
fieldKey,
|
|
104
132
|
production_barcode,
|
|
105
133
|
merchandise_trace_qrcode,
|
|
134
|
+
rack_barcode
|
|
106
135
|
},
|
|
107
136
|
data,
|
|
108
137
|
className,
|
|
@@ -113,7 +142,7 @@ class Block extends React.Component {
|
|
|
113
142
|
let content = null
|
|
114
143
|
|
|
115
144
|
if (!type || type === 'text') {
|
|
116
|
-
if (fieldType === '
|
|
145
|
+
if (fieldType === 'table') {
|
|
117
146
|
// 字段类型为表格
|
|
118
147
|
content = (
|
|
119
148
|
<TableType
|
|
@@ -123,11 +152,11 @@ class Block extends React.Component {
|
|
|
123
152
|
/>
|
|
124
153
|
)
|
|
125
154
|
} else {
|
|
126
|
-
/** html */
|
|
155
|
+
/** 渲染一个html */
|
|
127
156
|
const value = text.split(':')?.[1]
|
|
128
157
|
const isHtml = value && value.indexOf('_html') !== -1
|
|
129
158
|
content = isHtml ? (
|
|
130
|
-
<div dangerouslySetInnerHTML={{ __html: template(value, data) }}
|
|
159
|
+
<div dangerouslySetInnerHTML={{ __html: template(value, data) }}/>
|
|
131
160
|
) : (
|
|
132
161
|
template(text, data)
|
|
133
162
|
)
|
|
@@ -318,7 +347,7 @@ class Block extends React.Component {
|
|
|
318
347
|
)
|
|
319
348
|
} else if (type === 'diyqrcode') {
|
|
320
349
|
content = isStation ? (
|
|
321
|
-
<QrCode value={template(text, data)} size={parseInt(style.height)}
|
|
350
|
+
<QrCode value={template(text, data)} size={parseInt(style.height)}/>
|
|
322
351
|
) : (
|
|
323
352
|
<div
|
|
324
353
|
data-diyqrcode={template(text, data)}
|
|
@@ -339,6 +368,23 @@ class Block extends React.Component {
|
|
|
339
368
|
data-name={index}
|
|
340
369
|
/>
|
|
341
370
|
)
|
|
371
|
+
} else if (type === 'rack_barcode') {
|
|
372
|
+
/** 浏览器端的货位标签打印 */
|
|
373
|
+
content = (
|
|
374
|
+
<BarCode
|
|
375
|
+
value={template(rack_barcode, data)}
|
|
376
|
+
textAlign='center'
|
|
377
|
+
textMargin={0}
|
|
378
|
+
margin={0}
|
|
379
|
+
height={parseInt(style.height)}
|
|
380
|
+
width={2}
|
|
381
|
+
svgWidth={style.width}
|
|
382
|
+
// font={rack_barcode}
|
|
383
|
+
displayValue
|
|
384
|
+
dataName={rack_barcode}
|
|
385
|
+
background='transparent'
|
|
386
|
+
/>
|
|
387
|
+
)
|
|
342
388
|
}
|
|
343
389
|
const active = index === selected
|
|
344
390
|
|
|
@@ -351,14 +397,17 @@ class Block extends React.Component {
|
|
|
351
397
|
`gm-printer-label-block-type-${type}`,
|
|
352
398
|
className,
|
|
353
399
|
{
|
|
354
|
-
active
|
|
400
|
+
active
|
|
355
401
|
}
|
|
356
402
|
)}
|
|
357
403
|
draggable
|
|
404
|
+
ref={this.dragBlock}
|
|
358
405
|
onDragStart={this.handleDragStart}
|
|
359
406
|
onDragEnd={this.handleDragEnd}
|
|
360
407
|
onClick={this.handleClick}
|
|
361
408
|
onDoubleClick={this.handleDoubleClick}
|
|
409
|
+
/** TODO: 拖拉设置条形码宽高 */
|
|
410
|
+
// onMouseMove={this.handleMouseMove}
|
|
362
411
|
data-name={index}
|
|
363
412
|
>
|
|
364
413
|
{content}
|
|
@@ -381,7 +430,7 @@ Block.propTypes = {
|
|
|
381
430
|
config: PropTypes.object.isRequired,
|
|
382
431
|
data: PropTypes.object.isRequired,
|
|
383
432
|
selected: PropTypes.number,
|
|
384
|
-
isStation: PropTypes.bool
|
|
433
|
+
isStation: PropTypes.bool
|
|
385
434
|
}
|
|
386
435
|
|
|
387
436
|
export default Block
|
package/src/printer/printer.js
CHANGED
|
@@ -8,39 +8,37 @@ import { pageTypeMap } from '../common/config'
|
|
|
8
8
|
|
|
9
9
|
@observer
|
|
10
10
|
class Printer extends React.Component {
|
|
11
|
-
componentDidMount() {
|
|
11
|
+
componentDidMount () {
|
|
12
12
|
// Printer 不是立马就呈现出最终样式,有个过程。这个过程需要时间,什么 ready,不太清楚,估借 setState 来获取过程结束时刻
|
|
13
13
|
this.setState({}, () => {
|
|
14
14
|
this.props.onReady && this.props.onReady()
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
render() {
|
|
19
|
-
const { config, selected, data, isStation
|
|
20
|
-
const { type, style, customizeWidth, customizeHeight } =
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
render () {
|
|
19
|
+
const { config, selected, data, isStation } = this.props
|
|
20
|
+
const { type, style, customizeWidth, customizeHeight, doublePage } =
|
|
21
|
+
config.page
|
|
22
|
+
const ratio = doublePage ? 2 : 1
|
|
23
23
|
const width =
|
|
24
24
|
(type === '-1'
|
|
25
25
|
? customizeWidth
|
|
26
26
|
: +pageTypeMap[type].width.split('mm')[0]) *
|
|
27
27
|
ratio +
|
|
28
28
|
'mm'
|
|
29
|
-
console.log('width', width, type, customizeWidth)
|
|
30
29
|
const height =
|
|
31
30
|
(type === '-1'
|
|
32
31
|
? customizeHeight
|
|
33
32
|
: +pageTypeMap[type].height.split('mm')[0]) *
|
|
34
33
|
ratio +
|
|
35
34
|
'mm'
|
|
36
|
-
|
|
37
35
|
return (
|
|
38
36
|
<div
|
|
39
37
|
className='gm-printer-label'
|
|
40
38
|
style={{
|
|
41
39
|
...style,
|
|
42
40
|
width,
|
|
43
|
-
height
|
|
41
|
+
height
|
|
44
42
|
}}
|
|
45
43
|
>
|
|
46
44
|
<Page pageStyle={{ width, height }}>
|
|
@@ -65,9 +63,7 @@ Printer.propTypes = {
|
|
|
65
63
|
config: PropTypes.object.isRequired,
|
|
66
64
|
data: PropTypes.object.isRequired, // 格式化后的数据
|
|
67
65
|
onReady: PropTypes.func,
|
|
68
|
-
isStation: PropTypes.bool
|
|
69
|
-
/** 放大编辑窗口 */
|
|
70
|
-
doublePageType: PropTypes.bool,
|
|
66
|
+
isStation: PropTypes.bool
|
|
71
67
|
}
|
|
72
68
|
|
|
73
69
|
export default Printer
|
package/src/util.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
2
|
|
|
3
|
-
function pxAdd(origin, add) {
|
|
3
|
+
function pxAdd (origin, add) {
|
|
4
4
|
return parseFloat(origin, 10) + add + 'px'
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function getStyleWithDiff(style, diffX, diffY) {
|
|
7
|
+
function getStyleWithDiff (style, diffX, diffY) {
|
|
8
8
|
const newStyle = Object.assign({}, style)
|
|
9
9
|
|
|
10
10
|
if (!style.left && style.right) {
|
|
@@ -22,7 +22,7 @@ function getStyleWithDiff(style, diffX, diffY) {
|
|
|
22
22
|
return newStyle
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function insertCSS(cssString, target) {
|
|
25
|
+
function insertCSS (cssString, target) {
|
|
26
26
|
const style = window.document.createElement('style')
|
|
27
27
|
style.type = 'text/css'
|
|
28
28
|
style.appendChild(document.createTextNode(cssString))
|
|
@@ -34,24 +34,23 @@ function insertCSS(cssString, target) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function dispatchMsg(event, data) {
|
|
37
|
+
function dispatchMsg (event, data) {
|
|
38
38
|
window.document.dispatchEvent(
|
|
39
39
|
new window.CustomEvent(event, {
|
|
40
|
-
detail: data
|
|
40
|
+
detail: data
|
|
41
41
|
})
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
|
-
function substring(target, start = 0, end) {
|
|
44
|
+
function substring (target, start = 0, end) {
|
|
45
45
|
return target.substring(start, end)
|
|
46
46
|
}
|
|
47
|
-
function template(text, data) {
|
|
48
|
-
console.log('data', data)
|
|
47
|
+
function template (text, data) {
|
|
49
48
|
try {
|
|
50
49
|
return _.template(text, {
|
|
51
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
50
|
+
interpolate: /{{([\s\S]+?)}}/g
|
|
52
51
|
})({
|
|
53
52
|
...data,
|
|
54
|
-
substring: substring
|
|
53
|
+
substring: substring // 添加一个截取字符串函数
|
|
55
54
|
})
|
|
56
55
|
} catch (err) {
|
|
57
56
|
console.warn(err)
|
|
@@ -61,7 +60,7 @@ function template(text, data) {
|
|
|
61
60
|
|
|
62
61
|
let timer
|
|
63
62
|
|
|
64
|
-
function afterImgAndSvgLoaded(callback, $printer) {
|
|
63
|
+
function afterImgAndSvgLoaded (callback, $printer) {
|
|
65
64
|
const $imgList = $printer.querySelectorAll('img')
|
|
66
65
|
const $svgList = $printer.querySelectorAll('svg')
|
|
67
66
|
|
|
@@ -84,5 +83,5 @@ export {
|
|
|
84
83
|
dispatchMsg,
|
|
85
84
|
template,
|
|
86
85
|
afterImgAndSvgLoaded,
|
|
87
|
-
miniAppLink
|
|
86
|
+
miniAppLink
|
|
88
87
|
}
|