king
2024-11-07 a02fc6a77fa1b35c6516b2d37108d80e260c6c85
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import { Button, Card, Collapse, notification, Spin, Col } from 'antd'
import { RedoOutlined } from '@ant-design/icons'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import { updateCommonTable } from '@/utils/utils-update.js'
 
import asyncComponent from '@/utils/asyncComponent'
import SearchComponent from '@/templates/sharecomponent/searchcomponent'
import ActionComponent from '@/templates/sharecomponent/actioncomponent'
import ColumnComponent from '@/templates/sharecomponent/columncomponent'
 
import MenuForm from './menuform'
import Source from './source'
import './index.scss'
 
const { Panel } = Collapse
 
const UrlFieldComponent = asyncComponent(() => import('@/menu/urlfieldcomponent'))
const UpdateTable = asyncComponent(() => import('./updatetable'))
const Unattended = asyncComponent(() => import('@/templates/zshare/unattended'))
const SettingComponent = asyncComponent(() => import('@/templates/sharecomponent/settingcomponent'))
const TableComponent = asyncComponent(() => import('@/templates/sharecomponent/tablecomponent'))
const ChartGroupComponent = asyncComponent(() => import('@/templates/sharecomponent/chartgroupcomponent'))
const ChartComponent = asyncComponent(() => import('@/templates/sharecomponent/chartcomponent'))
const CardComponent = asyncComponent(() => import('@/templates/sharecomponent/cardcomponent'))
const TabsComponent = asyncComponent(() => import('@/templates/sharecomponent/tabscomponent'))
 
class ComTableConfig extends Component {
  static propTpyes = {
    menu: PropTypes.any,
    reloadmenu: PropTypes.func,
    handleView: PropTypes.func
  }
 
  state = {
    config: null,            // 页面配置
    formlist: null,          // 搜索条件、按钮、显示列表单字段
    menuloading: false,      // 菜单保存中
    menucloseloading: false, // 菜单关闭时,选择保存
    loading: false,          // 加载中,页面spin
    closeVisible: false,     // 关闭模态框
    originMenu: null,        // 原始菜单
    originActions: null,     // 原始按钮信息,使用已有用户模板
    delActions: [],          // 删除按钮列表
    copyActions: [],         // 复制按钮组
    tabviews: [],            // 所有标签页
    activeKey: '0',          // 默认展开基本信息
    chartview: null,         // 当前视图
    openEdition: '',         // 编辑版本标记,防止多人操作
  }
 
  /**
   * @description 数据预处理
   * 1、设置页面配置信息,新建或无配置信息时(切换模板后无配置信息),使用模板默认配置
   * 2、设置操作类型、原始菜单信息(每次保存后重置)、已使用表及基本信息表单
   */
  UNSAFE_componentWillMount () {
    const { menu } = this.props
    let _LongParam = menu.LongParam
    let _config = ''
 
    if (!_LongParam) {
      _config = fromJS(Source.baseConfig).toJS()
      _config.isAdd = true
    } else {
      _config = _LongParam
    }
 
    // 页面配置中保留菜单信息,只用于数据传递
    _config.ParentId = menu.ParentId
    _config.fstMenuId = menu.fstMenuId
    _config.MenuName = menu.MenuName || ''
    _config.MenuNo = menu.MenuNo || ''
    _config.OpenType = menu.PageParam ? menu.PageParam.OpenType : ''
    _config.easyCode = _config.easyCode || ''
    _config.uuid = menu.MenuID || ''
 
    // 版本兼容
    _config = updateCommonTable(_config)
    
    let _oriActions = []
    if (_config.type === 'user') {
      _config.action = _config.action.map(item => {
        let uuid = Utils.getuuid()
 
        if (item.linkTab) {
          item.linkTab = ''
        }
 
        if (item.OpenType === 'pop' || item.execMode === 'pop') { // 含有子配置项的按钮(表单)
          _oriActions.push({
            prebtn: fromJS(item).toJS(),
            curuuid: uuid,
            Template: 'Modal'
          })
        }
 
        item.uuid = uuid
        return item
      })
 
      // 重置标签ID
      _config.tabgroups.forEach(group => {
        group.sublist = group.sublist.map(tab => {
          tab.uuid = Utils.getuuid()
          
          if (tab.linkTab) {
            tab.linkTab = ''
          }
 
          return tab
        })
      })
    }
 
    this.setState({
      chartview: _config.charts ? _config.charts[0].uuid : '',
      config: _config,
      openEdition: menu.open_edition || '',
      activeKey: menu.activeKey || '0',
      originActions: _oriActions,
      originMenu: fromJS(_config).toJS()
    })
  }
 
  /**
   * @description 加载完成后, 获取所有标签页信息
   */
  componentDidMount () {
    this.reloadTab(false)
 
    document.onkeydown = (event) => {
      let e = event || window.event
      let keyCode = e.keyCode || e.which || e.charCode
      let preKey = ''
 
      if (e.ctrlKey) {
        preKey = 'ctrl'
      }
      if (e.shiftKey) {
        preKey = 'shift'
      } else if (e.altKey) {
        preKey = 'alt'
      }
      
      if (!preKey || !keyCode) return
      
      let _shortcut = `${preKey}+${keyCode}`
 
      if (_shortcut === 'ctrl+83') {
        let modals = document.querySelectorAll('.mk-pop-modal')
        let msg = null
        for (let i = 0; i < modals.length; i++) {
          if (msg) {
            break
          }
 
          let node = modals[i].querySelector('.mk-com-name')
 
          if (node) {
            msg = node.innerText
          }
        }
        if (msg) {
          notification.warning({
            top: 92,
            message: '请保存' + msg,
            duration: 5
          })
          return false
        }
 
        let node = document.getElementById('save-config')
        if (node && node.click) {
          node.click()
        }
        return false
      }
    }
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    document.onkeydown = () => {}
  }
 
  /**
   * @description 加载或刷新标签信息
   */
  reloadTab = (type) => {
    this.setState({
      loading: type,
      tabviews: []
    })
    Api.getCloudConfig({func: 'sPC_Get_UserTemp', TypeCharTwo: 'tab'}).then(res => {
      if (res.status) {
        this.setState({
          loading: false,
          tabviews: res.UserTemp.map(temp => {
            return {
              uuid: temp.MenuID,
              value: temp.MenuID,
              text: temp.MenuName,
              type: temp.Template,
              MenuNo: temp.MenuNo
            }
          })
        })
 
        if (type) {
          notification.success({
            top: 92,
            message: '刷新成功。',
            duration: 2
          })
        }
      } else {
        this.setState({
          loading: false
        })
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
    })
  }
 
  getFuncNames = (config) => {
    let funcNames = []
    let tableNames = []
 
    if (config.setting.tableName) {
      tableNames.push(config.setting.tableName)
    }
    if (config.setting.innerFunc) {
      funcNames.push({func: config.setting.innerFunc, label: config.MenuName || ''})
    }
    if (config.setting.outerFunc) {
      funcNames.push({func: config.setting.outerFunc, label: config.MenuName || ''})
    }
 
    config.action.forEach(item => {
      let tablename = item.OpenType === 'excelIn' ? (item.sheet || '') : (item.sql || '')
 
      if (item.OpenType === 'excelOut' && item.intertype === 'system') {
        tablename = config.setting.tableName || ''
      }
 
      if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut', 'funcbutton'].includes(item.OpenType)) {
        if (tablename) {
          tableNames.push(tablename)
        }
        if (item.innerFunc) {
          funcNames.push({func: item.innerFunc, label: item.label || ''})
        }
        if (item.callbackFunc) {
          funcNames.push({func: item.callbackFunc, label: item.label || ''})
        }
      }
    })
 
    tableNames = Array.from(new Set(tableNames))
 
    return {
      func: funcNames,
      table: tableNames
    }
  }
 
  /**
   * @description 三级菜单保存
   */
  // submitConfig = () => {
  //   const { menu } = this.props
  //   const { delActions, openEdition } = this.state
 
  //   let _config = fromJS(this.state.config).toJS()
 
  //   // 基本信息验证
  //   if (!_config.fstMenuId || !_config.ParentId || !_config.MenuName || !_config.MenuNo) {
  //     notification.warning({
  //       top: 92,
  //       message: '请完善菜单基本信息!',
  //       duration: 5
  //     })
  //     this.setState({activeKey: '0'})
  //     return
  //   }
 
  //   // 新建菜单,清除默认项
  //   if (_config.isAdd) {
  //     _config.search = _config.search.filter(item => !item.origin)
  //     _config.action = _config.action.filter(item => !item.origin)
  //     _config.columns = _config.columns.filter(item => !item.origin)
  //     _config.tabgroups[0].sublist = _config.tabgroups[0].sublist.filter(item => !item.origin)
  //   }
 
  //   // 使用已有菜单时,默认添加关联标签id
  //   if (_config.type === 'user') {
  //     _config.action = _config.action.map(item => {
  //       if (item.OpenType === 'popview' && !item.linkTab) {
  //         item.linkTab = Utils.getuuid()
  //       }
  //       return item
  //     })
  
  //     _config.tabgroups.forEach(group => {
  //       group.sublist = group.sublist.map(tab => {
  //         if (!tab.linkTab) {
  //           tab.linkTab = Utils.getuuid()
  //         }
  //         return tab
  //       })
  //     })
  //   }
 
  //   // 按钮不存在时,去掉绑定的双击按钮
  //   if (_config.setting.doubleClick && _config.action.findIndex((item) => item.uuid === _config.setting.doubleClick) === -1) {
  //     _config.setting.doubleClick = ''
  //   }
 
  //   // 未设置数据源或标签不合法时,启用状态为false
  //   let vresult = this.verifyconfig(_config)
  //   if (vresult !== true) {
  //     _config.enabled = false
  //   }
 
  //   if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
  //     this.setState({
  //       menucloseloading: true
  //     })
  //   } else {
  //     this.setState({
  //       menuloading: true
  //     })
  //   }
 
  //   let _LongParam = ''
 
  //   // 保存时删除配置类型,system 、user
  //   delete _config.type
  //   delete _config.isAdd
 
  //   try {
  //     _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
  //   } catch (e) {
  //     notification.warning({
  //       top: 92,
  //       message: '编译错误',
  //       duration: 5
  //     })
  //     this.setState({
  //       menucloseloading: false,
  //       menuloading: false
  //     })
  //     return
  //   }
 
  //   let _sort = 0
  //   // let btntabs = []
 
  //   let btnParam = {             // 添加菜单按钮
  //     func: 'sPC_Button_AddUpt',
  //     Type: 40,                  // 添加菜单下的按钮type为40,按钮下的按钮type为60
  //     ParentID: menu.MenuID,
  //     MenuNo: _config.MenuNo,
  //     Template: _config.Template || '',
  //     PageParam: '',
  //     LongParam: '',
  //     LText: []
  //   }
 
  //   _config.action.forEach(item => {
  //     if (item.hidden === 'true') return
  //     _sort++
  //     // if (item.OpenType === 'popview') {
  //     //   btntabs.push({
  //     //     uuid: item.uuid,
  //     //     linkTab: item.linkTab,
  //     //     label: item.label,
  //     //     sort: _sort
  //     //   })
  //     // }
      
  //     btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${_sort * 10}' as Sort`)
  //   })
 
  //   btnParam.LText = btnParam.LText.join(' union all ')
  //   btnParam.LText = Utils.formatOptions(btnParam.LText)
  //   btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
  //   btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
    
  //   // let tabParam = { // 添加菜单tab页
  //   //   func: 'sPC_sMenusTab_AddUpt',
  //   //   MenuID: menu.MenuID
  //   // }
 
  //   // let _LText = []
 
  //   // btntabs.forEach(item => {
  //   //   _LText.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${item.sort * 10}' as Sort`)
  //   // })
  //   // _config.tabgroups.forEach(group => {
  //   //   group.sublist.forEach(item => {
  //   //     _sort++
  //   //     _LText.push(`select '${menu.MenuID}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${_sort * 10}' as Sort`)
  //   //   })
  //   // })
 
  //   // _LText = _LText.join(' union all ')
 
  //   // 清空菜单下关联的标签
  //   // if (!_LText) {
  //   //   _LText = `select '${menu.MenuID}' as MenuID ,'' as Tabid,'' as TabName ,'0' as Sort`
  //   // }
 
  //   // tabParam.LText = Utils.formatOptions(_LText)
  //   // tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
  //   // tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
 
  //   let _vals = this.getFuncNames(_config)
 
  //   let param = {
  //     func: 'sPC_TrdMenu_AddUpt',
  //     FstID: _config.fstMenuId,
  //     SndID: _config.ParentId,
  //     ParentID: _config.ParentId,
  //     MenuID: menu.MenuID,
  //     MenuNo: _config.MenuNo,
  //     EasyCode: _config.easyCode || '',
  //     Template: _config.Template || '',
  //     MenuName: _config.MenuName,
  //     PageParam: JSON.stringify({...menu.PageParam, Template: _config.Template, OpenType: _config.OpenType, hidden: _config.hidden || 'false'}),
  //     LongParam: _LongParam,
  //     LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
  //     LTexttb: _vals.table.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`)
  //   }
 
  //   if (menu.menuSort) { // 菜单新建时设置排序
  //     param.Sort = menu.menuSort
  //   }
 
  //   param.LText = param.LText.join(' union all ')
  //   param.LText = Utils.formatOptions(param.LText)
  //   param.LTexttb = param.LTexttb.join(' union all ')
  //   param.LTexttb = Utils.formatOptions(param.LTexttb)
  //   param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
  //   param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
  //   if (openEdition) { // 版本管理
  //     param.open_edition = openEdition
  //   }
 
  //   setTimeout(() => {
  //     // 有按钮或标签删除时,先进行删除操作
  //     // 删除成功后,保存页面配置
  //     new Promise(resolve => {
  //       if (delActions.length > 0) {
  //         let deffers = delActions.map(item => {
  //           let _param = {
  //             func: 'sPC_MainMenu_Del',
  //             MenuID: item.card ? item.card.uuid : item.uuid
  //           }
 
  //           if (item.type === 'action') {
  //             let _ParentParam = null
 
  //             try {
  //               _ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
  //             } catch (e) {
  //               console.warn('Stringify Failure')
  //               _ParentParam = null
  //             }
 
  //             if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
  //               _param.ParentParam = _ParentParam
  //             }
  //           }
 
  //           return new Promise(resolve => {
  //             Api.getCloudConfig(_param).then(response => {
  //               resolve(response)
  //             })
  //           })
  //         })
  //         Promise.all(deffers).then(result => {
  //           let error = null
  //           result.forEach(response => {
  //             if (!response.status) {
  //               error = response
  //             }
  //           })
 
  //           if (error) {
  //             this.setState({
  //               menuloading: false,
  //               menucloseloading: false
  //             })
  //             notification.warning({
  //               top: 92,
  //               message: error.message,
  //               duration: 5
  //             })
  //             resolve(false)
  //           } else {
  //             this.setState({
  //               delActions: []
  //             })
  //             resolve(true)
  //           }
  //         })
  //       } else if (delActions.length === 0) {
  //         resolve(true)
  //       }
  //     }).then(resp => {
  //       if (resp === false) return
 
  //       return true
  //     }).then(res => {
  //       if (res === true || res === false) return res
 
  //       let msg = res.filter(Boolean)[0]
  //       if (msg) {
  //         notification.warning({
  //           top: 92,
  //           message: msg,
  //           duration: 5
  //         })
  //         return false
  //       } else {
  //         return true
  //       }
  //     }).then(resp => {
  //       if (resp === false) return
  //       Api.getCloudConfig(param).then(response => {
  //         if (response.status) {
  //           this.setState({
  //             config: _config,
  //             openEdition: response.open_edition || '',
  //             originMenu: fromJS(_config).toJS()
  //           })
 
  //           this.submitAction(btnParam)
  //         } else {
  //           this.setState({
  //             menuloading: false,
  //             menucloseloading: false
  //           })
  //           notification.warning({
  //             top: 92,
  //             message: response.message,
  //             duration: 5
  //           })
  //         }
  //       })
  //     })
  //   }, +sessionStorage.getItem('mkDelay'))
  // }
 
  /**
   * @description 保存或修改菜单按钮集
   */
  // submitAction = (btnParam) => {
  //   const { config } = this.state
 
  //   new Promise(resolve => {
  //     if (btnParam.LText) {
  //       Api.getCloudConfig(btnParam).then(result => {
  //         if (result.status) {
  //           this.setState({ // 保存成功后清空复制列表
  //             copyActions: []
  //           })
  //           resolve(result)
  //         } else {
  //           notification.warning({
  //             top: 92,
  //             message: result.message,
  //             duration: 5
  //           })
  //           resolve(false)
  //         }
  //       })
  //     } else {
  //       resolve(true)
  //     }
  //   }).then(response => {
  //     if (response === false) return response
 
  //     if (!this.state.originActions || this.state.originActions.length === 0) return 'true'
 
  //     let oriActions = []
  //     this.state.originActions.forEach(item => {
  //       let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 查看初始化按钮是否存在
  //       if (!curBtn) return
  //       if (curBtn.OpenType !== item.prebtn.OpenType) return
  //       if (curBtn.OpenType === 'funcbutton' && curBtn.execMode !== 'pop') return
 
  //       oriActions.push({
  //         prebtn: item.prebtn,
  //         curBtn: curBtn
  //       })
  //     })
 
  //     if (oriActions.length === 0) return 'true'
 
  //     oriActions.forEach(action => {
  //       if (!action.prebtn || !action.prebtn.uuid) return
 
  //       Api.getCloudConfig({
  //         func: 'sPC_Get_LongParam',
  //         MenuID: action.prebtn.uuid
  //       }).then(result => {
  //         if (result.status && result.LongParam) {
  //           let _temp = ''
 
  //           let _subconfig = ''
  //           try {
  //             _subconfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
  //             _temp = _subconfig.type
  //           } catch (e) {
  //             console.warn('Parse Failure')
  //             _subconfig = ''
  //           }
 
  //           if (!_subconfig) return
 
  //           let param = {
  //             func: 'sPC_ButtonParam_AddUpt',
  //             ParentID: this.props.menu.MenuID,
  //             MenuID: action.curBtn.uuid,
  //             MenuNo: config.MenuNo,
  //             Template: _temp,
  //             MenuName: action.curBtn.label,
  //             PageParam: JSON.stringify({Template: _temp}),
  //             LongParam: result.LongParam
  //           }
  //           Api.getCloudConfig(param).then(() => {})
  //         }
  //       })
  //     })
  //     return 'true'
  //   }).then(response => {
  //     if (response === 'true') {
  //       notification.success({
  //         top: 92,
  //         message: '保存成功',
  //         duration: 2
  //       })
  //       if (this.state.closeVisible) {
  //         this.props.handleView()
  //       } else {
  //         this.setState({
  //           originActions: [],
  //           menuloading: false,
  //           menucloseloading: false
  //         })
  //       }
  //       this.props.reloadmenu()
  //     } else {
  //       this.setState({
  //         menuloading: false,
  //         menucloseloading: false
  //       })
  //     }
  //   })
  // }
 
  /**
   * @description 点击返回时,判断配置保存状态
   */
  cancelConfig = () => {
    // const { config, originMenu } = this.state
 
    // let that = this
 
    // if (config.isAdd) {
    //   confirm({
    //     content: '菜单尚未提交,确定放弃保存吗?',
    //     onOk() {
    //       that.props.handleView()
    //     },
    //     onCancel() {}
    //   })
    // } else {
    //   if (!is(fromJS(originMenu), fromJS(config))) {
    //     this.setState({
    //       closeVisible: true
    //     })
    //   } else {
    //     this.props.handleView()
    //   }
    // }
 
    this.props.handleView()
  }
 
  /**
   * @description 设置可配置按钮
   */
  setSubConfig = (item, type) => {
    const { menu } = this.props
    const { config, originMenu, activeKey, openEdition } = this.state
 
    if (config.isAdd) { // 新建菜单,提示菜单尚未保存
      notification.warning({
        top: 92,
        message: '菜单尚未保存,请先保存菜单配置!',
        duration: 5
      })
    } else {
      if (!is(fromJS(originMenu), fromJS(config))) { // 菜单信息变化时,提示保存
        notification.warning({
          top: 92,
          message: '菜单配置已修改,请保存!',
          duration: 5
        })
        return
      }
 
      let submenu = menu.fstMenuList.filter(_menu => _menu.MenuID === config.fstMenuId)[0]
 
      let _Menu = {
        ...menu,
        LongParam: config,
        PageParam: {...menu.PageParam, Template: config.Template, OpenType: config.OpenType},
        MenuName: config.MenuName,
        MenuNo: config.MenuNo,
        ParentId: config.ParentId,
        fstMenuId: config.fstMenuId,
        supMenuList: submenu ? submenu.children : []
      }
 
      // 菜单信息验证通过后,跳转子配置页面
      let _view = ''
      let uuid = item.uuid
      let isbutton = true
      let _btnTab = null
      
      if (type === 'button' && (item.OpenType === 'pop' || item.execMode === 'pop')) {
        _view = 'Modal'      // 表单页面
      } else if (type === 'button' && item.OpenType === 'tab') {
        _view = 'FormTab'    // 表单标签页模板
        _btnTab = item
      } else if (type === 'button' && item.OpenType === 'popview') {
        _view = 'SubTable'   // 新弹窗标签模板 tabType 属性已去除
        uuid = item.linkTab
        isbutton = false
      } else if (type === 'tab') {
        _view = 'SubTable'   // 标签模板
        uuid = item.linkTab
        isbutton = false
      }
 
      _Menu.activeKey = activeKey       // 保存当前打开页签
      _Menu.open_edition = openEdition  // 更新版本号
 
      let param = {
        editMenu: _Menu,
        editTab: !isbutton ? item : '',
        tabConfig: null,
        editSubTab: null,
        subTabConfig: null,
        btnTab: _btnTab,
        btnTabConfig: null,
        editAction: isbutton ? item : '',
        subConfig: '',
        tabview: _view
      }
      
      // 当子表使用主页搜索条件时,将主页搜索向下传递
      if (param.editTab && param.editTab.searchPass === 'true') {
        param.editTab.mainsearch = fromJS(config.search).toJS()
      }
 
      this.setState({
        loading: true
      })
 
      Api.getCloudConfig({
        func: 'sPC_Get_LongParam',
        MenuID: uuid
      }).then(res => {
        if (res.status) {
          this.setState({
            loading: false
          })
          let _LongParam = ''
          if (res.LongParam) {
            try {
              _LongParam = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
            } catch (e) {
              console.warn('Parse Failure')
              _LongParam = ''
            }
          }
 
          if (_LongParam && param.tabview === 'Modal' && _LongParam.type === 'Modal') {
            param.subConfig = _LongParam
          } else if (_LongParam && param.tabview === 'FormTab' && _LongParam.type === 'FormTab') {
            param.subConfig = _LongParam
          } else if (_LongParam && param.tabview === 'SubTable' && _LongParam.Template === 'SubTable') {
            param.subConfig = _LongParam
          }
          
          if (param.editTab) {
            param.editTab.open_edition = res.open_edition || ''
          } else if (param.editAction) {
            param.editAction.open_edition = res.open_edition || ''
          } else if (param.btnTab) {
            param.btnTab.open_edition = res.open_edition || ''
          }
 
          this.props.handleView(param)
        } else {
          this.setState({
            loading: false
          })
          notification.warning({
            top: 92,
            message: res.message,
            duration: 5
          })
        }
      })
    }
  }
 
  /**
   * @description 页面启用停止切换
   */
  onEnabledChange = () => {
    const { config } = this.state
 
    let _enabled = !config.enabled
    let result = this.verifyconfig(config)
    if (_enabled && result !== true) {
      notification.warning({
        top: 92,
        message: result,
        duration: 5
      })
      return
    }
 
    this.setState({
      config: {...config, enabled: _enabled}
    })
  }
 
  /**
   * @description 校验配置信息的合法性
   */
  verifyconfig = (config) => {
    let tabinvalid = true
    if (config.tabgroups.length > 1) {
      config.tabgroups.forEach(group => {
        if (group.sublist.length === 0) {
          tabinvalid = false
        }
      })
    }
 
    let hasKey = false
    let chartcols = []
    config.columns.forEach(col => {
      if (col.field) {
        chartcols.push(col.field)
      }
      if (config.setting.primaryKey === col.field) {
        hasKey = true
      }
    })
 
    let chartError = ''
    config.charts && config.charts.forEach((chart, index) => {
      if (chartError) return
      if (chart.Hide === 'true') return
      if (!['line', 'bar', 'pie'].includes(chart.chartType)) return
 
      if (!chart.Xaxis) {
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段尚未设置,不可启用!`
      } else if (['line', 'bar'].includes(chart.chartType) && chart.datatype !== 'statistics' && (!chart.Yaxis || chart.Yaxis.length === 0)) { // query 查询数据
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段尚未设置,不可启用!`
      } else if (['line', 'bar'].includes(chart.chartType) && chart.datatype === 'statistics' && (!chart.InfoType || !chart.InfoValue)) { // statistics 统计数据
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段尚未设置,不可启用!`
      } else if (chart.chartType === 'pie' && !chart.Yaxis) {
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段尚未设置,不可启用!`
      } else if (!chartcols.includes(chart.Xaxis)) {
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段在显示列中不存在,不可启用!`
      } else if (chart.chartType === 'pie' && !chartcols.includes(chart.Yaxis)) {
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段在显示列中不存在,不可启用!`
      } else if (['line', 'bar'].includes(chart.chartType) && chart.datatype === 'statistics' && (!chartcols.includes(chart.InfoType) || !chartcols.includes(chart.InfoValue))) { // statistics 统计数据
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段在显示列中不存在,不可启用!`
      } else if (['line', 'bar'].includes(chart.chartType) && chart.datatype !== 'statistics' && chart.Yaxis.filter(yaxis => !chartcols.includes(yaxis)).length > 0) {
        chartError = `图表${chart.title ? '《' + chart.title + '》' : index + 1}坐标轴字段在显示列中不存在,不可启用!`
      }
    })
    
    config.action && config.action.forEach((btn) => {
      if (btn.intertype === 'custom' && btn.callbackType === 'script' && (!btn.verify || !btn.verify.cbScripts || !btn.verify.cbScripts.filter(item => item.status !== 'false').length === 0)) {
        notification.warning({
          top: 92,
          message: `按钮《${btn.label}》未设置回调脚本, 将不会生效!`,
          duration: 5
        })
      }
    })
 
    if (config.setting.interType === 'system' && config.setting.default === 'false' && config.setting.scripts && config.setting.scripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源中不执行默认sql,且未添加自定义脚本,不可启用!'
    } else if (config.setting.interType === 'custom' && config.setting.procMode !== 'inner' && config.setting.preScripts && config.setting.preScripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源未设置前置脚本,不可启用!'
    } else if (config.setting.interType === 'custom' && config.setting.callbackType === 'script' && config.setting.cbScripts && config.setting.cbScripts.filter(item => item.status !== 'false').length === 0) {
      return '数据源未设置回调脚本,不可启用!'
    } else if (!config.setting.primaryKey) {
      return '菜单尚未设置主键,不可启用!'
    } else if (config.columns.length === 0) {
      return '菜单尚未设置显示列,不可启用!'
    } else if (!hasKey) {
      return '显示列中不存在主键字段,不可启用!'
    } else if (!tabinvalid) {
      return '菜单标签页设置错误(存在多行标签时,行标签不可为空)!'
    } else if (chartError) {
      return chartError
    } else {
      return true
    }
  }
 
  /**
   * @description 选择不保存时,如有复制按钮,则删除
   */
  notsave = () => {
    this.state.copyActions.forEach(item => {
      let _param = {
        func: 'sPC_MainMenu_Del',
        MenuID: item
      }
      Api.getCloudConfig(_param)
    })
    this.props.handleView()
  }
 
  /**
   * @description 编辑功能完成更新,包括解冻按钮、粘贴、替换等
   */
  editConfig = (res) => {
    this.setState({
      config: res.config
    })
  }
 
  /**
   * @description 更新搜索条件配置信息
   */
  updatesearch = (config) => {
    this.setState({
      config: config
    })
  }
 
  /**
   * @description 更新按钮配置信息
   */
  updateaction = (config, copyId, delcard) => {
    const { copyActions, delActions } = this.state
 
    this.setState({
      config: config,
      copyActions: copyId ? [...copyActions, copyId] : copyActions,
      delActions: delcard ? [...delActions, delcard] : delActions
    })
  }
 
  /**
   * @description 更新图表组配置信息
   */
  updatechartgroup = (config, _chartview) => {
    this.setState({
      config: config,
      chartview: _chartview
    })
  }
  
  /**
   * @description 更新配置信息
   */
  updateconfig = (config) => {
    this.setState({
      config: config
    })
  }
 
  refreshConfig = () => {
    const { menu } = this.props
    
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: menu.MenuID
    }
 
    Api.getCloudConfig(param).then(res => {
      if (res.status) {
        let _config = ''
        if (res.LongParam) {
          try {
            _config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
          } catch (e) {
            console.warn('Parse Failure')
            _config = ''
          }
        }
 
        if (!_config) {
          notification.warning({
            top: 92,
            message: '未获取到配置信息!',
            duration: 5
          })
          return
        }
 
        _config.ParentId = menu.ParentId
        _config.fstMenuId = menu.fstMenuId
        _config.MenuName = menu.MenuName || ''
        _config.MenuNo = menu.MenuNo || ''
        _config.OpenType = menu.PageParam ? menu.PageParam.OpenType : ''
        _config.easyCode = _config.easyCode || ''
 
        // 版本兼容
        _config = updateCommonTable(_config)
 
        this.setState({
          config: null
        }, () => {
          this.setState({
            chartview: _config.charts ? _config.charts[0].uuid : '',
            config: _config,
            openEdition: res.open_edition || '',
            activeKey: menu.activeKey || '0',
            originActions: [],
            originMenu: fromJS(_config).toJS()
          })
        })
      } else {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 5
        })
      }
    })
  }
 
  render () {
    const { menu } = this.props
    const { activeKey, config, chartview } = this.state
 
    if (!config) return null
 
    let configTabs = []
    config.tabgroups.forEach(group => {
      configTabs.push(...group.sublist)
    })
 
    return (
      <div className="common-table-board">
        <DndProvider backend={HTML5Backend}>
          {/* 工具栏 */}
          <div className="tools">
            <Collapse accordion activeKey={activeKey} bordered={false} onChange={(key) => this.setState({activeKey: key})}>
              {/* 基本信息 */}
              <Panel forceRender={true} header="基本信息" key="0" id="main-basedata">
                {/* 菜单信息 */}
                <MenuForm
                  menu={menu}
                  config={config}
                  updatemenu={this.updateconfig}
                />
                {config ? <UrlFieldComponent
                  config={config}
                  updateConfig={this.updateconfig}
                /> : null}
                {/* 表名添加 */}
                <TableComponent
                  config={config}
                  containerId="main-basedata"
                  updatetable={this.updateconfig}
                />
              </Panel>
            </Collapse>
          </div>
          <div className="setting">
            <Card title={
              <div>
                页面配置 
                <RedoOutlined style={{marginLeft: '10px'}} title="刷新标签列表" onClick={() => this.reloadTab(true)} />
              </div>
            } bordered={false} extra={
              <div>
                <Unattended config={config} updateConfig={this.updateconfig}/>
                {/* <Versions MenuId={menu.MenuID} open_edition={openEdition} updateConfig={this.refreshConfig}/> */}
                {/* <ReplaceField type="table" config={config} updateConfig={this.updateconfig}/> */}
                {/* <EditComponent type="table" options={['search', 'form', 'action', 'columns']} config={this.state.config} refresh={this.editConfig}/> */}
                <UpdateTable config={config}/>
                {/* <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={this.state.config.enabled} onChange={this.onEnabledChange} /> */}
                {/* <Button type="primary" id="save-config" onClick={this.submitConfig} loading={this.state.menuloading}>保存</Button> */}
                <Button onClick={this.cancelConfig}>关闭</Button>
              </div>
            } style={{ width: '100%' }}>
              <SettingComponent
                config={config}
                MenuID={menu.MenuID}
                updatesetting={this.updateconfig}
              />
              <SearchComponent
                config={config}
                updatesearch={this.updatesearch}
              />
              {config.charts ? <div className="chart-view" style={{position: 'relative'}}>
                {/* 视图组 已弃用 */}
                <ChartGroupComponent
                  config={config}
                  updatechartgroup={this.updatechartgroup}
                />
                {config.charts.map(item => {
                  if (!config.expand && chartview !== item.uuid) return ''
 
                  if (item.chartType === 'table') {
                    return (
                      <Col span={item.width || 24} key={item.uuid}>
                        {config.charts.length > 1 && item.title ? <p className="chart-title">{item.title}</p> : null}
                        <ActionComponent
                          type="main"
                          menu={{ MenuID: this.props.menu.MenuID, MenuName: config.MenuName, MenuNo: config.MenuNo, fstMenuList: this.props.menu.fstMenuList }}
                          config={config}
                          tabs={this.state.tabviews}
                          setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}
                          updateaction={this.updateaction}
                        />
                        <ColumnComponent
                          config={config}
                          menu={this.props.menu}
                          updatecolumn={this.updateconfig}
                        />
                      </Col>
                    )
                  } else if (item.chartType === 'card') {
                    return (
                      <Col span={item.width} key={item.uuid}>
                        <CardComponent
                          card={item}
                          config={config}
                          plotchange={this.updateconfig}
                        />
                      </Col>
                    )
                  } else {
                    return (
                      <Col span={item.width} key={item.uuid}>
                        <ChartComponent
                          plot={item}
                          config={config}
                          plotchange={this.updateconfig}
                        />
                      </Col>
                    )
                  }
                })}
              </div> : <>
                <ActionComponent
                  type="main"
                  menu={{ MenuID: this.props.menu.MenuID, MenuName: config.MenuName, MenuNo: config.MenuNo, fstMenuList: this.props.menu.fstMenuList }}
                  config={config}
                  tabs={this.state.tabviews}
                  setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}
                  updateaction={this.updateaction}
                />
                <ColumnComponent
                  config={config}
                  menu={this.props.menu}
                  updatecolumn={this.updateconfig}
                />
              </>}
              {/* 标签组 */}
              <TabsComponent
                config={config}
                tabs={this.state.tabviews}
                setSubConfig={(item) => this.setSubConfig(item, 'tab')}
                updatetabs={this.updateconfig}
              />
            </Card>
          </div>
        </DndProvider>
        {/* 返回时未保存提示 */}
        {/* <Modal
          bodyStyle={{textAlign: 'center', color: '#000000', fontSize: '16px'}}
          closable={false}
          maskClosable={false}
          visible={this.state.closeVisible}
          onCancel={() => { this.setState({closeVisible: false}) }}
          footer={[
            <Button key="save" className="mk-btn mk-green" loading={this.state.menucloseloading} onClick={this.submitConfig}>保存</Button>,
            <Button key="notsave" className="mk-btn mk-yellow" onClick={this.notsave}>不保存</Button>,
            <Button key="cancel" onClick={() => { this.setState({closeVisible: false}) }}>取消</Button>
          ]}
          destroyOnClose
        >
          配置已修改,是否保存配置信息?
        </Modal> */}
        {this.state.loading && <Spin size="large" />}
      </div>
    )
  }
}
 
export default ComTableConfig