gm-printer-label 3.0.13 → 3.1.0-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/package.json +1 -1
- package/src/common/editor_compoents/edit.js +38 -22
- package/src/common/editor_compoents/edit_modify_filed.js +1 -2
- package/src/common/editor_compoents/store.js +2 -2
- package/src/printer/block.js +26 -19
- package/src/printer/page.js +7 -5
- package/src/printer/printer.js +25 -9
- package/src/util.js +12 -11
package/.eslintcache
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
[{"/
|
|
1
|
+
[{"/Volumes/gm-project/gm-printer-label/src/index.js":"1","/Volumes/gm-project/gm-printer-label/src/common/editor_compoents/edit_modify_filed.js":"2","/Volumes/gm-project/gm-printer-label/src/common/config.js":"3","/Volumes/gm-project/gm-printer-label/src/common/editor_compoents/store.js":"4","/Volumes/gm-project/gm-printer-label/src/util.js":"5","/Volumes/gm-project/gm-printer-label/src/printer/printer.js":"6","/Volumes/gm-project/gm-printer-label/src/printer/page.js":"7","/Volumes/gm-project/gm-printer-label/src/printer/block.js":"8","/Volumes/gm-project/gm-printer-label/src/common/editor_compoents/edit.js":"9"},{"size":180,"mtime":1658462117054,"results":"10","hashOfConfig":"11"},{"size":4629,"mtime":1658462013375},{"size":1699,"mtime":1658461960259},{"size":7194,"mtime":1658890412916,"results":"12","hashOfConfig":"11"},{"size":1962,"mtime":1660567552794},{"size":1913,"mtime":1660567552793},{"size":411,"mtime":1660567552793},{"size":10486,"mtime":1660567552793},{"size":2958,"mtime":1660567552792},{"filePath":"13","messages":"14","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"17s6x9q",{"filePath":"15","messages":"16","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Volumes/gm-project/gm-printer-label/src/index.js",[],"/Volumes/gm-project/gm-printer-label/src/common/editor_compoents/store.js",[]]
|
package/package.json
CHANGED
|
@@ -21,48 +21,62 @@ class Edit extends React.Component {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
render
|
|
25
|
-
const {
|
|
24
|
+
render() {
|
|
25
|
+
const {
|
|
26
|
+
data,
|
|
27
|
+
initDefaultTemp,
|
|
28
|
+
defaultTempList,
|
|
29
|
+
addFields,
|
|
30
|
+
onSave,
|
|
31
|
+
editStore,
|
|
32
|
+
insertBlocksConfig,
|
|
33
|
+
uploadQiniuImage,
|
|
34
|
+
doublePageType,
|
|
35
|
+
} = this.props
|
|
26
36
|
return (
|
|
27
37
|
<div className='gm-printer-label-edit'>
|
|
28
|
-
|
|
29
38
|
<Flex className='gm-printer-label-edit-title-fixed'>
|
|
30
|
-
<Title
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
<Title
|
|
40
|
+
title={i18next.t('模板预览')}
|
|
41
|
+
text={
|
|
42
|
+
<span className='gm-text-desc gm-padding-left-5'>
|
|
43
|
+
{i18next.t(
|
|
44
|
+
'说明:单击选中内容,双击编辑,可拖动以摆放位置,可方向键细调位置,可点击右键删除'
|
|
45
|
+
)}
|
|
46
|
+
</span>
|
|
47
|
+
}
|
|
48
|
+
/>
|
|
34
49
|
</Flex>
|
|
35
50
|
|
|
36
51
|
<div className='gm-printer-label-edit-header'>
|
|
37
|
-
<EditTitle
|
|
38
|
-
|
|
39
|
-
initDefaultTemp={initDefaultTemp}
|
|
40
|
-
/>
|
|
41
|
-
<Gap height='10px'/>
|
|
52
|
+
<EditTitle onSave={onSave} initDefaultTemp={initDefaultTemp} />
|
|
53
|
+
<Gap height='10px' />
|
|
42
54
|
<EditSelect
|
|
43
55
|
insertBlocksConfig={insertBlocksConfig}
|
|
44
56
|
initDefaultTemp={initDefaultTemp}
|
|
45
57
|
defaultTempList={defaultTempList}
|
|
46
58
|
uploadQiniuImage={uploadQiniuImage}
|
|
47
59
|
/>
|
|
48
|
-
<Gap height='5px'/>
|
|
49
|
-
<EditModifyFiled/>
|
|
50
|
-
<Gap height='5px'/>
|
|
51
|
-
<EditAddFiled data={addFields}/>
|
|
60
|
+
<Gap height='5px' />
|
|
61
|
+
<EditModifyFiled />
|
|
62
|
+
<Gap height='5px' />
|
|
63
|
+
<EditAddFiled data={addFields} />
|
|
52
64
|
|
|
53
65
|
{/* 挂载shadow down中的Dialog组件 */}
|
|
54
|
-
<div id='gm-printer-label-modal'/>
|
|
55
|
-
|
|
66
|
+
<div id='gm-printer-label-modal' />
|
|
56
67
|
</div>
|
|
57
68
|
|
|
58
|
-
<div
|
|
59
|
-
|
|
69
|
+
<div
|
|
70
|
+
className='gm-printer-label-edit-content'
|
|
71
|
+
onClick={this.handleCancel}
|
|
72
|
+
>
|
|
60
73
|
<ContextMenu>
|
|
61
74
|
<Printer
|
|
62
75
|
selected={editStore.selected}
|
|
63
76
|
config={editStore.config}
|
|
64
77
|
data={data}
|
|
65
78
|
onChange={this.handleChange}
|
|
79
|
+
doublePageType={doublePageType}
|
|
66
80
|
/>
|
|
67
81
|
</ContextMenu>
|
|
68
82
|
</div>
|
|
@@ -79,11 +93,13 @@ Edit.propTypes = {
|
|
|
79
93
|
initDefaultTemp: PropTypes.string,
|
|
80
94
|
defaultTempList: PropTypes.object,
|
|
81
95
|
addFields: PropTypes.object.isRequired,
|
|
82
|
-
insertBlocksConfig: PropTypes.array.isRequired
|
|
96
|
+
insertBlocksConfig: PropTypes.array.isRequired,
|
|
97
|
+
/** 放大编辑窗口 */
|
|
98
|
+
doublePageType: PropTypes.bool,
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
Edit.deaultProps = {
|
|
86
|
-
onSave: _.noop
|
|
102
|
+
onSave: _.noop,
|
|
87
103
|
}
|
|
88
104
|
|
|
89
105
|
export default Edit
|
|
@@ -84,8 +84,7 @@ class EditModifyFiled extends React.Component {
|
|
|
84
84
|
{(type === 'qrcode' ||
|
|
85
85
|
type === 'order_qrcode' ||
|
|
86
86
|
type === 'package_id_qrcode' ||
|
|
87
|
-
type === 'image'
|
|
88
|
-
type === 'merchandise_trace_qrcode') && (
|
|
87
|
+
type === 'image') && (
|
|
89
88
|
<div>
|
|
90
89
|
<Size
|
|
91
90
|
style={style}
|
package/src/printer/block.js
CHANGED
|
@@ -9,12 +9,12 @@ import QrCode from './qrcode'
|
|
|
9
9
|
|
|
10
10
|
@observer
|
|
11
11
|
class Block extends React.Component {
|
|
12
|
-
constructor
|
|
12
|
+
constructor(props) {
|
|
13
13
|
super(props)
|
|
14
14
|
this.state = {
|
|
15
15
|
clientX: null,
|
|
16
16
|
clientY: null,
|
|
17
|
-
isEdit: false
|
|
17
|
+
isEdit: false,
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -23,14 +23,14 @@ class Block extends React.Component {
|
|
|
23
23
|
|
|
24
24
|
this.setState({
|
|
25
25
|
clientX,
|
|
26
|
-
clientY
|
|
26
|
+
clientY,
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
window.document.dispatchEvent(
|
|
30
30
|
new window.CustomEvent('gm-printer-label-select', {
|
|
31
31
|
detail: {
|
|
32
|
-
selected: index
|
|
33
|
-
}
|
|
32
|
+
selected: index,
|
|
33
|
+
},
|
|
34
34
|
})
|
|
35
35
|
)
|
|
36
36
|
}
|
|
@@ -43,7 +43,7 @@ class Block extends React.Component {
|
|
|
43
43
|
const style = getStyleWithDiff(config.style, diffX, diffY)
|
|
44
44
|
|
|
45
45
|
dispatchMsg('gm-printer-label-block-style-set', {
|
|
46
|
-
style
|
|
46
|
+
style,
|
|
47
47
|
})
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -51,18 +51,18 @@ class Block extends React.Component {
|
|
|
51
51
|
const { index } = this.props
|
|
52
52
|
|
|
53
53
|
dispatchMsg('gm-printer-label-select', {
|
|
54
|
-
selected: index
|
|
54
|
+
selected: index,
|
|
55
55
|
})
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
handleDoubleClick = () => {
|
|
59
59
|
const {
|
|
60
|
-
config: { type }
|
|
60
|
+
config: { type },
|
|
61
61
|
} = this.props
|
|
62
62
|
if (!type || type === 'text') {
|
|
63
63
|
this.setState(
|
|
64
64
|
{
|
|
65
|
-
isEdit: true
|
|
65
|
+
isEdit: true,
|
|
66
66
|
},
|
|
67
67
|
() => {
|
|
68
68
|
this.refEdit.focus()
|
|
@@ -73,17 +73,17 @@ class Block extends React.Component {
|
|
|
73
73
|
|
|
74
74
|
handleEditBlur = () => {
|
|
75
75
|
this.setState({
|
|
76
|
-
isEdit: false
|
|
76
|
+
isEdit: false,
|
|
77
77
|
})
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
handleText = (e) => {
|
|
81
81
|
dispatchMsg('gm-printer-label-block-text-set', {
|
|
82
|
-
text: e.target.value
|
|
82
|
+
text: e.target.value,
|
|
83
83
|
})
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
render
|
|
86
|
+
render() {
|
|
87
87
|
const {
|
|
88
88
|
index,
|
|
89
89
|
selected,
|
|
@@ -101,7 +101,7 @@ class Block extends React.Component {
|
|
|
101
101
|
fieldType,
|
|
102
102
|
fieldKey,
|
|
103
103
|
production_barcode,
|
|
104
|
-
merchandise_trace_qrcode
|
|
104
|
+
merchandise_trace_qrcode,
|
|
105
105
|
},
|
|
106
106
|
data,
|
|
107
107
|
className,
|
|
@@ -111,7 +111,7 @@ class Block extends React.Component {
|
|
|
111
111
|
const { isEdit } = this.state
|
|
112
112
|
let content = null
|
|
113
113
|
if (!type || type === 'text') {
|
|
114
|
-
if (fieldType === '
|
|
114
|
+
if (fieldType === ' ') {
|
|
115
115
|
// 字段类型为表格
|
|
116
116
|
content = (
|
|
117
117
|
<TableType
|
|
@@ -309,7 +309,7 @@ class Block extends React.Component {
|
|
|
309
309
|
)
|
|
310
310
|
} else if (type === 'diyqrcode') {
|
|
311
311
|
content = isStation ? (
|
|
312
|
-
<QrCode value={template(text, data)} size={parseInt(style.height)}/>
|
|
312
|
+
<QrCode value={template(text, data)} size={parseInt(style.height)} />
|
|
313
313
|
) : (
|
|
314
314
|
<div
|
|
315
315
|
data-diyqrcode={template(text, data)}
|
|
@@ -331,7 +331,10 @@ class Block extends React.Component {
|
|
|
331
331
|
/>
|
|
332
332
|
)
|
|
333
333
|
}
|
|
334
|
-
|
|
334
|
+
console.log('content', content)
|
|
335
|
+
if (content.indexOf('div') != '-1') {
|
|
336
|
+
// console.log('content', dangerouslySetInnerHTML={{ __html: content }})
|
|
337
|
+
}
|
|
335
338
|
const active = index === selected
|
|
336
339
|
return (
|
|
337
340
|
<div
|
|
@@ -342,7 +345,7 @@ class Block extends React.Component {
|
|
|
342
345
|
`gm-printer-label-block-type-${type}`,
|
|
343
346
|
className,
|
|
344
347
|
{
|
|
345
|
-
active
|
|
348
|
+
active,
|
|
346
349
|
}
|
|
347
350
|
)}
|
|
348
351
|
draggable
|
|
@@ -352,7 +355,11 @@ class Block extends React.Component {
|
|
|
352
355
|
onDoubleClick={this.handleDoubleClick}
|
|
353
356
|
data-name={index}
|
|
354
357
|
>
|
|
355
|
-
{content
|
|
358
|
+
{content.indexOf('div') != '-1' ? (
|
|
359
|
+
<div dangerouslySetInnerHTML={{ __html: content }} />
|
|
360
|
+
) : (
|
|
361
|
+
content
|
|
362
|
+
)}
|
|
356
363
|
{(!type || type === 'text') && active && isEdit && (
|
|
357
364
|
<textarea
|
|
358
365
|
ref={(ref) => (this.refEdit = ref)}
|
|
@@ -372,7 +379,7 @@ Block.propTypes = {
|
|
|
372
379
|
config: PropTypes.object.isRequired,
|
|
373
380
|
data: PropTypes.object.isRequired,
|
|
374
381
|
selected: PropTypes.number,
|
|
375
|
-
isStation: PropTypes.bool
|
|
382
|
+
isStation: PropTypes.bool,
|
|
376
383
|
}
|
|
377
384
|
|
|
378
385
|
export default Block
|
package/src/printer/page.js
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
2
|
import { observer } from 'mobx-react'
|
|
3
|
-
import { pageTypeMap } from '../common/config'
|
|
4
3
|
|
|
5
4
|
@observer
|
|
6
5
|
class Page extends React.Component {
|
|
7
|
-
render
|
|
8
|
-
const {
|
|
6
|
+
render() {
|
|
7
|
+
const {
|
|
8
|
+
pageStyle: { width, height },
|
|
9
|
+
children,
|
|
10
|
+
} = this.props
|
|
9
11
|
|
|
10
12
|
return (
|
|
11
13
|
<div
|
|
12
14
|
className='gm-printer-label-page'
|
|
13
15
|
style={{
|
|
14
|
-
width
|
|
15
|
-
height
|
|
16
|
+
width,
|
|
17
|
+
height,
|
|
16
18
|
}}
|
|
17
19
|
>
|
|
18
20
|
{children}
|
package/src/printer/printer.js
CHANGED
|
@@ -8,28 +8,42 @@ 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 } = this.props
|
|
18
|
+
render() {
|
|
19
|
+
const { config, selected, data, isStation, doublePageType } = this.props
|
|
20
20
|
const { type, style, customizeWidth, customizeHeight } = config.page
|
|
21
|
+
const ratio = doublePageType ? 2 : 1
|
|
22
|
+
|
|
23
|
+
const width =
|
|
24
|
+
(type === '-1'
|
|
25
|
+
? customizeWidth
|
|
26
|
+
: +pageTypeMap[type].width.split('mm')[0]) *
|
|
27
|
+
ratio +
|
|
28
|
+
'mm'
|
|
29
|
+
console.log('width', width, type, customizeWidth)
|
|
30
|
+
const height =
|
|
31
|
+
(type === '-1'
|
|
32
|
+
? customizeHeight
|
|
33
|
+
: +pageTypeMap[type].height.split('mm')[0]) *
|
|
34
|
+
ratio +
|
|
35
|
+
'mm'
|
|
36
|
+
|
|
21
37
|
return (
|
|
22
38
|
<div
|
|
23
39
|
className='gm-printer-label'
|
|
24
40
|
style={{
|
|
25
41
|
...style,
|
|
26
|
-
width
|
|
27
|
-
|
|
28
|
-
height:
|
|
29
|
-
type === '-1' ? customizeHeight + 'mm' : pageTypeMap[type].height
|
|
42
|
+
width,
|
|
43
|
+
height,
|
|
30
44
|
}}
|
|
31
45
|
>
|
|
32
|
-
<Page
|
|
46
|
+
<Page pageStyle={{ width, height }}>
|
|
33
47
|
{_.map(config.blocks, (block, i) => (
|
|
34
48
|
<Block
|
|
35
49
|
key={i}
|
|
@@ -51,7 +65,9 @@ Printer.propTypes = {
|
|
|
51
65
|
config: PropTypes.object.isRequired,
|
|
52
66
|
data: PropTypes.object.isRequired, // 格式化后的数据
|
|
53
67
|
onReady: PropTypes.func,
|
|
54
|
-
isStation: PropTypes.bool
|
|
68
|
+
isStation: PropTypes.bool,
|
|
69
|
+
/** 放大编辑窗口 */
|
|
70
|
+
doublePageType: PropTypes.bool,
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
export default Printer
|
package/src/util.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import _ from 'lodash'
|
|
2
2
|
|
|
3
|
-
function pxAdd
|
|
3
|
+
function pxAdd(origin, add) {
|
|
4
4
|
return parseFloat(origin, 10) + add + 'px'
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
function getStyleWithDiff
|
|
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
|
|
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,23 +34,24 @@ function insertCSS (cssString, target) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function dispatchMsg
|
|
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
|
|
44
|
+
function substring(target, start = 0, end) {
|
|
45
45
|
return target.substring(start, end)
|
|
46
46
|
}
|
|
47
|
-
function template
|
|
47
|
+
function template(text, data) {
|
|
48
|
+
console.log('data', data)
|
|
48
49
|
try {
|
|
49
50
|
return _.template(text, {
|
|
50
|
-
interpolate: /{{([\s\S]+?)}}/g
|
|
51
|
+
interpolate: /{{([\s\S]+?)}}/g,
|
|
51
52
|
})({
|
|
52
53
|
...data,
|
|
53
|
-
substring: substring // 添加一个截取字符串函数
|
|
54
|
+
substring: substring, // 添加一个截取字符串函数
|
|
54
55
|
})
|
|
55
56
|
} catch (err) {
|
|
56
57
|
console.warn(err)
|
|
@@ -60,7 +61,7 @@ function template (text, data) {
|
|
|
60
61
|
|
|
61
62
|
let timer
|
|
62
63
|
|
|
63
|
-
function afterImgAndSvgLoaded
|
|
64
|
+
function afterImgAndSvgLoaded(callback, $printer) {
|
|
64
65
|
const $imgList = $printer.querySelectorAll('img')
|
|
65
66
|
const $svgList = $printer.querySelectorAll('svg')
|
|
66
67
|
|
|
@@ -83,5 +84,5 @@ export {
|
|
|
83
84
|
dispatchMsg,
|
|
84
85
|
template,
|
|
85
86
|
afterImgAndSvgLoaded,
|
|
86
|
-
miniAppLink
|
|
87
|
+
miniAppLink,
|
|
87
88
|
}
|