ls-pro-common 1.0.8 → 1.0.9

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.
@@ -1,4 +1,5 @@
1
1
  import type { ActionType } from 'ls-pro-table';
2
+ import type { exportParam } from 'ls-pro-table/lib/components/Export';
2
3
  import type { ProFormInstance } from 'ls-pro-form';
3
4
  import type { SingleParamType } from '../useSingle';
4
5
  export declare type DtlParamType = SingleParamType & {
@@ -25,5 +26,6 @@ declare function useDtl(dtlParam: DtlParamType): {
25
26
  onEditDtl: () => Promise<boolean>;
26
27
  onSaveMst: (values: any) => Promise<void>;
27
28
  onRemoveMst: () => Promise<boolean | undefined>;
29
+ onExportDtl: (url: string, param: exportParam) => Promise<boolean>;
28
30
  };
29
31
  export default useDtl;
@@ -9,7 +9,8 @@ var _excluded = ["current", "pageSize"];
9
9
  import React from "react";
10
10
  import { useState, useRef } from 'react';
11
11
  import { PlusOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons';
12
- import { showConfirm, showWarn, showSuccess } from '../../utils';
12
+ import { showConfirm, showWarn, showError, showSuccess } from '../../utils';
13
+ import { httpPost } from '../../http';
13
14
 
14
15
  function useDtl(dtlParam) {
15
16
  var mstService = dtlParam.service,
@@ -576,6 +577,77 @@ function useDtl(dtlParam) {
576
577
  };
577
578
  }();
578
579
 
580
+ var onExportDtl = /*#__PURE__*/function () {
581
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(url, param) {
582
+ var _param$exportColumns;
583
+
584
+ var _result$flag5, result, _result$flag6, _result$flag7;
585
+
586
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
587
+ while (1) {
588
+ switch (_context8.prev = _context8.next) {
589
+ case 0:
590
+ if ((_param$exportColumns = param.exportColumns) === null || _param$exportColumns === void 0 ? void 0 : _param$exportColumns.length) {
591
+ _context8.next = 3;
592
+ break;
593
+ }
594
+
595
+ showWarn('请选择要导出的列');
596
+ return _context8.abrupt("return", false);
597
+
598
+ case 3:
599
+ if (param.findUrl) {
600
+ _context8.next = 6;
601
+ break;
602
+ }
603
+
604
+ showWarn('请配置业务接口 bizApi 属性');
605
+ return _context8.abrupt("return", false);
606
+
607
+ case 6:
608
+ _context8.prev = 6;
609
+ _context8.next = 9;
610
+ return httpPost(url, param);
611
+
612
+ case 9:
613
+ result = _context8.sent;
614
+
615
+ if (!(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retCode) === '0')) {
616
+ _context8.next = 15;
617
+ break;
618
+ }
619
+
620
+ showSuccess(((_result$flag6 = result.flag) === null || _result$flag6 === void 0 ? void 0 : _result$flag6.retMsg) || '导出成功');
621
+ return _context8.abrupt("return", true);
622
+
623
+ case 15:
624
+ showError(((_result$flag7 = result.flag) === null || _result$flag7 === void 0 ? void 0 : _result$flag7.retMsg) || '导出失败,请联系系统管理员');
625
+ return _context8.abrupt("return", false);
626
+
627
+ case 17:
628
+ _context8.next = 24;
629
+ break;
630
+
631
+ case 19:
632
+ _context8.prev = 19;
633
+ _context8.t0 = _context8["catch"](6);
634
+ console.log(_context8.t0);
635
+ showError(_context8.t0.message);
636
+ return _context8.abrupt("return", false);
637
+
638
+ case 24:
639
+ case "end":
640
+ return _context8.stop();
641
+ }
642
+ }
643
+ }, _callee8, null, [[6, 19]]);
644
+ }));
645
+
646
+ return function onExportDtl(_x6, _x7) {
647
+ return _ref8.apply(this, arguments);
648
+ };
649
+ }();
650
+
579
651
  var tableTools = [];
580
652
 
581
653
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) {
@@ -646,7 +718,8 @@ function useDtl(dtlParam) {
646
718
  onAddDtl: onAddDtl,
647
719
  onEditDtl: onEditDtl,
648
720
  onSaveMst: onSaveMst,
649
- onRemoveMst: onRemoveMst
721
+ onRemoveMst: onRemoveMst,
722
+ onExportDtl: onExportDtl
650
723
  };
651
724
  }
652
725
 
@@ -1,4 +1,5 @@
1
1
  import type { ActionType } from 'ls-pro-table';
2
+ import type { exportParam } from 'ls-pro-table/lib/components/Export';
2
3
  import type { ProFormInstance } from 'ls-pro-form';
3
4
  import type { ApiResponse, TableToolbar } from '../../typing';
4
5
  export declare type SingleParamType = {
@@ -36,6 +37,6 @@ declare function useSingle(inParam: SingleParamType): {
36
37
  onLoad: (params: Record<string, any>, sort: Record<string, any>, filter: Record<string, any>) => Promise<any>;
37
38
  onAdd: () => Promise<void>;
38
39
  onEdit: () => Promise<void>;
39
- onExport: (url: string, param: any) => Promise<boolean>;
40
+ onExport: (url: string, param: exportParam) => Promise<boolean>;
40
41
  };
41
42
  export default useSingle;
@@ -9,7 +9,8 @@ var _excluded = ["current", "pageSize"];
9
9
  import React from "react";
10
10
  import { useState, useRef } from 'react';
11
11
  import { PlusOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons';
12
- import { showConfirm, showWarn, showSuccess } from '../../utils';
12
+ import { showConfirm, showWarn, showSuccess, showError } from '../../utils';
13
+ import { httpPost } from '../../http';
13
14
  /**
14
15
  * 单表基本增删改查 hooks
15
16
  * @param service 单表服务
@@ -171,9 +172,8 @@ function useSingle(inParam) {
171
172
  }
172
173
 
173
174
  showConfirm('确认要删除选择的数据?').then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
174
- var _result$flag;
175
+ var ids, _result$flag, result;
175
176
 
176
- var ids, result;
177
177
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
178
178
  while (1) {
179
179
  switch (_context3.prev = _context3.next) {
@@ -203,21 +203,22 @@ function useSingle(inParam) {
203
203
  });
204
204
  }
205
205
 
206
- _context3.next = 9;
206
+ _context3.prev = 7;
207
+ _context3.next = 10;
207
208
  return service.remove(ids);
208
209
 
209
- case 9:
210
+ case 10:
210
211
  result = _context3.sent;
211
212
 
212
213
  if (!afterRemove) {
213
- _context3.next = 13;
214
+ _context3.next = 14;
214
215
  break;
215
216
  }
216
217
 
217
218
  afterRemove(result, selectedRows);
218
219
  return _context3.abrupt("return");
219
220
 
220
- case 13:
221
+ case 14:
221
222
  if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0') {
222
223
  showSuccess(result.flag.retMsg);
223
224
 
@@ -226,12 +227,20 @@ function useSingle(inParam) {
226
227
  }
227
228
  }
228
229
 
229
- case 14:
230
+ _context3.next = 20;
231
+ break;
232
+
233
+ case 17:
234
+ _context3.prev = 17;
235
+ _context3.t0 = _context3["catch"](7);
236
+ console.log(_context3.t0);
237
+
238
+ case 20:
230
239
  case "end":
231
240
  return _context3.stop();
232
241
  }
233
242
  }
234
- }, _callee3);
243
+ }, _callee3, null, [[7, 17]]);
235
244
  })));
236
245
  };
237
246
  /** 新增,更改对应的保存事件 */
@@ -239,34 +248,34 @@ function useSingle(inParam) {
239
248
 
240
249
  var onSave = /*#__PURE__*/function () {
241
250
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(formData) {
242
- var _result$flag2;
251
+ var data, _result$flag2, result;
243
252
 
244
- var data, result;
245
253
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
246
254
  while (1) {
247
255
  switch (_context4.prev = _context4.next) {
248
256
  case 0:
249
257
  data = _objectSpread(_objectSpread({}, editItem), formData);
250
- _context4.next = 3;
258
+ _context4.prev = 1;
259
+ _context4.next = 4;
251
260
  return service.save(data);
252
261
 
253
- case 3:
262
+ case 4:
254
263
  result = _context4.sent;
255
264
 
256
265
  if (!afterSave) {
257
- _context4.next = 8;
266
+ _context4.next = 9;
258
267
  break;
259
268
  }
260
269
 
261
- _context4.next = 7;
270
+ _context4.next = 8;
262
271
  return afterSave(result, data);
263
272
 
264
- case 7:
273
+ case 8:
265
274
  return _context4.abrupt("return", _context4.sent);
266
275
 
267
- case 8:
276
+ case 9:
268
277
  if (!((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retCode) === '0')) {
269
- _context4.next = 12;
278
+ _context4.next = 13;
270
279
  break;
271
280
  }
272
281
 
@@ -278,15 +287,24 @@ function useSingle(inParam) {
278
287
 
279
288
  return _context4.abrupt("return", true);
280
289
 
281
- case 12:
290
+ case 13:
291
+ _context4.next = 18;
292
+ break;
293
+
294
+ case 15:
295
+ _context4.prev = 15;
296
+ _context4.t0 = _context4["catch"](1);
297
+ console.log(_context4.t0);
298
+
299
+ case 18:
282
300
  return _context4.abrupt("return", false);
283
301
 
284
- case 13:
302
+ case 19:
285
303
  case "end":
286
304
  return _context4.stop();
287
305
  }
288
306
  }
289
- }, _callee4);
307
+ }, _callee4, null, [[1, 15]]);
290
308
  }));
291
309
 
292
310
  return function onSave(_x) {
@@ -372,18 +390,68 @@ function useSingle(inParam) {
372
390
 
373
391
  var onExport = /*#__PURE__*/function () {
374
392
  var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url, param) {
393
+ var _param$exportColumns;
394
+
395
+ var _result$flag3, result, _result$flag4, _result$flag5;
396
+
375
397
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
376
398
  while (1) {
377
399
  switch (_context6.prev = _context6.next) {
378
400
  case 0:
401
+ if ((_param$exportColumns = param.exportColumns) === null || _param$exportColumns === void 0 ? void 0 : _param$exportColumns.length) {
402
+ _context6.next = 3;
403
+ break;
404
+ }
405
+
406
+ showWarn('请选择要导出的列');
407
+ return _context6.abrupt("return", false);
408
+
409
+ case 3:
410
+ if (param.findUrl) {
411
+ _context6.next = 6;
412
+ break;
413
+ }
414
+
415
+ showWarn('请配置业务接口 bizApi 属性');
416
+ return _context6.abrupt("return", false);
417
+
418
+ case 6:
419
+ _context6.prev = 6;
420
+ _context6.next = 9;
421
+ return httpPost(url, param);
422
+
423
+ case 9:
424
+ result = _context6.sent;
425
+
426
+ if (!(((_result$flag3 = result.flag) === null || _result$flag3 === void 0 ? void 0 : _result$flag3.retCode) === '0')) {
427
+ _context6.next = 15;
428
+ break;
429
+ }
430
+
431
+ showSuccess(((_result$flag4 = result.flag) === null || _result$flag4 === void 0 ? void 0 : _result$flag4.retMsg) || '导出成功');
379
432
  return _context6.abrupt("return", true);
380
433
 
381
- case 1:
434
+ case 15:
435
+ showError(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retMsg) || '导出失败,请联系系统管理员');
436
+ return _context6.abrupt("return", false);
437
+
438
+ case 17:
439
+ _context6.next = 24;
440
+ break;
441
+
442
+ case 19:
443
+ _context6.prev = 19;
444
+ _context6.t0 = _context6["catch"](6);
445
+ console.log(_context6.t0);
446
+ showError(_context6.t0.message);
447
+ return _context6.abrupt("return", false);
448
+
449
+ case 24:
382
450
  case "end":
383
451
  return _context6.stop();
384
452
  }
385
453
  }
386
- }, _callee6);
454
+ }, _callee6, null, [[6, 19]]);
387
455
  }));
388
456
 
389
457
  return function onExport(_x5, _x6) {
package/es/http/index.js CHANGED
@@ -2,7 +2,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import { extend } from 'umi-request';
5
- import { getCache, getUrlQuery, showError } from '../utils'; //默认超时时间为1分钟
5
+ import { getCache, getUrlQuery, showError, toGatewayUrl } from '../utils'; //默认超时时间为1分钟
6
6
 
7
7
  var request = extend({
8
8
  timeout: 60000
@@ -23,7 +23,7 @@ request.interceptors.request.use(function (url, options) {
23
23
  }
24
24
 
25
25
  return {
26
- url: url,
26
+ url: toGatewayUrl(url, ''),
27
27
  options: opts
28
28
  };
29
29
  });
package/es/utils/index.js CHANGED
@@ -229,9 +229,9 @@ export var treeEach = function treeEach(list, fn) {
229
229
  list.forEach(function (item, index) {
230
230
  fn(item, index, list); // @ts-ignore
231
231
 
232
- if (Array.isArray(list[children]) && list[children].length) {
232
+ if (Array.isArray(item[children]) && item[children].length) {
233
233
  // @ts-ignore
234
- treeEach(list[children], fn, children);
234
+ treeEach(item[children], fn, children);
235
235
  }
236
236
  });
237
237
  };
@@ -1,4 +1,5 @@
1
1
  import type { ActionType } from 'ls-pro-table';
2
+ import type { exportParam } from 'ls-pro-table/lib/components/Export';
2
3
  import type { ProFormInstance } from 'ls-pro-form';
3
4
  import type { SingleParamType } from '../useSingle';
4
5
  export declare type DtlParamType = SingleParamType & {
@@ -25,5 +26,6 @@ declare function useDtl(dtlParam: DtlParamType): {
25
26
  onEditDtl: () => Promise<boolean>;
26
27
  onSaveMst: (values: any) => Promise<void>;
27
28
  onRemoveMst: () => Promise<boolean | undefined>;
29
+ onExportDtl: (url: string, param: exportParam) => Promise<boolean>;
28
30
  };
29
31
  export default useDtl;
@@ -29,6 +29,8 @@ var _icons = require("@ant-design/icons");
29
29
 
30
30
  var _utils = require("../../utils");
31
31
 
32
+ var _http = require("../../http");
33
+
32
34
  var _excluded = ["current", "pageSize"];
33
35
 
34
36
  function useDtl(dtlParam) {
@@ -596,6 +598,77 @@ function useDtl(dtlParam) {
596
598
  };
597
599
  }();
598
600
 
601
+ var onExportDtl = /*#__PURE__*/function () {
602
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(url, param) {
603
+ var _param$exportColumns;
604
+
605
+ var _result$flag5, result, _result$flag6, _result$flag7;
606
+
607
+ return _regenerator.default.wrap(function _callee8$(_context8) {
608
+ while (1) {
609
+ switch (_context8.prev = _context8.next) {
610
+ case 0:
611
+ if ((_param$exportColumns = param.exportColumns) === null || _param$exportColumns === void 0 ? void 0 : _param$exportColumns.length) {
612
+ _context8.next = 3;
613
+ break;
614
+ }
615
+
616
+ (0, _utils.showWarn)('请选择要导出的列');
617
+ return _context8.abrupt("return", false);
618
+
619
+ case 3:
620
+ if (param.findUrl) {
621
+ _context8.next = 6;
622
+ break;
623
+ }
624
+
625
+ (0, _utils.showWarn)('请配置业务接口 bizApi 属性');
626
+ return _context8.abrupt("return", false);
627
+
628
+ case 6:
629
+ _context8.prev = 6;
630
+ _context8.next = 9;
631
+ return (0, _http.httpPost)(url, param);
632
+
633
+ case 9:
634
+ result = _context8.sent;
635
+
636
+ if (!(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retCode) === '0')) {
637
+ _context8.next = 15;
638
+ break;
639
+ }
640
+
641
+ (0, _utils.showSuccess)(((_result$flag6 = result.flag) === null || _result$flag6 === void 0 ? void 0 : _result$flag6.retMsg) || '导出成功');
642
+ return _context8.abrupt("return", true);
643
+
644
+ case 15:
645
+ (0, _utils.showError)(((_result$flag7 = result.flag) === null || _result$flag7 === void 0 ? void 0 : _result$flag7.retMsg) || '导出失败,请联系系统管理员');
646
+ return _context8.abrupt("return", false);
647
+
648
+ case 17:
649
+ _context8.next = 24;
650
+ break;
651
+
652
+ case 19:
653
+ _context8.prev = 19;
654
+ _context8.t0 = _context8["catch"](6);
655
+ console.log(_context8.t0);
656
+ (0, _utils.showError)(_context8.t0.message);
657
+ return _context8.abrupt("return", false);
658
+
659
+ case 24:
660
+ case "end":
661
+ return _context8.stop();
662
+ }
663
+ }
664
+ }, _callee8, null, [[6, 19]]);
665
+ }));
666
+
667
+ return function onExportDtl(_x6, _x7) {
668
+ return _ref8.apply(this, arguments);
669
+ };
670
+ }();
671
+
599
672
  var tableTools = [];
600
673
 
601
674
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) {
@@ -666,7 +739,8 @@ function useDtl(dtlParam) {
666
739
  onAddDtl: onAddDtl,
667
740
  onEditDtl: onEditDtl,
668
741
  onSaveMst: onSaveMst,
669
- onRemoveMst: onRemoveMst
742
+ onRemoveMst: onRemoveMst,
743
+ onExportDtl: onExportDtl
670
744
  };
671
745
  }
672
746
 
@@ -1,4 +1,5 @@
1
1
  import type { ActionType } from 'ls-pro-table';
2
+ import type { exportParam } from 'ls-pro-table/lib/components/Export';
2
3
  import type { ProFormInstance } from 'ls-pro-form';
3
4
  import type { ApiResponse, TableToolbar } from '../../typing';
4
5
  export declare type SingleParamType = {
@@ -36,6 +37,6 @@ declare function useSingle(inParam: SingleParamType): {
36
37
  onLoad: (params: Record<string, any>, sort: Record<string, any>, filter: Record<string, any>) => Promise<any>;
37
38
  onAdd: () => Promise<void>;
38
39
  onEdit: () => Promise<void>;
39
- onExport: (url: string, param: any) => Promise<boolean>;
40
+ onExport: (url: string, param: exportParam) => Promise<boolean>;
40
41
  };
41
42
  export default useSingle;