gm-printer-label 3.3.6 → 3.4.0

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.
Files changed (73) hide show
  1. package/lib/main.js +27 -0
  2. package/lib/package.json +96 -0
  3. package/package.json +10 -14
  4. package/.eslintrc.js +0 -12
  5. package/.github/workflows/release.yml +0 -46
  6. package/.prettierrc.js +0 -5
  7. package/.stylelintrc +0 -3
  8. package/babel.config.js +0 -7
  9. package/i18n.config.js +0 -9
  10. package/locales/en.json +0 -42
  11. package/locales/index.js +0 -32
  12. package/locales/th.json +0 -42
  13. package/locales/zh-HK.json +0 -43
  14. package/locales/zh.json +0 -1
  15. package/postcss.config.js +0 -9
  16. package/src/common/config.js +0 -82
  17. package/src/common/editor_compoents/component.js +0 -481
  18. package/src/common/editor_compoents/config_text.js +0 -47
  19. package/src/common/editor_compoents/context_menu.js +0 -129
  20. package/src/common/editor_compoents/edit.js +0 -106
  21. package/src/common/editor_compoents/edit_add_filed.js +0 -54
  22. package/src/common/editor_compoents/edit_modify_filed.js +0 -199
  23. package/src/common/editor_compoents/edit_select.js +0 -212
  24. package/src/common/editor_compoents/edit_title.js +0 -110
  25. package/src/common/editor_compoents/index.js +0 -10
  26. package/src/common/editor_compoents/store.js +0 -381
  27. package/src/common/editor_compoents/style.less +0 -425
  28. package/src/common/editor_compoents/with_shadow_dom_hoc.js +0 -30
  29. package/src/common/editor_compoents/with_store_hoc.js +0 -92
  30. package/src/components/css/animation.less +0 -95
  31. package/src/components/css/button.less +0 -49
  32. package/src/components/css/distance.less +0 -324
  33. package/src/components/css/text.less +0 -74
  34. package/src/components/css/variables.less +0 -12
  35. package/src/components/dialog/index.js +0 -72
  36. package/src/components/dialog/style.less +0 -64
  37. package/src/components/dropdown/drop_down.js +0 -67
  38. package/src/components/dropdown/drop_down_item.js +0 -37
  39. package/src/components/dropdown/drop_down_items.js +0 -22
  40. package/src/components/dropdown/index.js +0 -9
  41. package/src/components/dropdown/style.less +0 -51
  42. package/src/components/flex/index.js +0 -103
  43. package/src/components/flex/style.less +0 -101
  44. package/src/components/index.js +0 -15
  45. package/src/components/index.less +0 -10
  46. package/src/components/input_number/index.js +0 -158
  47. package/src/components/input_number/style.less +0 -10
  48. package/src/components/select/index.js +0 -7
  49. package/src/components/select/option.js +0 -32
  50. package/src/components/select/select.js +0 -122
  51. package/src/components/select/style.less +0 -79
  52. package/src/components/tip/index.js +0 -48
  53. package/src/components/tip/style.less +0 -22
  54. package/src/editor_label/edit_store.js +0 -3
  55. package/src/editor_label/editor.js +0 -5
  56. package/src/editor_label/editor_with_shadow_dom.js +0 -4
  57. package/src/editor_label/index.js +0 -1
  58. package/src/editor_presorting/edit_store.js +0 -3
  59. package/src/editor_presorting/editor_with_shadow_dom.js +0 -6
  60. package/src/editor_presorting/index.js +0 -1
  61. package/src/index.js +0 -7
  62. package/src/printer/barcode.js +0 -38
  63. package/src/printer/batch_printer.js +0 -43
  64. package/src/printer/block.js +0 -544
  65. package/src/printer/components/table_type.js +0 -46
  66. package/src/printer/index.js +0 -111
  67. package/src/printer/normalize.css +0 -341
  68. package/src/printer/page.js +0 -26
  69. package/src/printer/printer.js +0 -71
  70. package/src/printer/qrcode.js +0 -17
  71. package/src/printer/style.less +0 -28
  72. package/src/util.js +0 -87
  73. package/webpack.config.js +0 -53
@@ -1,481 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import classNames from 'classnames'
4
- import _ from 'lodash'
5
- import { borderStyleList } from '../config'
6
- import ReactDOM from 'react-dom'
7
- import Clipboard from 'clipboard'
8
- import { Flex, Tip } from '../../components'
9
- import i18next from '../../../locales'
10
- import { Request } from 'gm-util'
11
-
12
- class IconAlign extends React.Component {
13
- render () {
14
- const style = {
15
- display: 'block',
16
- background: 'black',
17
- width: '100%',
18
- height: '1px',
19
- marginBottom: '1px'
20
- }
21
-
22
- return (
23
- <span style={{
24
- display: 'inline-flex',
25
- width: '1em',
26
- verticalAlign: 'middle',
27
- flexDirection: 'column',
28
- alignItems: ({left: 'flex-start', center: 'center', right: 'flex-end'})[this.props.textAlign]
29
- }}>
30
- <span style={{...style}}/>
31
- <span style={{...style, width: '60%'}}/>
32
- <span style={{...style}}/>
33
- <span style={{...style, width: '60%'}}/>
34
- <span style={{...style}}/>
35
- </span>
36
- )
37
- }
38
- }
39
-
40
- IconAlign.propTypes = {
41
- textAlign: PropTypes.string
42
- }
43
-
44
- IconAlign.defaultProps = {
45
- textAlign: 'left'
46
- }
47
-
48
- class Separator extends React.Component {
49
- render () {
50
- return (
51
- <span style={{
52
- display: 'inline-block',
53
- margin: '0 5px',
54
- borderLeft: '1px solid #c1c8cc',
55
- height: '1em',
56
- verticalAlign: 'middle'
57
- }}/>
58
- )
59
- }
60
- }
61
-
62
- class Text extends React.Component {
63
- handleChange = (e) => {
64
- const {onChange} = this.props
65
- onChange(e.target.value)
66
- }
67
-
68
- render () {
69
- const {value, placeholder, style} = this.props
70
- return (
71
- <input
72
- type='text'
73
- value={value}
74
- placeholder={placeholder}
75
- onChange={this.handleChange}
76
- style={style}
77
- />
78
- )
79
- }
80
- }
81
-
82
- Text.propTypes = {
83
- value: PropTypes.string,
84
- placeholder: PropTypes.string,
85
- onChange: PropTypes.func.isRequired
86
- }
87
-
88
- class Textarea extends React.Component {
89
- handleChange = (e) => {
90
- const {onChange} = this.props
91
- onChange(e.target.value)
92
- }
93
-
94
- render () {
95
- const {value, placeholder, style} = this.props
96
- return (
97
- <textarea
98
- value={value}
99
- placeholder={placeholder}
100
- onChange={this.handleChange}
101
- style={{
102
- width: '100%',
103
- ...style
104
- }}
105
- />
106
- )
107
- }
108
- }
109
-
110
- Textarea.propTypes = {
111
- value: PropTypes.string,
112
- placeholder: PropTypes.string,
113
- onChange: PropTypes.func.isRequired
114
- }
115
-
116
- // 10px => 10 10% => 10%
117
- class TextPX extends React.Component {
118
- handleChange = (value) => {
119
- const {onChange} = this.props
120
- if (value === '') {
121
- onChange('')
122
- } else if (value.endsWith('%')) {
123
- onChange(value)
124
- } else {
125
- onChange(value + 'px')
126
- }
127
- }
128
-
129
- render () {
130
- const {value = ''} = this.props
131
-
132
- let nValue = value
133
- if (value.endsWith('px')) {
134
- nValue = value.replace(/px/g, '')
135
- }
136
-
137
- return (
138
- <Text value={nValue} onChange={this.handleChange} style={{width: '35px'}}/>
139
- )
140
- }
141
- }
142
-
143
- TextPX.propTypes = {
144
- value: PropTypes.string,
145
- onChange: PropTypes.func.isRequired
146
- }
147
-
148
- class Fonter extends React.Component {
149
- handleChange = (type, value) => {
150
- const {style, onChange} = this.props
151
-
152
- onChange({
153
- ...style,
154
- [type]: value
155
- })
156
- }
157
-
158
- render () {
159
- const {style} = this.props
160
-
161
- return (
162
- <span className='gm-printer-label-edit-fonter'>
163
- <TextPX value={style.fontSize} onChange={this.handleChange.bind(this, 'fontSize')}/>
164
- <Separator/>
165
- <span
166
- className={classNames('gm-printer-label-editor_compoents-btn', {
167
- active: style.fontWeight === 'bold'
168
- })}
169
- style={{fontWeight: 'bold'}}
170
- onClick={() => this.handleChange('fontWeight', style.fontWeight === 'bold' ? '' : 'bold')}
171
- >
172
- B
173
- </span>
174
- <span
175
- className={classNames('gm-printer-label-editor_compoents-btn', {active: style.fontStyle === 'italic'})}
176
- style={{fontStyle: 'italic'}}
177
- onClick={() => this.handleChange('fontStyle', style.fontStyle === 'italic' ? '' : 'italic')}
178
- >
179
- I
180
- </span>
181
- <span
182
- className={classNames('gm-printer-label-editor_compoents-btn', {active: style.textDecoration === 'underline'})}
183
- style={{textDecoration: 'underline'}}
184
- onClick={() => this.handleChange('textDecoration', style.textDecoration === 'underline' ? '' : 'underline')}
185
- >
186
- U
187
- </span>
188
- </span>
189
- )
190
- }
191
- }
192
-
193
- Fonter.propTypes = {
194
- style: PropTypes.object,
195
- onChange: PropTypes.func.isRequired
196
- }
197
-
198
- class TextAlign extends React.Component {
199
- handleChange = (textAlign) => {
200
- const {style, onChange} = this.props
201
- onChange({
202
- ...style,
203
- textAlign
204
- })
205
- }
206
-
207
- render () {
208
- const {style: {textAlign}} = this.props
209
-
210
- // TODO icon
211
- return (
212
- <span className='gm-printer-label-edit-text-align'>
213
- <span
214
- className={classNames('gm-printer-label-editor_compoents-btn', {
215
- active: textAlign === 'left'
216
- })}
217
- onClick={() => this.handleChange('left')}
218
- ><IconAlign textAlign='left'/></span>
219
- <span
220
- className={classNames('gm-printer-label-editor_compoents-btn', {
221
- active: textAlign === 'center'
222
- })}
223
- onClick={() => this.handleChange('center')}
224
- ><IconAlign textAlign='center'/></span>
225
- <span
226
- className={classNames('gm-printer-label-editor_compoents-btn', {
227
- active: textAlign === 'right'
228
- })}
229
- onClick={() => this.handleChange('right')}
230
- ><IconAlign textAlign='right'/></span>
231
- </span>
232
- )
233
- }
234
- }
235
-
236
- TextAlign.propTypes = {
237
- style: PropTypes.object,
238
- onChange: PropTypes.func.isRequired
239
- }
240
-
241
- class Position extends React.Component {
242
- handleChange = (type, value) => {
243
- const {style, onChange} = this.props
244
-
245
- onChange({
246
- ...style,
247
- [type]: value
248
- })
249
- }
250
-
251
- render () {
252
- const {style: {top, right, bottom, left}} = this.props
253
-
254
- return (
255
- <span>
256
- {i18next.t('上')} <TextPX value={top} onChange={this.handleChange.bind(this, 'top')}/>
257
- &nbsp;
258
- {i18next.t('左')} <TextPX value={left} onChange={this.handleChange.bind(this, 'left')}/>
259
- &nbsp;
260
- {i18next.t('下')} <TextPX value={bottom} onChange={this.handleChange.bind(this, 'bottom')}/>
261
- &nbsp;
262
- {i18next.t('右')} <TextPX value={right} onChange={this.handleChange.bind(this, 'right')}/>
263
- </span>
264
- )
265
- }
266
- }
267
-
268
- Position.propTypes = {
269
- style: PropTypes.object.isRequired,
270
- onChange: PropTypes.func.isRequired
271
- }
272
-
273
- class Line extends React.Component {
274
- handleChange = (type, value) => {
275
- const {style, onChange} = this.props
276
-
277
- onChange({
278
- ...style,
279
- [type]: value
280
- })
281
- }
282
-
283
- render () {
284
- const {style: {borderTopWidth, borderTopStyle, width}} = this.props
285
-
286
- return (
287
- <span>
288
- {i18next.t('宽')} <TextPX value={width} onChange={this.handleChange.bind(this, 'width')} style={{width: '35px'}}/>
289
- &nbsp;
290
- {i18next.t('粗细')} <TextPX value={borderTopWidth} onChange={this.handleChange.bind(this, 'borderTopWidth')}/>
291
- &nbsp;
292
- <select value={borderTopStyle} onChange={e => this.handleChange('borderTopStyle', e.target.value)}>
293
- {_.map(borderStyleList, v => <option key={v.value} value={v.value}>{v.text}</option>)}</select>
294
- </span>
295
- )
296
- }
297
- }
298
-
299
- Line.propTypes = {
300
- style: PropTypes.object.isRequired,
301
- onChange: PropTypes.func.isRequired
302
- }
303
-
304
- class Size extends React.Component {
305
- handleChange = (type, value) => {
306
- const {onChange, style} = this.props
307
-
308
- onChange({
309
- ...style,
310
- [type]: value
311
- })
312
- }
313
-
314
- render () {
315
- const {style, withoutWidth} = this.props
316
- return (
317
- <React.Fragment>
318
- {i18next.t('高')} <TextPX value={style.height} onChange={this.handleChange.bind(this, 'height')}/>
319
- &nbsp;
320
- {withoutWidth ? null
321
- : <React.Fragment>{i18next.t('宽')}{<TextPX value={style.width} onChange={this.handleChange.bind(this, 'width')}/>}</React.Fragment>
322
- }
323
- </React.Fragment>
324
- )
325
- }
326
- }
327
-
328
- Size.propTypes = {
329
- style: PropTypes.object.isRequired,
330
- onChange: PropTypes.func.isRequired
331
- }
332
-
333
- class Copy extends React.Component {
334
- componentDidMount () {
335
- this.clipboard = new Clipboard(ReactDOM.findDOMNode(this), {
336
- text: () => this.props.text
337
- })
338
-
339
- this.clipboard.on('success', () => {
340
- })
341
-
342
- this.clipboard.on('error', () => {
343
- })
344
- }
345
-
346
- componentWillUnmount () {
347
- this.clipboard.destroy()
348
- }
349
-
350
- render () {
351
- return this.props.children
352
- }
353
- }
354
-
355
- const Title = ({ title, text }) => <Flex alignCenter className='gm-printer-label-edit-title'>
356
- <span>{title}</span>
357
- <span className='gm-font-12'>{text}</span>
358
- </Flex>
359
-
360
- const Gap = ({ width = '100%', height = '3px' }) => <div style={{ width, height }}/>
361
-
362
- const TipInfo = ({ text }) => <Flex alignCenter className='gm-padding-top-5 gm-text-red'>{text}</Flex>
363
-
364
- const FieldBtn = ({ name, onClick }) => (
365
- <Flex alignCenter style={{ width: '50%', margin: '3px 0' }}>
366
- <span className='gm-printer-label-edit-plus-btn' onClick={onClick}>
367
- +
368
- </span>
369
- <span className='gm-padding-left-5'>{name}</span>
370
- </Flex>
371
- )
372
-
373
- const SubTitle = ({ text }) => (
374
- <div style={{ backgroundColor: '#eee', height: '1px', margin: '10px 0 13px 0', position: 'relative' }}>
375
- <span style={{
376
- position: 'absolute',
377
- top: '-8px',
378
- left: '20px',
379
- padding: '0 5px',
380
- backgroundColor: '#fff',
381
- color: '#848586'
382
- }}>{text}</span>
383
- </div>
384
- )
385
-
386
- class ImageUploader extends React.Component {
387
- constructor () {
388
- super()
389
- this.input = React.createRef()
390
- }
391
-
392
- handleUpload = event => {
393
- event.preventDefault()
394
- // 只上传单张图片
395
- const droppedFiles = event.dataTransfer
396
- ? event.dataTransfer.files
397
- : event.target.files
398
- const file = droppedFiles[0]
399
-
400
- if (file.size > 512 * 1024) {
401
- Tip.warning(i18next.t('图片大小不能超过500Kb'))
402
- return
403
- }
404
- if (this.props.uploadQiniuImage) {
405
- this.props.uploadQiniuImage(file).then((json) => {
406
- this.props.onSuccess(json.data.url)
407
- })
408
- return
409
- }
410
- const STATION_URL = {
411
- reqUrl: '/station/image/upload',
412
- imgUrl: 'http://img.guanmai.cn/station_pic'
413
- }
414
-
415
- const MANAGE_URL = {
416
- reqUrl: '/gm_account/image/upload',
417
- imgUrl: 'http://img.guanmai.cn/report_pic'
418
- }
419
-
420
- const { hostname } = window.location
421
- const isStation = /station/g.test(hostname)
422
- const url = isStation ? STATION_URL : MANAGE_URL
423
-
424
- Request(url.reqUrl)
425
- .data({
426
- image_file: file
427
- })
428
- .post()
429
- .then(json => {
430
- const imgURL = `${url.imgUrl}/${json.data.img_path_id}`
431
- this.props.onSuccess(imgURL)
432
- })
433
- }
434
-
435
- handleClick = () => {
436
- this.input.current.value = null
437
- this.input.current.click()
438
- }
439
-
440
- render () {
441
- return (
442
- <React.Fragment>
443
- <div onClick={this.handleClick} onDrop={this.handleUpload}>
444
- {this.props.text}
445
- </div>
446
- <input
447
- style={{ display: 'none' }}
448
- type='file'
449
- ref={this.input}
450
- accept='image/*'
451
- onChange={this.handleUpload}
452
- />
453
- </React.Fragment>
454
- )
455
- }
456
- }
457
-
458
- ImageUploader.propTypes = {
459
- onSuccess: PropTypes.func.isRequired,
460
- text: PropTypes.string.isRequired,
461
- uploadTengXunFile: PropTypes.func
462
- }
463
-
464
- export {
465
- Copy,
466
- Text,
467
- Textarea,
468
- TextPX,
469
- TextAlign,
470
- Separator,
471
- Fonter,
472
- Position,
473
- Line,
474
- Size,
475
- Title,
476
- Gap,
477
- TipInfo,
478
- FieldBtn,
479
- SubTitle,
480
- ImageUploader
481
- }
@@ -1,47 +0,0 @@
1
- import React from 'react'
2
- import PropTypes from 'prop-types'
3
- import { Copy } from './component'
4
- import i18next from '../../../locales'
5
- import { inject, observer } from 'mobx-react'
6
-
7
- @inject('editStore')
8
- @observer
9
- class ConfigText extends React.Component {
10
- handleChangeConfig = (e) => {
11
- this.props.onChange(JSON.parse(e.target.value))
12
- }
13
-
14
- render () {
15
- const { config } = this.props.editStore
16
-
17
- return (
18
- <div className='gm-printer-label-edit-config-text'>
19
- <hr/>
20
- <div style={{ padding: '10px' }}>
21
- <Copy text={JSON.stringify(config)}>
22
- <div>
23
- {i18next.t('请将以下配置代码发给观麦技术')}
24
- <button>{i18next.t('复制')}</button>
25
- </div>
26
- </Copy>
27
- <textarea
28
- style={{
29
- display: 'block',
30
- width: '500px',
31
- height: '300px'
32
- }}
33
- value={JSON.stringify(config, null, 2)}
34
- onChange={this.handleChangeConfig}
35
- />
36
- </div>
37
- </div>
38
- )
39
- }
40
- }
41
-
42
- ConfigText.propTypes = {
43
- editStore: PropTypes.object.isRequired,
44
- onChange: PropTypes.func.isRequired
45
- }
46
-
47
- export default ConfigText
@@ -1,129 +0,0 @@
1
- import React, { useEffect } from 'react'
2
- import i18next from '../../../locales'
3
- import PropTypes from 'prop-types'
4
- import { inject, observer } from 'mobx-react'
5
-
6
- @inject('editStore')
7
- @observer
8
- class ContextMenu extends React.Component {
9
- constructor (props) {
10
- super(props)
11
- this.state = {
12
- name: null,
13
- popup: {
14
- left: 0,
15
- top: 0
16
- }
17
- }
18
-
19
- this.menuRef = React.createRef()
20
- }
21
-
22
- componentDidMount () {
23
- window.shadowRoot.addEventListener('click', this.handleClick)
24
- }
25
-
26
- componentWillUnmount () {
27
- window.shadowRoot.addEventListener('click', this.handleClick)
28
- }
29
-
30
- handleClick = () => {
31
- // 简单处理,点击空白收起context_menu
32
- this.setState({
33
- name: null
34
- })
35
- }
36
-
37
- handleRemove = () => {
38
- const { name } = this.state
39
- const { setSelected, removeConfig } = this.props.editStore
40
- setSelected(name)
41
- removeConfig()
42
- }
43
-
44
- handleContextMenu = (e) => {
45
- // 从e.target.dataset中更新name值
46
- const { target: { dataset: { name } }, clientX, clientY } = e
47
-
48
- e.preventDefault()
49
-
50
- this.setState({
51
- name,
52
- popup: {
53
- left: clientX,
54
- top: clientY
55
- }
56
- })
57
- }
58
-
59
- detectContextMenuTop = () => {
60
- const { popup: { top } } = this.state
61
- const clientHeight = window.document.body.clientHeight
62
- const contextMenuHeight = this.menuRef.current.clientHeight
63
-
64
- if ((clientHeight - top) < contextMenuHeight) {
65
- this.setState({
66
- popup: {
67
- ...this.state.popup,
68
- top: clientHeight - contextMenuHeight
69
- }
70
- })
71
- }
72
- }
73
-
74
- renderBlocks = () => {
75
- return (
76
- <div onClick={this.handleRemove}>
77
- {i18next.t('移除')}
78
- </div>
79
- )
80
- }
81
-
82
- render () {
83
- const { children } = this.props
84
- const { popup, name } = this.state
85
- return (
86
- <div onClick={this.handleCancel} className='gm-pinter-label-eidt-wrap'
87
- onContextMenu={this.handleContextMenu}>
88
- {children}
89
- {name && (
90
- <Menu
91
- detectContextMenuTop={this.detectContextMenuTop}>
92
- {
93
- <div ref={this.menuRef} className='gm-printer-label-contextmenu'
94
- style={{
95
- position: 'fixed',
96
- ...popup
97
- }}>
98
- {this.renderBlocks()}
99
- </div>
100
- }
101
- </Menu>
102
- )}
103
- </div>
104
- )
105
- }
106
- }
107
-
108
- function Menu (props) {
109
- const { children, detectContextMenuTop } = props
110
- useEffect(() => {
111
- detectContextMenuTop()
112
- })
113
-
114
- return (
115
- <React.Fragment>
116
- {children}
117
- </React.Fragment>
118
- )
119
- }
120
-
121
- Menu.propTypes = {
122
- children: PropTypes.element.isRequired,
123
- detectContextMenuTop: PropTypes.func.isRequired
124
- }
125
-
126
- ContextMenu.propTypes = {
127
- children: PropTypes.element.isRequired
128
- }
129
- export default ContextMenu