@bchr/bchr-front-lib 0.6.11 → 0.6.12

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.
@@ -38,6 +38,7 @@ var PASSWORD_ICON_STYLE = {
38
38
  color: "#337DB7",
39
39
  fontWeight: "bolder"
40
40
  };
41
+ var MODIFY_INPUT_CLASS = "bchr-input-password-decrypt-modify";
41
42
  var normalizeValue = function normalizeValue(value) {
42
43
  if (value === null || value === undefined) {
43
44
  return "";
@@ -256,7 +257,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
256
257
  _context.n = 3;
257
258
  break;
258
259
  }
259
- commitValue("", false);
260
+ showPlainText("", false);
260
261
  if (inputRef.current && inputRef.current.focus) {
261
262
  inputRef.current.focus();
262
263
  }
@@ -266,7 +267,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
266
267
  _context.n = 4;
267
268
  break;
268
269
  }
269
- showPlainText(secret);
270
+ showPlainText(secret, false);
270
271
  return _context.a(2);
271
272
  case 4:
272
273
  if (secret) {
@@ -312,7 +313,7 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
312
313
  _antd.message.error("解密失败");
313
314
  return _context.a(2);
314
315
  case 11:
315
- showPlainText(result);
316
+ showPlainText(result, ui_render_type !== "modify");
316
317
  _context.n = 14;
317
318
  break;
318
319
  case 12:
@@ -347,36 +348,30 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
347
348
  if (onKeyDown) {
348
349
  onKeyDown(event);
349
350
  }
350
- if (disabled || toggle || composingRef.current || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
351
+ if (disabled || !toggle || event.defaultPrevented) {
351
352
  return;
352
353
  }
353
- if (event.key === "Backspace" || event.key === "Delete") {
354
- event.preventDefault();
355
- commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
356
- return;
357
- }
358
- if (event.key.length !== 1) {
359
- return;
360
- }
361
- event.preventDefault();
362
- commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
363
354
  };
364
355
  var onModifyPaste = function onModifyPaste(event) {
365
356
  if (onPaste) {
366
357
  onPaste(event);
367
358
  }
368
- if (disabled || toggle || composingRef.current || event.defaultPrevented) {
359
+ if (disabled) {
360
+ return;
361
+ }
362
+ if (!toggle) {
363
+ event.preventDefault();
369
364
  return;
370
365
  }
371
- var text = event.clipboardData ? event.clipboardData.getData("text") : "";
372
- event.preventDefault();
373
- if (!text) {
366
+ if (event.defaultPrevented) {
374
367
  return;
375
368
  }
376
- commitValue(editingRef.current ? realValueRef.current + text : text, false);
377
369
  };
378
370
  var onCompositionStart = function onCompositionStart(event) {
379
371
  clearRevealTimer();
372
+ if (!toggle) {
373
+ return;
374
+ }
380
375
  var compositionDisplayValue = event && event.target ? event.target.value : typeof event === "string" ? event : "";
381
376
  composingRef.current = true;
382
377
  composeBaseDisplayRef.current = compositionDisplayValue;
@@ -387,25 +382,19 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
387
382
  return;
388
383
  }
389
384
  composingRef.current = false;
390
- if (disabled || toggle) {
391
- return;
392
- }
393
- var domValue = event && event.target ? event.target.value : typeof event === "string" ? event : "";
394
- var baseValue = composeBaseDisplayRef.current;
395
- var composedText = baseValue && domValue.startsWith(baseValue) ? domValue.slice(baseValue.length) : domValue.replace(/^\*+/, "");
396
- if (!composedText) {
385
+ if (disabled || !toggle) {
397
386
  setCompositionDisplay(null);
398
387
  return;
399
388
  }
400
- commitValue(editingRef.current ? realValueRef.current + composedText : composedText, true);
389
+ commitValue(event && event.target ? event.target.value : "", false);
401
390
  };
402
391
  var onModifyChange = function onModifyChange(valueOrEvent) {
403
392
  var nextValue = valueOrEvent && valueOrEvent.target ? valueOrEvent.target.value : valueOrEvent;
404
- if (composingRef.current && !toggle) {
405
- setCompositionDisplay(nextValue);
393
+ if (disabled || !toggle) {
406
394
  return;
407
395
  }
408
- if (disabled || !toggle && nextValue !== "") {
396
+ if (composingRef.current) {
397
+ setCompositionDisplay(nextValue);
409
398
  return;
410
399
  }
411
400
  commitValue(nextValue, false);
@@ -443,22 +432,15 @@ var InputPasswordDecrypt = function InputPasswordDecrypt(props) {
443
432
  } else {
444
433
  modifyDisplay = maskValue(realValue, resolvedMaskLength);
445
434
  }
446
- return /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({}, restInputProps, {
435
+ return /*#__PURE__*/_react["default"].createElement(_antd.Input, _extends({}, restInputProps, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({
447
436
  ref: inputRef,
448
437
  className: className,
449
438
  style: style,
450
439
  value: modifyDisplay,
451
440
  placeholder: placeholder,
452
- disabled: disabled,
453
- allowClear: allowClear,
454
- maxLength: toggle && typeof maxLength === "number" ? maxLength : undefined,
455
- onChange: onModifyChange,
456
- onKeyDown: onModifyKeyDown,
457
- onPaste: onModifyPaste,
458
- onCompositionStart: onCompositionStart,
459
- onCompositionEnd: onCompositionEnd,
460
- suffix: renderToggleIcon()
461
- }));
441
+ disabled: !toggle || disabled,
442
+ allowClear: allowClear && toggle
443
+ }, "className", [className, MODIFY_INPUT_CLASS].filter(Boolean).join(" ")), "maxLength", toggle && typeof maxLength === "number" ? maxLength : undefined), "onChange", onModifyChange), "onKeyDown", onModifyKeyDown), "onPaste", onModifyPaste), "onCompositionStart", onCompositionStart), "onCompositionEnd", onCompositionEnd), "suffix", renderToggleIcon())));
462
444
  }
463
445
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
464
446
  className: className,
@@ -222,10 +222,10 @@ var ExcelKits = {
222
222
  children: child.children && _this.extractColumns(child.children, level + 1)
223
223
  });
224
224
  },
225
- /**
226
- * 收集Excel列头信息(复合表头)
227
- * @param gridColumns
228
- * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
225
+ /**
226
+ * 收集Excel列头信息(复合表头)
227
+ * @param gridColumns
228
+ * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
229
229
  */
230
230
  gatherExcelColumnHeaderStructureInfo: function gatherExcelColumnHeaderStructureInfo(gridColumns) {
231
231
  var _this2 = this;
@@ -298,14 +298,14 @@ var ExcelKits = {
298
298
  columnHeaderMergeCellArray: columnHeaderMergeCellArray
299
299
  };
300
300
  },
301
- /**
302
- * @return {Array} eg -
303
- * [
304
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
305
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
306
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
307
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
308
- * ]
301
+ /**
302
+ * @return {Array} eg -
303
+ * [
304
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
305
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
306
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
307
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
308
+ * ]
309
309
  */
310
310
  gatherExcelColumnHeaderMergeCellInfo: function gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount) {
311
311
  var currentColumnHeaderRowIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
@@ -246,6 +246,18 @@
246
246
  display: none;
247
247
  }
248
248
 
249
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled,
250
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled:hover {
251
+ border: 1px solid #d9d9d9;
252
+ padding-left: 11px;
253
+ background-color: #fff;
254
+ }
255
+
256
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled .ant-input[disabled] {
257
+ background: transparent;
258
+ border: none;
259
+ }
260
+
249
261
  .ant-select-dropdown {
250
262
  width: 100%;
251
263
  min-height: 38px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.11",
3
+ "version": "0.6.12",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
@@ -11,6 +11,7 @@ const PASSWORD_ICON_STYLE = {
11
11
  color: "#337DB7",
12
12
  fontWeight: "bolder"
13
13
  };
14
+ const MODIFY_INPUT_CLASS = "bchr-input-password-decrypt-modify";
14
15
 
15
16
  const normalizeValue = (value) => {
16
17
  if (value === null || value === undefined) {
@@ -210,14 +211,14 @@ const InputPasswordDecrypt = (props) => {
210
211
  const secret = realValueRef.current;
211
212
  if (ui_render_type === "modify") {
212
213
  if (!secret) {
213
- commitValue("", false);
214
+ showPlainText("", false);
214
215
  if (inputRef.current && inputRef.current.focus) {
215
216
  inputRef.current.focus();
216
217
  }
217
218
  return;
218
219
  }
219
220
  if (editingRef.current) {
220
- showPlainText(secret);
221
+ showPlainText(secret, false);
221
222
  return;
222
223
  }
223
224
  }
@@ -245,7 +246,7 @@ const InputPasswordDecrypt = (props) => {
245
246
  message.error("解密失败");
246
247
  return;
247
248
  }
248
- showPlainText(result);
249
+ showPlainText(result, ui_render_type !== "modify");
249
250
  } catch (error) {
250
251
  if (requestSeq !== requestSeqRef.current) {
251
252
  return;
@@ -265,38 +266,32 @@ const InputPasswordDecrypt = (props) => {
265
266
  if (onKeyDown) {
266
267
  onKeyDown(event);
267
268
  }
268
- if (disabled || toggle || composingRef.current || event.defaultPrevented || event.ctrlKey || event.metaKey || event.altKey || event.isComposing) {
269
+ if (disabled || !toggle || event.defaultPrevented) {
269
270
  return;
270
271
  }
271
- if (event.key === "Backspace" || event.key === "Delete") {
272
- event.preventDefault();
273
- commitValue(editingRef.current ? realValueRef.current.slice(0, -1) : "", false);
274
- return;
275
- }
276
- if (event.key.length !== 1) {
277
- return;
278
- }
279
- event.preventDefault();
280
- commitValue(editingRef.current ? realValueRef.current + event.key : event.key, true);
281
272
  };
282
273
 
283
274
  const onModifyPaste = (event) => {
284
275
  if (onPaste) {
285
276
  onPaste(event);
286
277
  }
287
- if (disabled || toggle || composingRef.current || event.defaultPrevented) {
278
+ if (disabled) {
279
+ return;
280
+ }
281
+ if (!toggle) {
282
+ event.preventDefault();
288
283
  return;
289
284
  }
290
- const text = event.clipboardData ? event.clipboardData.getData("text") : "";
291
- event.preventDefault();
292
- if (!text) {
285
+ if (event.defaultPrevented) {
293
286
  return;
294
287
  }
295
- commitValue(editingRef.current ? realValueRef.current + text : text, false);
296
288
  };
297
289
 
298
290
  const onCompositionStart = (event) => {
299
291
  clearRevealTimer();
292
+ if (!toggle) {
293
+ return;
294
+ }
300
295
  const compositionDisplayValue = event && event.target ? event.target.value : (typeof event === "string" ? event : "");
301
296
  composingRef.current = true;
302
297
  composeBaseDisplayRef.current = compositionDisplayValue;
@@ -308,28 +303,20 @@ const InputPasswordDecrypt = (props) => {
308
303
  return;
309
304
  }
310
305
  composingRef.current = false;
311
- if (disabled || toggle) {
312
- return;
313
- }
314
- const domValue = event && event.target ? event.target.value : (typeof event === "string" ? event : "");
315
- const baseValue = composeBaseDisplayRef.current;
316
- const composedText = baseValue && domValue.startsWith(baseValue)
317
- ? domValue.slice(baseValue.length)
318
- : domValue.replace(/^\*+/, "");
319
- if (!composedText) {
306
+ if (disabled || !toggle) {
320
307
  setCompositionDisplay(null);
321
308
  return;
322
309
  }
323
- commitValue(editingRef.current ? realValueRef.current + composedText : composedText, true);
310
+ commitValue(event && event.target ? event.target.value : "", false);
324
311
  };
325
312
 
326
313
  const onModifyChange = (valueOrEvent) => {
327
314
  const nextValue = valueOrEvent && valueOrEvent.target ? valueOrEvent.target.value : valueOrEvent;
328
- if (composingRef.current && !toggle) {
329
- setCompositionDisplay(nextValue);
315
+ if (disabled || !toggle) {
330
316
  return;
331
317
  }
332
- if (disabled || (!toggle && nextValue !== "")) {
318
+ if (composingRef.current) {
319
+ setCompositionDisplay(nextValue);
333
320
  return;
334
321
  }
335
322
  commitValue(nextValue, false);
@@ -375,8 +362,9 @@ const InputPasswordDecrypt = (props) => {
375
362
  style={style}
376
363
  value={modifyDisplay}
377
364
  placeholder={placeholder}
378
- disabled={disabled}
379
- allowClear={allowClear}
365
+ disabled={!toggle || disabled}
366
+ allowClear={allowClear && toggle}
367
+ className={[className, MODIFY_INPUT_CLASS].filter(Boolean).join(" ")}
380
368
  maxLength={toggle && typeof maxLength === "number" ? maxLength : undefined}
381
369
  onChange={onModifyChange}
382
370
  onKeyDown={onModifyKeyDown}
@@ -1,373 +1,373 @@
1
- import * as ExcelJS from "exceljs/dist/exceljs.bare.js";
2
- import {saveAs} from "file-saver";
3
- import Values from "./Values";
4
-
5
-
6
- const DEFAULT_BORDER_COLOR_FOR_EXCEL = "CCCCCC";
7
- const DEFAULT_FG_COLOR_FOR_EXCEL = "FFFFFF";
8
- const DEFAULT_COL_HEADER_BG_COLOR = "F2F3F5";
9
-
10
- const excelHeaderRowStyle = {
11
- font: {
12
- size: 10,
13
- bold: true
14
- },
15
- alignment: {
16
- vertical: 'middle',
17
- horizontal: 'center'
18
- },
19
- fill: {
20
- type: 'pattern',
21
- pattern: 'solid',
22
- fgColor: {
23
- argb: DEFAULT_COL_HEADER_BG_COLOR
24
- }
25
- },
26
- border: {
27
- top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
28
- left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
29
- bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
30
- right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
31
- }
32
- }
33
-
34
- const excelBodyRowStyle = {
35
- font: {
36
- size: 10,
37
- bold: true
38
- },
39
- alignment: {
40
- vertical: 'middle',
41
- horizontal: 'center'
42
- },
43
- fill: {
44
- type: 'pattern',
45
- pattern: 'solid',
46
- fgColor: {
47
- argb: DEFAULT_FG_COLOR_FOR_EXCEL
48
- }
49
- },
50
- border: {
51
- top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
52
- left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
53
- bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
54
- right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
55
- }
56
- }
57
-
58
- const ExcelKits = {
59
-
60
- exportHandsontableData2CSVFile(handsonTableInstance, fileName) {
61
- if (handsonTableInstance === null || handsonTableInstance === void 0) {
62
- throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2CSVFile");
63
- }
64
-
65
- if (Values.isBlankString(fileName)) {
66
- fileName = `${t('ui.export.csv.file')}-` + new Date().getTime();
67
- }
68
-
69
- const exportPlugin = handsonTableInstance.getPlugin('exportFile');
70
- exportPlugin.downloadFile('csv', {
71
- bom: false,
72
- columnDelimiter: ',',
73
- columnHeaders: false,
74
- exportHiddenColumns: true,
75
- exportHiddenRows: true,
76
- fileExtension: 'csv',
77
- filename: fileName,
78
- mimeType: 'text/csv',
79
- rowDelimiter: '\r\n',
80
- rowHeaders: true
81
- });
82
- },
83
-
84
- exportHandsontableData2ExcelFile(handsontableInstance, fileName) {
85
- if (handsontableInstance === null || handsontableInstance === void 0) {
86
- throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2ExcelFile");
87
- }
88
-
89
- if (Values.isBlankString(fileName)) {
90
- fileName = t('ui.export.excel.file') + "-" + new Date().getTime();
91
- }
92
-
93
- let exportGridColumns = [];
94
- let exportGridData = handsontableInstance.hotInstance.getSourceData();
95
-
96
- window.handsontableInstance = handsontableInstance;
97
-
98
- if (handsontableInstance.columnSettings && handsontableInstance.columnSettings.length) {
99
- handsontableInstance.columnSettings.forEach(column => {
100
- exportGridColumns.push({
101
- ...column,
102
- dataIndex: column.data
103
- })
104
- })
105
- }
106
-
107
- console.log('exportGridColumns :', exportGridColumns)
108
- console.log('exportGridData :', exportGridData)
109
-
110
- this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
111
- },
112
-
113
- exportTableData2ExcelFile(columns = [], data = [], fileName) {
114
-
115
- if (Values.isBlankString(fileName)) {
116
- fileName = `${t('ui.export.excel.file')}-` + new Date().getTime();
117
- }
118
-
119
- const workbook = new ExcelJS.Workbook();
120
- const worksheet = workbook.addWorksheet('sheet');
121
-
122
- let exportGridColumnsData = this.gatherExcelColumnHeaderStructureInfo(this.extractColumns(columns));
123
- let totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
124
- let columnHeaderData = exportGridColumnsData.columnHeaderData;
125
- let rowHeaderArray = exportGridColumnsData.rowHeaderArray;
126
- let columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
127
-
128
- let exportGridData = data;
129
-
130
- worksheet.columns = columnHeaderData;
131
- worksheet.spliceRows(1, 1);
132
- worksheet.insertRows(1, rowHeaderArray);
133
-
134
- exportGridData.forEach(gridItem => {
135
- worksheet.addRow(gridItem);
136
- })
137
-
138
- columnHeaderMergeCellArray.forEach(mergeCells => {
139
- worksheet.mergeCells(mergeCells)
140
- })
141
-
142
- // 设置表头样式
143
- const headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
144
- headerRows.forEach((row, rowIndex) => {
145
- row.eachCell((cell, cellIndex) => {
146
- cell.style = excelHeaderRowStyle;
147
- })
148
- })
149
-
150
- // 设置表体样式
151
- const bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
152
- bodyRows.forEach((row) => {
153
- row.eachCell((cell, cellIndex) => {
154
- cell.style = excelBodyRowStyle;
155
- })
156
- })
157
-
158
- workbook.xlsx.writeBuffer().then(buffer => {
159
- saveAs(new Blob([buffer], {
160
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
161
- }), fileName + ".xlsx")
162
- })
163
- },
164
-
165
- extractColumns(children, level) {
166
- let _this = this;
167
- if (level === void 0) {
168
- level = 0;
169
- }
170
- return Array.isArray(children)
171
- ? children.map(function (child) {
172
- return _this.extractChild(child, level);
173
- })
174
- : [children, _this.extractChild(children, level)];
175
- },
176
-
177
- extractChild(child, level) {
178
- let _this = this;
179
- if (level === void 0) {
180
- level = 0;
181
- }
182
- return Object.assign(Object.assign({}, child), {
183
- level: level,
184
- children: child.children && _this.extractColumns(child.children, level + 1)
185
- })
186
- },
187
-
188
- /**
189
- * 收集Excel列头信息(复合表头)
190
- * @param gridColumns
191
- * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
192
- */
193
- gatherExcelColumnHeaderStructureInfo(gridColumns) {
194
- let [totalColumnCount, totalColumnHeaderRowCount] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, 0, 1);
195
-
196
- let columnHeaderArray = [];
197
- for (let i = 0, count = gridColumns.length; i < count; i++) {
198
- let column = gridColumns[i];
199
- this.$buildColumnHeaderArray(column, columnHeaderArray);
200
- }
201
-
202
- for (let i = 0, count = columnHeaderArray.length; i < count; i++) {
203
- let subArray = columnHeaderArray[i];
204
- let lastElem = subArray[subArray.length - 1];
205
- for (let r = subArray.length; r < totalColumnHeaderRowCount; r++) {
206
- subArray.push(lastElem);
207
- }
208
- }
209
-
210
- let columnHeaderMergeCellArray = [];
211
- let nextColIndex = 1;
212
- for (let i = 0, count = gridColumns.length; i < count; i++) {
213
- let gridColumn = gridColumns[i];
214
- nextColIndex = this.gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, 1, nextColIndex);
215
- }
216
-
217
- let rowHeaderArray = [];
218
- for (let totalColumnHeaderRowStep = 0; totalColumnHeaderRowStep < totalColumnHeaderRowCount; totalColumnHeaderRowStep++) {
219
- let rowHeaderColumns = [];
220
- columnHeaderArray.forEach(columns => {
221
- rowHeaderColumns.push(columns[totalColumnHeaderRowStep])
222
- })
223
- rowHeaderArray.push(rowHeaderColumns);
224
- }
225
-
226
- let columnHeaderData = [];
227
- let columnIndex = 0;
228
-
229
- let addColumns = (columns, result) => {
230
- columns.forEach((column) => {
231
- let exporterColumn = this.$normalizedExportColumn(column);
232
- result.push(exporterColumn);
233
- if (column.children && column.children.length > 1) {
234
- let children = exporterColumn.columns = [];
235
- addColumns(column.children, children);
236
- } else {
237
- columnIndex++;
238
- }
239
- });
240
- };
241
- addColumns(gridColumns, columnHeaderData);
242
- const autoCreateArrayItems = function (column, columnStep, columns) {
243
- if (column.columns && column.columns.length) {
244
- columns.splice(columnStep, 1, ...column.columns);
245
- }
246
-
247
- if (columnStep === columns.length - 1) {
248
- console.log('success');
249
- } else {
250
- columnStep++;
251
- autoCreateArrayItems(columns[columnStep], columnStep, columns);
252
- }
253
- }
254
-
255
- autoCreateArrayItems(columnHeaderData[0], 0, columnHeaderData);
256
-
257
- return {
258
- totalColumnCount,
259
- totalColumnHeaderRowCount,
260
- columnHeaderArray,
261
- columnHeaderData,
262
- rowHeaderArray,
263
- columnHeaderMergeCellArray
264
- };
265
- },
266
-
267
- /**
268
- * @return {Array} eg -
269
- * [
270
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
271
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
272
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
273
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
274
- * ]
275
- */
276
- gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, currentColumnHeaderRowIndex = 1, colIndex) {
277
-
278
- let allChildColumnCount = this.$countAllChildColumnCount(gridColumn);
279
-
280
- if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
281
- let gridColumns = gridColumn.children;
282
- let gridColumnCount = gridColumns.length;
283
-
284
- columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, currentColumnHeaderRowIndex, colIndex + allChildColumnCount - 1]);
285
-
286
- for (let i = 0; i < gridColumnCount; i++) {
287
- this.gatherExcelColumnHeaderMergeCellInfo(gridColumns[i], columnHeaderMergeCellArray, totalColumnHeaderRowCount,
288
- currentColumnHeaderRowIndex + 1, colIndex + i);
289
- }
290
- } else {
291
- if (currentColumnHeaderRowIndex !== totalColumnHeaderRowCount) {
292
- columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, totalColumnHeaderRowCount, colIndex]);
293
- }
294
- }
295
-
296
- return colIndex + allChildColumnCount;
297
- },
298
-
299
- $countAllChildColumnCount(gridColumn) {
300
- let columnCount = 0;
301
- if (gridColumn === null || gridColumn === void 0) {
302
- return columnCount;
303
- }
304
-
305
- if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
306
- let gridColumns = gridColumn.children;
307
- let gridColumnCount = gridColumns.length;
308
-
309
- for (let i = 0; i < gridColumnCount; i++) {
310
- let childColumnCount = this.$countAllChildColumnCount(gridColumns[i]);
311
- columnCount = columnCount + childColumnCount;
312
- }
313
- } else {
314
- columnCount = 1;
315
- }
316
-
317
- return columnCount;
318
- },
319
-
320
- getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, totalColumnCount, totalColumnHeaderCount) {
321
- let maxN2 = totalColumnHeaderCount;
322
- for (let i = 0, count = gridColumns.length; i < count; i++) {
323
- let column = gridColumns[i];
324
- if (Array.isArray(column.children) && column.children.length) {
325
- let [n1, n2] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(column.children, 0, totalColumnHeaderCount + 1);
326
- totalColumnCount = totalColumnCount + n1;
327
- if (n2 > maxN2) {
328
- maxN2 = n2;
329
- }
330
- } else {
331
- totalColumnCount = totalColumnCount + 1;
332
- }
333
- }
334
-
335
- return [totalColumnCount, maxN2]
336
- },
337
-
338
- $buildColumnHeaderArray(column, columnHeaderArray, parentHeaderTitles) {
339
- if (Array.isArray(column.children) && column.children.length) {
340
- if (parentHeaderTitles === null || parentHeaderTitles == void 0) {
341
- parentHeaderTitles = [column.title];
342
- } else {
343
- parentHeaderTitles.push(column.title);
344
- }
345
-
346
- for (let i = 0, count = column.children.length; i < count; i++) {
347
- let childColumn = column.children[i];
348
- this.$buildColumnHeaderArray(childColumn, columnHeaderArray, parentHeaderTitles);
349
- }
350
- } else {
351
- let columnSelfHeaderTitleArray = [];
352
- if (Array.isArray(parentHeaderTitles)) {
353
- columnSelfHeaderTitleArray.push(...parentHeaderTitles);
354
- }
355
-
356
- columnSelfHeaderTitleArray.push(column.title);
357
-
358
- columnHeaderArray.push(columnSelfHeaderTitleArray)
359
- }
360
- },
361
-
362
-
363
- $normalizedExportColumn(column) {
364
- return {
365
- header : column.title,
366
- key : column.dataIndex,
367
- locked : column.locked,
368
- width : column.width != null ? column.width * 0.1 : undefined
369
- }
370
- }
371
- }
372
-
373
- export default ExcelKits;
1
+ import * as ExcelJS from "exceljs/dist/exceljs.bare.js";
2
+ import {saveAs} from "file-saver";
3
+ import Values from "./Values";
4
+
5
+
6
+ const DEFAULT_BORDER_COLOR_FOR_EXCEL = "CCCCCC";
7
+ const DEFAULT_FG_COLOR_FOR_EXCEL = "FFFFFF";
8
+ const DEFAULT_COL_HEADER_BG_COLOR = "F2F3F5";
9
+
10
+ const excelHeaderRowStyle = {
11
+ font: {
12
+ size: 10,
13
+ bold: true
14
+ },
15
+ alignment: {
16
+ vertical: 'middle',
17
+ horizontal: 'center'
18
+ },
19
+ fill: {
20
+ type: 'pattern',
21
+ pattern: 'solid',
22
+ fgColor: {
23
+ argb: DEFAULT_COL_HEADER_BG_COLOR
24
+ }
25
+ },
26
+ border: {
27
+ top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
28
+ left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
29
+ bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
30
+ right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
31
+ }
32
+ }
33
+
34
+ const excelBodyRowStyle = {
35
+ font: {
36
+ size: 10,
37
+ bold: true
38
+ },
39
+ alignment: {
40
+ vertical: 'middle',
41
+ horizontal: 'center'
42
+ },
43
+ fill: {
44
+ type: 'pattern',
45
+ pattern: 'solid',
46
+ fgColor: {
47
+ argb: DEFAULT_FG_COLOR_FOR_EXCEL
48
+ }
49
+ },
50
+ border: {
51
+ top: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
52
+ left: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
53
+ bottom: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}},
54
+ right: {style: 'thin', color: {argb: DEFAULT_BORDER_COLOR_FOR_EXCEL}}
55
+ }
56
+ }
57
+
58
+ const ExcelKits = {
59
+
60
+ exportHandsontableData2CSVFile(handsonTableInstance, fileName) {
61
+ if (handsonTableInstance === null || handsonTableInstance === void 0) {
62
+ throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2CSVFile");
63
+ }
64
+
65
+ if (Values.isBlankString(fileName)) {
66
+ fileName = `${t('ui.export.csv.file')}-` + new Date().getTime();
67
+ }
68
+
69
+ const exportPlugin = handsonTableInstance.getPlugin('exportFile');
70
+ exportPlugin.downloadFile('csv', {
71
+ bom: false,
72
+ columnDelimiter: ',',
73
+ columnHeaders: false,
74
+ exportHiddenColumns: true,
75
+ exportHiddenRows: true,
76
+ fileExtension: 'csv',
77
+ filename: fileName,
78
+ mimeType: 'text/csv',
79
+ rowDelimiter: '\r\n',
80
+ rowHeaders: true
81
+ });
82
+ },
83
+
84
+ exportHandsontableData2ExcelFile(handsontableInstance, fileName) {
85
+ if (handsontableInstance === null || handsontableInstance === void 0) {
86
+ throw new IllegalArgumentError("HandsontableInstance is null for ExcelKits#exportHandsontableData2ExcelFile");
87
+ }
88
+
89
+ if (Values.isBlankString(fileName)) {
90
+ fileName = t('ui.export.excel.file') + "-" + new Date().getTime();
91
+ }
92
+
93
+ let exportGridColumns = [];
94
+ let exportGridData = handsontableInstance.hotInstance.getSourceData();
95
+
96
+ window.handsontableInstance = handsontableInstance;
97
+
98
+ if (handsontableInstance.columnSettings && handsontableInstance.columnSettings.length) {
99
+ handsontableInstance.columnSettings.forEach(column => {
100
+ exportGridColumns.push({
101
+ ...column,
102
+ dataIndex: column.data
103
+ })
104
+ })
105
+ }
106
+
107
+ console.log('exportGridColumns :', exportGridColumns)
108
+ console.log('exportGridData :', exportGridData)
109
+
110
+ this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
111
+ },
112
+
113
+ exportTableData2ExcelFile(columns = [], data = [], fileName) {
114
+
115
+ if (Values.isBlankString(fileName)) {
116
+ fileName = `${t('ui.export.excel.file')}-` + new Date().getTime();
117
+ }
118
+
119
+ const workbook = new ExcelJS.Workbook();
120
+ const worksheet = workbook.addWorksheet('sheet');
121
+
122
+ let exportGridColumnsData = this.gatherExcelColumnHeaderStructureInfo(this.extractColumns(columns));
123
+ let totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
124
+ let columnHeaderData = exportGridColumnsData.columnHeaderData;
125
+ let rowHeaderArray = exportGridColumnsData.rowHeaderArray;
126
+ let columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
127
+
128
+ let exportGridData = data;
129
+
130
+ worksheet.columns = columnHeaderData;
131
+ worksheet.spliceRows(1, 1);
132
+ worksheet.insertRows(1, rowHeaderArray);
133
+
134
+ exportGridData.forEach(gridItem => {
135
+ worksheet.addRow(gridItem);
136
+ })
137
+
138
+ columnHeaderMergeCellArray.forEach(mergeCells => {
139
+ worksheet.mergeCells(mergeCells)
140
+ })
141
+
142
+ // 设置表头样式
143
+ const headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
144
+ headerRows.forEach((row, rowIndex) => {
145
+ row.eachCell((cell, cellIndex) => {
146
+ cell.style = excelHeaderRowStyle;
147
+ })
148
+ })
149
+
150
+ // 设置表体样式
151
+ const bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
152
+ bodyRows.forEach((row) => {
153
+ row.eachCell((cell, cellIndex) => {
154
+ cell.style = excelBodyRowStyle;
155
+ })
156
+ })
157
+
158
+ workbook.xlsx.writeBuffer().then(buffer => {
159
+ saveAs(new Blob([buffer], {
160
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
161
+ }), fileName + ".xlsx")
162
+ })
163
+ },
164
+
165
+ extractColumns(children, level) {
166
+ let _this = this;
167
+ if (level === void 0) {
168
+ level = 0;
169
+ }
170
+ return Array.isArray(children)
171
+ ? children.map(function (child) {
172
+ return _this.extractChild(child, level);
173
+ })
174
+ : [children, _this.extractChild(children, level)];
175
+ },
176
+
177
+ extractChild(child, level) {
178
+ let _this = this;
179
+ if (level === void 0) {
180
+ level = 0;
181
+ }
182
+ return Object.assign(Object.assign({}, child), {
183
+ level: level,
184
+ children: child.children && _this.extractColumns(child.children, level + 1)
185
+ })
186
+ },
187
+
188
+ /**
189
+ * 收集Excel列头信息(复合表头)
190
+ * @param gridColumns
191
+ * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
192
+ */
193
+ gatherExcelColumnHeaderStructureInfo(gridColumns) {
194
+ let [totalColumnCount, totalColumnHeaderRowCount] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, 0, 1);
195
+
196
+ let columnHeaderArray = [];
197
+ for (let i = 0, count = gridColumns.length; i < count; i++) {
198
+ let column = gridColumns[i];
199
+ this.$buildColumnHeaderArray(column, columnHeaderArray);
200
+ }
201
+
202
+ for (let i = 0, count = columnHeaderArray.length; i < count; i++) {
203
+ let subArray = columnHeaderArray[i];
204
+ let lastElem = subArray[subArray.length - 1];
205
+ for (let r = subArray.length; r < totalColumnHeaderRowCount; r++) {
206
+ subArray.push(lastElem);
207
+ }
208
+ }
209
+
210
+ let columnHeaderMergeCellArray = [];
211
+ let nextColIndex = 1;
212
+ for (let i = 0, count = gridColumns.length; i < count; i++) {
213
+ let gridColumn = gridColumns[i];
214
+ nextColIndex = this.gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, 1, nextColIndex);
215
+ }
216
+
217
+ let rowHeaderArray = [];
218
+ for (let totalColumnHeaderRowStep = 0; totalColumnHeaderRowStep < totalColumnHeaderRowCount; totalColumnHeaderRowStep++) {
219
+ let rowHeaderColumns = [];
220
+ columnHeaderArray.forEach(columns => {
221
+ rowHeaderColumns.push(columns[totalColumnHeaderRowStep])
222
+ })
223
+ rowHeaderArray.push(rowHeaderColumns);
224
+ }
225
+
226
+ let columnHeaderData = [];
227
+ let columnIndex = 0;
228
+
229
+ let addColumns = (columns, result) => {
230
+ columns.forEach((column) => {
231
+ let exporterColumn = this.$normalizedExportColumn(column);
232
+ result.push(exporterColumn);
233
+ if (column.children && column.children.length > 1) {
234
+ let children = exporterColumn.columns = [];
235
+ addColumns(column.children, children);
236
+ } else {
237
+ columnIndex++;
238
+ }
239
+ });
240
+ };
241
+ addColumns(gridColumns, columnHeaderData);
242
+ const autoCreateArrayItems = function (column, columnStep, columns) {
243
+ if (column.columns && column.columns.length) {
244
+ columns.splice(columnStep, 1, ...column.columns);
245
+ }
246
+
247
+ if (columnStep === columns.length - 1) {
248
+ console.log('success');
249
+ } else {
250
+ columnStep++;
251
+ autoCreateArrayItems(columns[columnStep], columnStep, columns);
252
+ }
253
+ }
254
+
255
+ autoCreateArrayItems(columnHeaderData[0], 0, columnHeaderData);
256
+
257
+ return {
258
+ totalColumnCount,
259
+ totalColumnHeaderRowCount,
260
+ columnHeaderArray,
261
+ columnHeaderData,
262
+ rowHeaderArray,
263
+ columnHeaderMergeCellArray
264
+ };
265
+ },
266
+
267
+ /**
268
+ * @return {Array} eg -
269
+ * [
270
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
271
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
272
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
273
+ * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
274
+ * ]
275
+ */
276
+ gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount, currentColumnHeaderRowIndex = 1, colIndex) {
277
+
278
+ let allChildColumnCount = this.$countAllChildColumnCount(gridColumn);
279
+
280
+ if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
281
+ let gridColumns = gridColumn.children;
282
+ let gridColumnCount = gridColumns.length;
283
+
284
+ columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, currentColumnHeaderRowIndex, colIndex + allChildColumnCount - 1]);
285
+
286
+ for (let i = 0; i < gridColumnCount; i++) {
287
+ this.gatherExcelColumnHeaderMergeCellInfo(gridColumns[i], columnHeaderMergeCellArray, totalColumnHeaderRowCount,
288
+ currentColumnHeaderRowIndex + 1, colIndex + i);
289
+ }
290
+ } else {
291
+ if (currentColumnHeaderRowIndex !== totalColumnHeaderRowCount) {
292
+ columnHeaderMergeCellArray.push([currentColumnHeaderRowIndex, colIndex, totalColumnHeaderRowCount, colIndex]);
293
+ }
294
+ }
295
+
296
+ return colIndex + allChildColumnCount;
297
+ },
298
+
299
+ $countAllChildColumnCount(gridColumn) {
300
+ let columnCount = 0;
301
+ if (gridColumn === null || gridColumn === void 0) {
302
+ return columnCount;
303
+ }
304
+
305
+ if (Array.isArray(gridColumn.children) && gridColumn.children.length) {
306
+ let gridColumns = gridColumn.children;
307
+ let gridColumnCount = gridColumns.length;
308
+
309
+ for (let i = 0; i < gridColumnCount; i++) {
310
+ let childColumnCount = this.$countAllChildColumnCount(gridColumns[i]);
311
+ columnCount = columnCount + childColumnCount;
312
+ }
313
+ } else {
314
+ columnCount = 1;
315
+ }
316
+
317
+ return columnCount;
318
+ },
319
+
320
+ getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, totalColumnCount, totalColumnHeaderCount) {
321
+ let maxN2 = totalColumnHeaderCount;
322
+ for (let i = 0, count = gridColumns.length; i < count; i++) {
323
+ let column = gridColumns[i];
324
+ if (Array.isArray(column.children) && column.children.length) {
325
+ let [n1, n2] = this.getTotalColumnCountAndTotalColumnHeaderRowCount(column.children, 0, totalColumnHeaderCount + 1);
326
+ totalColumnCount = totalColumnCount + n1;
327
+ if (n2 > maxN2) {
328
+ maxN2 = n2;
329
+ }
330
+ } else {
331
+ totalColumnCount = totalColumnCount + 1;
332
+ }
333
+ }
334
+
335
+ return [totalColumnCount, maxN2]
336
+ },
337
+
338
+ $buildColumnHeaderArray(column, columnHeaderArray, parentHeaderTitles) {
339
+ if (Array.isArray(column.children) && column.children.length) {
340
+ if (parentHeaderTitles === null || parentHeaderTitles == void 0) {
341
+ parentHeaderTitles = [column.title];
342
+ } else {
343
+ parentHeaderTitles.push(column.title);
344
+ }
345
+
346
+ for (let i = 0, count = column.children.length; i < count; i++) {
347
+ let childColumn = column.children[i];
348
+ this.$buildColumnHeaderArray(childColumn, columnHeaderArray, parentHeaderTitles);
349
+ }
350
+ } else {
351
+ let columnSelfHeaderTitleArray = [];
352
+ if (Array.isArray(parentHeaderTitles)) {
353
+ columnSelfHeaderTitleArray.push(...parentHeaderTitles);
354
+ }
355
+
356
+ columnSelfHeaderTitleArray.push(column.title);
357
+
358
+ columnHeaderArray.push(columnSelfHeaderTitleArray)
359
+ }
360
+ },
361
+
362
+
363
+ $normalizedExportColumn(column) {
364
+ return {
365
+ header : column.title,
366
+ key : column.dataIndex,
367
+ locked : column.locked,
368
+ width : column.width != null ? column.width * 0.1 : undefined
369
+ }
370
+ }
371
+ }
372
+
373
+ export default ExcelKits;
@@ -246,6 +246,18 @@
246
246
  display: none;
247
247
  }
248
248
 
249
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled,
250
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled:hover {
251
+ border: 1px solid #d9d9d9;
252
+ padding-left: 11px;
253
+ background-color: #fff;
254
+ }
255
+
256
+ .bchr-input-password-decrypt-modify.ant-input-affix-wrapper-disabled .ant-input[disabled] {
257
+ background: transparent;
258
+ border: none;
259
+ }
260
+
249
261
  .ant-select-dropdown {
250
262
  width: 100%;
251
263
  min-height: 38px;