king
2023-08-17 c7aece35a62b6e91fd98a625bf0e53f64bfbd18d
src/components/normalform/modalform/index.jsx
@@ -13,6 +13,7 @@
const { TextArea } = Input
const MKRadio = asyncComponent(() => import('./mkRadio'))
const MKTable = asyncComponent(() => import('./mkTable'))
const MKCheckbox = asyncComponent(() => import('./mkCheckbox'))
const StyleInput = asyncComponent(() => import('./styleInput'))
const MKFileUpload = asyncComponent(() => import('@/tabviews/zshare/fileupload'))
@@ -44,6 +45,8 @@
      
      item.hidden = false
      if (item.forbid && item.del) return false
      if (item.forbid) {
        item.hidden = true
      }
@@ -56,6 +59,10 @@
          required: item.required,
          message: item.label + '不可为空!'
        }]
        if (item.rules) {
          _rules.push(...item.rules)
        }
        
        item.rules = _rules
      } else if (item.type === 'number') {
@@ -66,13 +73,19 @@
          validator: (rule, value, callback) => this.handleConfirmPassword(rule, value, callback, item)
        }]
      } else if (item.type === 'textarea') {
        let _rules = [
        item.rules = [
          {
            required: item.required,
            message: item.label + '不可为空!'
          }
        ]
        item.rules = _rules
      } else if (item.type === 'table') {
        item.rules = [
          {
            required: item.required,
            message: '请添加' + item.label + '!'
          }
        ]
      } else {
        item.rules = [
          {
@@ -93,8 +106,13 @@
      if (!fieldMap.has(key)) return
      let supItem = fieldMap.get(key)
      let supval = supItem.initval
      if (supItem.initval && supItem.type !== 'checkbox' && JSON.stringify(supItem.initval) === '[]') {
        supval = ''
      }
      let fields = []
      controlFields[key].forEach(item => {
        if (!fieldMap.has(item.field)) return
@@ -102,18 +120,21 @@
        if (cell.hidden) return
        if (supItem.hidden) {
        if (cell.skip && supItem.forbid) { // 上级表单禁用时,此表单不受控制
        } else if (supItem.hidden) {
          cell.hidden = true
        } else if (supItem.type === 'checkbox') {
          let vals = [...supItem.initval, ...item.values]
          let vals = [...supval, ...item.values]
          if (vals.length === new Set(vals).size) {
            cell.hidden = true
          }
        } else if (item.notNull) {
          cell.hidden = !supItem.initval
        } else if (!item.values.includes(supItem.initval)) {
          cell.hidden = !supval
        } else if (!item.values.includes(supval)) {
          cell.hidden = true
        }
        fieldMap.set(item.field, cell)
        fields.push(item)
@@ -157,7 +178,9 @@
  recordChange = (values, item) => {
    this.record = {...this.record, ...values}
    if (item && item.controlFields) {
    if (!item) return
    if (item.controlFields) {
      let map = new Map()
      this.state.formlist.forEach(cell => {
        if (!cell.field) return
@@ -166,6 +189,10 @@
      let reset = (current) => {
        let val = this.record[current.field]
        if (val && current.type !== 'checkbox' && JSON.stringify(val) === '[]') {
          val = ''
        }
        current.controlFields.forEach(cell => {
          let m = map.get(cell.field)
@@ -214,6 +241,24 @@
          return item || cell
        })
      })
    } else if (item.reset_source) {
      let map = new Map()
      this.state.formlist.forEach(cell => {
        if (!cell.field) return
        map.set(cell.field, cell)
      })
      item.callback(map, this.record)
      this.setState({
        formlist: this.state.formlist.map(cell => {
          if (!cell.field) return cell
          let item = map.get(cell.field)
          return item || cell
        })
      })
    }
  }
@@ -246,27 +291,49 @@
      } else if (item.type === 'fileupload') {
        content = (<MKFileUpload config={item} onChange={(val) => this.recordChange({[item.field]: val})} />)
      } else if (item.type === 'cascader') {
        content = (<Cascader allowClear={!!item.allowClear} options={item.options} expandTrigger="hover" placeholder="" />)
        content = (<Cascader allowClear={!!item.allowClear} onChange={(val) => this.recordChange({[item.field]: val}, item)} options={item.options} expandTrigger="hover" placeholder="" />)
      } else if (item.type === 'textarea') {
        content = (<TextArea rows={item.rows || 2} placeholder=""/>)
      } else if (item.type === 'mkicon') {
        content = (<MkEditIcon allowClear={item.allowClear}/>)
      } else if (item.type === 'source') {
        content = (<SourceComponent type="" placement="right"/>)
      } else if (item.type === 'table') {
        content = (<MKTable tip={item.tip || ''} fixed={item.fixed === true} columns={item.columns || []} actions={item.actions || []}/>)
      } else if (item.type === 'hint') {
        fields.push(
          <Col span={24} key={index}>
            <div style={{color: '#1890ff', borderBottom: '1px solid #e9e9e9', marginBottom: '15px', paddingLeft: '10px'}}>{item.label}</div>
          </Col>
        )
        return
      }
      if (!content) return
      fields.push(
        <Col span={item.span || 12} key={index}>
          <Form.Item label={label}>
            {getFieldDecorator(item.field, {
              initialValue: item.initval,
              rules: item.rules
            })(content)}
          </Form.Item>
        </Col>
      )
      if (item.help) {
        fields.push(
          <Col span={item.span || 12} key={index}>
            <Form.Item label={label} help={<span style={{fontSize: '12px'}}>{item.help}</span>}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: item.rules
              })(content)}
            </Form.Item>
          </Col>
        )
      } else {
        fields.push(
          <Col span={item.span || 12} key={index}>
            <Form.Item label={label}>
              {getFieldDecorator(item.field, {
                initialValue: item.initval,
                rules: item.rules
              })(content)}
            </Form.Item>
          </Col>
        )
      }
    })
    
    return fields