gm-printer 10.13.5 → 10.13.7-beta.11

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
- [{"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js":"1","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js":"2","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js":"3","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js":"4","/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js":"5","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js":"6","/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js":"7","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js":"8","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js":"9","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js":"10","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_store.js":"11","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js":"12","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js":"13","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js":"14","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js":"15","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js":"16","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js":"17","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js":"18"},{"size":8813,"mtime":1635407151058,"results":"19","hashOfConfig":"20"},{"size":11761,"mtime":1636106494831,"results":"21","hashOfConfig":"20"},{"size":4244,"mtime":1635494969691,"results":"22","hashOfConfig":"20"},{"size":3683,"mtime":1635851060224,"results":"23","hashOfConfig":"20"},{"size":616,"mtime":1621235314060,"results":"24","hashOfConfig":"25"},{"size":9693,"mtime":1621242097206,"results":"26","hashOfConfig":"25"},{"size":5923,"mtime":1636025210364,"results":"27","hashOfConfig":"20"},{"size":8733,"mtime":1635931829112,"results":"28","hashOfConfig":"20"},{"size":3119,"mtime":1634191808754,"results":"29","hashOfConfig":"20"},{"size":1113,"mtime":1635407660514,"results":"30","hashOfConfig":"20"},{"size":3905,"mtime":1635304242763},{"size":861,"mtime":1635246075403,"results":"31","hashOfConfig":"20"},{"size":3260,"mtime":1635334661529,"results":"32","hashOfConfig":"20"},{"size":24504,"mtime":1635908548975,"results":"33","hashOfConfig":"20"},{"size":1907,"mtime":1635492860490,"results":"34","hashOfConfig":"20"},{"size":3548,"mtime":1635409410379,"results":"35","hashOfConfig":"20"},{"size":2989,"mtime":1635495718901,"results":"36","hashOfConfig":"20"},{"size":3465,"mtime":1635495798948,"results":"37","hashOfConfig":"20"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1j0d8vf",{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"175njjo",{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":13,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"62","messages":"63","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"68","messages":"69","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","errorCount":2,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js",["72","73","74","75","76","77","78","79","80","81","82","83","84"],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js",["85","86"],{"ruleId":"87","severity":2,"message":"88","line":47,"column":13,"nodeType":"89","messageId":"90","endLine":47,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":48,"column":30,"nodeType":"92","messageId":"90","endLine":48,"endColumn":36},{"ruleId":"87","severity":2,"message":"93","line":49,"column":31,"nodeType":"92","messageId":"90","endLine":49,"endColumn":47},{"ruleId":"87","severity":2,"message":"93","line":50,"column":21,"nodeType":"92","messageId":"90","endLine":50,"endColumn":37},{"ruleId":"87","severity":2,"message":"88","line":56,"column":13,"nodeType":"89","messageId":"90","endLine":56,"endColumn":22},{"ruleId":"87","severity":2,"message":"94","line":59,"column":20,"nodeType":"92","messageId":"90","endLine":59,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":61,"column":23,"nodeType":"92","messageId":"90","endLine":61,"endColumn":29},{"ruleId":"87","severity":2,"message":"95","line":61,"column":30,"nodeType":"92","messageId":"90","endLine":61,"endColumn":34},{"ruleId":"87","severity":2,"message":"96","line":63,"column":15,"nodeType":"92","messageId":"90","endLine":63,"endColumn":19},{"ruleId":"87","severity":2,"message":"88","line":67,"column":23,"nodeType":"89","messageId":"90","endLine":67,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":70,"column":32,"nodeType":"92","messageId":"90","endLine":70,"endColumn":38},{"ruleId":"87","severity":2,"message":"88","line":78,"column":13,"nodeType":"89","messageId":"90","endLine":78,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":84,"column":42,"nodeType":"92","messageId":"90","endLine":84,"endColumn":48},{"ruleId":"97","severity":2,"message":"98","line":64,"column":11,"nodeType":"92","endLine":64,"endColumn":17},{"ruleId":"97","severity":2,"message":"99","line":102,"column":24,"nodeType":"92","endLine":102,"endColumn":32},"react/prop-types","'editStore' is missing in props validation","Property","missingPropType","'editStore.config' is missing in props validation","Identifier","'editStore.config.batchPrintConfig' is missing in props validation","'editStore.originConfig' is missing in props validation","'editStore.config.name' is missing in props validation","'editStore.init' is missing in props validation","no-unused-vars","'keyArr' is assigned a value but never used.","'mockData' is assigned a value but never used."]
1
+ [{"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js":"1","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js":"2","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js":"3","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js":"4","/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js":"5","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js":"6","/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js":"7","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js":"8","/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js":"9","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js":"10","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_store.js":"11","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js":"12","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js":"13","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js":"14","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js":"15","/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js":"16","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js":"17","/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js":"18"},{"size":9238,"mtime":1637656903443,"results":"19","hashOfConfig":"20"},{"size":12694,"mtime":1637656744657,"results":"21","hashOfConfig":"20"},{"size":4244,"mtime":1635494969691,"results":"22","hashOfConfig":"20"},{"size":3683,"mtime":1635851060224,"results":"23","hashOfConfig":"20"},{"size":616,"mtime":1621235314060,"results":"24","hashOfConfig":"25"},{"size":9693,"mtime":1621242097206,"results":"26","hashOfConfig":"25"},{"size":7133,"mtime":1637651237275,"results":"27","hashOfConfig":"20"},{"size":8733,"mtime":1635931829112,"results":"28","hashOfConfig":"20"},{"size":3119,"mtime":1634191808754,"results":"29","hashOfConfig":"20"},{"size":1113,"mtime":1635407660514,"results":"30","hashOfConfig":"20"},{"size":3905,"mtime":1635304242763},{"size":861,"mtime":1635246075403,"results":"31","hashOfConfig":"20"},{"size":3260,"mtime":1635334661529,"results":"32","hashOfConfig":"20"},{"size":24504,"mtime":1635908548975,"results":"33","hashOfConfig":"20"},{"size":1907,"mtime":1635492860490,"results":"34","hashOfConfig":"20"},{"size":3548,"mtime":1635409410379,"results":"35","hashOfConfig":"20"},{"size":2989,"mtime":1635495718901,"results":"36","hashOfConfig":"20"},{"size":3465,"mtime":1635495798948,"results":"37","hashOfConfig":"20"},{"filePath":"38","messages":"39","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1j0d8vf",{"filePath":"40","messages":"41","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"42","messages":"43","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"44","messages":"45","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"46","messages":"47","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"175njjo",{"filePath":"48","messages":"49","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"50","messages":"51","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"52","messages":"53","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"54","messages":"55","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"56","messages":"57","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"58","messages":"59","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"60","messages":"61","errorCount":13,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},{"filePath":"62","messages":"63","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"64","messages":"65","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"66","messages":"67","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"68","messages":"69","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"70","messages":"71","errorCount":2,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/table.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor/context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/components/tooltip/index.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/common_context_menu.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/util.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/printer.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/printer/do_print.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_special_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/hoc_with_shadow_dom.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_title.js",["72","73","74","75","76","77","78","79","80","81","82","83","84"],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_store.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_add_field.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/common/editor_page_summary.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/editor.js",[],"/Users/yancheng/gm/gm-open-source/gm-printer/src/editor_account/context_menu.js",["85","86"],{"ruleId":"87","severity":2,"message":"88","line":47,"column":13,"nodeType":"89","messageId":"90","endLine":47,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":48,"column":30,"nodeType":"92","messageId":"90","endLine":48,"endColumn":36},{"ruleId":"87","severity":2,"message":"93","line":49,"column":31,"nodeType":"92","messageId":"90","endLine":49,"endColumn":47},{"ruleId":"87","severity":2,"message":"93","line":50,"column":21,"nodeType":"92","messageId":"90","endLine":50,"endColumn":37},{"ruleId":"87","severity":2,"message":"88","line":56,"column":13,"nodeType":"89","messageId":"90","endLine":56,"endColumn":22},{"ruleId":"87","severity":2,"message":"94","line":59,"column":20,"nodeType":"92","messageId":"90","endLine":59,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":61,"column":23,"nodeType":"92","messageId":"90","endLine":61,"endColumn":29},{"ruleId":"87","severity":2,"message":"95","line":61,"column":30,"nodeType":"92","messageId":"90","endLine":61,"endColumn":34},{"ruleId":"87","severity":2,"message":"96","line":63,"column":15,"nodeType":"92","messageId":"90","endLine":63,"endColumn":19},{"ruleId":"87","severity":2,"message":"88","line":67,"column":23,"nodeType":"89","messageId":"90","endLine":67,"endColumn":32},{"ruleId":"87","severity":2,"message":"91","line":70,"column":32,"nodeType":"92","messageId":"90","endLine":70,"endColumn":38},{"ruleId":"87","severity":2,"message":"88","line":78,"column":13,"nodeType":"89","messageId":"90","endLine":78,"endColumn":22},{"ruleId":"87","severity":2,"message":"91","line":84,"column":42,"nodeType":"92","messageId":"90","endLine":84,"endColumn":48},{"ruleId":"97","severity":2,"message":"98","line":64,"column":11,"nodeType":"92","endLine":64,"endColumn":17},{"ruleId":"97","severity":2,"message":"99","line":102,"column":24,"nodeType":"92","endLine":102,"endColumn":32},"react/prop-types","'editStore' is missing in props validation","Property","missingPropType","'editStore.config' is missing in props validation","Identifier","'editStore.config.batchPrintConfig' is missing in props validation","'editStore.originConfig' is missing in props validation","'editStore.config.name' is missing in props validation","'editStore.init' is missing in props validation","no-unused-vars","'keyArr' is assigned a value but never used.","'mockData' is assigned a value but never used."]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-printer",
3
- "version": "10.13.5",
3
+ "version": "10.13.7-beta.11",
4
4
  "description": "diy printer",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -3,7 +3,8 @@ import { action, observable } from 'mobx'
3
3
  import {
4
4
  getSumTrHeight,
5
5
  isMultiTable,
6
- caclSingleDetailsPageHeight
6
+ caclSingleDetailsPageHeight,
7
+ getArrayMid
7
8
  } from '../util'
8
9
  import _ from 'lodash'
9
10
  import Big from 'big.js'
@@ -78,14 +79,30 @@ class PrinterStore {
78
79
  }
79
80
 
80
81
  @action
81
- computedData(dataKey, table, end, currentRemainTableHeight) {
82
+ computedData(dataKey, table, [begin, end], currentRemainTableHeight) {
82
83
  /** 当前数据 */
83
84
  const tableData = this.data._table[dataKey] || []
85
+
86
+ let count = 0
87
+ _.forEach(Array(end).fill(1), (val, i) => {
88
+ const details = tableData[i]?.__details || []
89
+ count += details.length
90
+ })
91
+
84
92
  /** 明细data */
85
- const detailsData = tableData[end]?.__details || []
93
+ const detailsData = tableData[end]?.__details
94
+ // 如果没有details 和 明细不换行, 就不用计算了
95
+ if (!detailsData || dataKey.includes('noLineBreak')) {
96
+ return []
97
+ }
98
+
99
+ const detailsHeights = table.body.children.slice(
100
+ count,
101
+ count + detailsData.length
102
+ )
103
+
86
104
  const { ranges, detailsPageHeight } = caclSingleDetailsPageHeight(
87
- table,
88
- detailsData,
105
+ detailsHeights,
89
106
  currentRemainTableHeight
90
107
  )
91
108
 
@@ -165,7 +182,7 @@ class PrinterStore {
165
182
  /** 当前table剩余的高度 */
166
183
  let currentRemainTableHeight = 0
167
184
  /** 去最小的tr高度,用于下面的计算compare,(避免特殊情况:一般来说最小tr——height = 23, 比23还小的不考虑计算) */
168
- const minHeight = Math.max(Math.min(...table.body.heights), 23)
185
+ const minHeight = Math.max(getArrayMid(table.body.heights), 23)
169
186
 
170
187
  /* 遍历表格每一行,填充表格内容 */
171
188
  while (end < table.body.heights.length) {
@@ -179,24 +196,32 @@ class PrinterStore {
179
196
  .plus(table.body.heights[end])
180
197
 
181
198
  /**
182
- * 说明: 1. currentRemainTableHeight > minHeight 要比最小度高高,不然每次到这都进入if
183
- * 2. table.body.heights[end]至少要是currentRemainTableHeight的 2倍,怕出现打印时最后一行文字显示一半的情况
199
+ * 说明: 1. currentRemainTableHeight至少要是minHeight 2倍,不然每次到这都进入if,同时留下一点空白距离
200
+ * 2. table.body.heights[end]至少要是currentRemainTableHeight的 1倍,怕出现打印时最后一行文字显示一半的情况
184
201
  * 3. table.body.heights[end] 高度超过了 pageAccomodateTableHeight
185
202
  */
186
203
  if (
187
- (currentRemainTableHeight > minHeight &&
188
- table.body.heights[end] / minHeight > 2) ||
204
+ (currentRemainTableHeight / minHeight > 1.5 &&
205
+ table.body.heights[end] / currentRemainTableHeight > 1) ||
189
206
  table.body.heights[end] > pageAccomodateTableHeight
190
207
  ) {
191
208
  const detailsPageHeight = this.computedData(
192
209
  dataKey,
193
210
  table,
194
- end,
211
+ [begin, end],
195
212
  currentRemainTableHeight
196
213
  )
214
+
197
215
  // 拆分明细后,同时也要更新body.heights 不能影响后续计算
198
- table.body.heights.splice(end, 1, ...detailsPageHeight)
199
- end++
216
+ if (detailsPageHeight.length > 0) {
217
+ // 比较剩余高度和minHeight的大小,取最大(防止剩余一条明细时,第二页撑开的高度远大于一条明细的高度)
218
+ detailsPageHeight[1] = Math.max(
219
+ minHeight,
220
+ detailsPageHeight[1]
221
+ )
222
+ table.body.heights.splice(end, 1, ...detailsPageHeight)
223
+ end++
224
+ }
200
225
  }
201
226
  // 第一条极端会有问题
202
227
  if (end !== 0) {
@@ -220,7 +245,7 @@ class PrinterStore {
220
245
  begin = end
221
246
  // 开启新一页,重置页面高度
222
247
  pageAccomodateTableHeight = +new Big(this.pageHeight).minus(
223
- currentPageMinimumHeight
248
+ allPagesHaveThisHeight
224
249
  )
225
250
  currentTableHeight = allTableHaveThisHeight
226
251
  currentPageHeight = currentPageMinimumHeight
@@ -317,7 +342,9 @@ class PrinterStore {
317
342
  /** 简单处理下数据 */
318
343
  const filterList = (list, type = '') => {
319
344
  if (type === 'noLineBreak') {
320
- return list.map(d => `${compiled(d)}`).join(separator)
345
+ const details = list.map(d => `${compiled(d)}`).join(separator)
346
+
347
+ return `<div class='b-table-details'>${details}</div>`
321
348
  }
322
349
  return list
323
350
  .map(d => `<div class='b-table-details'> ${compiled(d)} </div>`)
@@ -183,6 +183,26 @@ class Table extends React.Component {
183
183
  </>
184
184
  )
185
185
  }
186
+ const getTdStyle = (index, style = {}) => {
187
+ const width = thWidths[index]
188
+ const { fontSize } = style
189
+ let tdStyle = {}
190
+ let minWidth = 24
191
+
192
+ if (!width) return tdStyle
193
+ if (fontSize) minWidth = _.parseInt(fontSize) * 2
194
+ if (width >= 150) {
195
+ tdStyle = {
196
+ minWidth: width
197
+ }
198
+ } else {
199
+ tdStyle = {
200
+ minWidth,
201
+ width
202
+ }
203
+ }
204
+ return tdStyle
205
+ }
186
206
 
187
207
  return (
188
208
  <table>
@@ -195,7 +215,7 @@ class Table extends React.Component {
195
215
  data-name={getTableColumnName(name, col.index)}
196
216
  draggable
197
217
  style={{
198
- maxWidth: thWidths[i],
218
+ ...getTdStyle(i, col.headStyle),
199
219
  ...col.headStyle
200
220
  }}
201
221
  className={classNames({
@@ -232,8 +252,7 @@ class Table extends React.Component {
232
252
  key={j}
233
253
  data-name={getTableColumnName(name, col.index)}
234
254
  style={{
235
- minWidth: '24px',
236
- maxWidth: thWidths[j],
255
+ ...getTdStyle(j, col.style),
237
256
  ...col.style
238
257
  }}
239
258
  className={classNames({
package/src/util.js CHANGED
@@ -179,16 +179,12 @@ const getDataKey = (dataKey, arrange) =>
179
179
  : dataKey
180
180
 
181
181
  /**
182
- * @param {*} table 当前单据的高度信息
182
+ * @param {*} detailsHeights 当钱明细高度集
183
183
  * @param {*} detailsData 当前所有tablelist
184
184
  * @param {*} curRemainPageHeight 可容纳table的总高度
185
185
  * @returns {ranges, detailsPageHeight} detailsPageHeight 每页高度合集
186
186
  */
187
- const caclSingleDetailsPageHeight = (
188
- table,
189
- detailsData,
190
- curRemainPageHeight
191
- ) => {
187
+ const caclSingleDetailsPageHeight = (detailsHeights, curRemainPageHeight) => {
192
188
  let [end, deadline] = [0, 0]
193
189
  const begin = 0
194
190
  /** 当前明细高度,默认为tr的border+padding的height */
@@ -199,12 +195,13 @@ const caclSingleDetailsPageHeight = (
199
195
  let remainDetailsHeight = 5
200
196
 
201
197
  // 如果当前累计高度高于当前剩余高度,则跳出返回
202
- while (end < detailsData.length) {
203
- if (currentDetailsMiniHeight < curRemainPageHeight) {
204
- currentDetailsMiniHeight += table.body.children[end]
205
- deadline = end
198
+ while (end < detailsHeights.length) {
199
+ const height = currentDetailsMiniHeight + detailsHeights[end]
200
+ if (height < curRemainPageHeight) {
201
+ currentDetailsMiniHeight = height
202
+ deadline++
206
203
  } else {
207
- remainDetailsHeight += table.body.children[end]
204
+ remainDetailsHeight += detailsHeights[end]
208
205
  }
209
206
  end++
210
207
  }
@@ -218,6 +215,60 @@ const caclSingleDetailsPageHeight = (
218
215
  }
219
216
  }
220
217
 
218
+ /**
219
+ * 取数组中位数, 有数量相同的则取最小的那个
220
+ * @param {*} arr
221
+ */
222
+ const getArrayMid = arr => {
223
+ /** 数组元素出现次数的集合 */
224
+ const mapArr = []
225
+ const map = new Map()
226
+ let majority = 23
227
+ /** 次数相同的元素集合 */
228
+ const majorityArr = []
229
+ const min = Math.min(...arr)
230
+
231
+ if (arr.length === 0) return majority
232
+
233
+ _.forEach(arr, (val, key) => {
234
+ if (map.has(val)) {
235
+ map.set(val, map.get(val) + 1)
236
+ } else {
237
+ map.set(val, 1)
238
+ }
239
+ })
240
+
241
+ for (const val of map.values()) {
242
+ mapArr.push(val)
243
+ }
244
+ // 如果没有众数,就取最小值
245
+ if (Array.from(new Set(mapArr)).length === 1) {
246
+ // 如果说min也远远大于23, 就返回23吧
247
+ if (min / 23 > 10) {
248
+ return 23
249
+ }
250
+ return min
251
+ }
252
+
253
+ const maxCount = Math.max(...mapArr)
254
+ for (const val of map.keys()) {
255
+ if (map.get(val) === maxCount) {
256
+ majorityArr.push(val)
257
+ }
258
+ }
259
+ majority = Math.min(...majorityArr)
260
+ // 如果说取的众数也远远大于min,
261
+ if (majority / min > 3) {
262
+ // 如果说min也远远大于23, 就返回23吧
263
+ if (min / 23 > 10) {
264
+ return 23
265
+ }
266
+ return min
267
+ }
268
+
269
+ return majority
270
+ }
271
+
221
272
  export {
222
273
  getHeight,
223
274
  getWidth,
@@ -234,5 +285,6 @@ export {
234
285
  getDataKey,
235
286
  isMultiTable,
236
287
  getMultiNumber,
237
- caclSingleDetailsPageHeight
288
+ caclSingleDetailsPageHeight,
289
+ getArrayMid
238
290
  }