king
2025-05-23 24842b40de5cd60700bf69dfd38a0332f5431e36
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -6,11 +6,9 @@
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 UtilsDM from '@/utils/utils-datamanage.js'
import MKEmitter from '@/utils/events.js'
import MkIcon from '@/components/mk-icon'
// import './index.scss'
@@ -32,7 +30,6 @@
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    visible: false,
    formdata: null,
    selines: null,
@@ -41,7 +38,8 @@
    loading: false,
    disabled: false,
    hidden: false,
    autoMatic: false
    autoMatic: false,
    dict: window.GLOB.dict
  }
  UNSAFE_componentWillMount () {
@@ -94,7 +92,7 @@
      if (data.length > 0) {
        data.forEach(item => {
          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
          if (btn.controlVals.includes(s)) {
          if (btn.controlVals.includes(s) || item.$lock) {
            disabled = true
          }
        })
@@ -134,34 +132,33 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record, type) => {
    const { BID, btn, selectedData, setting } = this.props
    const { loading, disabled } = this.state
  actionTrigger = (triggerId, record, type, lid) => {
    const { BID, btn, selectedData, setting, LID } = this.props
    const { loading, disabled, dict } = this.state
    if (loading || disabled) return
    if (triggerId && btn.uuid !== triggerId) return
    if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
    if (setting.supModule && !BID) {
      notification.warning({
        top: 92,
        message: '需要上级主键值!',
        message: setting.supModTip || dict['sup_key_req'] || '需要上级主键值!',
        duration: 5
      })
      return
    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
      return
    }
    this.setState({autoMatic: type === 'autoMatic'})
    let _this = this
    let that = this
    let data = record || selectedData || []
    if (btn.Ot !== 'notRequired' && data.length === 0) {
      // 需要选择行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectline'],
        message: dict['select_row'] || '请选择行!',
        duration: 5
      })
      return
@@ -169,25 +166,7 @@
      // 需要选择单行时,校验数据
      notification.warning({
        top: 92,
        message: this.state.dict['main.action.confirm.selectSingleLine'],
        duration: 5
      })
      return
    } else if (!['requiredSgl', 'notRequired', 'requiredOnce', 'required'].includes(btn.Ot)) {
      // 数据选择类型校验
      this.actionSettingError()
      return
    } else if (!btn.verify || !btn.verify.printMode) {
      notification.warning({
        top: 92,
        message: '请完善打印验证信息!',
        duration: 5
      })
      return
    } else if (btn.intertype === 'system' && btn.verify.dataType === 'custom' && (!btn.verify.setting || btn.verify.columns.length === 0)) {
      notification.warning({
        top: 92,
        message: '自定义打印数据请设置数据源!',
        message: dict['select_single_row'] || '请选择单行数据!',
        duration: 5
      })
      return
@@ -201,6 +180,7 @@
      let modal = this.state.btnconfig
      if (!modal && btn.modal) {
        modal = this.handleModelConfig(btn.modal)
        modal.uuid = btn.uuid
      }
      this.setState({
@@ -212,12 +192,14 @@
    } else if (btn.execMode === 'prompt') {
      this.setState({ loading: true })
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: dict['exec_sure'] || '确定要执行吗?',
        okText: dict['ok'] || '确定',
        cancelText: dict['cancel'] || '取消',
        onOk() {
          _this.triggerPrint(data)
          that.triggerPrint(data)
        },
        onCancel() {
          _this.setState({ loading: false })
          that.setState({ loading: false })
        }
      })
    } else {
@@ -278,6 +260,9 @@
            Object.keys(cell).forEach(key => {
              let _key = key.toLowerCase()
              if (/^\$/.test(_key)) return
              _cell[_key] = cell[key]
            })
@@ -413,7 +398,6 @@
            errorMsg = {
              ErrCode: 'N',
              message: _temp.error,
              ErrMesg: _temp.error,
              status: false
            }
          } else {
@@ -514,7 +498,7 @@
      if (list.length === 0) {
        notification.warning({
          top: 92,
          message: '未获取到打印数据!',
          message: window.GLOB.dict['no_data'] || '未获取到打印数据!',
          duration: 5
        })
        return false
@@ -533,7 +517,7 @@
      return Api.getSystemCacheConfig(param)
    }).then(result => {
      if (!result) {
      if (!result || result.ErrCode === 'LoginError') {
        this.setState({ loading: false })
        return
      }
@@ -541,7 +525,7 @@
      if (!result.ConfigParam) {
        notification.warning({
          top: 92,
          message: '未获取到打印模板信息!',
          message: window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!',
          duration: 5
        })
        this.setState({ loading: false })
@@ -573,17 +557,66 @@
  execCustomPrint = (printlist, formdata) => {
    const { btn } = this.props
    this.execSuccess({
      ErrCode: '-1',
      message: '',
      ErrMesg: '',
      status: true
    })
    let callback = null
    let printReject = null
    let skip = false
    let send = false
    let data = fromJS({
      data: printlist,
      form: formdata
    }).toJS()
    if (!window.GLOB.errorLog) {
      printReject = (msg) => {
        if (send) return
        send = true
        data.message = msg
        window.mkInfo(JSON.stringify(data))
      }
    } else {
      printReject = (msg) => {
        if (send) return
        send = true
        data.message = msg
        let param = {
          func: 's_special_error_note_log',
          api_url: btn.logLabel,
          error_code: 507,
          error_time: moment().format('YYYY-MM-DD HH:mm:ss'),
          api_param: JSON.stringify(data)
        }
        Api.genericInterface(param)
      }
    }
    if (/callback\(\)/.test(btn.verify.printFunc)) {
      callback = () => {
        if (skip) return
        skip = true
        this.execSuccess({
          ErrCode: '-1',
          message: '',
          status: true
        })
      }
    } else {
      this.execSuccess({
        ErrCode: '-1',
        message: '',
        status: true
      })
    }
    try {
      // eslint-disable-next-line
      let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', btn.verify.printFunc)
      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
      let func = new Function('data', 'form', 'printer', 'notification', 'Api', 'systemType', 'callback', 'printReject', btn.verify.printFunc)
      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback, printReject)
      // 自定义打印示例
      // let defaultPrinter = printer.defaultPrinter || 'lackprinter'
@@ -779,18 +812,13 @@
    } catch (e) {
      console.warn(e)
      try {
        // eslint-disable-next-line
        let evalfunc = eval('(true && function (data, form, printer, notification, Api, systemType) {' + btn.verify.printFunc + '})')
        evalfunc(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType)
      } catch (error) {
        console.warn(error)
        notification.warning({
          top: 92,
          message: '自定义函数执行错误!',
          duration: 5
        })
      }
      notification.warning({
        top: 92,
        message: window.GLOB.dict['func_error'] || '自定义函数执行错误!',
        duration: 5
      })
      printReject(window.GLOB.dict['func_error'] || '自定义函数执行错误!')
    }
  }
@@ -912,6 +940,14 @@
        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') || ''
            }
            if (btn.dataM === 'true') {
              _param.dataM = sessionStorage.getItem('dataM') === 'true' ? 'Y' : ''
            }
  
            return _param
          })
@@ -928,7 +964,7 @@
          Promise.all(deffers).then(result => {
            let errorMsg = ''
            result.forEach(res => {
              if (!res.status) {
              if (!res.status && !errorMsg) {
                errorMsg = res
              }
            })
@@ -954,12 +990,71 @@
  getDefaultSql = (formlist, data, ID) => {
    const { BID, btn, columns } = this.props
    if (window.backend && window.GLOB.CacheData.has('sql_' + btn.uuid)) {
      let setting = {...btn.verify.setting}
      setting.interType = 'system'
      setting.uuid = btn.uuid
      let _param = UtilsDM.getQueryDataParams(setting, [], setting.order, 1, 9999, BID, ID)
      let item = window.GLOB.CacheData.get('sql_' + btn.uuid)
      _param.data[0].exps = _param.data[0].exps.filter(n => n.key !== 'mk_search')
      let formkeys = []
      formlist.forEach(form => {
        if (!item.reps.includes(form.key)) return
        formkeys.push(form.key)
        let val = form.value
        if (form.type === 'number' || form.type === 'rate') {
          if (isNaN(val) || val === '') {
            val = 0
          }
        } else if (['date', 'datemonth'].includes(form.type)) {
          val = val || '1949-10-01'
        }
        _param.data[0].exps.push({
          key: 'mk_' + form.key + '_mk',
          value: val
        })
      })
      if (data && columns && columns.length > 0) {
        let datavars = {}
        Object.keys(data).forEach(key => {
          datavars[key.toLowerCase()] = data[key]
        })
        columns.forEach(col => {
          if (!item.reps.includes(col.field) || formkeys.includes(col.field)) return
          if (!col.datatype) return
          let _key = col.field.toLowerCase()
          let _val = datavars.hasOwnProperty(_key) ? datavars[_key] : ''
          if (/^date/ig.test(col.datatype) && !_val) {
            _val = '1949-10-01'
          }
          _param.data[0].exps.push({
            key: 'mk_' + col.field + '_mk',
            value: _val
          })
        })
      }
      return _param
    }
    let arrFields = btn.verify.columns.map(col => col.field).join(',')
    let param = {
      func: 'sPC_Get_TableData',
      obj_name: 'data',
      exec_type: 'y',
      exec_type: window.GLOB.execType || 'y',
      arr_field: arrFields,
      default_sql: btn.verify.setting.defaultSql
    }
@@ -985,10 +1080,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,18 +1098,40 @@
      _dataresource = ''
    }
    let custompage = false
    if (/order\s+by\s+sort_id\s*$/i.test(_dataresource)) {
      custompage = true
    } else if (/@pageSize@|@orderBy@|@mk_total/i.test(_dataresource + _customScript + _tailScript)) {
      custompage = true
    }
    let isDataM = sessionStorage.getItem('dataM') === 'true'
    let regoptions = [
      { reg: /@orderBy@/ig, value: btn.verify.setting.order },
      { reg: /@pageSize@/ig, value: '9999' },
      { reg: /@pageIndex@/ig, value: '1'},
      { 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: /@lang@/ig, value: `'${sessionStorage.getItem('lang')}'`},
      { 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(/@datam@/ig, '\'Y\'')
      _dataresource = _dataresource.replace(/@\$/ig, '*/')
      _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
      _customScript = _customScript.replace(/@\$/ig, '*/')
    } 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)
@@ -1023,13 +1145,11 @@
    formlist.forEach(form => {
      let _key = form.key.toLowerCase()
      if (_vars.includes(_key)) return
      _vars.push(_key)
      if (form.type === 'number' || form.type === 'rate') {
        let val = form.value
        if (isNaN(val)) {
        if (isNaN(val) || val === '') {
          val = 0
        }
        _initvars.push(`@${_key}=${val}`)
@@ -1039,7 +1159,7 @@
        _initvars.push(`@${_key}='${form.value}'`)
      }
      if (form.fieldlen && form.fieldlen > 2048) {
      if (form.fieldlen && form.fieldlen > 4000) {
        form.fieldlen = 'max'
      }
@@ -1097,7 +1217,6 @@
        select ${_initvars.join(',')}
      `
    }
    
    if (_customScript) {
      _customScript = `${initsql}
@@ -1105,49 +1224,40 @@
      `
    }
    _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 = ''
    if (_dataresource) {
      LText = `/*system_query*/select ${arrFields} from (select ${arrFields} ,ROW_NUMBER() over(order by ${btn.verify.setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
      if (custompage) {
        LText = `/*system_query*/select ${arrFields} from ${_dataresource} `
      } else {
        LText = `/*system_query*/select ${arrFields} from (select ${arrFields} ,ROW_NUMBER() over(order by ${btn.verify.setting.order}) as rows from ${_dataresource}) tmptable order by tmptable.rows `
      }
    }
    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}
@@ -1155,20 +1265,23 @@
    }
    // 测试系统打印查询语句
    if (window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')) {
      _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'))
    if (window.GLOB.debugger === true) {
      _customScript && window.mkInfo(`${btn.logLabel ? `/*${btn.logLabel} 自定义脚本*/\n` : ''}${LText ? '' : '/*不执行默认sql*/\n'}${_customScript}`)
      LText && window.mkInfo(`${btn.logLabel ? `/*${btn.logLabel} 数据源*/\n` : ''}` + LText.replace(/\n\s{8}/ig, '\n'))
    }
    if (btn.logLabel) {
      param.menuname = btn.logLabel
    }
    param.custom_script = Utils.formatOptions(_customScript)
    param.LText = Utils.formatOptions(LText)
    param.custom_script = Utils.formatOptions(_customScript, param.exec_type)
    param.LText = Utils.formatOptions(LText, param.exec_type)
    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'
@@ -1183,6 +1296,7 @@
  printOuterLoopRequest = (params, btn, _list, _resolve) => {
    let param = params.shift()
    let _outParam = null
    let ver_token = false
    new Promise(resolve => {
      // 内部请求
@@ -1217,40 +1331,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 || ''
          }
      } 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
        }
      }
@@ -1260,9 +1361,13 @@
      return Api.genericInterface(res)
    }).then(response => {
      if (!response) return
      if (!response || response.ErrCode === 'LoginError') return
      if (btn.callbackFunc) {
      if (ver_token && response.ErrCode === 'token_error') {
        response.ErrCode = 'E'
        this.execError(response)
        _resolve({next: false, list: []})
      } else if (btn.callbackFunc) {
        // 存在回调函数时,调用
        delete response.message
        delete response.status
@@ -1286,7 +1391,7 @@
        _resolve({next: false, list: []})
      }
    }).then(response => {
      if (!response) return
      if (!response || response.ErrCode === 'LoginError') return
      if (response.status) {
        _list.push(response)
@@ -1335,7 +1440,7 @@
    let imgs = []
    if (!res.ConfigParam) {
      error = '未获取到打印模板信息!'
      error = window.GLOB.dict['no_print_temp'] || '未获取到打印模板信息!'
    } else {
      try {
        configParam = JSON.parse(window.decodeURIComponent(window.atob(res.ConfigParam)))
@@ -1436,8 +1541,13 @@
          if (item.Field) {
            fields.push(item.Field)
            // 条码二维码字段不可为空
            if (item.Type === 'qrcode' || item.Type === 'barcode') {
            if (item.Type === 'barcode') {
              nonEFields.push(item.Field)
            }
          } else if (!item.Value) {
            // 条码二维码内容不可为空
            if (item.Type === 'barcode') {
              error = '模板中条码/二维码内容不可为空!'
            }
          }
@@ -1492,7 +1602,7 @@
    if (list.length === 0) {
      notification.warning({
        top: 92,
        message: '未获取到打印数据!',
        message: window.GLOB.dict['no_data'] || '未获取到打印数据!',
        duration: 5
      })
      this.setState({ loading: false })
@@ -1611,7 +1721,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: window.GLOB.dict['print_out'] || '打印请求已发出。', status: true })
        } else {
          setTimeout(() => {
            this.loopRFIDPrint(params)
@@ -1629,6 +1739,43 @@
  execPrint = (list, template) => {
    const { btn } = this.props
    const { dict } = this.state
    let printReject = null
    let send = false
    let data = fromJS({
      data: list,
      template: template
    }).toJS()
    if (!window.GLOB.errorLog) {
      printReject = (msg) => {
        if (send) return
        send = true
        data.message = msg
        window.mkInfo(JSON.stringify(data))
      }
    } else {
      printReject = (msg) => {
        if (send) return
        send = true
        data.message = msg
        let param = {
          func: 's_special_error_note_log',
          api_url: btn.logLabel,
          error_code: 507,
          error_time: moment().format('YYYY-MM-DD HH:mm:ss'),
          api_param: JSON.stringify(data)
        }
        Api.genericInterface(param)
      }
    }
    let _errors = []
    let defaultPrinter = btn.verify.defaultPrinter || 'lackprinter'
@@ -1729,15 +1876,13 @@
      if (btn.verify.emptyTip === 'false') {
        this.execSuccess({
          ErrCode: '-1',
          message: '未获取到打印信息!',
          ErrMesg: '',
          message: dict['no_data'] || '未获取到打印信息!',
          status: true
        })
      } else {
        this.execError({
          ErrCode: 'N',
          message: '未获取到打印信息!',
          ErrMesg: '',
          message: dict['no_data'] || '未获取到打印信息!',
          status: false
        })
      }
@@ -1751,7 +1896,7 @@
          lackerror.push(`数据中未获取到模板(${err.title})${err.lacks.join('、')} 字段`)
        }
        if (err.emptys.length > 0) {
          emptyerror.push(`数据中模板(${err.title}) ${err.emptys.join('、')} 字段不可为空`)
          emptyerror.push(dict['not_empty'] ? `${err.title}: ${err.emptys.join('、')} ${dict['not_empty']}` : `数据中模板(${err.title}) ${err.emptys.join('、')} 字段不可为空`)
        }
      })
@@ -1767,8 +1912,16 @@
      this.execError({
        ErrCode: 'N',
        message: msg.join(' ; ') + ' !',
        ErrMesg: '',
        status: false
      })
      return
    }
    if (printerList.length === 0) {
      this.execSuccess({
        ErrCode: '-1',
        message: dict['no_data'] || '未获取到打印信息!',
        status: true
      })
      return
    }
@@ -1776,25 +1929,23 @@
    if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + btn.verify.linkUrl) {
      socket = new WebSocket('ws://' + btn.verify.linkUrl)
    } else {
      this.syncMessageSend(printerList)
      this.execSuccess({
        ErrCode: 'S',
        message: '',
        ErrMesg: '打印请求已发出。',
        status: true
      this.syncMessageSend(printerList, () => {
        this.execSuccess({
          ErrCode: 'S',
          message: dict['print_out'] || '打印请求已发出。',
          status: true
        })
      })
    }
    // 打开Socket
    socket.onopen = () =>{
      this.syncMessageSend(printerList)
      this.execSuccess({
        ErrCode: 'S',
        message: '',
        ErrMesg: '打印请求已发出。',
        status: true
      this.syncMessageSend(printerList, () => {
        this.execSuccess({
          ErrCode: 'S',
          message: dict['print_out'] || '打印请求已发出。',
          status: true
        })
      })
    }
    // 监听消息
@@ -1808,7 +1959,6 @@
          this.execError({
            ErrCode: 'N',
            message: event.data,
            ErrMesg: '',
            status: false
          })
@@ -1828,8 +1978,7 @@
      //   this.execSuccess({
      //     ErrCode: 'S',
      //     message: '',
      //     ErrMesg: '打印请求已发出。',
      //     message: '打印请求已发出。',
      //     status: true
      //   })
      // } else if (data && data.message && !data.status) {
@@ -1837,33 +1986,42 @@
        this.execError({
          ErrCode: 'N',
          message: data.message,
          ErrMesg: '',
          status: false
        })
        printReject(data.message)
      }
    }
    socket.onerror = () => {
      this.execError({
        ErrCode: 'N',
        message: '无法连接到:' + btn.verify.linkUrl,
        ErrMesg: '',
        message: (dict['un_connect'] || '无法连接到') + ':' + btn.verify.linkUrl,
        status: false
      })
    }
  }
  syncMessageSend = (list) => {
  syncMessageSend = (list, callback) => {
    let param = list.shift()
    if (socket && param) {
      socket.send(JSON.stringify(param))
    if (socket) {
      try {
        socket.send(JSON.stringify(param))
      } catch(e) {
        console.warn('打印请求发送失败!')
      }
    }
    if (list && list.length > 0) {
      setTimeout(() => {this.syncMessageSend(list)}, 3000)
    if (list.length > 0) {
      setTimeout(() => {
        this.syncMessageSend(list, callback)
      }, 3000)
    } else {
      callback()
    }
  }
  /**
   * @description 操作成功后处理
   * 1、excel导出,成功后取消导出按钮加载中状态
@@ -1872,19 +2030,20 @@
   * 4、模态框执行成功后是否关闭
   * 5、通知主列表刷新
   */
  execSuccess = (res) => {
  execSuccess = (res = {}) => {
    const { btn } = this.props
    const { autoMatic, btnconfig } = this.state
    const { autoMatic, btnconfig, dict } = 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 || dict['exc_success'] || '执行成功!',
        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 || dict['exc_success'] || '执行成功!',
        okText: dict['got_it'] || '知道了'
      })
    } else if (res.ErrCode === '-1') { // 完成后不提示
@@ -1909,6 +2068,10 @@
    if (btn.execSuccess !== 'never') {
      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines)
    }
    if (btn.execSuccess === 'popclose' && btn.$tabId) { // 标签关闭刷新
      MKEmitter.emit('refreshPopButton', btn.$tabId)
    }
  }
  /**
@@ -1919,27 +2082,32 @@
   */
  execError = (res) => {
    const { btn } = this.props
    const { btnconfig, autoMatic } = this.state
    const { btnconfig, autoMatic, dict } = 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 || dict['exc_fail'] || '执行失败!',
        okText: dict['got_it'] || '知道了'
      })
    } else if (res.ErrCode === 'N' || autoMatic) {
      notification.error({
        top: 92,
        message: res.message || res.ErrMesg,
        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 || res.ErrMesg,
        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 || res.ErrMesg)
      message.error(res.message || dict['exc_fail'] || '执行失败!')
    }
    
    this.setState({
@@ -1952,6 +2120,8 @@
      return
    }
    if (res.ErrCode === '-2') return
    if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) {
      MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus)
    }
@@ -1959,17 +2129,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) => {
@@ -2055,6 +2214,7 @@
        } else {
          _LongParam = updateForm(_LongParam)
          _LongParam = this.handleModelConfig(_LongParam)
          _LongParam.uuid = btn.uuid
          this.setState({
            btnconfig: _LongParam
@@ -2096,8 +2256,8 @@
  }
  modelconfirm = () => {
    const { btnconfig, selines } = this.state
    let _this = this
    const { btnconfig, selines, dict } = this.state
    let that = this
    let result = []
    let _data = {}
    let BData = {}
@@ -2115,82 +2275,147 @@
    
    btnconfig.fields.forEach(item => {
      if (!item.field) return
      let _readin = item.readin !== 'false'
      let _initval = item.initval
      if (item.type === 'linkMain' || item.type === 'funcvar') {
      let _item = {
        key: item.field,
        readin: item.readin !== 'false' && item.readin !== 'top',
        fieldlen: item.fieldlength || 50,
        writein: item.writein !== 'false',
        type: item.type,
        value: item.initval,
        isconst: item.constant === 'true'
      }
      let key = item.field.toLowerCase()
      let _readin = item.readin !== 'false'
      if (item.type === 'linkMain' && item.verifyVal === 'true') {
        _item.$verify = true
        _item.label = item.label
      }
      if (_item.type === 'date') { // 时间兼容
        _item.precision = item.precision || 'day'
      } else if (_item.type === 'datetime') {
        _item.type = 'date'
        _item.precision = 'second'
      } else if (['funcvar', 'linkMain'].includes(_item.type)) {
        _readin = false
      } else if (['select', 'link', 'radio'].includes(item.type)) { // 选中第一项
        if (typeof(_initval) === 'string' && _initval.indexOf('$first') > -1) {
          _initval = ''
        _item.readin = false
      } else if (['select', 'link', 'radio'].includes(_item.type)) { // 选中第一项
        if (/^\s*\$first\s*$/.test(_item.value)) {
          _item.value = ''
          if (item.resourceType === '0' && item.options[0] && item.options[0].Value) {
            _initval = item.options[0].Value
            _item.value = item.options[0].Value
          }
        }
      }
      if (item.type === 'linkMain' && BData.hasOwnProperty(item.field.toLowerCase())) {
        _initval = BData[item.field.toLowerCase()]
      } else if (_readin && _data.hasOwnProperty(item.field.toLowerCase())) {
        _initval = _data[item.field.toLowerCase()]
      } else if (item.type === 'date' && _initval) {
        _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD')
      } else if (item.type === 'datemonth' && _initval) {
        _initval = moment().subtract(_initval, 'month').format('YYYY-MM')
      } else if (item.type === 'datetime' && _initval) {
        _initval = moment().subtract(_initval, 'days').format('YYYY-MM-DD HH:mm:ss')
      if (_item.type === 'funcvar') {
        _item.value = ''
      } else if (_item.type === 'linkMain' && BData.hasOwnProperty(key)) {
        _item.value = BData[key]
      } else if (_readin && _data.hasOwnProperty(key)) {
        _item.value = _data[key]
      } else if (_item.type === 'date' && _item.value) {
        _item.value = moment().subtract(_item.value, 'days').format(_item.precision === 'day' ? 'YYYY-MM-DD' : 'YYYY-MM-DD HH:mm:ss')
      } else if (_item.type === 'datemonth' && _item.value) {
        _item.value = moment().subtract(_item.value, 'month').format('YYYY-MM')
      }
      let _fieldlen = item.fieldlength || 50
      if (item.type === 'textarea' || item.type === 'fileupload' || item.type === 'multiselect') {
        _fieldlen = item.fieldlength || 512
      } else if (item.type === 'number') {
        _fieldlen = item.decimal ? item.decimal : 0
      } else if (item.type === 'rate') {
        item.rateCount = item.rateCount || 5
        let allowHalf = item.allowHalf === 'true'
      _item.value = _item.value === undefined ? '' : _item.value
        if (allowHalf) {
          _initval = parseFloat(_initval)
          if (_initval % 0.5 !== 0) {
            _initval = parseInt(_initval)
      if (_item.type === 'number' || item.declare === 'decimal') {
        _item.type = 'number'
        _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, '')       // 去除制表符
        if (item.interception !== 'false') {                    // 去除首尾空格
          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 if (item.interception === 'charTure') {
            let str = _item.value.replace(/(^\s*|\s*$)/g, '')
            let result = ''
            for (let i = 0 ; i < str.length; i++) {
              let code = str.charCodeAt(i)
              if (code >= 65281 && code <= 65373) {
                result += String.fromCharCode(str.charCodeAt(i) - 65248)
              } else if (code === 12288) {
                result += String.fromCharCode(str.charCodeAt(i) - 12288 + 32)
              } else {
                result += str.charAt(i)
              }
            }
            _item.value = result
          } else {
            _item.value = _item.value.replace(/(^\s*|\s*$)/g, '')
          }
        }
        if (_item.type === 'text') {
          if (/@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 || ''))
          }
          if (/@currentYear@/ig.test(_item.value)) { // 系统变量替换
            _item.value = _item.value.replace(/@currentYear@/ig, moment().format('YYYY'))
          }
        }
        if (_item.type === 'text' && item.lenControl && item.lenControl !== 'limit') {
          if (item.lenControl === 'left') {
            _item.value = _item.value.substr(0, item.fieldlength)
          } else {
            _item.value = _item.value.slice(-item.fieldlength)
          }
        }
      } else if (_item.type === 'datemonth') {
        _item.type = 'text'
      } else  if (_item.type === 'date') {
        _item.type = item.declareType === 'nvarchar(50)' ? 'text' : 'date'
      } else if (_item.type === 'switch' || _item.type === 'check') {
        if (_readin) {
          _item.value = _item.value === item.openVal ? item.openVal : item.closeVal
        } else {
          _initval = parseInt(_initval)
          if (item.initval === true) {
            _item.value = item.openVal
          } else {
            _item.value = item.closeVal
          }
        }
      } else if (_item.type === 'rate') {
        let count = item.rateCount || 5
        _item.value = parseInt(_item.value)
        if (isNaN(_initval) || _initval < 0) {
          _initval = 0
        } else if (_initval > item.rateCount) {
          _initval = item.rateCount
        if (isNaN(_item.value) || _item.value < 0) {
          _item.value = 0
        } else if (_item.value > count) {
          _item.value = count
        }
      }
      if (_initval === undefined) {
        _initval = ''
      }
      result.push({
        key: item.field,
        readonly: item.readonly === 'true',
        readin: item.readin !== 'false' && item.readin !== 'top',
        fieldlen: _fieldlen,
        type: item.type,
        value: _initval
      })
      result.push(_item)
    })
    if (btnconfig.setting.display === 'exec') {
      this.execSubmit(selines, () => {}, result)
    } else {
      confirm({
        title: this.state.dict['main.action.confirm.tip'],
        title: dict['exec_sure'] || '确定要执行吗?',
        okText: dict['ok'] || '确定',
        cancelText: dict['cancel'] || '取消',
        onOk() {
          _this.triggerPrint(selines, result)
          that.triggerPrint(selines, result)
        },
        onCancel() {
          _this.setState({ loading: false })
          that.setState({ loading: false })
        }
      })
    }
@@ -2201,7 +2426,7 @@
   */
  getModels = () => {
    const { BID, btn } = this.props
    const { btnconfig } = this.state
    const { btnconfig, dict } = this.state
    if (!this.state.visible || !btnconfig || !btnconfig.setting) return null
@@ -2219,6 +2444,13 @@
      clickouter = true
    }
    if (btnconfig.setting.icon) {
      title = <>
        <span className={'mk-modal-icon-' + btnconfig.setting.iconType} style={{background: btnconfig.setting.iconColor || 'unset', color: btnconfig.setting.iconColor || 'inherit'}}><MkIcon type={btnconfig.setting.icon}/></span>
        {title}
      </>
    }
    return (
      <Modal
        title={title}
@@ -2228,6 +2460,8 @@
        visible={this.state.visible}
        confirmLoading={this.state.confirmLoading}
        width={width}
        okText={dict['ok'] || '确定'}
        cancelText={dict['cancel'] || '取消'}
        maskStyle={btnconfig.setting.moveable === 'true' ?  {backgroundColor: 'rgba(0, 0, 0, 0.15)'} : null}
        onOk={this.handleOk}
        onCancel={this.handleCancel}
@@ -2235,7 +2469,6 @@
      >
        <MutilForm
          BID={BID}
          dict={this.state.dict}
          action={btnconfig}
          inputSubmit={this.handleOk}
          data={this.state.selines[0]}
@@ -2290,38 +2523,24 @@
    if (hidden) return null
    let label = ''
    let icon = ''
    let type = 'link'
    let className = ''
    if (btn.show === 'button') {
      label = btn.label
      icon = btn.icon || ''
    } else if (btn.show === 'link') {
      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
      icon = ''
    if (btn.show === 'link') {
      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
    } else if (btn.show === 'icon') {
      icon = btn.icon || ''
    } else if (!btn.$toolbtn) {
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
      label = !loading ? <MkIcon type={btn.icon} /> : null
    } else {
      type = ''
      icon = btn.icon || ''
      label = btn.label
      className = 'mk-btn mk-' + btn.class
      label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span>
    }
    return <>
      <Button
        type={type}
        type="link"
        id={'button' + btn.uuid}
        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
        loading={loading}
        disabled={disabled}
        style={btn.style || null}
        icon={icon}
        className={className}
        className={btn.hover || ''}
        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
      >{label}</Button>
      <span onClick={(e) => {e.stopPropagation()}}>{this.getModels()}</span>