gm-printer 10.42.3-beta.0 → 10.42.3

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.
@@ -132,7 +132,7 @@ class Printer extends React.Component {
132
132
  printerStore.changeTableData()
133
133
  printerStore.computedPages()
134
134
  }
135
- // 获取剩余空白高度,传到 editor
135
+ // 获取剩余空白高度,传到editor
136
136
  getremainpageHeight && getremainpageHeight(printerStore.remainPageHeight)
137
137
  }
138
138
  printerStore.setReady(true)
@@ -7,8 +7,7 @@ import {
7
7
  getDataKey,
8
8
  caclSingleDetailsPageHeight,
9
9
  getArrayMid,
10
- getOverallOrderTrHeight,
11
- isMaskedValue
10
+ getOverallOrderTrHeight
12
11
  } from '../util'
13
12
  import {
14
13
  isDetailOneRowSelectKey,
@@ -47,8 +46,6 @@ const canSplitRowDetails = (dataKey, row) => {
47
46
  }
48
47
 
49
48
  const price = (n, f = 2) => {
50
- // 脱敏值 '***' 原样返回(不能走 isNaN 判空,空单元格仍需显空)
51
- if (isMaskedValue(n)) return n
52
49
  if (isNaN(n)) return null
53
50
  return Big(n || 0).toFixed(f)
54
51
  }
@@ -398,7 +395,7 @@ class PrinterStore {
398
395
  const currentPageMinimumHeight =
399
396
  allPagesHaveThisHeight + allTableHaveThisHeight
400
397
  // 最后一项是表格时,末页仍要渲染签名:装行可用高度预留签名,避免空行顶进签名区
401
- const isLastContent = index === contentsLength - 1
398
+ const isLastContent = index === this.config.contents.length - 1
402
399
  const signReserve = isLastContent ? this.getSignHeight() : 0
403
400
  /** 当前page可容纳的table高度 */
404
401
  let pageAccomodateTableHeight = roundHeight(
@@ -490,7 +487,7 @@ class PrinterStore {
490
487
  )
491
488
  break
492
489
  }
493
- // 行无法拆分(普通长文本列)或拆分失败时,强制推进 end 防止死循环
490
+ // 行无法拆分(普通长文本列)或拆分失败
494
491
  if (end === begin) {
495
492
  // 新一页可容纳的 table 高度(页高 - 页眉页脚)
496
493
  const fullPageAccomodateTableHeight = roundHeight(
@@ -609,8 +606,9 @@ class PrinterStore {
609
606
  currentPageHeight += this.getSignHeight()
610
607
  }
611
608
 
612
- this.remainPageHeight = Math.round(
613
- Math.max(0, pageHeight - currentPageHeight)
609
+ this.remainPageHeight = Math.max(
610
+ 0,
611
+ Math.round(pageHeight - currentPageHeight)
614
612
  )
615
613
  this.isSave = false
616
614
  this.config.isSave = false
@@ -2,9 +2,10 @@ import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import _ from 'lodash'
4
4
  // import Big from 'big.js'
5
- import { coverDigit2Uppercase, getDataKey, maskedSum } from '../util'
5
+ import { coverDigit2Uppercase, getDataKey } from '../util'
6
6
  import { observer } from 'mobx-react'
7
7
  import classNames from 'classnames'
8
+ import Big from 'big.js'
8
9
 
9
10
  const DiyOverallOrder = props => {
10
11
  const {
@@ -14,14 +15,20 @@ const DiyOverallOrder = props => {
14
15
  } = props
15
16
  const tableData = printerStore.data._table[getDataKey(dataKey)] || []
16
17
 
17
- // 计算合计:任一渲染结果脱敏 '***' 则合计显 '***'(整格判定假设同 table_diy_summary_tr)
18
+ // 计算合计
18
19
  const sumData = field => {
19
- const values = _.map(tableData, (b, i) =>
20
- printerStore
21
- .templateTable(field, dataKey, i, pageIndex)
22
- .replace(/\(\)/g, '')
23
- )
24
- return maskedSum(values)
20
+ return _.reduce(
21
+ tableData,
22
+ (a, b, i) => {
23
+ let result = a
24
+ const bRes = printerStore
25
+ .templateTable(field, dataKey, i, pageIndex)
26
+ .replace(/\(\)/g, '')
27
+ result = a.plus(+bRes || 0)
28
+ return result
29
+ },
30
+ Big(0)
31
+ ).toFixed(2)
25
32
  }
26
33
 
27
34
  if (!diyOverallOrder?.show || !printerStore?.ready) {
@@ -1,15 +1,11 @@
1
1
  import React from 'react'
2
2
  import PropTypes from 'prop-types'
3
3
  import _ from 'lodash'
4
- import {
5
- coverDigit2Uppercase,
6
- getDataKey,
7
- isMultiTable,
8
- maskedSum
9
- } from '../util'
4
+ import { coverDigit2Uppercase, getDataKey, isMultiTable } from '../util'
10
5
  import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
11
6
  import { observer } from 'mobx-react'
12
7
  import classNames from 'classnames'
8
+ import Big from 'big.js'
13
9
 
14
10
  function buildTemplateField(fieldStr, suffix) {
15
11
  // 如果 field 是 "{{列.下单数}}",提取出 "下单数"
@@ -49,18 +45,39 @@ const DiySummary = props => {
49
45
 
50
46
  // 计算合计
51
47
  const sumData = field => {
52
- // 收集本列渲染结果(含多栏后缀列),任一脱敏 '***' 则合计显 '***'
53
- // 注意:基于渲染后字符串判定,假设模板整格就是脱敏值;带前后缀的模板(如 '{{列.金额}}元')无法识别
54
- const values = []
55
- _.each(tableData, (b, i) => {
56
- values.push(getRes(field, i))
57
- if (isMulti) {
58
- // 双栏/三栏取后缀字段
59
- values.push(getRes(buildTemplateField(field, MULTI_SUFFIX), i))
60
- values.push(getRes(buildTemplateField(field, MULTI_SUFFIX3), i))
61
- }
62
- })
63
- return maskedSum(values)
48
+ if (isMulti) {
49
+ return _.reduce(
50
+ tableData,
51
+ (a, b, i) => {
52
+ let result = a
53
+ // 先通过 templateTable 获取原始字段的值
54
+ const bRes = getRes(field, i)
55
+ result = a.plus(+bRes || 0)
56
+
57
+ // 双栏
58
+ const multiField = buildTemplateField(field, MULTI_SUFFIX)
59
+ result = result.plus(+getRes(multiField, i) || 0)
60
+
61
+ // 三栏
62
+ const multiField3 = buildTemplateField(field, MULTI_SUFFIX3)
63
+ result = result.plus(+getRes(multiField3, i) || 0)
64
+
65
+ return result
66
+ },
67
+ Big(0)
68
+ ).toFixed(2)
69
+ }
70
+
71
+ return _.reduce(
72
+ tableData,
73
+ (a, b, i) => {
74
+ let result = a
75
+ const bRes = getRes(field, i)
76
+ result = a.plus(+bRes || 0)
77
+ return result
78
+ },
79
+ Big(0)
80
+ ).toFixed(2)
64
81
 
65
82
  function getRes(field, i) {
66
83
  return printerStore
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import _ from 'lodash'
5
5
  import { MULTI_SUFFIX, MULTI_SUFFIX3 } from '../config'
6
6
  import Big from 'big.js'
7
- import { coverDigit2Uppercase, getDataKey, maskedSum } from '../util'
7
+ import { coverDigit2Uppercase, getDataKey } from '../util'
8
8
  import { observer } from 'mobx-react'
9
9
  import { get } from 'mobx'
10
10
  import classNames from 'classnames'
@@ -76,18 +76,21 @@ const SubtotalTr = props => {
76
76
  if (field === 'real_item_price') field = '出库金额'
77
77
  if (field === 'settle_money2') field = '结算金额'
78
78
  if (field === 'total_money2') field = '金额'
79
- // 收集本列所有值(含多栏后缀列),任一脱敏 '***' 则合计显 '***',否则 Big('***') 会崩溃
80
- const values = []
81
- _.each(list, b => {
82
- values.push(b[field])
83
- if (b?.[field + MULTI_SUFFIX]) {
84
- values.push(b[field + MULTI_SUFFIX])
85
- }
86
- if (b?.[field + MULTI_SUFFIX3]) {
87
- values.push(b[field + MULTI_SUFFIX3])
88
- }
89
- })
90
- return maskedSum(values)
79
+ return _.reduce(
80
+ list,
81
+ (a, b) => {
82
+ let result = a
83
+ result = a.plus(b[field] || 0)
84
+ if (b?.[field + MULTI_SUFFIX]) {
85
+ result = result.plus(b?.[field + MULTI_SUFFIX])
86
+ }
87
+ if (b?.[field + MULTI_SUFFIX3]) {
88
+ result = result.plus(b?.[field + MULTI_SUFFIX3])
89
+ }
90
+ return result
91
+ },
92
+ Big(0)
93
+ ).toFixed(2)
91
94
  }
92
95
 
93
96
  const getData = field => {
package/src/util.js CHANGED
@@ -120,23 +120,7 @@ function getOverallOrderTrHeight(overallOrder) {
120
120
  }
121
121
 
122
122
  // eslint-disable-next-line
123
- // 成本权限脱敏值:后端对无成本权限用户的金额字段返回 '***'(商品维度混合脱敏)
124
- const MASKED_VALUE = '***'
125
- const isMaskedValue = v => v === MASKED_VALUE
126
-
127
- /**
128
- * 脱敏感知求和:任一值为 '***' 则整体返回 '***'(口径:合计不能暴露脱敏行的贡献)
129
- * 非数字值按 0 容错,同时兼容原始数值字段与渲染后字符串
130
- * @param {Array} values 参与求和的值
131
- */
132
- const maskedSum = values => {
133
- if (values.some(isMaskedValue)) return MASKED_VALUE
134
- return values.reduce((a, b) => a.plus(+b || 0), Big(0)).toFixed(2)
135
- }
136
-
137
123
  const coverDigit2Uppercase = n => {
138
- // 脱敏值直接透传:否则 Math.abs('***') 得 NaN,Big(NaN) 会抛异常
139
- if (isMaskedValue(n)) return MASKED_VALUE
140
124
  if (_.isNil(n) || _.isNaN(n)) {
141
125
  return '-'
142
126
  }
@@ -400,8 +384,5 @@ export {
400
384
  caclSingleDetailsPageHeight,
401
385
  getArrayMid,
402
386
  getColSpanLength,
403
- getOverallOrderTrHeight,
404
- MASKED_VALUE,
405
- isMaskedValue,
406
- maskedSum
387
+ getOverallOrderTrHeight
407
388
  }