gm-printer-label 3.0.9-beta.1 → 3.0.10-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/.eslintcache +1 -1
- package/.prettierrc.js +5 -0
- package/package.json +11 -5
- package/src/common/config.js +4 -26
- package/src/common/editor_compoents/store.js +13 -0
- package/src/common/editor_compoents/style.lesss +14 -0
- package/src/printer/barcode.js +27 -0
- package/src/printer/batch_printer.js +43 -0
- package/src/printer/block.js +107 -17
- package/src/printer/index.js +85 -3
- package/src/printer/printer.js +16 -5
- package/src/printer/qrcode.js +17 -0
- package/src/util.js +26 -4
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/
|
|
1
|
+
[{"/Users/xurora/Desktop/gm-printer-label/src/util.js":"1","/Users/xurora/Desktop/gm-printer-label/src/printer/block.js":"2","/Users/xurora/Desktop/gm-printer-label/src/common/editor_compoents/store.js":"3"},{"size":1935,"mtime":1655908329945,"results":"4","hashOfConfig":"5"},{"size":10369,"mtime":1655970030340,"results":"6","hashOfConfig":"5"},{"size":7160,"mtime":1655951736143,"results":"7","hashOfConfig":"5"},{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"10llghp",{"filePath":"10","messages":"11","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"12","messages":"13","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/xurora/Desktop/gm-printer-label/src/util.js",[],"/Users/xurora/Desktop/gm-printer-label/src/printer/block.js",[],"/Users/xurora/Desktop/gm-printer-label/src/common/editor_compoents/store.js",[]]
|
package/.prettierrc.js
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gm-printer-label",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10-beta.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"precommit": "lint-staged",
|
|
8
|
-
"start": "webpack-dev-server"
|
|
8
|
+
"start": "webpack-dev-server",
|
|
9
|
+
"publish-latest": "npm publish --force-publish --registry https://registry.npmjs.org/",
|
|
10
|
+
"publish-beta": "npm publish --force-publish --dist-tag beta --preid beta --registry https://registry.npmjs.org/",
|
|
11
|
+
"publish-alpha": "npm publish --force-publish --dist-tag alpha --preid alpha --registry https://registry.npmjs.org/"
|
|
9
12
|
},
|
|
10
13
|
"lint-staged": {
|
|
11
14
|
"./src/**/*.js": [
|
|
@@ -29,7 +32,8 @@
|
|
|
29
32
|
"lodash": "^4.17.10",
|
|
30
33
|
"moment": "^2.22.2",
|
|
31
34
|
"react": "^16.8.5",
|
|
32
|
-
"react-dom": "^16.8.5"
|
|
35
|
+
"react-dom": "^16.8.5",
|
|
36
|
+
"qrcode.react": "^0.9.2"
|
|
33
37
|
},
|
|
34
38
|
"dependencies": {
|
|
35
39
|
"clipboard": "^2.0.1",
|
|
@@ -37,7 +41,8 @@
|
|
|
37
41
|
"gm-util": "^5.10.4",
|
|
38
42
|
"mobx": "^4.3.0",
|
|
39
43
|
"mobx-react": "^6.1.1",
|
|
40
|
-
"precss": "^4.0.0"
|
|
44
|
+
"precss": "^4.0.0",
|
|
45
|
+
"qrcode.react": "^0.9.2"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
48
|
"@babel/cli": "^7.6.0",
|
|
@@ -86,6 +91,7 @@
|
|
|
86
91
|
"url-loader": "^1.0.1",
|
|
87
92
|
"webpack": "^4.10.1",
|
|
88
93
|
"webpack-cli": "^3.3.0",
|
|
89
|
-
"webpack-dev-server": "^3.1.4"
|
|
94
|
+
"webpack-dev-server": "^3.1.4",
|
|
95
|
+
"jsbarcode": "^3.11.0"
|
|
90
96
|
}
|
|
91
97
|
}
|
package/src/common/config.js
CHANGED
|
@@ -32,31 +32,6 @@ const pageTypeMap = {
|
|
|
32
32
|
'40X30': {
|
|
33
33
|
width: '40mm',
|
|
34
34
|
height: '28mm'
|
|
35
|
-
},
|
|
36
|
-
// 箱签
|
|
37
|
-
A4: {
|
|
38
|
-
width: '210mm',
|
|
39
|
-
height: '297mm'
|
|
40
|
-
},
|
|
41
|
-
A5: {
|
|
42
|
-
width: '148mm',
|
|
43
|
-
height: '210mm'
|
|
44
|
-
},
|
|
45
|
-
'A4/2': {
|
|
46
|
-
width: '210mm',
|
|
47
|
-
height: '140mm'
|
|
48
|
-
},
|
|
49
|
-
'A4/3': {
|
|
50
|
-
width: '210mm',
|
|
51
|
-
height: '93mm'
|
|
52
|
-
},
|
|
53
|
-
'241x280': {
|
|
54
|
-
width: '241mm',
|
|
55
|
-
height: '280mm'
|
|
56
|
-
},
|
|
57
|
-
'241x140': {
|
|
58
|
-
width: '241mm',
|
|
59
|
-
height: '140mm'
|
|
60
35
|
}
|
|
61
36
|
}
|
|
62
37
|
|
|
@@ -66,4 +41,7 @@ const borderStyleList = [
|
|
|
66
41
|
{ value: 'dotted', text: i18next.t('圆点') }
|
|
67
42
|
]
|
|
68
43
|
|
|
69
|
-
export {
|
|
44
|
+
export {
|
|
45
|
+
borderStyleList,
|
|
46
|
+
pageTypeMap
|
|
47
|
+
}
|
|
@@ -106,6 +106,19 @@ class EditStore {
|
|
|
106
106
|
}
|
|
107
107
|
})
|
|
108
108
|
break
|
|
109
|
+
case 'merchandise_trace_qrcode':
|
|
110
|
+
this.config.blocks.push({
|
|
111
|
+
type,
|
|
112
|
+
merchandise_trace_qrcode: i18next.t('{{商品溯源二维码}}'),
|
|
113
|
+
style: {
|
|
114
|
+
position: 'absolute',
|
|
115
|
+
left: '0px',
|
|
116
|
+
top: '0px',
|
|
117
|
+
width: '100px',
|
|
118
|
+
height: '100px'
|
|
119
|
+
}
|
|
120
|
+
})
|
|
121
|
+
break
|
|
109
122
|
case 'order_qrcode':
|
|
110
123
|
this.config.blocks.push({
|
|
111
124
|
type,
|
|
@@ -202,6 +202,8 @@
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
+
|
|
206
|
+
|
|
205
207
|
&.gm-printer-label-block-type-diyqrcode {
|
|
206
208
|
div[data-diyqrcode] {
|
|
207
209
|
outline: 1px solid red;
|
|
@@ -265,6 +267,18 @@
|
|
|
265
267
|
top: calc(50% - 0.5em);
|
|
266
268
|
}
|
|
267
269
|
}
|
|
270
|
+
|
|
271
|
+
div[data-traceqrcode] {
|
|
272
|
+
outline: 1px solid red;
|
|
273
|
+
|
|
274
|
+
&::before {
|
|
275
|
+
content: '商品溯源二维码';
|
|
276
|
+
position: absolute;
|
|
277
|
+
font-style: italic;
|
|
278
|
+
left: calc(50% - 1.5em);
|
|
279
|
+
top: calc(50% - 0.5em);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
268
282
|
|
|
269
283
|
div[data-diycode] {
|
|
270
284
|
outline: 1px solid red;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import jsBarcode from 'jsbarcode'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
|
|
5
|
+
class BarCode extends React.Component {
|
|
6
|
+
barcode = React.createRef()
|
|
7
|
+
|
|
8
|
+
componentDidMount () {
|
|
9
|
+
const { value, ...rest } = this.props
|
|
10
|
+
if (!value) return
|
|
11
|
+
jsBarcode(this.barcode.current, value, {
|
|
12
|
+
...rest
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
render () {
|
|
17
|
+
const { dataName } = this.props
|
|
18
|
+
return <svg data-name={dataName} ref={this.barcode}/>
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
BarCode.propTypes = {
|
|
23
|
+
value: PropTypes.string,
|
|
24
|
+
dataName: PropTypes.string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default BarCode
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import Printer from './printer'
|
|
3
|
+
import _ from 'lodash'
|
|
4
|
+
import PropTypes from 'prop-types'
|
|
5
|
+
|
|
6
|
+
class BatchPrinter extends React.Component {
|
|
7
|
+
constructor (props) {
|
|
8
|
+
super(props)
|
|
9
|
+
this.ready = 0
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
handleReady = () => {
|
|
13
|
+
this.ready++
|
|
14
|
+
if (this.ready === this.props.list.length) {
|
|
15
|
+
this.props.onReady()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
render () {
|
|
20
|
+
const { list, isStation } = this.props
|
|
21
|
+
return _.map(list, ({ config, data }, i) => (
|
|
22
|
+
<Printer
|
|
23
|
+
key={i}
|
|
24
|
+
data={data}
|
|
25
|
+
config={config}
|
|
26
|
+
onReady={this.handleReady}
|
|
27
|
+
isStation={isStation}
|
|
28
|
+
/>
|
|
29
|
+
))
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
BatchPrinter.propTypes = {
|
|
34
|
+
list: PropTypes.array.isRequired,
|
|
35
|
+
onReady: PropTypes.func,
|
|
36
|
+
isStation: PropTypes.bool
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
BatchPrinter.defaultProps = {
|
|
40
|
+
onReady: _.noop
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default BatchPrinter
|
package/src/printer/block.js
CHANGED
|
@@ -2,8 +2,10 @@ import React from 'react'
|
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import classNames from 'classnames'
|
|
4
4
|
import { observer } from 'mobx-react'
|
|
5
|
-
import { getStyleWithDiff, dispatchMsg, template } from '../util'
|
|
5
|
+
import { getStyleWithDiff, dispatchMsg, template, miniAppLink } from '../util'
|
|
6
6
|
import TableType from './components/table_type'
|
|
7
|
+
import BarCode from './barcode'
|
|
8
|
+
import QrCode from './qrcode'
|
|
7
9
|
|
|
8
10
|
@observer
|
|
9
11
|
class Block extends React.Component {
|
|
@@ -31,7 +33,7 @@ class Block extends React.Component {
|
|
|
31
33
|
}
|
|
32
34
|
})
|
|
33
35
|
)
|
|
34
|
-
}
|
|
36
|
+
}
|
|
35
37
|
|
|
36
38
|
handleDragEnd = ({ clientX, clientY }) => {
|
|
37
39
|
const { config } = this.props
|
|
@@ -43,7 +45,7 @@ class Block extends React.Component {
|
|
|
43
45
|
dispatchMsg('gm-printer-label-block-style-set', {
|
|
44
46
|
style
|
|
45
47
|
})
|
|
46
|
-
}
|
|
48
|
+
}
|
|
47
49
|
|
|
48
50
|
handleClick = () => {
|
|
49
51
|
const { index } = this.props
|
|
@@ -51,7 +53,7 @@ class Block extends React.Component {
|
|
|
51
53
|
dispatchMsg('gm-printer-label-select', {
|
|
52
54
|
selected: index
|
|
53
55
|
})
|
|
54
|
-
}
|
|
56
|
+
}
|
|
55
57
|
|
|
56
58
|
handleDoubleClick = () => {
|
|
57
59
|
const {
|
|
@@ -67,19 +69,19 @@ class Block extends React.Component {
|
|
|
67
69
|
}
|
|
68
70
|
)
|
|
69
71
|
}
|
|
70
|
-
}
|
|
72
|
+
}
|
|
71
73
|
|
|
72
74
|
handleEditBlur = () => {
|
|
73
75
|
this.setState({
|
|
74
76
|
isEdit: false
|
|
75
77
|
})
|
|
76
|
-
}
|
|
78
|
+
}
|
|
77
79
|
|
|
78
80
|
handleText = (e) => {
|
|
79
81
|
dispatchMsg('gm-printer-label-block-text-set', {
|
|
80
82
|
text: e.target.value
|
|
81
83
|
})
|
|
82
|
-
}
|
|
84
|
+
}
|
|
83
85
|
|
|
84
86
|
render () {
|
|
85
87
|
const {
|
|
@@ -98,12 +100,15 @@ class Block extends React.Component {
|
|
|
98
100
|
url,
|
|
99
101
|
fieldType,
|
|
100
102
|
fieldKey,
|
|
101
|
-
production_barcode
|
|
103
|
+
production_barcode,
|
|
104
|
+
merchandise_trace_qrcode
|
|
102
105
|
},
|
|
103
106
|
data,
|
|
104
107
|
className,
|
|
108
|
+
isStation,
|
|
105
109
|
...rest
|
|
106
110
|
} = this.props
|
|
111
|
+
console.log('test', merchandise_trace_qrcode)
|
|
107
112
|
const { isEdit } = this.state
|
|
108
113
|
let content = null
|
|
109
114
|
if (!type || type === 'text') {
|
|
@@ -122,7 +127,12 @@ class Block extends React.Component {
|
|
|
122
127
|
} else if (type === 'line') {
|
|
123
128
|
content = null
|
|
124
129
|
} else if (type === 'qrcode') {
|
|
125
|
-
content = (
|
|
130
|
+
content = isStation ? (
|
|
131
|
+
<QrCode
|
|
132
|
+
value={miniAppLink + template(qrcode, data)}
|
|
133
|
+
size={parseInt(style.height)}
|
|
134
|
+
/>
|
|
135
|
+
) : (
|
|
126
136
|
<div
|
|
127
137
|
data-qrcode={template(qrcode, data)}
|
|
128
138
|
data-width={style.width}
|
|
@@ -133,7 +143,12 @@ class Block extends React.Component {
|
|
|
133
143
|
/>
|
|
134
144
|
)
|
|
135
145
|
} else if (type === 'order_qrcode') {
|
|
136
|
-
content = (
|
|
146
|
+
content = isStation ? (
|
|
147
|
+
<QrCode
|
|
148
|
+
value={miniAppLink + template(order_qrcode, data)}
|
|
149
|
+
size={parseInt(style.height)}
|
|
150
|
+
/>
|
|
151
|
+
) : (
|
|
137
152
|
<div
|
|
138
153
|
data-orderQrcode={template(order_qrcode, data)}
|
|
139
154
|
data-width={style.width}
|
|
@@ -143,8 +158,39 @@ class Block extends React.Component {
|
|
|
143
158
|
data-placeholder='订单溯源'
|
|
144
159
|
/>
|
|
145
160
|
)
|
|
161
|
+
} else if (type === 'merchandise_trace_qrcode') {
|
|
162
|
+
console.log('template(merchandise_trace_qrcode, data)', merchandise_trace_qrcode, data, template(merchandise_trace_qrcode, data))
|
|
163
|
+
content = isStation ? (
|
|
164
|
+
<QrCode
|
|
165
|
+
value={miniAppLink + template(merchandise_trace_qrcode, data)}
|
|
166
|
+
size={parseInt(style.height)}
|
|
167
|
+
/>
|
|
168
|
+
) : (
|
|
169
|
+
<div
|
|
170
|
+
data-traceqrcode={template(merchandise_trace_qrcode, data)}
|
|
171
|
+
data-width={style.width}
|
|
172
|
+
data-height={style.height}
|
|
173
|
+
data-name={index}
|
|
174
|
+
style={{ width: '100%', height: '100%' }}
|
|
175
|
+
data-placeholder='商品溯源二维码'
|
|
176
|
+
/>
|
|
177
|
+
)
|
|
146
178
|
} else if (type === 'barcode') {
|
|
147
|
-
content = (
|
|
179
|
+
content = isStation ? (
|
|
180
|
+
<>
|
|
181
|
+
<BarCode
|
|
182
|
+
value={template(barcode, data)}
|
|
183
|
+
textMargin={0}
|
|
184
|
+
margin={0}
|
|
185
|
+
height={parseInt(style.height) - 14}
|
|
186
|
+
width={2}
|
|
187
|
+
displayValue={false}
|
|
188
|
+
dataName={barcode}
|
|
189
|
+
background='transparent'
|
|
190
|
+
/>
|
|
191
|
+
<div style={{ marginLeft: '50px' }}>{template(barcode, data)}</div>
|
|
192
|
+
</>
|
|
193
|
+
) : (
|
|
148
194
|
<div
|
|
149
195
|
data-packagecode='验货条形码'
|
|
150
196
|
data-name={index}
|
|
@@ -161,7 +207,18 @@ class Block extends React.Component {
|
|
|
161
207
|
</div>
|
|
162
208
|
)
|
|
163
209
|
} else if (type === 'in_stock_barcode') {
|
|
164
|
-
content = (
|
|
210
|
+
content = isStation ? (
|
|
211
|
+
<BarCode
|
|
212
|
+
value={template(in_stock_barcode, data)}
|
|
213
|
+
textMargin={0}
|
|
214
|
+
margin={0}
|
|
215
|
+
height={parseInt(style.height) - 14}
|
|
216
|
+
width={2}
|
|
217
|
+
displayValue={false}
|
|
218
|
+
dataName={in_stock_barcode}
|
|
219
|
+
background='transparent'
|
|
220
|
+
/>
|
|
221
|
+
) : (
|
|
165
222
|
<div
|
|
166
223
|
data-instockcode='入库条码'
|
|
167
224
|
data-name={index}
|
|
@@ -178,7 +235,18 @@ class Block extends React.Component {
|
|
|
178
235
|
</div>
|
|
179
236
|
)
|
|
180
237
|
} else if (type === 'production_barcode') {
|
|
181
|
-
content = (
|
|
238
|
+
content = isStation ? (
|
|
239
|
+
<BarCode
|
|
240
|
+
value={template(production_barcode, data)}
|
|
241
|
+
textMargin={0}
|
|
242
|
+
margin={0}
|
|
243
|
+
height={parseInt(style.height) - 14}
|
|
244
|
+
width={2}
|
|
245
|
+
displayValue={false}
|
|
246
|
+
dataName={production_barcode}
|
|
247
|
+
background='transparent'
|
|
248
|
+
/>
|
|
249
|
+
) : (
|
|
182
250
|
<div
|
|
183
251
|
data-productionbarcode='商品条码'
|
|
184
252
|
data-name={index}
|
|
@@ -195,7 +263,12 @@ class Block extends React.Component {
|
|
|
195
263
|
</div>
|
|
196
264
|
)
|
|
197
265
|
} else if (type === 'package_id_qrcode') {
|
|
198
|
-
content = (
|
|
266
|
+
content = isStation ? (
|
|
267
|
+
<QrCode
|
|
268
|
+
value={template(package_id_qrcode, data)}
|
|
269
|
+
size={parseInt(style.height)}
|
|
270
|
+
/>
|
|
271
|
+
) : (
|
|
199
272
|
<div
|
|
200
273
|
data-packageqrcode={template(package_id_qrcode, data)}
|
|
201
274
|
data-width={style.width}
|
|
@@ -206,7 +279,21 @@ class Block extends React.Component {
|
|
|
206
279
|
/>
|
|
207
280
|
)
|
|
208
281
|
} else if (type === 'diycode') {
|
|
209
|
-
content = (
|
|
282
|
+
content = isStation ? (
|
|
283
|
+
<>
|
|
284
|
+
<BarCode
|
|
285
|
+
value={template(diycode, data)}
|
|
286
|
+
textMargin={0}
|
|
287
|
+
margin={0}
|
|
288
|
+
height={35}
|
|
289
|
+
width={2}
|
|
290
|
+
displayValue={false}
|
|
291
|
+
dataName={'diycode'}
|
|
292
|
+
background='transparent'
|
|
293
|
+
/>
|
|
294
|
+
<div style={{ marginLeft: '50px' }}>{template(diycode, data)}</div>
|
|
295
|
+
</>
|
|
296
|
+
) : (
|
|
210
297
|
<div
|
|
211
298
|
data-diycode='自定义编码条形码'
|
|
212
299
|
data-name={index}
|
|
@@ -223,7 +310,9 @@ class Block extends React.Component {
|
|
|
223
310
|
</div>
|
|
224
311
|
)
|
|
225
312
|
} else if (type === 'diyqrcode') {
|
|
226
|
-
content = (
|
|
313
|
+
content = isStation ? (
|
|
314
|
+
<QrCode value={template(text, data)} size={parseInt(style.height)}/>
|
|
315
|
+
) : (
|
|
227
316
|
<div
|
|
228
317
|
data-diyqrcode={template(text, data)}
|
|
229
318
|
data-width={style.width}
|
|
@@ -284,7 +373,8 @@ Block.propTypes = {
|
|
|
284
373
|
index: PropTypes.number.isRequired,
|
|
285
374
|
config: PropTypes.object.isRequired,
|
|
286
375
|
data: PropTypes.object.isRequired,
|
|
287
|
-
selected: PropTypes.number
|
|
376
|
+
selected: PropTypes.number,
|
|
377
|
+
isStation: PropTypes.bool
|
|
288
378
|
}
|
|
289
379
|
|
|
290
380
|
export default Block
|
package/src/printer/index.js
CHANGED
|
@@ -2,11 +2,15 @@ import React from 'react'
|
|
|
2
2
|
import ReactDOMServer from 'react-dom/server'
|
|
3
3
|
import Printer from './printer'
|
|
4
4
|
import _ from 'lodash'
|
|
5
|
+
import { isZoom } from 'gm-util'
|
|
6
|
+
import ReactDOM from 'react-dom'
|
|
7
|
+
import BatchPrinter from './batch_printer'
|
|
5
8
|
|
|
6
9
|
// eslint-disable-next-line
|
|
7
|
-
import normalizeCSS from
|
|
10
|
+
import normalizeCSS from 'css-loader!./normalize.csss'
|
|
8
11
|
// eslint-disable-next-line
|
|
9
|
-
import printerCSS from
|
|
12
|
+
import printerCSS from 'css-loader!postcss-loader!less-loader!./style.lesss'
|
|
13
|
+
import { afterImgAndSvgLoaded } from '../util'
|
|
10
14
|
|
|
11
15
|
function getHtml (props) {
|
|
12
16
|
return ReactDOMServer.renderToString(<Printer {...props}/>)
|
|
@@ -26,4 +30,82 @@ function getCSS () {
|
|
|
26
30
|
return normalizeCSS.toString() + printerCSS.toString()
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
const printerId = '_gm-printer_' + Math.random()
|
|
34
|
+
let $printer = window.document.getElementById(printerId)
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {boolean} isTest 是否test
|
|
38
|
+
* @param {boolean} isTipZoom zoom的时候是否提示
|
|
39
|
+
*/
|
|
40
|
+
function init ({ isTest, isTipZoom = true } = {}) {
|
|
41
|
+
isTipZoom &&
|
|
42
|
+
isZoom() &&
|
|
43
|
+
window.alert(
|
|
44
|
+
'检测您的浏览器使用了缩放,为了避免影响打印布局,请重置缩放到100%后再进行打印'
|
|
45
|
+
)
|
|
46
|
+
if (!$printer) {
|
|
47
|
+
$printer = window.document.createElement('iframe')
|
|
48
|
+
$printer.id = printerId
|
|
49
|
+
$printer.style.position = 'fixed'
|
|
50
|
+
$printer.style.top = '0'
|
|
51
|
+
$printer.style.width = '100%' // 使移动端可滚动
|
|
52
|
+
if (isTest) {
|
|
53
|
+
// 模板编辑[测试打印],隐藏起来
|
|
54
|
+
// $printer.style.left = '-2000px'
|
|
55
|
+
} else {
|
|
56
|
+
$printer.style.left = '0px'
|
|
57
|
+
$printer.style.height = '100vh'
|
|
58
|
+
}
|
|
59
|
+
window.document.body.appendChild($printer)
|
|
60
|
+
|
|
61
|
+
const idocument = $printer.contentDocument
|
|
62
|
+
idocument.open()
|
|
63
|
+
idocument.write('<!DOCTYPE html><html><head></head><body></body></html>')
|
|
64
|
+
idocument.close()
|
|
65
|
+
|
|
66
|
+
const doc = $printer.contentWindow.document
|
|
67
|
+
|
|
68
|
+
const style = doc.createElement('style')
|
|
69
|
+
style.type = 'text/css'
|
|
70
|
+
style.appendChild(doc.createTextNode(getCSS()))
|
|
71
|
+
doc.head.appendChild(style)
|
|
72
|
+
|
|
73
|
+
const div = doc.createElement('div')
|
|
74
|
+
div.id = 'appContainer'
|
|
75
|
+
|
|
76
|
+
doc.body.appendChild(div)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function doBatchPrint (
|
|
81
|
+
list,
|
|
82
|
+
isTest,
|
|
83
|
+
extraCofnig = { isPrint: true, isTipZoom: true },
|
|
84
|
+
isStation = false
|
|
85
|
+
) {
|
|
86
|
+
init({ isTest, isTipZoom: extraCofnig.isTipZoom })
|
|
87
|
+
|
|
88
|
+
return toDoPrintBatch(list, extraCofnig.isPrint, isStation)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function toDoPrintBatch (list, isPrint = true, isStation = false) {
|
|
92
|
+
return new window.Promise((resolve) => {
|
|
93
|
+
const $app = $printer.contentWindow.document.getElementById('appContainer')
|
|
94
|
+
|
|
95
|
+
ReactDOM.unmountComponentAtNode($app)
|
|
96
|
+
ReactDOM.render(
|
|
97
|
+
<BatchPrinter
|
|
98
|
+
list={list}
|
|
99
|
+
isStation={isStation}
|
|
100
|
+
onReady={() => {
|
|
101
|
+
afterImgAndSvgLoaded(() => {
|
|
102
|
+
isPrint && $printer.contentWindow.print()
|
|
103
|
+
resolve()
|
|
104
|
+
}, $app)
|
|
105
|
+
}}
|
|
106
|
+
/>,
|
|
107
|
+
$app
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
export { getHtml, getBatchHtml, getCSS, Printer, doBatchPrint }
|
package/src/printer/printer.js
CHANGED
|
@@ -8,17 +8,25 @@ import { pageTypeMap } from '../common/config'
|
|
|
8
8
|
|
|
9
9
|
@observer
|
|
10
10
|
class Printer extends React.Component {
|
|
11
|
+
componentDidMount () {
|
|
12
|
+
// Printer 不是立马就呈现出最终样式,有个过程。这个过程需要时间,什么 ready,不太清楚,估借 setState 来获取过程结束时刻
|
|
13
|
+
this.setState({}, () => {
|
|
14
|
+
this.props.onReady && this.props.onReady()
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
|
|
11
18
|
render () {
|
|
12
|
-
const { config, selected, data } = this.props
|
|
19
|
+
const { config, selected, data, isStation } = this.props
|
|
13
20
|
const { type, style, customizeWidth, customizeHeight } = config.page
|
|
14
|
-
const isDiy = type === '-1' || type === 'DIY'
|
|
15
21
|
return (
|
|
16
22
|
<div
|
|
17
23
|
className='gm-printer-label'
|
|
18
24
|
style={{
|
|
19
25
|
...style,
|
|
20
|
-
width:
|
|
21
|
-
|
|
26
|
+
width:
|
|
27
|
+
type === '-1' ? customizeWidth + 'mm' : pageTypeMap[type].width,
|
|
28
|
+
height:
|
|
29
|
+
type === '-1' ? customizeHeight + 'mm' : pageTypeMap[type].height
|
|
22
30
|
}}
|
|
23
31
|
>
|
|
24
32
|
<Page config={config.page}>
|
|
@@ -29,6 +37,7 @@ class Printer extends React.Component {
|
|
|
29
37
|
selected={selected}
|
|
30
38
|
config={block}
|
|
31
39
|
data={data}
|
|
40
|
+
isStation={isStation}
|
|
32
41
|
/>
|
|
33
42
|
))}
|
|
34
43
|
</Page>
|
|
@@ -40,7 +49,9 @@ class Printer extends React.Component {
|
|
|
40
49
|
Printer.propTypes = {
|
|
41
50
|
selected: PropTypes.number,
|
|
42
51
|
config: PropTypes.object.isRequired,
|
|
43
|
-
data: PropTypes.object.isRequired // 格式化后的数据
|
|
52
|
+
data: PropTypes.object.isRequired, // 格式化后的数据
|
|
53
|
+
onReady: PropTypes.func,
|
|
54
|
+
isStation: PropTypes.bool
|
|
44
55
|
}
|
|
45
56
|
|
|
46
57
|
export default Printer
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import QRCode from 'qrcode.react'
|
|
3
|
+
import PropTypes from 'prop-types'
|
|
4
|
+
import _ from 'lodash'
|
|
5
|
+
|
|
6
|
+
const QrCode = props => {
|
|
7
|
+
const { value, size } = props
|
|
8
|
+
return (
|
|
9
|
+
<QRCode renderAs='svg' value={value} size={_.isFinite(size) ? size : 75}/>
|
|
10
|
+
)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
QrCode.propTypes = {
|
|
14
|
+
value: PropTypes.string.isRequired,
|
|
15
|
+
size: PropTypes.number.isRequired
|
|
16
|
+
}
|
|
17
|
+
export default QrCode
|
package/src/util.js
CHANGED
|
@@ -35,9 +35,11 @@ function insertCSS (cssString, target) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function dispatchMsg (event, data) {
|
|
38
|
-
window.document.dispatchEvent(
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
window.document.dispatchEvent(
|
|
39
|
+
new window.CustomEvent(event, {
|
|
40
|
+
detail: data
|
|
41
|
+
})
|
|
42
|
+
)
|
|
41
43
|
}
|
|
42
44
|
function substring (target, start = 0, end) {
|
|
43
45
|
return target.substring(start, end)
|
|
@@ -56,10 +58,30 @@ function template (text, data) {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
|
|
61
|
+
let timer
|
|
62
|
+
|
|
63
|
+
function afterImgAndSvgLoaded (callback, $printer) {
|
|
64
|
+
const $imgList = $printer.querySelectorAll('img')
|
|
65
|
+
const $svgList = $printer.querySelectorAll('svg')
|
|
66
|
+
|
|
67
|
+
clearTimeout(timer)
|
|
68
|
+
|
|
69
|
+
const everyThingIsOk =
|
|
70
|
+
_.every($imgList, (img) => img.complete) &&
|
|
71
|
+
_.every($svgList, (svg) => svg.children.length)
|
|
72
|
+
if (everyThingIsOk) {
|
|
73
|
+
callback()
|
|
74
|
+
} else {
|
|
75
|
+
timer = setTimeout(afterImgAndSvgLoaded.bind(this, callback, $printer), 300)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const miniAppLink = 'https://q.guanmai.cn/trace#/commodity_arch'
|
|
59
79
|
export {
|
|
60
80
|
pxAdd,
|
|
61
81
|
getStyleWithDiff,
|
|
62
82
|
insertCSS,
|
|
63
83
|
dispatchMsg,
|
|
64
|
-
template
|
|
84
|
+
template,
|
|
85
|
+
afterImgAndSvgLoaded,
|
|
86
|
+
miniAppLink
|
|
65
87
|
}
|