This repository was archived by the owner on Mar 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathufec.js
More file actions
4947 lines (4432 loc) · 140 KB
/
Copy pathufec.js
File metadata and controls
4947 lines (4432 loc) · 140 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { createBrowserHistory } from 'history';
import 'antd/es/spin/style';
import _Spin from 'antd/es/spin';
import 'antd/es/icon/style';
import _Icon from 'antd/es/icon';
import 'antd/es/tabs/style';
import _Tabs from 'antd/es/tabs';
import React, { Component } from 'react';
import 'antd/es/dropdown/style';
import _Dropdown from 'antd/es/dropdown';
import 'antd/es/button/style';
import _Button from 'antd/es/button';
import 'antd/es/menu/style';
import _Menu from 'antd/es/menu';
import 'antd/es/select/style';
import _Select from 'antd/es/select';
import 'antd/es/table/style';
import _Table from 'antd/es/table';
import 'antd/es/alert/style';
import _Alert from 'antd/es/alert';
import 'antd/es/input/style';
import _Input from 'antd/es/input';
import 'antd/es/auto-complete/style';
import _AutoComplete from 'antd/es/auto-complete';
import 'antd/es/form/style';
import _Form from 'antd/es/form';
import 'antd/es/tooltip/style';
import _Tooltip from 'antd/es/tooltip';
import 'antd/es/input-number/style';
import _InputNumber from 'antd/es/input-number';
import 'antd/es/radio/style';
import _Radio from 'antd/es/radio';
import 'antd/es/slider/style';
import _Slider from 'antd/es/slider';
import 'antd/es/switch/style';
import _Switch from 'antd/es/switch';
import 'antd/es/checkbox/style';
import _Checkbox from 'antd/es/checkbox';
import 'antd/es/tree-select/style';
import _TreeSelect from 'antd/es/tree-select';
import 'antd/es/date-picker/style';
import _DatePicker from 'antd/es/date-picker';
import 'antd/es/modal/style';
import _Modal from 'antd/es/modal';
import ReactDOM from 'react-dom';
import { Link } from 'react-router-dom';
import 'antd/es/steps/style';
import _Steps from 'antd/es/steps';
import RSVP from 'rsvp';
/**
* history.push(path, [state])
* history.replace(path, [state])
* history.go(n)
* history.goBack()
* history.goForward()
*
* history.listen(func) // listen for changes to the current location
*
* history.getPathList() // return pathlist array
*/
var currentUfecApp = window.CURRENT_UFEC_APP || HALO.application.current_application || 'dashboard';
var getPathList = function getPathList() {
return window.location.pathname.split('/').filter(function (m) {
return !!m && m !== currentUfecApp;
});
};
var HISTORY = createBrowserHistory({
basename: '/' + currentUfecApp
});
// 注意!这里的pathList是将basename忽略的!!为了跟忽略basename的link和route统一
HISTORY.getPathList = getPathList;
HISTORY.currentUfecApp = currentUfecApp;
var classCallCheck = function (instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
};
var createClass = function () {
function defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
return function (Constructor, protoProps, staticProps) {
if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;
};
}();
var defineProperty = function (obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
};
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
var inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
};
var possibleConstructorReturn = function (self, call) {
if (!self) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return call && (typeof call === "object" || typeof call === "function") ? call : self;
};
var TabPane = _Tabs.TabPane;
var Detail = function (_React$Component) {
inherits(Detail, _React$Component);
function Detail(props) {
classCallCheck(this, Detail);
var _this = possibleConstructorReturn(this, (Detail.__proto__ || Object.getPrototypeOf(Detail)).call(this, props));
_this.state = {
visible: false,
loading: false,
contents: {},
defaultKey: _this.props.detail.tabs && _this.props.detail.tabs.find(function (tab) {
return tab.default;
}).key,
currentKey: _this.props.detail.tabs && _this.props.detail.tabs.find(function (tab) {
return tab.default;
}).key
};
_this.open = function () {
_this.setState({
visible: true
});
};
_this.close = function () {
_this.setState({
visible: false,
currentKey: _this.state.defaultKey,
contents: {}
}, function () {
HISTORY.push('/' + HISTORY.getPathList()[0]);
});
};
return _this;
}
createClass(Detail, [{
key: 'onChangTabs',
value: function onChangTabs(key) {
var _this2 = this;
if (key === this.state.currentKey) {
return;
}
this.setState({
currentKey: key
}, function () {
_this2.props.onClickTabs && _this2.props.onClickTabs(null, key);
});
}
}, {
key: 'loading',
value: function loading(bool, cb) {
this.setState({
loading: bool
}, cb || function () {});
}
}, {
key: 'render',
value: function render() {
var props = this.props;
var state = this.state;
var title = props.tabs && props.tabs.find(function (t) {
return t.default;
}).name;
var tabs = props.detail.tabs;
return React.createElement(
'div',
{ className: 'garen-com-table-detail' + (state.visible ? ' visible' : '') },
React.createElement(
'div',
{ className: 'detail-wrapper' },
React.createElement(
'div',
{ className: 'header' },
React.createElement(
'div',
{ className: 'left' },
React.createElement(
'span',
{ onClick: this.close },
React.createElement(_Icon, { type: 'left' }),
title
)
),
React.createElement(
'div',
{ className: 'center' },
props.row ? props.row.id : ''
)
),
React.createElement(
'div',
{ className: 'content' },
tabs && tabs.length > 1 ? React.createElement(
'div',
{ className: 'tabs' },
React.createElement(
_Tabs,
{ activeKey: state.currentKey, onTabClick: this.onChangTabs.bind(this), type: 'card' },
tabs.map(function (tab) {
return React.createElement(TabPane, { tab: tab.name, key: tab.key });
})
)
) : null,
props.tableLoading || state.loading ? React.createElement(
'div',
{ className: 'loading-wrapper' },
React.createElement(_Spin, { indicator: React.createElement(_Icon, { type: 'loading', style: { fontSize: 30 } }) })
) : Object.keys(state.contents).length > 0 && Object.keys(state.contents).map(function (key) {
return state.contents[key] ? React.createElement(
'div',
{
key: key,
className: 'detail-content',
style: { display: key === state.currentKey ? 'block' : 'none' }
},
state.contents[key]
) : null;
})
)
)
);
}
}]);
return Detail;
}(React.Component);
var ButtonList = function (_React$Component) {
inherits(ButtonList, _React$Component);
function ButtonList(props) {
classCallCheck(this, ButtonList);
var _this = possibleConstructorReturn(this, (ButtonList.__proto__ || Object.getPrototypeOf(ButtonList)).call(this, props));
_this.state = {
btns: _this.formatData(_this.props.btns) // eslint-disable-line
};
return _this;
}
createClass(ButtonList, [{
key: 'formatData',
value: function formatData(btns) {
var formatedBtns = {};
btns.forEach(function (btn) {
if (btn.dropdown) {
btn.dropdown.forEach(function (item) {
if (!item.type) {
formatedBtns[item.key] = item;
}
});
} else {
formatedBtns[btn.key] = btn;
}
});
return formatedBtns;
}
}, {
key: 'onClickDropdownList',
value: function onClickDropdownList(_ref) {
var item = _ref.item,
key = _ref.key,
keyPath = _ref.keyPath;
this.props.onAction('btnList', 'click', {
key: key
});
}
}, {
key: 'onClickBtnList',
value: function onClickBtnList(key) {
this.props.onAction('btnList', 'click', {
key: key
});
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var props = this.props,
btns = props.btns,
tableLoading = props.loading;
return React.createElement(
'div',
{ className: 'btn-list' },
btns.map(function (btn) {
if (btn.dropdown) {
var menu = React.createElement(
_Menu,
{ onClick: _this2.onClickDropdownList.bind(_this2) },
btn.dropdown.map(function (drop, i) {
return drop.type && drop.type === 'divider' ? React.createElement(_Menu.Divider, { key: i }) : React.createElement(
_Menu.Item,
{ key: drop.key, disabled: tableLoading || drop.disabled },
drop.value
);
})
);
return React.createElement(
_Dropdown,
{ key: btn.key, overlay: menu, trigger: ['click'], disabled: btn.disabled },
React.createElement(
_Button,
{ type: btn.type },
React.createElement(_Icon, { type: btn.iconPrefix || 'more' }),
btn.value,
' ',
React.createElement(_Icon, { type: btn.iconSuffix || 'caret-down-right' })
)
);
}
return React.createElement(
_Button,
{
onClick: _this2.onClickBtnList.bind(_this2, btn.key),
key: btn.key,
type: btn.type,
icon: btn.icon ? btn.icon : null,
loading: btn.key === 'refresh' ? tableLoading : false,
disabled: tableLoading || btn.disabled
},
btn.value
);
})
);
}
}]);
return ButtonList;
}(React.Component);
var OpSelect = function (_React$Component) {
inherits(OpSelect, _React$Component);
function OpSelect(props) {
classCallCheck(this, OpSelect);
var _this = possibleConstructorReturn(this, (OpSelect.__proto__ || Object.getPrototypeOf(OpSelect)).call(this, props));
_this.state = {
operation: _this.props.operation,
value: _this.props.operation.value || _this.props.operation.data[0].value,
disabled: _this.props.operation.disabled,
data: _this.props.operation.data,
tableLoading: _this.props.tableLoading
};
_this.onChangeSelect = function (key, value, option) {
_this.setState({
value: value
}, function () {
_this.props.onChangeSelect(key, value, option);
});
};
return _this;
}
createClass(OpSelect, [{
key: 'render',
value: function render() {
var props = this.props;
var state = this.state;
var __ = props.__;
var operation = state.operation;
return React.createElement(
_Select,
{
disabled: state.tableLoading || state.disabled,
onChange: this.onChangeSelect.bind(this, operation.key),
value: state.value,
style: { width: operation.width || 100 }
},
state.data.map(function (d) {
return React.createElement(
_Select.Option,
{
key: d.value,
value: d.value
},
operation.transpile ? __[d.name] : d.name,
d.suffix
);
})
);
}
}], [{
key: 'getDerivedStateFromProps',
value: function getDerivedStateFromProps(nextProps, prevState) {
var operation = nextProps.operation;
return {
value: operation.value || prevState.value,
disabled: operation.disabled,
data: operation.data,
tableLoading: nextProps.tableLoading
};
}
}]);
return OpSelect;
}(React.Component);
var Operation = function (_React$Component) {
inherits(Operation, _React$Component);
function Operation(props) {
classCallCheck(this, Operation);
var _this = possibleConstructorReturn(this, (Operation.__proto__ || Object.getPrototypeOf(Operation)).call(this, props));
_this.state = {
operations: _this.props.operations
};
_this.onChangeSelect = function (key, value, option) {
_this.props.onAction('operation', 'select', {
key: key,
value: value
});
};
['onChangeSelect'].forEach(function (func) {
return _this[func] = _this[func].bind(_this);
});
return _this;
}
createClass(Operation, [{
key: 'handleCheckboxChange',
value: function handleCheckboxChange(operKey, key, e) {
this.props.onAction('operation', 'checkbox', {
key: operKey,
value: key
});
}
}, {
key: 'render',
value: function render() {
var _this2 = this;
var props = this.props,
__ = props.__,
state = this.state,
tableLoading = props.loading,
operations = state.operations;
return React.createElement(
'div',
{ className: 'operations-wrapper' },
operations.map(function (operation, i) {
if (operation.type === 'select') {
// 下拉框类型
return operation.data && operation.data.length > 0 ? React.createElement(OpSelect, {
key: i,
__: __,
operation: operation,
tableLoading: tableLoading,
onChangeSelect: _this2.onChangeSelect
}) : null;
} else if (operation.type === 'checkbox') {
// 类 checkbox 类型
return operation.data && operation.data.length > 0 ? React.createElement(
'div',
{
className: 'main-operation-checkbox-wrapper',
key: operation.key
},
React.createElement(
'ul',
null,
operation.data.map(function (item) {
return React.createElement(
'li',
{
key: item.value,
className: item.checked ? 'checked' : '',
onClick: _this2.handleCheckboxChange.bind(_this2, operation.key, item.value)
},
React.createElement(
'span',
{ className: 'checkbox-content' },
__[item.name]
),
// 额外的补充内容
item.suffix
);
})
)
) : null;
}
return null;
})
);
}
}], [{
key: 'getDerivedStateFromProps',
value: function getDerivedStateFromProps(nextProps, prevState) {
return {
operations: nextProps.operations
};
}
}]);
return Operation;
}(React.Component);
/**
* @func: convert obj value into specific language
*/
var converter = {
getLangValue: function getLangValue(lang, obj) {
if (Object.prototype.toString.call(obj) === '[object Array]') {
var strs = '';
obj.forEach(function (str) {
strs += lang[str] || str;
});
return strs;
}
return lang[obj] || obj;
},
convertLang: function convertLang(lang, config) {
var _this = this;
if (config.banner) {
config.banner.message = this.getLangValue(lang, config.banner.message);
config.banner.description = this.getLangValue(lang, config.banner.description);
}
if (config.tabs) {
config.tabs.forEach(function (item) {
item.name = _this.getLangValue(lang, item.name);
});
}
if (config.title) {
config.title = this.getLangValue(lang, config.title);
}
if (config.search && config.search.placeholder) {
config.search.placeholder = this.getLangValue(lang, config.search.placeholder);
}
if (config.btns) {
config.btns.forEach(function (btn) {
if (btn.value) {
btn.value = _this.getLangValue(lang, btn.value);
if (btn.dropdown) {
btn.dropdown.forEach(function (item) {
if (!item.type) {
item.value = _this.getLangValue(lang, item.value);
}
});
}
}
});
}
if (config.table) {
config.table.columns.forEach(function (col) {
col.title = _this.getLangValue(lang, col.title);
});
}
if (config.table.detail) {
config.table.detail.tabs && config.table.detail.tabs.forEach(function (tab) {
tab.name = _this.getLangValue(lang, tab.name);
});
}
}
};
var TabPane$1 = _Tabs.TabPane;
var Search = _Input.Search;
var Modal = function (_React$Component) {
inherits(Modal, _React$Component);
function Modal(props) {
classCallCheck(this, Modal);
var _this = possibleConstructorReturn(this, (Modal.__proto__ || Object.getPrototypeOf(Modal)).call(this, props));
_this.state = {
config: _this.props.config,
currentRow: {},
rows: [],
selectedRowKeys: [],
pathList: HISTORY.getPathList()
};
_this.operationsRef = React.createRef();
_this.btnListRef = React.createRef();
_this.detailRef = React.createRef();
_this.__ = props.__ || {};
_this.tableColRender(_this.props.config.table.columns);
converter.convertLang(_this.__, props.config);
['onAction', 'onClickCaptain', 'onClickDetailTabs', 'getCurrentKey'].forEach(function (func) {
_this[func] = _this[func].bind(_this);
});
return _this;
}
createClass(Modal, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;
var _config = this.state.config;
if (!_config.table.loading) {
_config.table.loading = true;
this.setState({
config: _config
}, function () {
_this2.props.onInitialize();
});
} else {
this.props.onInitialize();
}
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
// 当组件unmount的时候,需要重置main的数据并且更新detail为关闭状态.
this.clearState(true);
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
var nextPathList = HISTORY.getPathList();
// 当同模块带detail跳转的时候,需要重新走onInitialize.
if (!this.state.currentRow && prevState.pathList.length > 1 && nextPathList.length > 1 && prevState.pathList[0] === nextPathList[0] && prevState.pathList[1] !== nextPathList[1] // 以上条件判断两个url的id不同但是模块相同.
&& !this.props.config.table.loading) {
this.props.onInitialize();
}
// 当第一次强刷带detail初始化的时候,需要触发onClickDetailTabs去更新默认tab的content;
if (this.enableDetail(prevProps, prevState)) {
this.onClickDetailTabs();
}
// 打开detail的操作。
// 如果当前url带id && detail处于关闭状态 && currentRow有数据 就打开detail
var detailRef = this.detailRef.current;
if (HISTORY.getPathList().length > 1 && !detailRef.state.visible && this.hasCurrentRow()) {
detailRef.open();
}
}
}, {
key: 'enableDetail',
value: function enableDetail(prevProps, prevState) {
return HISTORY.getPathList().length > 1 && (prevProps.config.table.data.length > 0 || !prevProps.config.table.loading) && this.hasCurrentRow();
}
}, {
key: 'hasCurrentRow',
value: function hasCurrentRow() {
return this.state.currentRow && Object.keys(this.state.currentRow).length > 0;
}
}, {
key: 'tableColRender',
value: function tableColRender(columns) {
var _this3 = this;
columns.forEach(function (column) {
switch (column.type) {
case 'captain':
column.render = function (text, row, index) {
var formatData = column.formatter && column.formatter(text, row, index);
if (!formatData) {
var key = _this3.props.config.table.rowKey;
formatData = text || '(' + row[key].substr(0, 8) + ')';
}
return React.createElement(
'a',
{ className: 'captain', onClick: _this3.onClickCaptain.bind(_this3, row) },
formatData
);
};
break;
default:
break;
}
});
}
}, {
key: 'onAction',
value: function onAction(field, actionType, data, refs) {
if (!data) {
data = {};
}
if (!data.rows) {
data.rows = this.state.rows;
}
var func = this.props.onAction;
func && func(field, actionType, data, refs);
}
}, {
key: 'onClickCaptain',
value: function onClickCaptain(row, e) {
e.preventDefault();
var pathList = HISTORY.getPathList();
// 没有二级路由的时候添加二级路由
if (pathList.length < 2 || row.id !== pathList[1]) {
HISTORY.push('/' + pathList[0] + '/' + row.id);
} else {
// 有二级路由的时候关闭二级路由
HISTORY.push('/' + pathList[0]);
}
}
}, {
key: 'onChangeTabs',
value: function onChangeTabs(key) {
if (key === HISTORY.getPathList()[0]) {
return;
}
HISTORY.push('/' + key);
}
}, {
key: 'onSearchTable',
value: function onSearchTable(value) {
this.onAction('search', 'click', {
value: value
});
}
}, {
key: 'onClickDetailTabs',
value: function onClickDetailTabs(rows) {
var key = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.getCurrentKey();
if (!rows) {
rows = [this.state.currentRow];
}
this.onAction('detail', 'click', {
key: key,
rows: rows
}, this.detailRef.current);
}
}, {
key: 'getCurrentKey',
value: function getCurrentKey() {
var detailRef = this.detailRef.current;
return detailRef.state.currentKey;
}
}, {
key: 'clearState',
value: function clearState(closeDetail) {
var _this4 = this;
this.setState({
rows: [],
currentRow: {},
selectedRowKeys: []
}, function () {
_this4.btnListRender(_this4.state.rows);
if (closeDetail) {
_this4.detailRef.setState({
visible: false
});
}
});
}
}, {
key: 'btnListRender',
value: function btnListRender(selectedRows) {
if (!this.props.btnListRender) {
return;
}
var refs = this.btnListRef.current;
var btns = refs.state.btns;
refs.setState({
btns: this.props.btnListRender(selectedRows, btns)
});
}
}, {
key: 'render',
value: function render() {
var _this5 = this;
var _config = this.props.config,
tabs = _config.tabs,
title = _config.title,
banner = _config.banner,
btns = _config.btns,
table = _config.table,
columns = table.columns,
data = table.data,
detail = table.detail,
size = table.size,
search = _config.search,
operations = _config.operations,
showPage = _extends({
withPage: true
}, table.showPage),
pagination = table.pagination === false ? false : _extends({
hideOnSinglePage: true,
pageSize: table.limit,
showQuickJumper: true,
total: table.total,
onChange: function onChange(page, pageSize) {
_this5.onAction('pagination', 'click', {
type: 'page',
page: page,
pageSize: pageSize
});
},
onShowSizeChange: function onShowSizeChange(current, pageSize) {
_this5.onAction('pagination', 'click', {
type: 'pageSize',
current: current,
pageSize: pageSize
});
}
}, table.pagination);
// 判断是否显示页数
var tableClass = showPage.withPage ? 'table-box' : 'table-box without-page';
// 当前匹配的模块
var selectedRowKeys = this.state.selectedRowKeys;
var rowSelection = {
selectedRowKeys: selectedRowKeys,
onChange: function onChange(_selectedRowKeys, selectedRows) {
_this5.setState({
rows: selectedRows,
selectedRowKeys: _selectedRowKeys
}, function () {
_this5.btnListRender(selectedRows);
});
}
};
// 在数据加载完之后如果直接置为false的话,会出问题
// 因为在antd的Table中,判断传入的loading是false的话,loadingProps会变成默认的
// 自定义的loading icon会有一瞬间编程默认的loading icon
var spinProps = {
spinning: table.loading,
indicator: React.createElement(_Icon, { type: 'loading', style: { fontSize: 30 } })
};
return React.createElement(
'div',
{ className: 'garen-com-main' },
React.createElement(
'div',
{ className: 'margin-wrapper' },
banner ? React.createElement(
'div',
{ className: 'banner-wrapper' },
React.createElement(_Alert, banner)
) : null,
title ? React.createElement(
'div',
{ className: 'title' },
title
) : null,
React.createElement(
'div',
{ className: 'main-content' },
tabs ? React.createElement(
'div',
{ className: 'submenu-tabs' },
React.createElement(
_Tabs,
{ activeKey: tabs.find(function (tab) {
return tab.default;
}).key, onTabClick: this.onChangeTabs.bind(this), type: 'card' },
tabs.map(function (tab) {
return React.createElement(TabPane$1, { tab: tab.name, key: tab.key });
})
)
) : null,
btns && btns.length > 0 || search ? React.createElement(
'div',
{ className: 'operation-list' },
React.createElement(
'div',
{ className: 'left' },
React.createElement(ButtonList, {
loading: table.loading,
ref: this.btnListRef,
onAction: this.onAction,
btns: btns
}),
operations ? React.createElement(Operation, {
onAction: this.onAction,
ref: this.operationsRef,
loading: table.loading,
operations: operations,
__: this.__
}) : null
),
search ? React.createElement(
'div',
{ className: 'search-wrapper' },
React.createElement(Search, {
placeholder: search.placeholder || 'Search',
onSearch: this.onSearchTable.bind(this),
style: { width: 180 },
enterButton: true
})
) : null
) : null,
React.createElement(
'div',
{ className: tableClass },
table ? React.createElement(_Table, {
loading: spinProps,
locale: { emptyText: this.props.no_data },
pagination: pagination,
size: size,
columns: columns,
dataKey: table.dataKey,
rowSelection: table.checkbox ? rowSelection : null,
expandedRowRender: table.expandedRowRender,
rowKey: table.rowKey,
dataSource: data
}) : null
)
)
),
detail ? React.createElement(Detail, {
ref: this.detailRef,
tabs: tabs,
detail: detail,
tableLoading: table.loading,
row: this.state.currentRow,
onClickTabs: this.onClickDetailTabs.bind(this)
}) : null
);
}
}], [{
key: 'getDerivedStateFromProps',
value: function getDerivedStateFromProps(nextProps, prevState) {
var path = HISTORY.getPathList();
return {
// decodeURIComponent解决url中文乱码
currentRow: path.length > 1 ? nextProps.config.table.data.find(function (d) {
return d.id.toString() === decodeURIComponent(path[1]);
}) : {},
pathList: HISTORY.getPathList()
};
}