king
2025-05-08 b6c698c8833836971184a0a9c2645a15f8174d37
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, notification, Modal, message } from 'antd'
import moment from 'moment'
import md5 from 'md5'
 
import Api from '@/api'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
import './index.scss'
 
const { confirm } = Modal
 
class NewPageButton extends Component {
  static propTpyes = {
    BID: PropTypes.any,               // BID
    BData: PropTypes.any,             // 主表数据
    btn: PropTypes.object,            // 按钮
    selectedData: PropTypes.any,      // 子表中选择数据
    disabled: PropTypes.any,          // 行按钮禁用
    name: PropTypes.any
  }
 
  state = {
    disabled: false,
    loading: false,
    hidden: false,
    visible: false,
    dict: window.GLOB.dict
  }
 
  UNSAFE_componentWillMount () {
    const { btn, selectedData, BData, disabled } = this.props
 
    if (btn.controlField) {
      this.setStatus(btn, selectedData || [], BData, disabled)
    } else if (disabled) {
      this.setState({disabled: true})
    }
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
  }
 
  componentDidMount () {
    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    const { btn } = this.props
 
    if (btn.controlField) {
      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
    } else {
      this.setState({disabled: nextProps.disabled === true})
    }
  }
 
  componentWillUnmount () {
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
  }
 
  setStatus = (btn, data, BData, disprop) => {
    let disabled = false
    let hidden = false
 
    if (btn.control !== 'parent') {
      if (data.length > 0) {
        data.forEach(item => {
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (btn.controlVals.includes(s) || item.$lock) {
            disabled = true
          }
        })
      } else if (btn.controlVals.includes('')) {
        disabled = true
      }
    } else {
      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
        hidden = true
      } else {
        let s = BData[btn.controlField] + ''
        if (btn.controlVals.includes(s)) {
          hidden = true
        }
      }
    }
 
    if (disabled && btn.control === 'hidden') {
      hidden = true
    }
 
    if (disprop) {
      disabled = true
    }
 
    this.setState({hidden, disabled})
  }
  
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record, type, lid) => {
    const { btn, selectedData, BID, LID } = this.props
    const { disabled, dict } = this.state
 
    if (disabled) return
    if (triggerId && btn.uuid !== triggerId) return
    if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
 
    let data = record || selectedData || []
 
    if (btn.Ot !== 'notRequired' && data.length === 0) {
      // 需要选择行时,校验数据
      notification.warning({
        top: 92,
        message: dict['select_row'] || '请选择行!',
        duration: 5
      })
      return
    } else if (btn.Ot === 'requiredSgl' && data.length !== 1) {
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: dict['select_single_row'] || '请选择单行数据!',
        duration: 5
      })
      return
    } else if (btn.pageTemplate === 'custom' && window.GLOB.systemType === 'production' && !btn.proUrl) {
      notification.warning({
        top: 92,
        message: dict['no_prod_link'] || '尚未设置正式系统链接地址!',
        duration: 5
      })
      return
    } else if (!btn.pageTemplate) {
      notification.warning({
        top: 92,
        message: '页面类型设置错误!',
        duration: 5
      })
      return
    }
 
    let Id = ''
    let name = ''
    let MenuNo = ''
    let lang = ''
    if (btn.Ot === 'requiredSgl' && data[0]) {
      Id = data[0].$$uuid || ''
      name = data[0].PrintTempName || ''
      MenuNo = data[0].PrintTempNO || ''
      lang = data[0].lang_s || ''
    }
 
    if (btn.pageTemplate === 'billprint') {
      if (btn.preHandle === 'true' && btn.pre_func) {
        MKEmitter.emit('queryModuleParam', btn.$menuId, (res) => {
          let searches = {}
          res.search && res.search.forEach(item => {
            searches[item.key] = item.value
          })
 
          if (btn.Ot === 'requiredOnce') {
            Id = data.map(item => item.$$uuid).filter(Boolean).join(',')
          }
 
          if (btn.Ot === 'required') {
            data.forEach(item => {
              let _param = { id: item.$$uuid || '', tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
              try {
                // eslint-disable-next-line
                let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func)
                _param = func(btn, searches, [item], _param, window.GLOB.systemType)
              } catch (e) {
                console.warn(e)
              }
 
              if (!_param || _param.error) {
                notification.warning({
                  top: 92,
                  message: _param ? _param.error : '未获取到打印参数,自定义脚本错误!',
                  duration: 5
                })
                return
              }
              
              window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
            })
          } else {
            let _param = { id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
            try {
              // eslint-disable-next-line
              let func = new Function('btn', 'searches', 'data', 'param', 'systemType', btn.pre_func)
              _param = func(btn, searches, data, _param, window.GLOB.systemType)
            } catch (e) {
              console.warn(e)
            }
 
            if (!_param || _param.error) {
              notification.warning({
                top: 92,
                message: _param ? _param.error : '未获取到打印参数,自定义脚本错误!',
                duration: 5
              })
              return
            }
 
            window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
          }
        })
      } else {
        if (btn.Ot === 'required') {
          data.forEach(item => {
            let _param = { id: item.$$uuid || '', tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
 
            Object.keys(item).forEach(key => {
              if (/^\$/.test(key)) return
              if (typeof(item[key]) !== 'string' && typeof(item[key]) !== 'number') return
              if (typeof(item[key]) === 'string' && item[key].length > 50) return
              if (['id', 'tempid', 'pageid', 'datam'].includes(key.toLowerCase())) return
 
              _param[key.toLowerCase()] = item[key]
            })
 
            let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
            window.open(url)
          })
        } else if (btn.Ot === 'requiredOnce') {
          Id = data.map(item => item.$$uuid).filter(Boolean).join(',')
          let _param = { id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
          let item = data[0]
 
          Object.keys(item).forEach(key => {
            if (/^\$/.test(key)) return
            if (typeof(item[key]) !== 'string' && typeof(item[key]) !== 'number') return
            if (typeof(item[key]) === 'string' && item[key].length > 50) return
            if (['id', 'tempid', 'pageid', 'datam'].includes(key.toLowerCase())) return
 
            _param[key.toLowerCase()] = item[key]
          })
  
          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
        } else {
          let _param = { id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM')}
          let item = data[0]
 
          if (item) {
            Object.keys(item).forEach(key => {
              if (/^\$/.test(key)) return
              if (typeof(item[key]) !== 'string' && typeof(item[key]) !== 'number') return
              if (typeof(item[key]) === 'string' && item[key].length > 50) return
              if (['id', 'tempid', 'pageid', 'datam'].includes(key.toLowerCase())) return
  
              _param[key.toLowerCase()] = item[key]
            })
          }
 
          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
        }
      }
    } else if (btn.pageTemplate === 'billprintTemp') {
      let src = '#/menudesign/' + window.btoa(window.encodeURIComponent(JSON.stringify({ MenuType: 'billPrint', MenuId: Id, MenuNo: MenuNo, MenuName: name || '打印', lang })))
      window.open(src)
    } else if (btn.pageTemplate === 'print') {
      let src = '#/print/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, lang })))
      window.open(src)
    } else if (btn.pageTemplate === 'pay') {
      let appId = ''
      let merchId = ''
 
      if (btn.wxApp) {
        appId = btn.wxApp
        if (!window.GLOB.WXApps || window.GLOB.WXApps.findIndex(item => item.appId === btn.wxApp) === -1) {
          notification.warning({
            top: 92,
            message: '按钮关联应用不在可用列表中,请重新保存按钮配置!',
            duration: 5
          })
          return
        }
      }
      if (btn.wxMerch) {
        merchId = btn.wxMerch
        if (!window.GLOB.WXApps || window.GLOB.WXApps.findIndex(item => item.appId === btn.wxMerch) === -1) {
          notification.warning({
            top: 92,
            message: '按钮关联商户不在可用列表中,请重新保存按钮配置!',
            duration: 5
          })
          return
        }
      }
 
      if (btn.payMode === 'system' || btn.payMode === 'inner') {
        this.prequest(Id, data[0] || {}, appId, merchId)
      } else {
        confirm({
          title: '请在付款页面完成订单支付。',
          content: '',
          className: 'pay-query',
          okText: '支付成功',
          cancelText: '支付遇到问题',
          onOk() {
            // 支付后刷新界面
            MKEmitter.emit('reloadMenuView', btn.$MenuID)
          },
          onCancel() {
            MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
          },
        })
 
        window.open('#/pay/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, appId, merchId }))))
      }
    } else if (btn.pageTemplate === 'custom') {
      let url = btn.url
      if (window.GLOB.systemType === 'production') {
        url = btn.proUrl
      }
 
      if (btn.Ot === 'notRequired' && BID) {
        Id = BID
      }
      
      if (/#\/iframe\//.test(url)) {
        url = url.replace(/@loginuid@/ig, sessionStorage.getItem('LoginUID'))
        url = url + '/' + Id
 
        let menu = {
          MenuID: btn.uuid,
          MenuName: btn.label,
          type: 'iframe',
          OpenType: 'newtab',
          src: url
        }
        MKEmitter.emit('modifyTabs', menu)
 
        return
      }
      
      if (btn.joint === 'true') {
        let con = '?'
  
        if (/\?/ig.test(url)) {
          con = '&'
        }
        url = url + `${con}id=${Id}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
      } else if (/@/.test(url)) {
        url = url.replace(/@id@/ig, Id)
        url = url.replace(/@appkey@/ig, window.GLOB.appkey)
        url = url.replace(/@userid@/ig, sessionStorage.getItem('UserID'))
        url = url.replace(/@LoginUID@/ig, sessionStorage.getItem('LoginUID'))
 
        if (btn.Ot === 'requiredSgl' && data[0]) {
          Object.keys(data[0]).forEach(key => {
            if (/^\$/.test(key)) return
            let reg = new RegExp('@' + key + '@', 'ig')
            url = url.replace(reg, data[0][key])
          })
        }
      }
 
      window.open(url)
    }
 
    if (window.GLOB.systemType === 'production') {
      let _temname = {
        billprint: '单据打印',
        pay: '直接执行',
      }
 
      MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: _temname[btn.pageTemplate] || '新页面'})
    }
  }
 
  prequest = (ID, data, appId, merchId) => {
    const { btn, BID } = this.props
 
    let param = null
    if (btn.payMode === 'inner') {
      param = {
        func: btn.innerFunc || '',
        BID: BID || '',
        username: sessionStorage.getItem('User_Name') || '',
        fullname: sessionStorage.getItem('Full_Name') || '',
        dataM: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
        ID: ID
      }
    } else if (window.backend && window.GLOB.CacheData.has('sql_' + btn.uuid)) {
      param = this.getbackParam(ID, data)
    } else {
      let sql = this.getSysDeclareSql(ID, data)
 
      param = {
        func: 'sPC_TableData_InUpDe',
        BID: BID || '',
        exec_type: window.GLOB.execType || 'y',
        timestamp: moment().format('YYYY-MM-DD HH:mm:ss')
      }
 
      param.secretkey = Utils.encrypt('', param.timestamp)
      param.LText = Utils.formatOptions(sql, param.exec_type)
 
      if (btn.output) {
        param.key_back_type = 'Y'
      }
 
      if (window.GLOB.mkHS) { // 函数 sPC_TableData_InUpDe 云端验证
        param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
      }
 
      param.menuname = btn.logLabel
 
      if (window.GLOB.probation) {
        param.s_debug_type = 'Y'
      }
    }
 
    this.setState({loading: true})
    Api.genericInterface(param).then(res => {
      this.setState({loading: false})
      if (res.status) {
        let id = ID
        if (btn.output) {
          id = res.mk_b_id || res[btn.output] || ID
        }
 
        confirm({
          title: '请在付款页面完成订单支付。',
          content: '',
          className: 'pay-query',
          okText: '支付成功',
          cancelText: '支付遇到问题',
          onOk() {
            // 支付后刷新界面
            MKEmitter.emit('reloadMenuView', btn.$MenuID)
          },
          onCancel() {
            MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
          },
        })
 
        window.open('#/pay/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: id, appId, merchId }))))
      } else {
        this.execError(res)
      }
    })
  }
 
  getbackParam = (ID, data) => {
    const { columns, btn, BID } = this.props
 
    let ex = window.GLOB.CacheData.get('sql_' + btn.uuid)
    let exps = []
    let values = {
      time_id: Utils.getguid(),
      roleid: sessionStorage.getItem('role_id') || '',
      mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
      mk_organization: sessionStorage.getItem('organization') || '',
      mk_user_type: sessionStorage.getItem('mk_user_type') || '',
      mk_nation: sessionStorage.getItem('nation') || '',
      mk_province: sessionStorage.getItem('province') || '',
      mk_city: sessionStorage.getItem('city') || '',
      mk_district: sessionStorage.getItem('district') || '',
      mk_address: sessionStorage.getItem('address') || '',
      id: ID || '',
      bid: BID || '',
      typename: 'admin',
      datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
      datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
      datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
    }
  
    if (window.GLOB.externalDatabase !== null) {
      values.db = window.GLOB.externalDatabase
    }
 
    ex.reps.forEach(n => {
      let key = n.toLowerCase()
      if (values.hasOwnProperty(key)) {
        exps.push({
          key: n,
          value: values[key]
        })
      }
    })
 
    let _data = {}
    Object.keys(data).forEach(key => {
      _data[key.toLowerCase()] = data[key]
    })
  
    columns.forEach(col => {
      if (!ex.reps.includes(col.field)) return
      if (!col.datatype) return
 
      let _key = col.field.toLowerCase()
      let _val = _data.hasOwnProperty(_key) ? _data[_key] : ''
 
      if (/^date/ig.test(col.datatype) && !_val) {
        _val = '1949-10-01'
      }
 
      exps.push({
        key: 'mk_' + col.field + '_mk',
        value: _val
      })
    })
 
    let md5_id = ''
    if (window.GLOB.probation) {
      md5_id = md5(ex.id + JSON.stringify(exps) + Math.floor(new Date().getTime() / 600000))
      md5_id = moment().format('YYYYMMDDHHmmss') + md5_id.slice(-18)
    }
 
    return {
      $backend: true,
      $type: 's_TableData_InUpDe',
      data: [{
        id: ex.id,
        menuname: btn.logLabel || '',
        exps: exps,
        md5_id: md5_id
      }]
    }
  }
 
  getSysDeclareSql = (ID, data) => {
    const { columns, btn, BID } = this.props
 
    // 系统变量
    let _vars = ['tbid', 'errorcode', 'retmsg', 'username', 'fullname', 'roleid', 'mk_departmentcode', 'mk_organization', 'mk_user_type', 'mk_nation', 'mk_province', 'mk_city', 'mk_district', 'mk_address', 'bid']
    let _declare = []
    let _initVal = []
  
    let _data = {}
    Object.keys(data).forEach(key => {
      _data[key.toLowerCase()] = data[key]
    })
  
    columns.forEach(col => {
      let _key = col.field.toLowerCase()
 
      if (_vars.includes(_key)) return
 
      _declare.push(`@${_key} ${col.datatype}`)
 
      let _val = _data.hasOwnProperty(_key) ? _data[_key] : ''
 
      if (/^date/ig.test(col.datatype) && !_val) {
        _val = '1949-10-01'
      }
 
      if (/'/.test(_val)) {
        _val = _val.replace(/'/ig, '"')
      }
 
      _initVal.push(`@${_key}='${_val}'`)
    })
  
    // 变量声明
    _declare = _declare.join(',')
    if (_declare) {
      _declare = ',' + _declare
    }
 
    let _sql = `/* 系统生成 */
      Declare @ErrorCode nvarchar(50),@retmsg nvarchar(4000), @UserName nvarchar(50),@FullName nvarchar(50),@RoleID nvarchar(512),@mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20),@mk_nation nvarchar(50),@mk_province nvarchar(50),@mk_city nvarchar(50),@mk_district nvarchar(50),@mk_address nvarchar(100),@bid nvarchar(50),@tbid nvarchar(50)${_declare}
    `
  
    let userName = sessionStorage.getItem('User_Name') || ''
    let fullName = sessionStorage.getItem('Full_Name') || ''
    let RoleID = sessionStorage.getItem('role_id') || ''
    let departmentcode = sessionStorage.getItem('departmentcode') || ''
    let organization = sessionStorage.getItem('organization') || ''
    let mk_user_type = sessionStorage.getItem('mk_user_type') || ''
    let nation = sessionStorage.getItem('nation') || ''
    let province = sessionStorage.getItem('province') || ''
    let city = sessionStorage.getItem('city') || ''
    let district = sessionStorage.getItem('district') || ''
    let address = sessionStorage.getItem('address') || ''
  
    // 初始化凭证及用户信息字段
    _sql += `
      /* 用户信息初始化赋值 */
      select @ErrorCode='',@retmsg='',@UserName='${userName}', @FullName='${fullName}', @RoleID='${RoleID}', @mk_departmentcode='${departmentcode}', @mk_organization='${organization}', @mk_user_type='${mk_user_type}', @mk_nation='${nation}', @mk_province='${province}', @mk_city='${city}', @mk_district='${district}', @mk_address='${address}', @bid='${BID}'
    `
    _sql += `
      /* 显示列变量赋值 */
      select ${_initVal.join(',')}
    `
 
    btn.verify.scripts.forEach(item => {
      if (item.status === 'false') return
 
      _sql += `
      ${item.sql}
      `
    })
 
    if (btn.output) {
      _sql += `
        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg,${btn.output} as mk_b_id`
    } else {
      _sql += `
        aaa: select @ErrorCode as ErrorCode,@retmsg as retmsg`
    }
 
    _sql = _sql.replace(/@ID@/ig, `'${ID || ''}'`)
    _sql = _sql.replace(/@BID@/ig, `'${BID || ''}'`)
    _sql = _sql.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    _sql = _sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    _sql = _sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _sql = _sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _sql = _sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
    _sql = _sql.replace(/@typename@/ig, `'admin'`)
 
    if (window.GLOB.externalDatabase !== null) {
      _sql = _sql.replace(/@db@/ig, window.GLOB.externalDatabase)
    }
 
    if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
      _sql = _sql.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, `'Y'`)
    } else {
      _sql = _sql.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, `''`)
    }
 
    if (window.GLOB.debugger === true) {
      window.mkInfo('%c' + btn.logLabel, 'color: blue')
      window.mkInfo(_sql)
    }
 
    return _sql
  }
 
  execError = (res) => {
    const { btn } = this.props
    const { dict } = this.state
 
    if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) {
      res.ErrCode = 'E'
    }
 
    if (res.ErrCode === 'E') {
      Modal.error({
        title: res.message || dict['exc_fail'] || '执行失败!',
        okText: dict['got_it'] || '知道了'
      })
    } else if (res.ErrCode === 'N') {
      notification.error({
        top: 92,
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
      })
    } else if (res.ErrCode === 'F') {
      notification.error({
        className: 'notification-custom-error',
        top: 92,
        message: res.message || dict['exc_fail'] || '执行失败!',
        duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || dict['exc_fail'] || '执行失败!')
    }
  }
 
  render() {
    const { btn, name } = this.props
    const { disabled, hidden, loading } = this.state
 
    if (hidden) return null
 
    let label = ''
 
    if (btn.show === 'link') {
      label = <span>{name || btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
    } else if (btn.show === 'icon') {
      label = <MkIcon type={btn.icon} />
    } else {
      label = <span>{btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{name || btn.label}</span>
    }
 
    return (
      <Button
        type="link"
        id={'button' + btn.uuid}
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
        style={btn.style || null}
        loading={loading}
        disabled={disabled}
        className={btn.hover || ''}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
    )
  }
}
 
export default NewPageButton