king
2025-05-08 400fee62fb40006a9839f1c3a8244b82566b5057
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { notification, Spin, Row, Col } from 'antd'
import md5 from 'md5'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
import NotFount from '@/components/404'
import './index.scss'
 
// 通用组件
const AntvTabs = asyncComponent(() => import('@/tabviews/custom/components/tabs/antv-tabs'))
const MkBaseTable = asyncComponent(() => import('@/tabviews/custom/components/table/base-table'))
const FlowFloat = asyncComponent(() => import('@/tabviews/zshare/flowFloat'))
const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
const TableNodes = asyncComponent(() => import('@/tabviews/zshare/tablenodes'))
const DeepSeek = asyncComponent(() => import('@/tabviews/zshare/deepseek'))
const AutoMatic = asyncComponent(() => import('@/tabviews/zshare/automatic'))
const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
 
class BasePage extends Component {
  static propTpyes = {
    param: PropTypes.any,        // 其他页面传递的参数
    Tab: PropTypes.string,       // 弹窗标签
    MenuID: PropTypes.string,    // 菜单Id
    MenuName: PropTypes.string,  // 菜单名称
    changeTemp: PropTypes.func
  }
 
  state = {
    ContainerId: Utils.getuuid(), // 菜单外层html Id
    BID: '',              // 页面跳转时携带ID
    loadingview: true,    // 页面加载中
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: null,         // 页面配置信息,包括组件等
    userConfig: null,     // 用户自定义设置
    visible: false,       // 标签页控制
    shortcuts: null,      // 快捷键
    autoMatic: null,
    noParam: false
  }
 
  /**
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { MenuID, MenuName, param } = this.props
    const { noParam } = this.state
 
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuID
    }
 
    if (window.GLOB.mkHS) {
      _param.lang = 'zh-CN'
    }
    
    let result = await Api.getCacheConfig(_param)
 
    if (result.status) {
      let config = ''
      let shortcuts = []
 
      try { // 配置信息解析
        config = window.decodeURIComponent(window.atob(result.LongParam))
        config = config.replace(/@mywebsite@\//ig, window.GLOB.baseurl)
        config = JSON.parse(config)
        config.MenuID = MenuID
        config.MenuName = MenuName || config.MenuName
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
      }
 
      // 页面配置解析错误时提示
      if (!config) {
        this.setState({
          viewlost: true,
          loadingview: false
        })
        return
      }
 
      // 页面未启用时,显示未启用页面
      if (!config.enabled) {
        this.setState({
          viewlost: true,
          loadingview: false,
          lostmsg: '抱歉,您访问的页面未启用,请联系管理员。'
        })
        return
      }
 
      // 模板错误
      if (config.Template !== 'BaseTable') {
        if (config.Template === 'CustomPage' || config.Template === 'CommonTable') {
          this.props.changeTemp(MenuID, config.Template)
        } else {
          this.setState({
            viewlost: true,
            loadingview: false,
            lostmsg: '菜单信息错误,可能原因:1、当前用户无权限;2、打开此菜单的按钮需要更新。'
          })
        }
        return
      }
 
      if (config.process === 'true') {
        let unset = true
        if (result.works_flow_code && result.works_long_param) {
          try { // 流程信息解析
            let flowConfig = JSON.parse(window.decodeURIComponent(window.atob(result.works_long_param)))
            flowConfig.flow_code = result.works_flow_code
            flowConfig.flow_name = result.works_flow_name
            config.flow_code = result.works_flow_code
            config.flow_name = result.works_flow_name
            unset = false
            window.GLOB.UserCacheMap.set('flow' + MenuID, flowConfig)
          } catch (e) {
            unset = true
            console.warn('Parse Failure')
          }
        }
        
        if (unset) {
          this.setState({
            config: config,
            viewlost: true,
            loadingview: false,
            lostmsg: '抱歉,您访问的页面未设置工作流,请联系管理员。'
          })
          return
        }
      } else if (result.works_flow_code) {
        Api.getSystemConfig({
          func: 's_works_flow_param_sso_menu_upt_v6',
          upt_type: 'del',
          works_flow_code: '',
          works_flow_name: '',
          long_param: '',
          flow_id: '',
          menuid: config.MenuID,
          menuname: config.MenuName,
          username: sessionStorage.getItem('User_Name') || '',
          fullName: sessionStorage.getItem('Full_Name') || ''
        })
      }
 
      // HS不使用自定义设置
      if (result.LongParamUser) {
        try { // 配置信息解析
          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
          if (userConfig) {
            shortcuts = userConfig.action || []
            userConfig.printers && userConfig.printers.forEach(item => {
              window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
            })
          }
        } catch (e) {
          console.warn('Parse Failure')
        }
      }
 
      // 权限过滤
      let roleId = sessionStorage.getItem('role_id') || '' // 角色ID
      let skip = window.GLOB.mkHS
      let urlparam = {} // url参数
      if (param) {
        if (!noParam) {
          Object.keys(param).forEach(key => {
            if (/^\$/.test(key)) {
              urlparam[key] = param[key]
            } else {
              urlparam[key.toLowerCase()] = param[key]
            }
          })
        } else {
          urlparam.$BID = param.$BID
        }
      }
 
      if (config.urlFields && config.urlFields.length) {
        config.urlFields.forEach(field => {
          let key = field.toLowerCase()
          if (urlparam[key] !== undefined) return
 
          urlparam[key] = ''
        })
      }
 
      window.GLOB.CacheData.set(MenuID, urlparam)
 
      if (window.backend && config.allSqls) {
        let keys = Object.keys(urlparam)
        config.allSqls.forEach(item => {
          item.id = md5(window.GLOB.appkey + item.v_id)
          if (['datasource', 'interface', 'excelOut'].includes(item.type)) {
            item.urlkeys = keys
            item.urlparam = urlparam
            if (config.flow_code) {
              item.works_flow_code = config.flow_code
            }
          }
          window.GLOB.CacheData.set('sql_' + item.uuid, item)
        })
      }
 
      let userName = sessionStorage.getItem('User_Name') || ''
      let fullName = sessionStorage.getItem('Full_Name') || ''
 
      let regs = [
        { reg: /@userName@/ig, value: `'${userName}'` },
        { reg: /@fullName@/ig, value: `'${fullName}'` }
      ]
      
      if (window.GLOB.externalDatabase !== null) {
        regs.push({
          reg: /@db@/ig,
          value: window.GLOB.externalDatabase
        })
      }
      if (config.urlFields) {
        config.urlFields.forEach(field => {
          let val = `'${urlparam[field.toLowerCase()]}'`
          regs.push({
            reg: new RegExp('@' + field + '@', 'ig'),
            value: val
          })
        })
      }
 
      if (config.flow_code) {
        regs.push({ reg: /@works_flow_code@/ig, value: `'${config.flow_code}'` })
      }
 
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, skip, urlparam, MenuID, config.MenuName, config.process === 'true')
 
      let autoMatic = null
      if (config.autoMatic && config.autoMatic.enable === 'true') {
        config.components[0].action.forEach(item => {
          if (item.uuid === config.autoMatic.action) {
            autoMatic = config.autoMatic
            autoMatic.OpenType = item.execMode || item.OpenType
            config.components[0].wrap.selected = 'false'
            config.components[0].MenuID = config.components[0].uuid
            config.components[0].autoMatic = true
            item.autoMatic = true
          }
        })
      }
 
      // 获取主搜索条件
      config.components.forEach(component => {
        if (component.type === 'tabs') return
 
        if (component.$searches.length) {
          component.$main = true
          
          window.GLOB.SearchBox.set(MenuID, component.$searches)
  
          if (component.$s_req) {
            window.GLOB.SearchBox.set(MenuID + 'required', true)
          }
        }
      })
 
      let BID = urlparam.$BID || ''
 
      config.components = this.formatSetting(config.components, regs)
 
      this.setState({
        BID: BID,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        config,
        autoMatic
      }, () => {
        setTimeout(() => { // 延时加载状态
          this.setState({
            loadingview: false
          })
        }, 1000)
        
        if (!this.props.Tab) {
          this.setShortcut()
        }
      })
    } else {
      this.setState({
        loadingview: false,
        viewlost: true
      })
      notification.warning({
        top: 92,
        message: result.message,
        duration: 5
      })
    }
  }
 
  setShortcut = () => {
    const { shortcuts } = this.state
 
    document.onkeydown = (event) => {
      let e = event || window.event
      let keyCode = e.keyCode || e.which || e.charCode
      let preKey = ''
 
      if (e.ctrlKey) {
        preKey = 'ctrl'
      } else if (e.shiftKey) {
        preKey = 'shift'
      } else if (e.altKey) {
        preKey = 'alt'
      }
 
      if (!preKey || !keyCode) return
      
      let _shortcut = `${preKey}+${keyCode}`
 
      if (window.GLOB.breakpoint && _shortcut === 'ctrl+67') {
        window.GLOB.breakpoint = false
        sessionStorage.removeItem('breakpoint')
        
        MKEmitter.emit('debugChange')
      }
 
      if (!shortcuts) return
 
      shortcuts.some(item => {
        if (item.$shortcut === _shortcut) {
          MKEmitter.emit('triggerBtnId', item.uuid)
          return true
        }
        return false
      })
    }
  }
 
  filterComponent = (components, roleId, permAction, skip, urlparam, pageId, MenuName, process) => {
    return components.filter(item => {
      item.$pageId = pageId
      item.$searchId = pageId
 
      if (process) {
        item.$process = process
        item.$flowId = 'flow' + this.props.MenuID
      }
 
      item.$menuname = (MenuName || '') + '-' + (item.name || '主表')
 
      if (item.type === 'tabs') {
        item.subtabs = item.subtabs.filter(tab => {
          if (!skip && !permAction[tab.components[0].uuid] && tab.permission === 'true') {
            return false
          } else if (tab.hide === 'true') {
            return false
          }
          return true
        })
 
        if (item.subtabs.length === 0) return false
 
        item.subtabs = item.subtabs.map(tab => {
          tab.components[0].name = tab.label
          if (tab.permission !== 'true') { // 权限未开启不做权限控制
            skip = true
          }
          tab.components = this.filterComponent(tab.components, roleId, permAction, skip, urlparam, pageId, MenuName, process)
          return tab
        })
 
        return true
      } else {
        item.name = (MenuName || '')
      }
 
      if (item.setting.supModule) {
        let pid = item.setting.supModule.pop()
        if (pid && pid !== 'empty') {
          item.setting.supModule = pid
        } else {
          item.setting.supModule = ''
        }
      }
 
      // 搜索条件初始化
      Utils.initSearchVal(item)
 
      if (urlparam.$searchkey) {
        let reg = new RegExp('(^|,)' + urlparam.$searchkey + '($|,)', 'ig')
        item.search.forEach(cell => {
          if (reg.test(cell.field) && ['text', 'select', 'link', 'checkcard'].includes(cell.type)) {
            cell.initval = urlparam.$searchval
          }
        })
      }
 
      item.$searches = Utils.initMainSearch(item.search)
 
      let statFields = []
      let getCols = (cols) => {
        return cols.filter(col => {
          if (col.blacklist && col.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
            return false
          } else if (col.Hide === 'true') {
            return false
          } else if (col.type === 'action') {
            col.type = 'custom'
          }
          
          if (col.type === 'index') {
            col.field = '$Index'
            col.type = 'text'
          } else if (col.type === 'number') {
            if (col.sum === 'true') {
              statFields.push(col)
            }
            if (typeof(col.decimal) === 'number') {
              col.round = Math.pow(10, col.decimal)
              if (col.format === 'percent') {
                col.decimal = col.decimal > 2 ? col.decimal - 2 : 0
              }
            }
          } else if (col.type === 'colspan') {
            col.subcols = getCols(col.subcols || [])
            if (col.subcols.length === 0) {
              return false
            }
          } else if (col.type === 'custom') {
            col.elements = col.elements.filter(cell => {
              if (cell.eleType === 'button') {
                if (cell.hidden === 'true') return false
          
                cell = this.resetButton(item, cell)
 
                if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                  cell = this.getPrinter(cell, item.uuid)
                }
 
                return skip || permAction[cell.uuid] || cell.permission === 'false'
              } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
                if (!cell.height) {
                  cell.innerHeight = 'auto'
                }
                if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                  cell.round = Math.pow(10, cell.decimal)
                  if (cell.format === 'percent') {
                    cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                  }
                }
              }
 
              if (cell.linkmenu && cell.linkmenu.length > 0) {
                let menu_id = cell.linkmenu.pop()
                cell.linkThdMenu = window.GLOB.mkThdMenus.get(menu_id) || ''
                if (!cell.linkThdMenu) {
                  cell.link = ''
                }
              }
 
              if (cell.marks && cell.marks.length === 0) {
                cell.marks = null
              }
              if (cell.anchors && cell.anchors.length === 0) {
                cell.anchors = null
              }
 
              return true
            })
 
            if (col.elements.length === 0) {
              return false
            }
          }
    
          if (col.linkmenu && col.linkmenu.length > 0) {
            let menu_id = col.linkmenu.pop()
            col.linkThdMenu = window.GLOB.mkThdMenus.get(menu_id) || ''
          } else {
            col.linkThdMenu = ''
          }
 
          if (col.marks && col.marks.length === 0) {
            col.marks = null
          }
 
          return true
        })
      }
      
      item.cols = getCols(item.cols)
      item.statFields = Array.from(new Set(statFields))
 
      // 权限过滤
      if (item.action && item.action.length > 0) {
        item.action = item.action.filter(cell => {
          if (cell.hidden === 'true') return false
 
          cell = this.resetButton(item, cell)
 
          cell.$toolbtn = true
 
          if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
            cell = this.getPrinter(cell, item.uuid)
          }
 
          return skip || permAction[cell.uuid] || cell.permission === 'false'
        })
      }
      
      return true
    })
  }
 
  resetButton = (item, cell) => {
    cell.logLabel = item.$menuname + '-' + cell.label
    cell.Ot = cell.Ot || 'requiredSgl'
    cell.ContainerId = this.state.ContainerId
    cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
    cell.$menuId = item.uuid
    cell.$MenuID = this.props.MenuID
    cell.$view = 'popview'
 
    if (item.$process) {
      cell.$process = true
      cell.$flowId = 'flow' + this.props.MenuID
    }
 
    if (cell.controlField) {
      if (/,/ig.test(cell.controlVal)) {
        cell.controlVals = cell.controlVal.split(',')
      } else {
        cell.controlVals = [(cell.controlVal || '')]
      }
    }
 
    if (cell.OpenType === 'excelOut') { // 导出
      cell.$menuName = item.$menuname
    } else if (cell.OpenType === 'pop' && cell.modal) {
      cell.modal.uuid = cell.uuid + '_pop'
    }
 
    if (cell.verify) {
      if (cell.verify.invalid === 'true') {
        if (item.setting && item.setting.maxScript && item.setting.maxScript >= 300) {
          cell.verify.invalid = 'false'
        } else if (cell.intertype !== 'system' && cell.procMode !== 'system') {
          cell.verify.invalid = 'false'
        } else if (cell.sqlType === 'insert') {
          cell.verify.invalid = 'false'
        } else if (cell.Ot === 'notRequired') {
          cell.verify.invalid = 'false'
        }
      }
 
      if (cell.verify.linkEnable === 'true' && /@/.test(cell.verify.linkUrl)) {
        cell.returnValue = 'true'
      }
 
      if (cell.verify.preHandle === 'true') {
        let script = cell.verify.pre_func
        if (!/#position-/.test(script) || /#position-init/.test(script)) {
          try {
            // eslint-disable-next-line
            let func = new Function('btn', 'position', 'systemType', script)
            func(cell, 'init', window.GLOB.systemType)
          } catch (e) {
            console.warn(e)
          }
        }
        if (/#position-inner/.test(script)) {
          cell.$innerScript = script
 
          if (window.backend && window.GLOB.CacheData.has('sql_' + cell.uuid) && !/\$backend/.test(script)) {
            window.GLOB.CacheData.delete('sql_' + cell.uuid)
          }
        }
        if (/#position-outer/.test(script)) {
          cell.$outerScript = script
        }
        if (/#position-callback/.test(script)) {
          cell.$callbackScript = script
 
          if (window.backend && window.GLOB.CacheData.has('sql_back_' + cell.uuid) && !/\$backend/.test(script)) {
            window.GLOB.CacheData.delete('sql_back_' + cell.uuid)
          }
        }
      }
    }
 
    if (cell.syncComponentId) {
      if (cell.syncComponentId === item.setting.supModule) {
        cell.syncComponentId = ''
        if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
          cell.execSuccess = 'mainline'
        }
      } else if (cell.syncComponentId === 'multiComponent') {
        let ids = cell.syncComponents.map(m => {
          if (Array.isArray(m)) return m.pop() || ''
          return m.syncComId.pop() || ''
        })
 
        if (item.setting.supModule && ids.includes(item.setting.supModule)) {
          if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
            cell.execSuccess = 'mainline'
          }
          ids = ids.filter(id => id !== item.setting.supModule)
        }
        
        if (ids.length === 0) {
          cell.syncComponentId = ''
        } else {
          cell.syncComponentIds = ids
        }
      }
    }
 
    return cell
  }
 
  getPrinter = (item, parentId) => {
    let _item = window.GLOB.UserCacheMap.get(parentId + item.uuid)
 
    item.verify.logLabel = item.logLabel
    
    if (_item) {
      item.printer = _item.printer || ''
      item.verify.defaultPrinter = _item.printer || ''
      if (item.verify.printerTypeList && _item.printerList) {
        item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
          cell.printer = _item.printerList[cell.Value] || ''
 
          return cell
        })
      }
    }
 
    return item
  }
 
  // 格式化默认设置
  formatSetting = (components, regs) => {
    let delay = 20
    return components.map(component => {
      if (component.type === 'tabs') {
        component.subtabs = component.subtabs.map(tab => {
          tab.components = this.formatSetting(tab.components, regs)
          return tab
        })
        return component
      }
 
      component.setting.arr_field = component.columns.map(col => col.field).join(',')
      component.setting.useMSearch = component.setting.useMSearch === 'true'
      if (component.setting.useMSearch) {
        if (!window.GLOB.SearchBox.has(component.$searchId)) {
          component.setting.useMSearch = false
        } else if (window.GLOB.SearchBox.has(component.$searchId + 'required')) {
          component.$s_req = true
        }
      }
 
      if (component.setting.interType !== 'system') { // 不使用系统函数时
        component.setting.sync = 'false'
        component.setting.dataresource = ''
        component.setting.laypage = component.setting.laypage === 'true'
        return component
      }
 
      component.setting.uuid = component.uuid
 
      let _customScript = ''
      let _tailScript = ''
      component.scripts && component.scripts.forEach(script => {
        if (script.status === 'false') return
        if (script.position !== 'back') {
          _customScript += `
          ${script.sql}
          `
        } else {
          _tailScript += `
          ${script.sql}
          `
        }
      })
      delete component.scripts
      component.setting.$name = component.$menuname || ''
      component.setting.execute = component.setting.execute !== 'false'  // 默认sql是否执行,转为boolean 统一格式
      component.setting.laypage = component.setting.laypage === 'true'   // 是否分页,转为boolean 统一格式
 
      if (!component.setting.execute) {
        component.setting.dataresource = ''
      }
  
      if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
        component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
        _tailScript = _tailScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      } else {
        component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _tailScript = _tailScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
      }
 
      regs.forEach(cell => {
        component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value)
        _customScript = _customScript.replace(cell.reg, cell.value)
        _tailScript = _tailScript.replace(cell.reg, cell.value)
      })
 
      component.setting.customScript = _customScript // 整理后自定义脚本
      component.setting.tailScript = _tailScript     // 后置自定义脚本
      component.setting.custompage = false
 
      if (/order\s+by\s+sort_id\s*$/i.test(component.setting.dataresource)) {
        component.setting.custompage = true
      } else if (/@pageSize@|@orderBy@|@mk_total/i.test(component.setting.dataresource + component.setting.customScript)) {
        component.setting.custompage = true
      }
 
      if (/\s/.test(component.setting.dataresource)) {
        component.setting.dataresource = '(' + component.setting.dataresource + ') tb'
      }
 
      if (!component.setting.execute || component.setting.custompage) {
        component.forbidLine = true
      }
      
      component.setting.delay = delay + (component.setting.delay || 0)
      delay += 20
 
      return component
    })
  }
 
  reloadMenuView = (menuId, clear) => {
    const { MenuID } = this.props
 
    if (MenuID !== menuId) return
 
    this.reloadview(clear)
  }
 
  resetActiveMenu = (menuId) => {
    const { MenuID, Tab } = this.props
 
    if (MenuID !== menuId || Tab) return
 
    this.setShortcut()
  }
 
  UNSAFE_componentWillMount () {
    // 组件加载时,获取菜单数据
    this.loadconfig()
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidMount () {
    MKEmitter.addListener('debugChange', this.debugChange)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
  }
 
  /**
   * @description 组件销毁,清除state更新,清除快捷键设置
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('debugChange', this.debugChange)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
 
    window.GLOB.CacheData.delete(this.props.MenuID)
    if (this.state.config) {
      this.deleteCache(this.state.config.components)
    }
  }
 
  debugChange = () => {
    this.setState({visible: !this.state.visible})
  }
 
  deleteCache = (components) => {
    components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          this.deleteCache(tab.components)
        })
      } else {
        window.GLOB.CacheData.delete(item.uuid)
      }
      if (item.type !== 'tabs' && item.$main) {
        window.GLOB.SearchBox.delete(item.$searchId)
      }
    })
  }
 
  reloadview = (clear) => {
    window.GLOB.CacheData.delete(this.props.MenuID)
    if (this.state.config) {
      this.deleteCache(this.state.config.components)
    }
    
    this.setState({
      BID: '',              // 页面跳转时携带ID
      loadingview: true,    // 页面加载中
      viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
      config: null,         // 页面配置信息,包括组件等
      shortcuts: null,
      noParam: clear === true
    }, () => {
      this.loadconfig()
    })
  }
 
  getComponents = () => {
    const { config } = this.state
 
    if (!config || !config.components) return
 
    return config.components.map(item => {
      if (item.type === 'tabs') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvTabs config={item}/>
          </Col>
        )
      } else {
        return (
          <Col span={item.width} key={item.uuid}>
            <MkBaseTable config={item}/>
          </Col>
        )
      }
    })
  }
 
  render() {
    const { loadingview, viewlost, config, shortcuts, autoMatic } = this.state
 
    if (!config || viewlost) {
      return (
        <div className="custom-table-wrap">
          {loadingview ? <Spin className="view-spin" size="large" /> : null}
          {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
          <div className="user-tools">
            {config && config.process === 'true' ? <FlowFloat init={true} config={config}/> : null}
          </div>
        </div>
      )
    }
 
    return (
      <div className="custom-table-wrap" id={this.state.ContainerId} style={config.style}>
        <Row className="component-wrap">{this.getComponents()}</Row>
        {window.GLOB.breakpoint ? <DebugTable /> : null}
        <div className="user-tools">
          {autoMatic ? <AutoMatic autoMatic={autoMatic} tabId={config.MenuID} config={config.components[0]} /> : null}
          {config.process === 'true' ? <FlowFloat config={config}/> : null}
          <SettingComponent config={config} shortcuts={shortcuts || []}/>
          <TableNodes config={config} />
          <DeepSeek/>
        </div>
      </div>
    )
  }
}
 
export default BasePage