king
2024-05-16 b69b5f6329ca5f87932436b7a6c1ddfc3377e10f
src/tabviews/zshare/actionList/printbutton/index.jsx
@@ -130,12 +130,13 @@
  /**
   * @description 触发按钮操作
   */
  actionTrigger = (triggerId, record, type) => {
    const { BID, btn, selectedData, setting } = this.props
  actionTrigger = (triggerId, record, type, lid) => {
    const { BID, btn, selectedData, setting, LID } = this.props
    const { loading, disabled } = 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({
@@ -143,8 +144,6 @@
        message: '需要上级主键值!',
        duration: 5
      })
      return
    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
      return
    }
@@ -270,6 +269,9 @@
            Object.keys(cell).forEach(key => {
              let _key = key.toLowerCase()
              if (/^\$/.test(_key)) return
              _cell[_key] = cell[key]
            })
@@ -564,16 +566,28 @@
  execCustomPrint = (printlist, formdata) => {
    const { btn } = this.props
    this.execSuccess({
      ErrCode: '-1',
      message: '',
      status: true
    })
    let callback = null
    if (/callback\(\)/.test(btn.verify.printFunc)) {
      callback = () => {
        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', btn.verify.printFunc)
      func(printlist, formdata, btn.verify, notification, Api, window.GLOB.systemType, callback)
      // 自定义打印示例
      // let defaultPrinter = printer.defaultPrinter || 'lackprinter'
@@ -769,18 +783,11 @@
    } 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: '自定义函数执行错误!',
        duration: 5
      })
    }
  }
@@ -907,6 +914,9 @@
              _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
          })
@@ -954,7 +964,7 @@
    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
    }
@@ -999,7 +1009,11 @@
    }
    let isDataM = sessionStorage.getItem('dataM') === 'true'
    let custompage = /@pageSize@|@orderBy@/i.test(_dataresource + _customScript + _tailScript)
    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') || ''}'`},
@@ -1117,7 +1131,11 @@
    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) {
@@ -1160,8 +1178,8 @@
      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)
@@ -1761,26 +1779,35 @@
      return
    }
    if (printerList.length === 0) {
      this.execSuccess({
        ErrCode: '-1',
        message: '未获取到打印信息!',
        status: true
      })
      return
    }
    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: '打印请求已发出。',
        status: true
      this.syncMessageSend(printerList, () => {
        this.execSuccess({
          ErrCode: 'S',
          message: '打印请求已发出。',
          status: true
        })
      })
    }
    // 打开Socket
    socket.onopen = () =>{
      this.syncMessageSend(printerList)
      this.execSuccess({
        ErrCode: 'S',
        message: '打印请求已发出。',
        status: true
      this.syncMessageSend(printerList, () => {
        this.execSuccess({
          ErrCode: 'S',
          message: '打印请求已发出。',
          status: true
        })
      })
    }
    // 监听消息
@@ -1835,17 +1862,26 @@
    }
  }
  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导出,成功后取消导出按钮加载中状态
@@ -1941,6 +1977,8 @@
      MKEmitter.emit('autoExecOver', btn.uuid, 'error')
      return
    }
    if (res.ErrCode === '-2') return
    if (btnconfig && btnconfig.setting && btnconfig.setting.errFocus) {
      MKEmitter.emit('mkFC', 'focus', btnconfig.setting.errFocus)
@@ -2148,7 +2186,33 @@
        _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 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' && /@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 || ''))
@@ -2226,6 +2290,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}
@@ -2296,39 +2367,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>