gm-printer 10.39.4-beta.2 → 10.39.4-beta.21

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 (37) hide show
  1. package/build/demo.js +9 -9
  2. package/locales/en.json +3 -0
  3. package/locales/th.json +3 -0
  4. package/locales/zh-HK.json +3 -0
  5. package/package.json +1 -1
  6. package/src/common/common_context_menu.js +6 -4
  7. package/src/common/component.js +64 -8
  8. package/src/common/data_key_util.js +35 -0
  9. package/src/common/editor_edit_field.js +288 -167
  10. package/src/common/editor_store.js +230 -42
  11. package/src/common/hoc_with_store.js +9 -0
  12. package/src/common/style.lesss +43 -0
  13. package/src/common/util.js +58 -4
  14. package/src/editor/context_menu.js +17 -0
  15. package/src/editor/store.js +13 -0
  16. package/src/editor_purchase/editor.js +2 -1
  17. package/src/editor_purchase/editor_special_table.js +39 -17
  18. package/src/editor_purchase/editor_sum_table.js +5 -1
  19. package/src/editor_purchase/store.js +48 -45
  20. package/src/finance_voucher/components/table_subtotal_tr.js +12 -18
  21. package/src/index.js +6 -2
  22. package/src/printer/block.js +154 -4
  23. package/src/printer/compute_pages.js +122 -0
  24. package/src/printer/index.js +3 -1
  25. package/src/printer/long_print_table/index.js +14 -4
  26. package/src/printer/multi_column.js +1 -0
  27. package/src/printer/page_summary.js +3 -1
  28. package/src/printer/printer.js +23 -3
  29. package/src/printer/store.js +141 -91
  30. package/src/printer/table.js +11 -3
  31. package/src/printer/table_diy_overallOrder_tr.js +8 -15
  32. package/src/printer/table_diy_summary_tr.js +18 -35
  33. package/src/printer/table_overallOrder_tr.js +49 -37
  34. package/src/printer/table_special_tr.js +17 -2
  35. package/src/printer/table_subtotal_tr.js +100 -16
  36. package/src/util.js +34 -8
  37. package/yarn-error.log +372 -152
package/locales/en.json CHANGED
@@ -16,6 +16,9 @@
16
16
  "粗细": "",
17
17
  "高": "",
18
18
  "图片大小不能超过500Kb": "",
19
+ "图片大小不能超过2M": "Image size cannot exceed 2M",
20
+ "仅支持jpg、jpeg、png格式的图片": "Only JPG, JPEG, and PNG images are supported",
21
+ "支持插入2M以内的jpg、jpeg、png格式图片": "Support inserting JPG, JPEG, or PNG images within 2M",
19
22
  "配送单特殊控制": "",
20
23
  "添加字段": "",
21
24
  "编辑字段": "",
package/locales/th.json CHANGED
@@ -16,6 +16,9 @@
16
16
  "粗细": "",
17
17
  "高": "",
18
18
  "图片大小不能超过500Kb": "",
19
+ "图片大小不能超过2M": "ขนาดรูปภาพต้องไม่เกิน 2M",
20
+ "仅支持jpg、jpeg、png格式的图片": "รองรับเฉพาะรูปภาพรูปแบบ jpg, jpeg, png",
21
+ "支持插入2M以内的jpg、jpeg、png格式图片": "รองรับการแทรกรูปภาพ jpg, jpeg, png ขนาดไม่เกิน 2M",
19
22
  "配送单特殊控制": "",
20
23
  "添加字段": "",
21
24
  "编辑字段": "",
@@ -16,6 +16,9 @@
16
16
  "粗细": "粗細",
17
17
  "高": "高",
18
18
  "图片大小不能超过500Kb": "圖片大小不能超過500Kb",
19
+ "图片大小不能超过2M": "圖片大小不能超過2M",
20
+ "仅支持jpg、jpeg、png格式的图片": "僅支持jpg、jpeg、png格式的圖片",
21
+ "支持插入2M以内的jpg、jpeg、png格式图片": "支持插入2M以內的jpg、jpeg、png格式圖片",
19
22
  "添加字段": "添加字段",
20
23
  "编辑字段": "編輯字段",
21
24
  "配送单特殊控制": "配送单特殊控制",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.39.4-beta.2",
3
+ "version": "10.39.4-beta.21",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -109,7 +109,7 @@ class CommonContextMenu extends React.Component {
109
109
  })
110
110
  }
111
111
 
112
- handleInsertBlock = (type, link) => {
112
+ handleInsertBlock = (type, link, ratio) => {
113
113
  const { editStore } = this.props
114
114
  const { name, block } = this.state
115
115
 
@@ -120,7 +120,8 @@ class CommonContextMenu extends React.Component {
120
120
  left: block.left + 'px',
121
121
  top: block.top + 'px'
122
122
  },
123
- link
123
+ link,
124
+ ratio
124
125
  )
125
126
 
126
127
  this.setState({
@@ -160,8 +161,8 @@ class CommonContextMenu extends React.Component {
160
161
  })
161
162
  }
162
163
 
163
- handleInsertImage = imgURL => {
164
- this.handleInsertBlock('image', imgURL)
164
+ handleInsertImage = (imgURL, ratio) => {
165
+ this.handleInsertBlock('image', imgURL, ratio)
165
166
  }
166
167
 
167
168
  handleRemove = () => {
@@ -327,6 +328,7 @@ class CommonContextMenu extends React.Component {
327
328
  onSuccess={this.handleInsertImage}
328
329
  key={v.value}
329
330
  text={v.text}
331
+ imageConfig={this.props.editStore.imageConfig}
330
332
  />
331
333
  ) : (
332
334
  <div
@@ -391,12 +391,26 @@ Line.propTypes = {
391
391
 
392
392
  class Size extends React.Component {
393
393
  handleChange = (type, value) => {
394
- const { onChange, style } = this.props
394
+ const { onChange, style, ratio } = this.props
395
395
 
396
- onChange({
396
+ const next = {
397
397
  ...style,
398
398
  [type]: value
399
- })
399
+ }
400
+
401
+ // 电子签章:有原始比例时宽高联动,不允许拉变形
402
+ if (ratio && value !== '' && !value.endsWith('%')) {
403
+ const num = parseFloat(value)
404
+ if (!_.isNaN(num) && num > 0) {
405
+ if (type === 'width') {
406
+ next.height = Math.round(num / ratio) + 'px'
407
+ } else {
408
+ next.width = Math.round(num * ratio) + 'px'
409
+ }
410
+ }
411
+ }
412
+
413
+ onChange(next)
400
414
  }
401
415
 
402
416
  render() {
@@ -420,7 +434,8 @@ class Size extends React.Component {
420
434
 
421
435
  Size.propTypes = {
422
436
  style: PropTypes.object.isRequired,
423
- onChange: PropTypes.func.isRequired
437
+ onChange: PropTypes.func.isRequired,
438
+ ratio: PropTypes.number
424
439
  }
425
440
 
426
441
  class ImageUploader extends React.Component {
@@ -437,7 +452,26 @@ class ImageUploader extends React.Component {
437
452
  : event.target.files
438
453
  const file = droppedFiles[0]
439
454
 
440
- if (file.size > 512 * 1024) {
455
+ if (!file) return
456
+
457
+ const { imageConfig } = this.props
458
+
459
+ if (imageConfig) {
460
+ // 增强模式(电子签章):校验类型与大小,提示文案由配置方给出
461
+ const acceptTypes = imageConfig.acceptTypes || [
462
+ 'image/jpeg',
463
+ 'image/jpg',
464
+ 'image/png'
465
+ ]
466
+ if (!_.includes(acceptTypes, file.type)) {
467
+ Tip.warning(imageConfig.wrongTypeTip)
468
+ return
469
+ }
470
+ if (file.size > imageConfig.maxSize) {
471
+ Tip.warning(imageConfig.overSizeTip)
472
+ return
473
+ }
474
+ } else if (file.size > 512 * 1024) {
441
475
  Tip.warning(i18next.t('图片大小不能超过500Kb'))
442
476
  return
443
477
  }
@@ -463,7 +497,21 @@ class ImageUploader extends React.Component {
463
497
  .post()
464
498
  .then(json => {
465
499
  const imgURL = `${url.imgUrl}/${json.data.img_path_id}`
466
- this.props.onSuccess(imgURL)
500
+
501
+ // 增强模式下加载原图尺寸,记录原始比例供锁比例使用
502
+ if (imageConfig) {
503
+ const img = document.createElement('img')
504
+ img.onload = () => {
505
+ this.props.onSuccess(imgURL, img.naturalWidth / img.naturalHeight)
506
+ }
507
+ img.onerror = () => {
508
+ // 拿不到尺寸时降级:只插入不锁比例
509
+ this.props.onSuccess(imgURL)
510
+ }
511
+ img.src = imgURL
512
+ } else {
513
+ this.props.onSuccess(imgURL)
514
+ }
467
515
  })
468
516
  }
469
517
 
@@ -473,16 +521,23 @@ class ImageUploader extends React.Component {
473
521
  }
474
522
 
475
523
  render() {
524
+ const { imageConfig } = this.props
525
+
476
526
  return (
477
527
  <>
478
528
  <div onClick={this.handleClick} onDrop={this.handleUpload}>
479
529
  {this.props.text}
530
+ {imageConfig && imageConfig.acceptHint && (
531
+ <div className='gm-printer-contextmenu-hint'>
532
+ {imageConfig.acceptHint}
533
+ </div>
534
+ )}
480
535
  </div>
481
536
  <input
482
537
  style={{ display: 'none' }}
483
538
  type='file'
484
539
  ref={this.input}
485
- accept='image/*'
540
+ accept={(imageConfig && imageConfig.accept) || 'image/*'}
486
541
  onChange={this.handleUpload}
487
542
  />
488
543
  </>
@@ -492,7 +547,8 @@ class ImageUploader extends React.Component {
492
547
 
493
548
  ImageUploader.propTypes = {
494
549
  onSuccess: PropTypes.func.isRequired,
495
- text: PropTypes.string.isRequired
550
+ text: PropTypes.string.isRequired,
551
+ imageConfig: PropTypes.object
496
552
  }
497
553
 
498
554
  class InputWithUnit extends React.Component {
@@ -0,0 +1,35 @@
1
+ /**
2
+ * 模板 table.dataKey 前缀工具。
3
+ * 采购模板:purchase_*;分拣明细模板:sorting_detail_*(后缀与采购一致)。
4
+ */
5
+ export const SORTING_DETAIL_PREFIX = 'sorting_detail_'
6
+ export const PURCHASE_PREFIX = 'purchase_'
7
+
8
+ export function getDataKeyPrefix(dataKey) {
9
+ if (dataKey?.startsWith(SORTING_DETAIL_PREFIX)) return SORTING_DETAIL_PREFIX
10
+ return PURCHASE_PREFIX
11
+ }
12
+
13
+ export function getDataKeySuffix(dataKey) {
14
+ if (!dataKey || typeof dataKey !== 'string') return ''
15
+ return dataKey.replace(/^(sorting_detail_|purchase_)/, '')
16
+ }
17
+
18
+ export function buildDataKey(prefix, suffix) {
19
+ return `${prefix}${suffix}`
20
+ }
21
+
22
+ /** 下拉选中「按明细单行」时的 value(detail_one_row) */
23
+ export function isDetailOneRowSelectKey(dataKey) {
24
+ return getDataKeySuffix(dataKey) === 'detail_one_row'
25
+ }
26
+
27
+ export function isIndependentRolDataKey(dataKey) {
28
+ const suffix = getDataKeySuffix(dataKey)
29
+ return suffix === 'independent_rol_sku' || suffix === 'independent_rol_address'
30
+ }
31
+
32
+ export function isLastColDataKey(dataKey) {
33
+ const suffix = getDataKeySuffix(dataKey)
34
+ return suffix === 'last_col' || suffix === 'last_col_noLineBreak'
35
+ }