king
2025-05-08 b6c698c8833836971184a0a9c2645a15f8174d37
src/tabviews/zshare/actionList/newpagebutton/index.jsx
@@ -1,8 +1,12 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Button, notification, Modal } from 'antd'
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'
@@ -21,8 +25,10 @@
  state = {
    disabled: false,
    loading: false,
    hidden: false,
    visible: false
    visible: false,
    dict: window.GLOB.dict
  }
  UNSAFE_componentWillMount () {
@@ -102,7 +108,7 @@
   */
  actionTrigger = (triggerId, record, type, lid) => {
    const { btn, selectedData, BID, LID } = this.props
    const { disabled } = this.state
    const { disabled, dict } = this.state
    if (disabled) return
    if (triggerId && btn.uuid !== triggerId) return
@@ -114,7 +120,7 @@
      // 需要选择行时,校验数据
      notification.warning({
        top: 92,
        message: window.GLOB.dict['select_row'] || '请选择行!',
        message: dict['select_row'] || '请选择行!',
        duration: 5
      })
      return
@@ -122,14 +128,14 @@
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: window.GLOB.dict['select_single_row'] || '请选择单行数据!',
        message: dict['select_single_row'] || '请选择单行数据!',
        duration: 5
      })
      return
    } else if (btn.pageTemplate === 'custom' && window.GLOB.systemType === 'production' && !btn.proUrl) {
      notification.warning({
        top: 92,
        message: window.GLOB.dict['no_prod_link'] || '尚未设置正式系统链接地址!',
        message: dict['no_prod_link'] || '尚未设置正式系统链接地址!',
        duration: 5
      })
      return
@@ -153,10 +159,7 @@
      lang = data[0].lang_s || ''
    }
    let _name = '新页面'
    if (btn.pageTemplate === 'billprint') {
      _name = '单据打印'
      if (btn.preHandle === 'true' && btn.pre_func) {
        MKEmitter.emit('queryModuleParam', btn.$menuId, (res) => {
          let searches = {}
@@ -215,16 +218,51 @@
      } else {
        if (btn.Ot === 'required') {
          data.forEach(item => {
            let _id = item.$$uuid || ''
            let url = '#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: _id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') })))
            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({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') }))))
          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify(_param))))
        } else {
          window.open('#/billprint/' + window.btoa(window.encodeURIComponent(JSON.stringify({ id: Id, tempId: btn.printTemp, pageId: btn.$MenuID || '', dataM: sessionStorage.getItem('dataM') }))))
          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') {
@@ -234,25 +272,52 @@
      let src = '#/print/' + window.btoa(window.encodeURIComponent(JSON.stringify({ ID: Id, lang })))
      window.open(src)
    } else if (btn.pageTemplate === 'pay') {
      let _p = `ID=${Id}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID')}&logo=${window.GLOB.doclogo}&name=${sessionStorage.getItem('Full_Name')}&icp=${window.GLOB.ICP}&copyRight=${window.GLOB.copyRight}`
      let url = '#/pay/' +  window.btoa(window.encodeURIComponent(_p))
      _name = '支付'
      confirm({
        title: '请在付款页面完成订单支付。',
        content: '',
        className: 'pay-query',
        okText: '支付成功',
        cancelText: '支付遇到问题',
        onOk() {
          // 支付后刷新界面
          MKEmitter.emit('reloadMenuView', btn.$MenuID)
        },
        onCancel() {
          MKEmitter.emit('refreshByButtonResult', btn.$menuId, 'grid', btn)
        },
      })
      window.open(url)
      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') {
@@ -305,13 +370,309 @@
    }
    if (window.GLOB.systemType === 'production') {
      MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: _name})
      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 } = this.state
    const { disabled, hidden, loading } = this.state
    if (hidden) return null
@@ -331,6 +692,7 @@
        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()}}