@bchr/bchr-front-lib 0.6.9 → 0.6.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.
@@ -4,9 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
+ var ExcelJS = _interopRequireWildcard(require("exceljs/dist/exceljs.bare.js"));
7
8
  var _fileSaver = require("file-saver");
8
9
  var _Values = _interopRequireDefault(require("./Values"));
9
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
12
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
11
13
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
12
14
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -18,11 +20,6 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
18
20
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
19
21
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
20
22
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
21
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
22
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
23
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
24
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
25
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
26
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
27
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
28
25
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -161,70 +158,50 @@ var ExcelKits = {
161
158
  this.exportTableData2ExcelFile(exportGridColumns, exportGridData, fileName);
162
159
  },
163
160
  exportTableData2ExcelFile: function exportTableData2ExcelFile() {
164
- var _arguments = arguments,
165
- _this2 = this;
166
- return _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
167
- var _excelModule$default;
168
- var columns, data, fileName, excelModule, ExcelJS, workbook, worksheet, exportGridColumnsData, totalColumnHeaderRowCount, columnHeaderData, rowHeaderArray, columnHeaderMergeCellArray, exportGridData, headerRows, bodyRows;
169
- return _regenerator().w(function (_context) {
170
- while (1) switch (_context.n) {
171
- case 0:
172
- columns = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : [];
173
- data = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : [];
174
- fileName = _arguments.length > 2 ? _arguments[2] : undefined;
175
- if (_Values["default"].isBlankString(fileName)) {
176
- fileName = "".concat(t('ui.export.excel.file'), "-") + new Date().getTime();
177
- }
178
- _context.n = 1;
179
- return Promise.resolve().then(function () {
180
- return _interopRequireWildcard(require("exceljs/dist/exceljs.bare.min.js"));
181
- });
182
- case 1:
183
- excelModule = _context.v;
184
- ExcelJS = (_excelModule$default = excelModule["default"]) !== null && _excelModule$default !== void 0 ? _excelModule$default : excelModule;
185
- workbook = new ExcelJS.Workbook();
186
- worksheet = workbook.addWorksheet('sheet');
187
- exportGridColumnsData = _this2.gatherExcelColumnHeaderStructureInfo(_this2.extractColumns(columns));
188
- totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
189
- columnHeaderData = exportGridColumnsData.columnHeaderData;
190
- rowHeaderArray = exportGridColumnsData.rowHeaderArray;
191
- columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
192
- exportGridData = data;
193
- worksheet.columns = columnHeaderData;
194
- worksheet.spliceRows(1, 1);
195
- worksheet.insertRows(1, rowHeaderArray);
196
- exportGridData.forEach(function (gridItem) {
197
- worksheet.addRow(gridItem);
198
- });
199
- columnHeaderMergeCellArray.forEach(function (mergeCells) {
200
- worksheet.mergeCells(mergeCells);
201
- });
161
+ var columns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
162
+ var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
163
+ var fileName = arguments.length > 2 ? arguments[2] : undefined;
164
+ if (_Values["default"].isBlankString(fileName)) {
165
+ fileName = "".concat(t('ui.export.excel.file'), "-") + new Date().getTime();
166
+ }
167
+ var workbook = new ExcelJS.Workbook();
168
+ var worksheet = workbook.addWorksheet('sheet');
169
+ var exportGridColumnsData = this.gatherExcelColumnHeaderStructureInfo(this.extractColumns(columns));
170
+ var totalColumnHeaderRowCount = exportGridColumnsData.totalColumnHeaderRowCount;
171
+ var columnHeaderData = exportGridColumnsData.columnHeaderData;
172
+ var rowHeaderArray = exportGridColumnsData.rowHeaderArray;
173
+ var columnHeaderMergeCellArray = exportGridColumnsData.columnHeaderMergeCellArray;
174
+ var exportGridData = data;
175
+ worksheet.columns = columnHeaderData;
176
+ worksheet.spliceRows(1, 1);
177
+ worksheet.insertRows(1, rowHeaderArray);
178
+ exportGridData.forEach(function (gridItem) {
179
+ worksheet.addRow(gridItem);
180
+ });
181
+ columnHeaderMergeCellArray.forEach(function (mergeCells) {
182
+ worksheet.mergeCells(mergeCells);
183
+ });
202
184
 
203
- // 设置表头样式
204
- headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
205
- headerRows.forEach(function (row, rowIndex) {
206
- row.eachCell(function (cell, cellIndex) {
207
- cell.style = excelHeaderRowStyle;
208
- });
209
- });
185
+ // 设置表头样式
186
+ var headerRows = worksheet.getRows(1, totalColumnHeaderRowCount);
187
+ headerRows.forEach(function (row, rowIndex) {
188
+ row.eachCell(function (cell, cellIndex) {
189
+ cell.style = excelHeaderRowStyle;
190
+ });
191
+ });
210
192
 
211
- // 设置表体样式
212
- bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
213
- bodyRows.forEach(function (row) {
214
- row.eachCell(function (cell, cellIndex) {
215
- cell.style = excelBodyRowStyle;
216
- });
217
- });
218
- workbook.xlsx.writeBuffer().then(function (buffer) {
219
- (0, _fileSaver.saveAs)(new Blob([buffer], {
220
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
221
- }), fileName + ".xlsx");
222
- });
223
- case 2:
224
- return _context.a(2);
225
- }
226
- }, _callee);
227
- }))();
193
+ // 设置表体样式
194
+ var bodyRows = worksheet.getRows(totalColumnHeaderRowCount + 1, totalColumnHeaderRowCount + exportGridData.length + 5);
195
+ bodyRows.forEach(function (row) {
196
+ row.eachCell(function (cell, cellIndex) {
197
+ cell.style = excelBodyRowStyle;
198
+ });
199
+ });
200
+ workbook.xlsx.writeBuffer().then(function (buffer) {
201
+ (0, _fileSaver.saveAs)(new Blob([buffer], {
202
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
203
+ }), fileName + ".xlsx");
204
+ });
228
205
  },
229
206
  extractColumns: function extractColumns(children, level) {
230
207
  var _this = this;
@@ -245,13 +222,13 @@ var ExcelKits = {
245
222
  children: child.children && _this.extractColumns(child.children, level + 1)
246
223
  });
247
224
  },
248
- /**
249
- * 收集Excel列头信息(复合表头)
250
- * @param gridColumns
251
- * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
225
+ /**
226
+ * 收集Excel列头信息(复合表头)
227
+ * @param gridColumns
228
+ * @returns {{totalColumnCount: {int}, totalColumnHeaderRowCount: {int}, columnHeaderArray: [] }}
252
229
  */
253
230
  gatherExcelColumnHeaderStructureInfo: function gatherExcelColumnHeaderStructureInfo(gridColumns) {
254
- var _this3 = this;
231
+ var _this2 = this;
255
232
  var _this$getTotalColumnC = this.getTotalColumnCountAndTotalColumnHeaderRowCount(gridColumns, 0, 1),
256
233
  _this$getTotalColumnC2 = _slicedToArray(_this$getTotalColumnC, 2),
257
234
  totalColumnCount = _this$getTotalColumnC2[0],
@@ -289,7 +266,7 @@ var ExcelKits = {
289
266
  var columnIndex = 0;
290
267
  var _addColumns = function addColumns(columns, result) {
291
268
  columns.forEach(function (column) {
292
- var exporterColumn = _this3.$normalizedExportColumn(column);
269
+ var exporterColumn = _this2.$normalizedExportColumn(column);
293
270
  result.push(exporterColumn);
294
271
  if (column.children && column.children.length > 1) {
295
272
  var children = exporterColumn.columns = [];
@@ -321,14 +298,14 @@ var ExcelKits = {
321
298
  columnHeaderMergeCellArray: columnHeaderMergeCellArray
322
299
  };
323
300
  },
324
- /**
325
- * @return {Array} eg -
326
- * [
327
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
328
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
329
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
330
- * [leftTopRowIndex, leftTopColumnIndex, rightBottomRowIndex, rightBottomColumnIndex],
331
- * ]
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
+ * ]
332
309
  */
333
310
  gatherExcelColumnHeaderMergeCellInfo: function gatherExcelColumnHeaderMergeCellInfo(gridColumn, columnHeaderMergeCellArray, totalColumnHeaderRowCount) {
334
311
  var currentColumnHeaderRowIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 1;
@@ -409,7 +386,7 @@ var ExcelKits = {
409
386
  header: column.title,
410
387
  key: column.dataIndex,
411
388
  locked: column.locked,
412
- width: column.width * 0.1
389
+ width: column.width != null ? column.width * 0.1 : undefined
413
390
  };
414
391
  }
415
392
  };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@bchr/bchr-front-lib",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "description": "bchr front lib",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {
7
7
  "prepublish": "babel src --out-dir lib --copy-files",
8
8
  "login": "npm login",
9
- "publish": "npm publish "
9
+ "publish": "npm publish ",
10
+ "unpublish": "npm unpublish "
10
11
  },
11
12
  "publishConfig": {
12
13
  "registry": "https://registry.npmjs.org",