ls-pro-common 1.0.19 → 1.0.22

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,16 +1,17 @@
1
1
  import "antd/es/button/style";
2
2
  import _Button from "antd/es/button";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
5
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
6
6
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
7
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
8
8
  var _excluded = ["current", "pageSize"];
9
9
  import React from "react";
10
- import { useState, useRef } from 'react';
11
- import { PlusOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons';
10
+ import { useState, useRef, useMemo, useCallback } from 'react';
11
+ import { PlusOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined, CheckOutlined } from '@ant-design/icons';
12
12
  import { showConfirm, showWarn, showSuccess, showError } from '../../utils';
13
13
  import { httpPost } from '../../http';
14
+ import usePermission from '../usePermission';
14
15
  /**
15
16
  * 单表基本增删改查 hooks
16
17
  * @param service 单表服务
@@ -21,15 +22,25 @@ import { httpPost } from '../../http';
21
22
  */
22
23
 
23
24
  function useSingle(inParam) {
25
+ var _usePermission = usePermission(),
26
+ resourceId = _usePermission.resourceId,
27
+ checkRight = _usePermission.checkRight;
28
+
24
29
  var service = inParam.service,
25
30
  toolConfig = inParam.toolConfig,
26
31
  initItem = inParam.initItem,
32
+ statusField = inParam.statusField,
33
+ auditStatus = inParam.auditStatus,
34
+ beforeAudit = inParam.beforeAudit,
27
35
  beforeLoad = inParam.beforeLoad,
28
36
  beforeRemove = inParam.beforeRemove,
29
37
  beforeAdd = inParam.beforeAdd,
30
38
  beforeEdit = inParam.beforeEdit,
39
+ beforeSave = inParam.beforeSave,
31
40
  afterRemove = inParam.afterRemove,
32
- afterSave = inParam.afterSave;
41
+ afterSave = inParam.afterSave,
42
+ afterAudit = inParam.afterAudit,
43
+ btnStatus = inParam.btnStatus;
33
44
  /** @name 选中行数据 */
34
45
 
35
46
  var _useState = useState([]),
@@ -63,38 +74,42 @@ function useSingle(inParam) {
63
74
  /** 新增按钮事件 */
64
75
 
65
76
  var onAdd = /*#__PURE__*/function () {
66
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
77
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(item) {
67
78
  return _regeneratorRuntime.wrap(function _callee$(_context) {
68
79
  while (1) {
69
80
  switch (_context.prev = _context.next) {
70
81
  case 0:
82
+ if (!item) {
83
+ item = _objectSpread({}, initItem);
84
+ }
85
+
71
86
  _context.t0 = beforeAdd;
72
87
 
73
88
  if (!_context.t0) {
74
- _context.next = 6;
89
+ _context.next = 7;
75
90
  break;
76
91
  }
77
92
 
78
- _context.next = 4;
79
- return beforeAdd(initItem);
93
+ _context.next = 5;
94
+ return beforeAdd(item);
80
95
 
81
- case 4:
96
+ case 5:
82
97
  _context.t1 = _context.sent;
83
98
  _context.t0 = _context.t1 === false;
84
99
 
85
- case 6:
100
+ case 7:
86
101
  if (!_context.t0) {
87
- _context.next = 8;
102
+ _context.next = 9;
88
103
  break;
89
104
  }
90
105
 
91
106
  return _context.abrupt("return");
92
107
 
93
- case 8:
94
- setEditItem(initItem);
108
+ case 9:
109
+ setEditItem(item);
95
110
  setShowEdit(true);
96
111
 
97
- case 10:
112
+ case 11:
98
113
  case "end":
99
114
  return _context.stop();
100
115
  }
@@ -102,7 +117,7 @@ function useSingle(inParam) {
102
117
  }, _callee);
103
118
  }));
104
119
 
105
- return function onAdd() {
120
+ return function onAdd(_x) {
106
121
  return _ref.apply(this, arguments);
107
122
  };
108
123
  }();
@@ -110,12 +125,12 @@ function useSingle(inParam) {
110
125
 
111
126
 
112
127
  var onEdit = /*#__PURE__*/function () {
113
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
128
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(item) {
114
129
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
115
130
  while (1) {
116
131
  switch (_context2.prev = _context2.next) {
117
132
  case 0:
118
- if (selectedRows.length) {
133
+ if (!(!item && !selectedRows.length)) {
119
134
  _context2.next = 3;
120
135
  break;
121
136
  }
@@ -124,33 +139,37 @@ function useSingle(inParam) {
124
139
  return _context2.abrupt("return");
125
140
 
126
141
  case 3:
142
+ if (!item) {
143
+ item = _objectSpread({}, selectedRows[0]);
144
+ }
145
+
127
146
  _context2.t0 = beforeEdit;
128
147
 
129
148
  if (!_context2.t0) {
130
- _context2.next = 9;
149
+ _context2.next = 10;
131
150
  break;
132
151
  }
133
152
 
134
- _context2.next = 7;
135
- return beforeEdit(selectedRows[0]);
153
+ _context2.next = 8;
154
+ return beforeEdit(item);
136
155
 
137
- case 7:
156
+ case 8:
138
157
  _context2.t1 = _context2.sent;
139
158
  _context2.t0 = _context2.t1 === false;
140
159
 
141
- case 9:
160
+ case 10:
142
161
  if (!_context2.t0) {
143
- _context2.next = 11;
162
+ _context2.next = 12;
144
163
  break;
145
164
  }
146
165
 
147
166
  return _context2.abrupt("return");
148
167
 
149
- case 11:
150
- setEditItem(selectedRows[0]);
168
+ case 12:
169
+ setEditItem(item);
151
170
  setShowEdit(true);
152
171
 
153
- case 13:
172
+ case 14:
154
173
  case "end":
155
174
  return _context2.stop();
156
175
  }
@@ -158,67 +177,87 @@ function useSingle(inParam) {
158
177
  }, _callee2);
159
178
  }));
160
179
 
161
- return function onEdit() {
180
+ return function onEdit(_x2) {
162
181
  return _ref2.apply(this, arguments);
163
182
  };
164
183
  }();
165
184
  /** 删除按钮事件 */
166
185
 
167
186
 
168
- var onRemove = function onRemove() {
169
- if (!selectedRows.length) {
187
+ var onRemove = function onRemove(row) {
188
+ if (!row || !selectedRows.length) {
170
189
  showWarn('请选择需要删除的数据');
171
190
  return;
172
191
  }
173
192
 
193
+ if (isAudit(row)) {
194
+ showWarn('选择中数据中有已审核,不能删除!');
195
+ return;
196
+ }
197
+
174
198
  showConfirm('确认要删除选择的数据?').then( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
175
- var ids, _result$flag, result;
199
+ var rows, ids, _result$flag, result;
176
200
 
177
201
  return _regeneratorRuntime.wrap(function _callee3$(_context3) {
178
202
  while (1) {
179
203
  switch (_context3.prev = _context3.next) {
180
204
  case 0:
205
+ rows = row ? [row] : selectedRows;
206
+
181
207
  if (!beforeRemove) {
182
- _context3.next = 6;
208
+ _context3.next = 7;
183
209
  break;
184
210
  }
185
211
 
186
- _context3.next = 3;
187
- return beforeRemove(selectedRows);
212
+ _context3.next = 4;
213
+ return beforeRemove(rows);
188
214
 
189
- case 3:
215
+ case 4:
190
216
  ids = _context3.sent;
191
217
 
192
218
  if (!(ids === false)) {
193
- _context3.next = 6;
219
+ _context3.next = 7;
194
220
  break;
195
221
  }
196
222
 
197
223
  return _context3.abrupt("return");
198
224
 
199
- case 6:
225
+ case 7:
200
226
  if (!ids) {
201
- ids = selectedRows.map(function (o) {
227
+ ids = rows.map(function (o) {
202
228
  return o.id;
203
229
  });
204
230
  }
205
231
 
206
- _context3.prev = 7;
207
- _context3.next = 10;
232
+ _context3.prev = 8;
233
+ _context3.next = 11;
208
234
  return service.remove(ids);
209
235
 
210
- case 10:
236
+ case 11:
211
237
  result = _context3.sent;
238
+ _context3.t0 = afterRemove;
212
239
 
213
- if (!afterRemove) {
214
- _context3.next = 14;
240
+ if (!_context3.t0) {
241
+ _context3.next = 18;
242
+ break;
243
+ }
244
+
245
+ _context3.next = 16;
246
+ return afterRemove(result, rows);
247
+
248
+ case 16:
249
+ _context3.t1 = _context3.sent;
250
+ _context3.t0 = _context3.t1 === false;
251
+
252
+ case 18:
253
+ if (!_context3.t0) {
254
+ _context3.next = 20;
215
255
  break;
216
256
  }
217
257
 
218
- afterRemove(result, selectedRows);
219
258
  return _context3.abrupt("return");
220
259
 
221
- case 14:
260
+ case 20:
222
261
  if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0') {
223
262
  showSuccess(result.flag.retMsg);
224
263
 
@@ -227,55 +266,182 @@ function useSingle(inParam) {
227
266
  }
228
267
  }
229
268
 
230
- _context3.next = 20;
269
+ _context3.next = 26;
231
270
  break;
232
271
 
233
- case 17:
234
- _context3.prev = 17;
235
- _context3.t0 = _context3["catch"](7);
236
- console.log(_context3.t0);
272
+ case 23:
273
+ _context3.prev = 23;
274
+ _context3.t2 = _context3["catch"](8);
275
+ console.log(_context3.t2);
237
276
 
238
- case 20:
277
+ case 26:
239
278
  case "end":
240
279
  return _context3.stop();
241
280
  }
242
281
  }
243
- }, _callee3, null, [[7, 17]]);
282
+ }, _callee3, null, [[8, 23]]);
244
283
  })));
245
284
  };
246
- /** 新增,更改对应的保存事件 */
285
+ /** 审核按钮事件 */
247
286
 
248
287
 
249
- var onSave = /*#__PURE__*/function () {
250
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(formData) {
251
- var data, _result$flag2, result;
288
+ var onAudit = /*#__PURE__*/function () {
289
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(row) {
290
+ var rows, _result$flag2, result;
252
291
 
253
292
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
254
293
  while (1) {
255
294
  switch (_context4.prev = _context4.next) {
295
+ case 0:
296
+ if (!(!row || !selectedRows.length)) {
297
+ _context4.next = 3;
298
+ break;
299
+ }
300
+
301
+ showWarn('请选择需要审核的数据');
302
+ return _context4.abrupt("return");
303
+
304
+ case 3:
305
+ if (!isAudit(row)) {
306
+ _context4.next = 6;
307
+ break;
308
+ }
309
+
310
+ showWarn('选择中数据中有已审核,不能再次进行操作!');
311
+ return _context4.abrupt("return");
312
+
313
+ case 6:
314
+ rows = (row ? [row] : selectedRows).map(function (o) {
315
+ var obj = _objectSpread({}, o); //@ts-ignore
316
+
317
+
318
+ obj[statusField] = auditStatus;
319
+ return obj;
320
+ }); // beforeAudit 强式终止
321
+
322
+ _context4.t0 = beforeAudit;
323
+
324
+ if (!_context4.t0) {
325
+ _context4.next = 13;
326
+ break;
327
+ }
328
+
329
+ _context4.next = 11;
330
+ return beforeAudit(rows);
331
+
332
+ case 11:
333
+ _context4.t1 = _context4.sent;
334
+ _context4.t0 = _context4.t1 === false;
335
+
336
+ case 13:
337
+ if (!_context4.t0) {
338
+ _context4.next = 15;
339
+ break;
340
+ }
341
+
342
+ return _context4.abrupt("return");
343
+
344
+ case 15:
345
+ _context4.prev = 15;
346
+ _context4.next = 18;
347
+ return service.audit(rows);
348
+
349
+ case 18:
350
+ result = _context4.sent;
351
+
352
+ if (!afterAudit) {
353
+ _context4.next = 22;
354
+ break;
355
+ }
356
+
357
+ afterAudit(result, rows);
358
+ return _context4.abrupt("return");
359
+
360
+ case 22:
361
+ if ((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retCode) === '0') {
362
+ showSuccess(result.flag.retMsg);
363
+
364
+ if (tableRef.current) {
365
+ tableRef.current.reload(false);
366
+ }
367
+ }
368
+
369
+ _context4.next = 28;
370
+ break;
371
+
372
+ case 25:
373
+ _context4.prev = 25;
374
+ _context4.t2 = _context4["catch"](15);
375
+ console.log(_context4.t2);
376
+
377
+ case 28:
378
+ case "end":
379
+ return _context4.stop();
380
+ }
381
+ }
382
+ }, _callee4, null, [[15, 25]]);
383
+ }));
384
+
385
+ return function onAudit(_x3) {
386
+ return _ref4.apply(this, arguments);
387
+ };
388
+ }();
389
+ /** 新增,更改对应的保存事件 */
390
+
391
+
392
+ var onSave = /*#__PURE__*/function () {
393
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(formData) {
394
+ var data, _result$flag3, result;
395
+
396
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
397
+ while (1) {
398
+ switch (_context5.prev = _context5.next) {
256
399
  case 0:
257
400
  data = _objectSpread(_objectSpread({}, editItem), formData);
258
- _context4.prev = 1;
259
- _context4.next = 4;
401
+ _context5.prev = 1;
402
+ _context5.t0 = beforeSave;
403
+
404
+ if (!_context5.t0) {
405
+ _context5.next = 8;
406
+ break;
407
+ }
408
+
409
+ _context5.next = 6;
410
+ return beforeSave(data);
411
+
412
+ case 6:
413
+ _context5.t1 = _context5.sent;
414
+ _context5.t0 = _context5.t1 === false;
415
+
416
+ case 8:
417
+ if (!_context5.t0) {
418
+ _context5.next = 10;
419
+ break;
420
+ }
421
+
422
+ return _context5.abrupt("return", false);
423
+
424
+ case 10:
425
+ _context5.next = 12;
260
426
  return service.save(data);
261
427
 
262
- case 4:
263
- result = _context4.sent;
428
+ case 12:
429
+ result = _context5.sent;
264
430
 
265
431
  if (!afterSave) {
266
- _context4.next = 9;
432
+ _context5.next = 17;
267
433
  break;
268
434
  }
269
435
 
270
- _context4.next = 8;
271
- return afterSave(result, data);
436
+ _context5.next = 16;
437
+ return afterSave(result, data, false);
272
438
 
273
- case 8:
274
- return _context4.abrupt("return", _context4.sent);
439
+ case 16:
440
+ return _context5.abrupt("return", _context5.sent);
275
441
 
276
- case 9:
277
- if (!((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retCode) === '0')) {
278
- _context4.next = 13;
442
+ case 17:
443
+ if (!((result === null || result === void 0 ? void 0 : (_result$flag3 = result.flag) === null || _result$flag3 === void 0 ? void 0 : _result$flag3.retCode) === '0')) {
444
+ _context5.next = 21;
279
445
  break;
280
446
  }
281
447
 
@@ -285,41 +451,41 @@ function useSingle(inParam) {
285
451
  tableRef.current.reload(false);
286
452
  }
287
453
 
288
- return _context4.abrupt("return", true);
454
+ return _context5.abrupt("return", true);
289
455
 
290
- case 13:
291
- _context4.next = 18;
456
+ case 21:
457
+ _context5.next = 26;
292
458
  break;
293
459
 
294
- case 15:
295
- _context4.prev = 15;
296
- _context4.t0 = _context4["catch"](1);
297
- console.log(_context4.t0);
460
+ case 23:
461
+ _context5.prev = 23;
462
+ _context5.t2 = _context5["catch"](1);
463
+ console.log(_context5.t2);
298
464
 
299
- case 18:
300
- return _context4.abrupt("return", false);
465
+ case 26:
466
+ return _context5.abrupt("return", false);
301
467
 
302
- case 19:
468
+ case 27:
303
469
  case "end":
304
- return _context4.stop();
470
+ return _context5.stop();
305
471
  }
306
472
  }
307
- }, _callee4, null, [[1, 15]]);
473
+ }, _callee5, null, [[1, 23]]);
308
474
  }));
309
475
 
310
- return function onSave(_x) {
311
- return _ref4.apply(this, arguments);
476
+ return function onSave(_x4) {
477
+ return _ref5.apply(this, arguments);
312
478
  };
313
479
  }();
314
480
  /** 加载数据方法 */
315
481
 
316
482
 
317
483
  var onLoad = /*#__PURE__*/function () {
318
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(params, sort, filter) {
484
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(params, sort, filter) {
319
485
  var current, pageSize, rest, param, key, result;
320
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
486
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
321
487
  while (1) {
322
- switch (_context5.prev = _context5.next) {
488
+ switch (_context6.prev = _context6.next) {
323
489
  case 0:
324
490
  current = params.current, pageSize = params.pageSize, rest = _objectWithoutProperties(params, _excluded);
325
491
  param = {};
@@ -339,157 +505,188 @@ function useSingle(inParam) {
339
505
  param.where = rest;
340
506
  }
341
507
 
342
- _context5.t0 = beforeLoad;
508
+ _context6.t0 = beforeLoad;
343
509
 
344
- if (!_context5.t0) {
345
- _context5.next = 11;
510
+ if (!_context6.t0) {
511
+ _context6.next = 11;
346
512
  break;
347
513
  }
348
514
 
349
- _context5.next = 9;
515
+ _context6.next = 9;
350
516
  return beforeLoad(param);
351
517
 
352
518
  case 9:
353
- _context5.t1 = _context5.sent;
354
- _context5.t0 = _context5.t1 === false;
519
+ _context6.t1 = _context6.sent;
520
+ _context6.t0 = _context6.t1 === false;
355
521
 
356
522
  case 11:
357
- if (!_context5.t0) {
358
- _context5.next = 13;
523
+ if (!_context6.t0) {
524
+ _context6.next = 13;
359
525
  break;
360
526
  }
361
527
 
362
- return _context5.abrupt("return", {
528
+ return _context6.abrupt("return", {
363
529
  data: [],
364
530
  success: false,
365
531
  total: 0
366
532
  });
367
533
 
368
534
  case 13:
369
- _context5.next = 15;
535
+ _context6.next = 15;
370
536
  return service.load(param);
371
537
 
372
538
  case 15:
373
- result = _context5.sent;
539
+ result = _context6.sent;
374
540
  result.data = result.rows;
375
541
  result.success = true;
376
- return _context5.abrupt("return", result);
542
+ return _context6.abrupt("return", result);
377
543
 
378
544
  case 19:
379
545
  case "end":
380
- return _context5.stop();
546
+ return _context6.stop();
381
547
  }
382
548
  }
383
- }, _callee5);
549
+ }, _callee6);
384
550
  }));
385
551
 
386
- return function onLoad(_x2, _x3, _x4) {
387
- return _ref5.apply(this, arguments);
552
+ return function onLoad(_x5, _x6, _x7) {
553
+ return _ref6.apply(this, arguments);
388
554
  };
389
555
  }();
390
556
 
391
557
  var onExport = /*#__PURE__*/function () {
392
- var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url, param) {
558
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(url, param) {
393
559
  var _param$exportColumns;
394
560
 
395
- var _result$flag3, result, _result$flag4, _result$flag5;
561
+ var _result$flag4, result, _result$flag5, _result$flag6;
396
562
 
397
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
563
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
398
564
  while (1) {
399
- switch (_context6.prev = _context6.next) {
565
+ switch (_context7.prev = _context7.next) {
400
566
  case 0:
401
567
  if ((_param$exportColumns = param.exportColumns) === null || _param$exportColumns === void 0 ? void 0 : _param$exportColumns.length) {
402
- _context6.next = 3;
568
+ _context7.next = 3;
403
569
  break;
404
570
  }
405
571
 
406
572
  showWarn('请选择要导出的列');
407
- return _context6.abrupt("return", false);
573
+ return _context7.abrupt("return", false);
408
574
 
409
575
  case 3:
410
576
  if (param.findUrl) {
411
- _context6.next = 6;
577
+ _context7.next = 6;
412
578
  break;
413
579
  }
414
580
 
415
581
  showWarn('请配置业务接口 bizApi 属性');
416
- return _context6.abrupt("return", false);
582
+ return _context7.abrupt("return", false);
417
583
 
418
584
  case 6:
419
- _context6.prev = 6;
420
- _context6.next = 9;
585
+ _context7.prev = 6;
586
+ _context7.next = 9;
421
587
  return httpPost(url, param);
422
588
 
423
589
  case 9:
424
- result = _context6.sent;
590
+ result = _context7.sent;
425
591
 
426
- if (!(((_result$flag3 = result.flag) === null || _result$flag3 === void 0 ? void 0 : _result$flag3.retCode) === '0')) {
427
- _context6.next = 15;
592
+ if (!(((_result$flag4 = result.flag) === null || _result$flag4 === void 0 ? void 0 : _result$flag4.retCode) === '0')) {
593
+ _context7.next = 15;
428
594
  break;
429
595
  }
430
596
 
431
- showSuccess(((_result$flag4 = result.flag) === null || _result$flag4 === void 0 ? void 0 : _result$flag4.retMsg) || '导出成功');
432
- return _context6.abrupt("return", true);
597
+ showSuccess(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retMsg) || '导出成功');
598
+ return _context7.abrupt("return", true);
433
599
 
434
600
  case 15:
435
- showError(((_result$flag5 = result.flag) === null || _result$flag5 === void 0 ? void 0 : _result$flag5.retMsg) || '导出失败,请联系系统管理员');
436
- return _context6.abrupt("return", false);
601
+ showError(((_result$flag6 = result.flag) === null || _result$flag6 === void 0 ? void 0 : _result$flag6.retMsg) || '导出失败,请联系系统管理员');
602
+ return _context7.abrupt("return", false);
437
603
 
438
604
  case 17:
439
- _context6.next = 24;
605
+ _context7.next = 24;
440
606
  break;
441
607
 
442
608
  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);
609
+ _context7.prev = 19;
610
+ _context7.t0 = _context7["catch"](6);
611
+ console.log(_context7.t0);
612
+ showError(_context7.t0.message);
613
+ return _context7.abrupt("return", false);
448
614
 
449
615
  case 24:
450
616
  case "end":
451
- return _context6.stop();
617
+ return _context7.stop();
452
618
  }
453
619
  }
454
- }, _callee6, null, [[6, 19]]);
620
+ }, _callee7, null, [[6, 19]]);
455
621
  }));
456
622
 
457
- return function onExport(_x5, _x6) {
458
- return _ref6.apply(this, arguments);
623
+ return function onExport(_x8, _x9) {
624
+ return _ref7.apply(this, arguments);
459
625
  };
460
626
  }();
461
627
 
462
- var tableTools = [];
628
+ var btnDisabled = function btnDisabled(key) {
629
+ if (btnStatus && typeof btnStatus(key) === 'boolean') return btnStatus(key);
463
630
 
464
- if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) {
465
- tableTools.push( /*#__PURE__*/React.createElement(_Button, {
631
+ switch (key) {
632
+ case 'edit':
633
+ return selectedRows.length !== 1 || isAudit();
634
+
635
+ case 'remove':
636
+ case 'audit':
637
+ return selectedRows.length === 0 || isAudit();
638
+
639
+ default:
640
+ return false;
641
+ }
642
+ };
643
+ /** 判断是否已审核,只有传入审核状态和状态字段才进行判断 */
644
+
645
+
646
+ var isAudit = useCallback(function () {
647
+ var row = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
648
+ if (!auditStatus || !statusField) return false;
649
+ if (!row && !selectedRows.length) return false;
650
+
651
+ if (row) {
652
+ return Number(row[statusField] || 0) >= auditStatus;
653
+ }
654
+
655
+ return selectedRows.findIndex(function (o) {
656
+ return Number(o[statusField] || 0) >= auditStatus;
657
+ }) > -1;
658
+ }, [auditStatus, statusField, selectedRows]); // 处理内置 table 按钮,新增,编辑,删除,审核,导入,导出
659
+
660
+ var tableTools = useMemo(function () {
661
+ return [(toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) && checkRight(2) ? /*#__PURE__*/React.createElement(_Button, {
466
662
  key: "add",
467
- onClick: onAdd,
663
+ onClick: function onClick() {
664
+ return onAdd(null);
665
+ },
468
666
  icon: /*#__PURE__*/React.createElement(PlusOutlined, null)
469
- }, "\u65B0\u589E"));
470
- }
471
-
472
- if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) {
473
- tableTools.push( /*#__PURE__*/React.createElement(_Button, {
667
+ }, "\u65B0\u589E") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.edit) && checkRight(4) ? /*#__PURE__*/React.createElement(_Button, {
474
668
  key: "edit",
475
- disabled: selectedRows.length !== 1,
476
- onClick: onEdit,
669
+ disabled: btnDisabled('edit'),
670
+ onClick: function onClick() {
671
+ return onEdit(null);
672
+ },
477
673
  icon: /*#__PURE__*/React.createElement(EditOutlined, null)
478
- }, "\u7F16\u8F91"));
479
- }
480
-
481
- if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) {
482
- tableTools.push( /*#__PURE__*/React.createElement(_Button, {
674
+ }, "\u7F16\u8F91") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.remove) && (checkRight(8) || checkRight(32)) ? /*#__PURE__*/React.createElement(_Button, {
483
675
  key: "remove",
484
- onClick: onRemove,
676
+ onClick: function onClick() {
677
+ return onRemove(null);
678
+ },
485
679
  danger: true,
486
- disabled: selectedRows.length === 0,
680
+ disabled: btnDisabled('remove'),
487
681
  icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
488
- }, "\u5220\u9664"));
489
- }
490
-
491
- if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) {
492
- tableTools.push( /*#__PURE__*/React.createElement(_Button, {
682
+ }, "\u5220\u9664") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.audit) && checkRight(64) ? /*#__PURE__*/React.createElement(_Button, {
683
+ key: "audit",
684
+ onClick: function onClick() {
685
+ return onAudit(null);
686
+ },
687
+ disabled: btnDisabled('audit'),
688
+ icon: /*#__PURE__*/React.createElement(CheckOutlined, null)
689
+ }, "\u5BA1\u6838") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && checkRight(128) ? /*#__PURE__*/React.createElement(_Button, {
493
690
  key: "import",
494
691
  onClick: function onClick() {
495
692
  var _tableRef$current, _tableRef$current$sho;
@@ -497,11 +694,7 @@ function useSingle(inParam) {
497
694
  tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$sho = _tableRef$current.showImport) === null || _tableRef$current$sho === void 0 ? void 0 : _tableRef$current$sho.call(_tableRef$current);
498
695
  },
499
696
  icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
500
- }, "\u5BFC\u5165"));
501
- }
502
-
503
- if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) {
504
- tableTools.push( /*#__PURE__*/React.createElement(_Button, {
697
+ }, "\u5BFC\u5165") : false, (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) && checkRight(256) ? /*#__PURE__*/React.createElement(_Button, {
505
698
  key: "export",
506
699
  onClick: function onClick() {
507
700
  var _tableRef$current2, _tableRef$current2$sh;
@@ -509,9 +702,10 @@ function useSingle(inParam) {
509
702
  tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$sh = _tableRef$current2.showExport) === null || _tableRef$current2$sh === void 0 ? void 0 : _tableRef$current2$sh.call(_tableRef$current2);
510
703
  },
511
704
  icon: /*#__PURE__*/React.createElement(ExportOutlined, null)
512
- }, "\u5BFC\u51FA"));
513
- }
514
-
705
+ }, "\u5BFC\u51FA") : false].filter(function (o) {
706
+ return o !== false;
707
+ });
708
+ }, [selectedRows]);
515
709
  return {
516
710
  formRef: formRef,
517
711
  editFormRef: editFormRef,
@@ -528,7 +722,11 @@ function useSingle(inParam) {
528
722
  onLoad: onLoad,
529
723
  onAdd: onAdd,
530
724
  onEdit: onEdit,
531
- onExport: onExport
725
+ onExport: onExport,
726
+ onAudit: onAudit,
727
+ resourceId: resourceId,
728
+ checkRight: checkRight,
729
+ isAudit: isAudit
532
730
  };
533
731
  }
534
732