king
2023-10-04 ae46c8e640ed64abd7605b289554377e0cdc0cb7
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -6,9 +6,6 @@
import Api from '@/api'
import Utils from '@/utils/utils.js'
import options from '@/store/options.js'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import asyncSpinComponent from '@/utils/asyncSpinComponent'
import { updateForm } from '@/utils/utils-update.js'
import MKEmitter from '@/utils/events.js'
@@ -32,7 +29,6 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    formdata: null,
    selines: null,
@@ -161,7 +157,7 @@
      // 需要选择行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectline'],
        message: '请选择行!',
        duration: 5
      })
      return
@@ -169,13 +165,9 @@
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectSingleLine'],
        message: '请选择单行数据!',
        duration: 5
      })
      return
    } else if (!['requiredSgl', 'notRequired', 'requiredOnce', 'required'].includes(btn.Ot)) {
      // 数据选择类型校验
      this.actionSettingError()
      return
    } else if (!btn.verify || !btn.verify.printMode) {
      notification.warning({
@@ -212,7 +204,7 @@
    } else if (btn.execMode === 'prompt') {
      this.setState({ loading: true })
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: '确定要执行吗?',
        onOk() {
          _this.triggerPrint(data)
        },
@@ -413,7 +405,6 @@
            errorMsg = {
              ErrCode: 'N',
              message: _temp.error,
              ErrMesg: _temp.error,
              status: false
            }
          } else {
@@ -576,7 +567,6 @@
    this.execSuccess({
      ErrCode: '-1',
      message: '',
      ErrMesg: '',
      status: true
    })
@@ -912,6 +902,11 @@
        if (btn.intertype === 'inner') {
          params = params.map(_param => {
            _param.func = btn.innerFunc
            if (btn.recordUser === 'true') {
              _param.username = sessionStorage.getItem('User_Name') || ''
              _param.fullname = sessionStorage.getItem('Full_Name') || ''
            }
  
            return _param
          })
@@ -985,10 +980,15 @@
    let _dataresource = btn.verify.setting.dataresource
    let _customScript = ''
    let _tailScript = ''
    btn.verify.scripts && btn.verify.scripts.forEach(script => {
      if (script.status !== 'false') {
      if (script.status === 'false') return
      if (script.position !== 'back') {
        _customScript += `
        ${script.sql}
        `
      } else {
        _tailScript += `
        ${script.sql}
        `
      }
@@ -998,16 +998,28 @@
      _dataresource = ''
    }
    let isDataM = sessionStorage.getItem('dataM') === 'true'
    let regoptions = [
      { reg: /@ID@/ig, value: `'${ID}'`},
      { reg: /@BID@/ig, value: `'${BID || ''}'`},
      { reg: /@LoginUID@/ig, value: `'${sessionStorage.getItem('LoginUID') || ''}'`},
      { reg: /@SessionUid@/ig, value: `'${localStorage.getItem('SessionUid') || ''}'`},
      { reg: /@UserID@/ig, value: `'${sessionStorage.getItem('UserID') || ''}'`},
      { reg: /@Appkey@/ig, value: `'${window.GLOB.appkey || ''}'`},
      { reg: /@typename@/ig, value: `'admin'`},
      { reg: /\$@/ig, value: isDataM ? '/*' : ''},
      { reg: /@\$/ig, value: isDataM ? '*/' : ''},
      { reg: /@datam@/ig, value: isDataM ? `'Y'` : `''`},
    ]
    regoptions.forEach(item => {
      _dataresource = _dataresource.replace(item.reg, item.value)
      _customScript = _customScript.replace(item.reg, item.value)
      _tailScript = _tailScript.replace(item.reg, item.value)
    })
    if (/\s/.test(_dataresource)) {
      _dataresource = '(' + _dataresource + ') tb'
    }
    if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
      _dataresource = _dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
    } else {
      _dataresource = _dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
      _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
    }
    let initsql = `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)
@@ -1037,7 +1049,7 @@
        _initvars.push(`@${_key}='${form.value}'`)
      }
      if (form.fieldlen && form.fieldlen > 2048) {
      if (form.fieldlen && form.fieldlen > 4000) {
        form.fieldlen = 'max'
      }
@@ -1095,36 +1107,12 @@
        select ${_initvars.join(',')}
      `
    }
    
    if (_customScript) {
      _customScript = `${initsql}
        ${_customScript}
      `
    }
    _dataresource = _dataresource.replace(/@select\$|\$select@/ig, '')
    _customScript = _customScript.replace(/@select\$|\$select@/ig, '')
    _dataresource = _dataresource.replace(/\$sum@/ig, '/*')
    _dataresource = _dataresource.replace(/@sum\$/ig, '*/')
    _customScript = _customScript.replace(/\$sum@/ig, '/*')
    _customScript = _customScript.replace(/@sum\$/ig, '*/')
    _dataresource = _dataresource.replace(/@ID@/ig, `'${ID}'`)
    _customScript = _customScript.replace(/@ID@/ig, `'${ID}'`)
    _dataresource = _dataresource.replace(/@BID@/ig, `'${BID || ''}'`)
    _customScript = _customScript.replace(/@BID@/ig, `'${BID || ''}'`)
    _dataresource = _dataresource.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    _customScript = _customScript.replace(/@LoginUID@/ig, `'${sessionStorage.getItem('LoginUID') || ''}'`)
    _dataresource = _dataresource.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    _customScript = _customScript.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid') || ''}'`)
    _dataresource = _dataresource.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _customScript = _customScript.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID') || ''}'`)
    _dataresource = _dataresource.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _customScript = _customScript.replace(/@Appkey@/ig, `'${window.GLOB.appkey || ''}'`)
    _dataresource = _dataresource.replace(/@typename@/ig, `'admin'`)
    _customScript = _customScript.replace(/@typename@/ig, `'admin'`)
    let LText = ''
@@ -1135,17 +1123,27 @@
    if (_customScript) {
      if (LText) {
        LText = `${LText}
          ${_tailScript}
          aaa:
          if @ErrorCode!=''
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
        `
      } else {
        _customScript = `${_customScript}
          ${_tailScript}
          aaa:
          if @ErrorCode!=''
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
        `
      }
    } else if (_tailScript) {
      LText = `${initsql}
        ${LText}
        ${_tailScript}
        aaa:
        if @ErrorCode!=''
          insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,'${sessionStorage.getItem('UserID') || ''}'
      `
    } else {
      LText = `${initsql}
        ${LText}
@@ -1153,7 +1151,7 @@
    }
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
    if (window.GLOB.debugger === true) {
      _customScript && console.info(`${btn.logLabel ? `/*${btn.logLabel} 自定义脚本*/\n` : ''}${LText ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      LText && console.info(`${btn.logLabel ? `/*${btn.logLabel} 数据源*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
    }
@@ -1167,6 +1165,9 @@
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt('', param.timestamp)
    param.username = userName
    param.fullname = fullName
    if (window.GLOB.probation) {
      param.s_debug_type = 'Y'
@@ -1216,41 +1217,27 @@
      // 外部请求
      _outParam = JSON.parse(JSON.stringify(res))
      if (window.GLOB.mkHS) {
        if (btn.sysInterface === 'true' && options.cloudServiceApi) {
          res.rduri = options.cloudServiceApi
          res.userid = sessionStorage.getItem('CloudUserID') || ''
          res.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
        } else if (btn.sysInterface !== 'true') {
          if (window.GLOB.systemType === 'production' && btn.proInterface) {
            res.rduri = btn.proInterface
          } else {
            res.rduri = btn.interface
          }
      if (btn.sysInterface === 'true') {
        if (window.GLOB.mainSystemApi) {
          res.rduri = window.GLOB.mainSystemApi
        }
      } else {
        if (btn.sysInterface === 'true') {
          if (window.GLOB.mainSystemApi) {
            res.rduri = window.GLOB.mainSystemApi
          }
        } else if (btn.sysInterface === 'external') {
          if (window.GLOB.systemType === 'production') {
            res.$token = btn.exProInterface || ''
          } else {
            res.$token = btn.exInterface || ''
          }
          ver_token = true
      } else if (btn.sysInterface === 'external') {
        if (window.GLOB.systemType === 'production') {
          res.$token = btn.exProInterface || ''
        } else {
          if (window.GLOB.systemType === 'production' && btn.proInterface) {
            res.rduri = btn.proInterface
          } else {
            res.rduri = btn.interface
          }
          res.$token = btn.exInterface || ''
        }
        ver_token = true
      } else {
        if (window.GLOB.systemType === 'production' && btn.proInterface) {
          res.rduri = btn.proInterface
        } else {
          res.rduri = btn.interface
        }
          let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
          if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) {
            res.$login = true
          }
        let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
        if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) {
          res.$login = true
        }
      }
@@ -1262,7 +1249,8 @@
    }).then(response => {
      if (!response || response.ErrCode === 'LoginError') return
      if (ver_token && response.ErrMesg === 'token_error') {
      if (ver_token && response.ErrCode === 'token_error') {
        response.ErrCode = 'E'
        this.execError(response)
        _resolve({next: false, list: []})
      } else if (btn.callbackFunc) {
@@ -1614,7 +1602,7 @@
    Api.postekPrint(param).then(res => {
      if (res.retval === '0') {
        if (params.length === 0) {
          this.execSuccess({ ErrCode: 'S', message: '', ErrMesg: '打印请求已发出。', status: true })
          this.execSuccess({ ErrCode: 'S', message: '打印请求已发出。', status: true })
        } else {
          setTimeout(() => {
            this.loopRFIDPrint(params)
@@ -1733,14 +1721,12 @@
        this.execSuccess({
          ErrCode: '-1',
          message: '未获取到打印信息!',
          ErrMesg: '',
          status: true
        })
      } else {
        this.execError({
          ErrCode: 'N',
          message: '未获取到打印信息!',
          ErrMesg: '',
          status: false
        })
      }
@@ -1770,7 +1756,6 @@
      this.execError({
        ErrCode: 'N',
        message: msg.join(' ; ') + ' !',
        ErrMesg: '',
        status: false
      })
      return
@@ -1783,8 +1768,7 @@
      this.execSuccess({
        ErrCode: 'S',
        message: '',
        ErrMesg: '打印请求已发出。',
        message: '打印请求已发出。',
        status: true
      })
    }
@@ -1795,8 +1779,7 @@
      this.execSuccess({
        ErrCode: 'S',
        message: '',
        ErrMesg: '打印请求已发出。',
        message: '打印请求已发出。',
        status: true
      })
    }
@@ -1811,7 +1794,6 @@
          this.execError({
            ErrCode: 'N',
            message: event.data,
            ErrMesg: '',
            status: false
          })
@@ -1831,8 +1813,7 @@
      //   this.execSuccess({
      //     ErrCode: 'S',
      //     message: '',
      //     ErrMesg: '打印请求已发出。',
      //     message: '打印请求已发出。',
      //     status: true
      //   })
      // } else if (data && data.message && !data.status) {
@@ -1840,7 +1821,6 @@
        this.execError({
          ErrCode: 'N',
          message: data.message,
          ErrMesg: '',
          status: false
        })
      }
@@ -1850,7 +1830,6 @@
      this.execError({
        ErrCode: 'N',
        message: '无法连接到:' + btn.verify.linkUrl,
        ErrMesg: '',
        status: false
      })
    }
@@ -1875,19 +1854,19 @@
   * 4、模态框执行成功后是否关闭
   * 5、通知主列表刷新
   */
  execSuccess = (res) => {
  execSuccess = (res = {}) => {
    const { btn } = this.props
    const { autoMatic, btnconfig } = this.state
    if ((res.ErrCode === 'S' || !res.ErrCode) || autoMatic) { // 执行成功
      notification.success({
        top: 92,
        message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
        message: res.message || '执行成功!',
        duration: btn.verify && btn.verify.stime ? btn.verify.stime : 2
      })
    } else if (res.ErrCode === 'Y') { // 执行成功
      Modal.success({
        title: res.ErrMesg || this.state.dict['main.action.confirm.success']
        title: res.message || '执行成功!'
      })
    } else if (res.ErrCode === '-1') { // 完成后不提示
@@ -1928,25 +1907,29 @@
    const { btn } = this.props
    const { btnconfig, autoMatic } = this.state
    if (!['LoginError', 'C', '-2', 'E', 'N', 'F', 'NM'].includes(res.ErrCode)) {
      res.ErrCode = 'E'
    }
    if (res.ErrCode === 'E' && !autoMatic) {
      Modal.error({
        title: res.message || res.ErrMesg,
        title: res.message || '执行失败!',
      })
    } else if (res.ErrCode === 'N' || autoMatic) {
      notification.error({
        top: 92,
        message: res.message || res.ErrMesg,
        message: res.message || '执行失败!',
        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 || res.ErrMesg,
        message: res.message || '执行失败!',
        duration: btn.verify && btn.verify.ftime ? btn.verify.ftime : 10
      })
    } else if (res.ErrCode === 'NM') {
      message.error(res.message || res.ErrMesg)
      message.error(res.message || '执行失败!')
    }
    
    this.setState({
@@ -1966,17 +1949,6 @@
    if (btn.execError !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
    }
  }
  /**
   * @description 按钮配置信息错误提示
   */
  actionSettingError = () => {
    notification.warning({
      top: 92,
      message: '按钮设置错误!',
      duration: 5
    })
  }
  handleModelConfig = (config) => {
@@ -2173,10 +2145,22 @@
        _item.fieldlen = item.decimal || 0
      } else if (['text', 'textarea', 'linkMain'].includes(_item.type)) {
        _item.value = _item.value + ''
        _item.value = _item.value.replace(/\t*|\v*/g, '')       // 去除制表符
        _item.value = _item.value.replace(/\t+|\v+/g, '')       // 去除制表符
        if (item.interception !== 'false') {                    // 去除首尾空格
          _item.value = _item.value.replace(/(^\s*|\s*$)/g, '')
          if (item.interception === 'func') {
            try {
              // eslint-disable-next-line
              let func = new Function('value', 'data', item.func)
              _item.value = func(_item.value, _data)
              _item.value = _item.value !== undefined ? _item.value : ''
            } catch (e) {
              console.warn(e)
              _item.value = ''
            }
          } else {
            _item.value = _item.value.replace(/(^\s*|\s*$)/g, '')
          }
        }
        if (_item.type === 'text' && /@appkey@|@SessionUid@|@bid@/ig.test(_item.value)) { // 特殊字段替换
          _item.value = _item.value.replace(/^(\s*)@appkey@(\s*)$/ig, window.GLOB.appkey).replace(/^(\s*)@SessionUid@(\s*)$/ig, (localStorage.getItem('SessionUid') || '')).replace(/^(\s*)@bid@(\s*)$/ig, (this.props.BID || ''))
@@ -2220,7 +2204,7 @@
      this.execSubmit(selines, () => {}, result)
    } else {
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: '确定要执行吗?',
        onOk() {
          _this.triggerPrint(selines, result)
        },