gm-printer-label 3.0.12 → 3.1.0-beta.2

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 CHANGED
@@ -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"},{"size":180,"mtime":1658462117054,"results":"5","hashOfConfig":"6"},{"size":4629,"mtime":1658462013375},{"size":1699,"mtime":1658461960259},{"size":7194,"mtime":1658890412916,"results":"7","hashOfConfig":"6"},{"filePath":"8","messages":"9","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"17s6x9q",{"filePath":"10","messages":"11","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",[]]
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":10502,"mtime":1660726333740},{"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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer-label",
3
- "version": "3.0.12",
3
+ "version": "3.1.0-beta.2",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -21,48 +21,62 @@ class Edit extends React.Component {
21
21
  }
22
22
  }
23
23
 
24
- render () {
25
- const { data, initDefaultTemp, defaultTempList, addFields, onSave, editStore, insertBlocksConfig, uploadQiniuImage } = this.props
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 title={i18next.t('模板预览')}
31
- text={<span className='gm-text-desc gm-padding-left-5'>
32
- {i18next.t('说明:单击选中内容,双击编辑,可拖动以摆放位置,可方向键细调位置,可点击右键删除')}
33
- </span>}/>
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
- onSave={onSave}
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 className='gm-printer-label-edit-content'
59
- onClick={this.handleCancel}>
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
@@ -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 === 'table') {
114
+ if (fieldType === ' ') {
115
115
  // 字段类型为表格
116
116
  content = (
117
117
  <TableType
@@ -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
@@ -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.split(':')?.(1) }}/>
360
+ ) : (
361
+ content
362
+ )}
356
363
  {(!type || type === 'text') && active && isEdit && (
357
364
  <textarea
358
365
  ref={(ref) => (this.refEdit = ref)}
@@ -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 {config: {type, customizeWidth, customizeHeight}, children} = this.props
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: type === '-1' ? customizeWidth + 'mm' : pageTypeMap[type].width,
15
- height: type === '-1' ? customizeHeight + 'mm' : pageTypeMap[type].height
16
+ width,
17
+ height,
16
18
  }}
17
19
  >
18
20
  {children}
@@ -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
- type === '-1' ? customizeWidth + 'mm' : pageTypeMap[type].width,
28
- height:
29
- type === '-1' ? customizeHeight + 'mm' : pageTypeMap[type].height
42
+ width,
43
+ height,
30
44
  }}
31
45
  >
32
- <Page config={config.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 (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,23 +34,24 @@ 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) {
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 (callback, $printer) {
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
  }