king
2023-03-02 d1f19b794216b37417e114b71c1cd7a2ac3d7748
src/tabviews/zshare/mutilform/index.jsx
@@ -35,17 +35,19 @@
    data: PropTypes.any,         // 表格数据
    BID: PropTypes.any,          // 主表ID
    BData: PropTypes.any,        // 主表数据
    unload: PropTypes.any,       // 下拉菜单不加载数据
    inputSubmit: PropTypes.func  // input回车提交
  }
  state = {
    formlist: [],    // 表单项
    ID: ''
  }
  record = {}
  componentDidMount () {
    const { action } = this.props
    const { action, unload } = this.props
    let data = {}
    let BData = {}
@@ -133,6 +135,9 @@
        readin = false
        item.readin = false
        item.hidden = true
      } else if (item.type === 'linkMain') {
        readin = false
        item.readin = false
      } else if (item.type === 'number') {
        item.decimal = item.decimal || 0
        item.fieldlength = item.decimal
@@ -163,23 +168,16 @@
      if (readin && data.hasOwnProperty(key)) {
        newval = data[key]
      }
      if (item.type === 'linkMain') {
        newval = BData[key] || '$empty'
      } else if (item.type === 'date') { // 时间搜索
        let format = 'YYYY-MM-DD'
      if (item.type === 'linkMain' && BData.hasOwnProperty(key)) {
        newval = BData[key]
      } else if (item.type === 'date') { // 时间表单,提交值为天或秒
        let _format = 'YYYY-MM-DD HH:mm:ss'
        if (item.precision === 'day') {
          _format = 'YYYY-MM-DD'
        } else if (item.precision === 'hour') {
          format = 'YYYY-MM-DD HH'
        } else if (item.precision === 'minute') {
          format = 'YYYY-MM-DD HH:mm'
        } else if (item.precision === 'second') {
          format = 'YYYY-MM-DD HH:mm:ss'
        }
        if (newval !== '$empty') {
          newval = moment(newval, format).format(_format)
          newval = moment(newval, 'YYYY-MM-DD HH:mm:ss').format(_format)
          newval = newval === 'Invalid date' ? '$empty' : newval
        }
        if (newval === '$empty' && item.initval) {
@@ -193,18 +191,6 @@
        if (newval === '$empty' && item.initval) {
          newval = moment().subtract(item.initval, 'month').format('YYYY-MM')
        }
      // } else if (item.type === 'datetime') {
      //   if (newval !== '$empty') {
      //     newval = moment(newval, 'YYYY-MM-DD HH:mm:ss').format('YYYY-MM-DD HH:mm:ss')
      //     newval = newval === 'Invalid date' ? '$empty' : newval
      //   }
      //   if (newval === '$empty' && item.initval) {
      //     if (item.initval === '0') {
      //       newval = moment().format('YYYY-MM-DD HH:mm:ss')
      //     } else {
      //       newval = moment().subtract(item.initval, 'days').format('YYYY-MM-DD') + ' 00:00:00'
      //     }
      //   }
      } else if (item.type === 'switch') { // 开关只接收固定值
        if (newval !== '$empty' && (newval === item.closeVal || newval === item.openVal)) {
@@ -221,7 +207,11 @@
        item.initval = ''
      }
      if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && item.resourceType === '1') {
      if (item.type === 'number') {
        if (isNaN(item.initval)) {
          item.initval = 0
        }
      } else if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && item.resourceType === '1') {
        deForms.push(item)
      } else if (item.type === 'rate') {
        item.rateCount = item.rateCount || 5
@@ -244,9 +234,7 @@
      }
      if (item.type === 'text') {
        if (typeof(item.initval) === 'number') {
          item.initval = item.initval + ''
        }
        item.initval = item.initval + ''
        let _rules = [{
          pattern: /^[^']*$/ig,
          message: '不可使用英文状态的单引号!'
@@ -272,39 +260,50 @@
        if (item.regular) {
          if (item.regular === 'number') {
            let reg = /^[0-9.-]*$/
            if (item.regularExtra) {
              reg = new RegExp('^[0-9.-' + item.regularExtra.replace(/\.|-/g, '') + ']*$')
            }
            _rules.push({
              pattern: /^[0-9.-]*$/,
              message: formRule.input.numbermsg
              pattern: reg,
              message: item.regularText || formRule.input.numbermsg
            })
          } else if (item.regular === 'letter') {
            let reg = /^[a-zA-Z]*$/
            if (item.regularExtra) {
              reg = new RegExp('^[a-zA-Z' + item.regularExtra + ']*$')
            }
            _rules.push({
              pattern: /^[a-zA-Z]*$/,
              message: formRule.input.lettermsg
              pattern: reg,
              message: item.regularText || formRule.input.lettermsg
            })
          } else if (item.regular === 'letter_number') {
            let reg = /^[a-zA-Z0-9]*$/
            if (item.regularExtra) {
              reg = new RegExp('^[a-zA-Z0-9' + item.regularExtra + ']*$')
            }
            _rules.push({
              pattern: /^[a-zA-Z0-9]*$/,
              message: '请输入数字或字母'
              pattern: reg,
              message: item.regularText || '请输入数字或字母'
            })
          } else if (item.regular === 'letter&number') {
            let reg = /^[a-zA-Z0-9@_.]*$/
            if (item.regularExtra) {
              reg = new RegExp('^[a-zA-Z0-9@_.' + item.regularExtra.replace(/\.|_|@/g, '') + ']*$')
            }
            _rules.push({
              pattern: /^[a-zA-Z0-9@_.]*$/,
              message: '请输入数字、字母以及@_.'
              pattern: reg,
              message: item.regularText || '请输入数字、字母以及@_.'
            })
          } else if (item.regular === 'phone') {
            _rules.push({
              pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
              message: '请正确输入手机号'
              message: item.regularText || '请正确输入手机号'
            })
          } else if (item.regular === 'email') {
            _rules.push({
              pattern: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/,
              message: '请正确输入邮箱地址'
            })
          } else if (item.regular === 'funcname') {
            _rules.push({
              pattern: /^[\u4E00-\u9FA50-9a-zA-Z_]*$/,
              message: formRule.input.funcname
              pattern: /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/,
              message: item.regularText || '请正确输入邮箱地址'
            })
          }
        }
@@ -508,7 +507,9 @@
    this.record = record
    this.setState({ formlist }, () => {
    this.setState({ formlist, ID: this.props.data ? this.props.data.$$uuid || '' : '' }, () => {
      if (unload) return
      if (action.setting && action.setting.focus && fieldMap.has(action.setting.focus)) {
        setTimeout(() => {
          MKEmitter.emit('mkFC', 'focus', fieldMap.get(action.setting.focus).uuid)
@@ -535,19 +536,36 @@
    let mainItems = []  // 云端或单点数据
    let localItems = [] // 本地数据
    let cache = action.setting.cache !== 'false'
    let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')
    let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
    let _sso = _sql
    deForms.forEach(item => {
      if (item.database === 'sso') {
        mainItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
        let sql = _sso + item.base_sql
        _sso = ''
        sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
        sql = sql.replace(/@BID@/ig, `'${BID}'`)
        if (debug) {
          console.info(sql)
        }
        mainItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`)
      } else {
        localItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
        let sql = _sql + item.base_sql
        _sql = ''
        sql = sql.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
        sql = sql.replace(/@BID@/ig, `'${BID}'`)
        if (debug) {
          console.info(sql)
        }
        localItems.push(`select '${item.field}' as obj_name,'${item.arr_field}' as arr_field,'${window.btoa(window.encodeURIComponent(sql))}' as LText`)
      }
    })
    if (!window.GLOB.mkHS && options.sysType !== 'local') {
      localItems = [...localItems, ...mainItems]
      mainItems = []
    }
    // 本地请求
    let param = {
@@ -555,8 +573,7 @@
      LText: localItems.join(' union all '),
      obj_name: '',
      arr_field: '',
      table_type: 'Y',
      BID: BID || ''
      table_type: 'Y'
    }
    if (param.LText) {
@@ -590,8 +607,7 @@
      LText: mainItems.join(' union all '),
      obj_name: '',
      arr_field: '',
      table_type: 'Y',
      BID: BID || ''
      table_type: 'Y'
    }
    if (mainparam.LText) {
@@ -643,16 +659,25 @@
   */
  improveSimpleActionForm = (deForms) => {
    let cache = this.props.action.setting.cache !== 'false'
    let debug = window.GLOB.debugger === true || (window.debugger === true && options.sysType !== 'cloud')
    let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
    let deffers = deForms.map((form, index) => {
      let param = {
        func: 'sPC_Get_SelectedList',
        LText: form.data_sql,
        LText: _sql + form.base_sql,
        obj_name: form.field,
        arr_field: form.arr_field,
        BID: this.props.BID || ''
        arr_field: form.arr_field
      }
      param.LText = param.LText.replace(/@ID@/ig, `'${this.state.ID || ''}'`)
      param.LText = param.LText.replace(/@BID@/ig, `'${this.props.BID || ''}'`)
      if (debug) {
        console.info(param.LText)
      }
  
      param.LText = Utils.formatOptions(param.LText)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
@@ -699,6 +724,7 @@
      if (['select', 'link', 'radio', 'checkbox', 'checkcard', 'multiselect', 'cascader'].includes(item.type) && result[item.field] && result[item.field].length > 0) {
        let options = []
        let map = new Map()
        let all = false
        result[item.field].forEach(cell => {
          let _cell = { key: Utils.getuuid() , ParentID: ''}
@@ -709,12 +735,26 @@
          if (item.type !== 'checkcard') {
            _cell.value = cell[item.valueField]
            _cell.label = cell[item.valueText] + ''
            if (!_cell.label || map.has(_cell.ParentID + _cell.value)) return
            if (map.has(_cell.ParentID + _cell.value)) return
            if (!_cell.label) {
              if (!all) {
                _cell.label = '全部'
                all = true
              } else {
                return
              }
            }
            
            map.set(_cell.ParentID + _cell.value, 0)
          } else {
            _cell.$value = cell[item.cardValField]
            _cell = {..._cell, ...cell}
            if (item.urlField) {
              _cell.$url = cell[item.urlField] || ''
            } else if (item.colorField) {
              _cell.$color = cell[item.colorField] || ''
            }
            if (map.has(_cell.ParentID + _cell.$value)) return
            
@@ -855,6 +895,7 @@
    formlist.forEach((item, index) => {
      if (item.hidden) return
      if (item.empty === 'hidden' && item.options.length === 0) return
      if (item.type === 'split') {
        fields.push(
@@ -962,7 +1003,6 @@
    
          let _item = {
            type: item.type,
            readonly: item.readonly,
            readin: item.readin,
            writein: item.writein,
            fieldlen: item.fieldlength,
@@ -973,29 +1013,29 @@
    
          if (item.type === 'funcvar') {
            _item.value = ''
          } else if (_item.value && (item.type === 'text' || item.type === 'textarea' || item.type === 'linkMain') && typeof(_item.value) === 'string') {
          } else if (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 === 'true') {           // 去除首尾空格
            if (item.interception !== 'false') {                    // 去除首尾空格
              _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 || ''))
            }
            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.indexOf('date') > -1) {
            if (item.declareType === 'nvarchar(50)') {
              _item.type = 'text'
            }
          } else if (item.declare === 'decimal' && ['select', 'link', 'radio', 'checkcard'].includes(item.type)) {
            _item.type = 'number'
            _item.fieldlen = item.decimal || 0
          }
          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)
            }
          }