king
2022-08-02 8d66ff34fae5b048a6b7923cc75d34f13a08be9d
src/menu/components/form/simple-form/index.jsx
copy from src/menu/components/form/normal-form/index.jsx copy to src/menu/components/form/simple-form/index.jsx
File was copied from src/menu/components/form/normal-form/index.jsx
@@ -18,12 +18,12 @@
import './index.scss'
const ModalForm = asyncComponent(() => import('@/templates/zshare/modalform'))
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
const SettingComponent = asyncIconComponent(() => import('@/menu/datasource'))
const NormalForm = asyncIconComponent(() => import('@/components/normalform'))
const CardComponent = asyncComponent(() => import('@/templates/modalconfig/dragelement'))
const MobCardComponent = asyncComponent(() => import('@/mob/components/formdragelement'))
const FormTitle = asyncComponent(() => import('../dragtitle'))
const FormAction = asyncComponent(() => import('../formaction'))
const NormalHeader = asyncComponent(() => import('@/menu/components/share/normalheader'))
const CopyComponent = asyncIconComponent(() => import('@/menu/components/share/copycomponent'))
const PasteComponent = asyncIconComponent(() => import('@/menu/components/share/pastecomponent'))
const UserComponent = asyncIconComponent(() => import('@/menu/components/share/usercomponent'))
@@ -31,7 +31,7 @@
const { confirm } = Modal
class PropCardEditComponent extends Component {
class SimpleFormComponent extends Component {
  static propTpyes = {
    card: PropTypes.object,
    deletecomponent: PropTypes.func,
@@ -43,7 +43,6 @@
    appType: sessionStorage.getItem('appType'),
    card: null,
    back: false,
    group: null,
    showField: false,
    visible: false,
    editform: null,
@@ -68,20 +67,18 @@
        width: card.width || 24,
        name: card.name,
        subtype: card.subtype,
        setting: { },
        wrap: { name: card.name, width: card.width || 24, datatype: 'static', groupLabel: 'show', color: '#1890ff' },
        setting: { interType: 'system' },
        wrap: { name: card.name, width: card.width || 24, datatype: 'static' },
        style: { marginLeft: '0px', marginRight: '0px', marginTop: '8px', marginBottom: '8px' },
        headerStyle: { fontSize: '16px', borderBottomWidth: '1px', borderBottomColor: '#e8e8e8' },
        columns: [],
        scripts: [],
        subcards: [{
          uuid: Utils.getuuid(),
          setting: {title: '第一步', align: 'left_right'},
          sort: 1,
          setting: {title: '空', align: 'left_right', enable: 'true'},
          style: {},
          fields: [],
          prevButton: {label: '上一步', type: 'prev', enable: 'false', style: {marginRight: '15px', paddingTop: '5px', paddingBottom: '5px'}},
          subButton: {label: '提交', type: 'submit', enable: 'true', style: {backgroundColor: '#1890ff', color: '#ffffff', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px'}},
          nextButton: {label: '跳过', type: 'next', enable: 'false', style: {paddingTop: '5px', paddingBottom: '5px'}}
          subButton: {label: '提交', type: 'submit', intertype: 'system', reload: 'false', sqlType: 'update', sql: '', Ot: 'notRequired', execSuccess: 'never', enable: 'true', style: {backgroundColor: '#1890ff', color: '#ffffff', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px'}},
        }]
      }
@@ -105,16 +102,11 @@
          return scard
        })
      }
      this.setState({
        card: _card,
        group: _card.subcards[0] || null
      })
      this.props.updateConfig(_card)
      this.updateComponent(_card)
    } else {
      let _card = fromJS(card).toJS()
      this.setState({
        card: _card,
        group: _card.subcards[0] || null
        card: _card
      })
    }
  }
@@ -159,15 +151,55 @@
  /**
   * @description 卡片行外层信息更新(数据源,样式等)
   */
  updateComponent = (component) => {
  updateComponent = (card) => {
    card.width = card.wrap.width
    card.name = card.wrap.name
    card.errors = []
    if (card.wrap.datatype !== 'static') {
      if (card.setting.interType === 'system' && card.setting.execute !== 'false' && !card.setting.dataresource) {
        card.errors.push({ level: 0, detail: '未设置数据源!'})
      } else if (card.setting.interType === 'system' && card.setting.execute === 'false' && card.scripts.filter(script => script.status !== 'false').length === 0) {
        card.errors.push({ level: 0, detail: '数据源中无可用脚本!'})
      } else if (!card.setting.primaryKey) {
        card.errors.push({ level: 0, detail: '未设置主键!'})
      } else if (!card.setting.supModule) {
        card.errors.push({ level: 0, detail: '未设置上级组件!'})
      }
      let supModule = card.setting.supModule ? card.setting.supModule[card.setting.supModule.length - 1] || '' : ''
      if (supModule === 'empty') {
        supModule = ''
      }
      let columns = card.columns.map(c => c.field)
      let lowcols = card.columns.map(c => c.field.toLowerCase())
      card.subcards.forEach(item => {
        item.fields.forEach(m => {
          if (m.type === 'linkMain' && !supModule) {
            card.errors.push({ level: 1, detail: `关联主表表单“${m.label}”无效`})
          } else if (m.field && !columns.includes(m.field) && lowcols.includes(m.field.toLowerCase())) {
            card.errors.push({ level: 1, detail: `表单“${m.label}”大小写与字段集不一致`})
          }
        })
      })
    } else {
      let supModule = card.wrap.supModule ? card.wrap.supModule[card.wrap.supModule.length - 1] : ''
      card.subcards.forEach(item => {
        item.fields.forEach(m => {
          if (m.type === 'linkMain' && !supModule) {
            card.errors.push({ level: 1, detail: `关联主表表单“${m.label}”无效`})
          }
        })
      })
    }
    this.setState({
      card: component
      card: card
    })
    component.width = component.wrap.width
    component.name = component.wrap.name
    this.props.updateConfig(component)
    this.props.updateConfig(card)
  }
  /**
@@ -181,9 +213,7 @@
      return item
    })
    this.setState({card})
    this.props.updateConfig(card)
    this.updateComponent(card)
  }
  changeStyle = () => {
@@ -193,18 +223,18 @@
  }
  getStyle = (comIds, style) => {
    const { card, group } = this.state
    const { card } = this.state
    if (comIds[0] === 'form') {
      let Index = group.fields.findIndex(n => n.uuid === comIds[1])
      let Index = card.subcards[0].fields.findIndex(n => n.uuid === comIds[1])
      if (Index === -1) return
      
      let _group = fromJS(group).toJS()
      let _card = fromJS(card).toJS()
      _group.fields[Index].style = style
      _card.subcards[0].fields[Index].style = style
      this.updateGroup(_group)
      this.updateComponent(_card)
      return
    }
@@ -213,107 +243,32 @@
    let _card = {...card, style}
    this.setState({
      card: _card
    })
    this.props.updateConfig(_card)
    this.updateComponent(_card)
  }
  addCard = () => {
  updateGroup = (res) => {
    let card = fromJS(this.state.card).toJS()
    let newcard = {
      uuid: Utils.getuuid(),
      setting: { title: `第${card.subcards.length + 1}步`, align: 'left_right' },
      sort: card.subcards.length + 1,
      style: {},
      fields: [],
      prevButton: {label: '上一步', type: 'prev', enable: 'false', style: {marginRight: '15px', paddingTop: '5px', paddingBottom: '5px'}},
      subButton: {label: '提交', type: 'submit', enable: 'true', style: {backgroundColor: '#1890ff', color: '#ffffff', paddingLeft: '25px', paddingRight: '25px', paddingTop: '5px', paddingBottom: '5px'}},
      nextButton: {label: '跳过', type: 'next', enable: 'false', style: {paddingTop: '5px', paddingBottom: '5px'}}
    }
    card.subcards[0] = res
    card.subcards.push(newcard)
    this.setState({
      card,
      group: newcard
    })
    this.props.updateConfig(card)
  }
  changecards = (list) => {
    let card = fromJS(this.state.card).toJS()
    card.subcards = list.map((item, index) => {
      item.sort = index + 1
      return item
    })
    this.setState({card})
    this.props.updateConfig(card)
  }
  selectGroup = (item) => {
    this.setState({
      group: item
    })
  }
  changeGroup = (item) => {
    this.updateGroup(item)
  }
  closeGroup = (cell) => {
    const { group } = this.state
    let card = fromJS(this.state.card).toJS()
    const _this = this
    confirm({
      content: '确定删除分组吗?',
      onOk() {
        card.subcards = card.subcards.filter(item => item.uuid !== cell.uuid)
        let _group = group
        if (group.uuid === cell.uuid) {
          _group = card.subcards[0] || null
        }
        _this.setState({card, group: _group})
        _this.props.updateConfig(card)
      },
      onCancel() {}
    })
  }
  updateGroup = (group) => {
    let card = fromJS(this.state.card).toJS()
    card.subcards = card.subcards.map(item => {
      if (item.uuid === group.uuid) {
        return group
      }
      return item
    })
    this.setState({card, group})
    this.props.updateConfig(card)
    this.updateComponent(card)
  }
  plusFields = (items) => {
    let _group = fromJS(this.state.group).toJS()
    const { card } = this.state
    _group.fields.push(...items)
    let _card = fromJS(card).toJS()
    this.updateGroup(_group)
    _card.subcards[0].fields.push(...items)
    this.updateComponent(_card)
  }
  changecols = (type) => {
    let card = fromJS(this.state.card).toJS()
    let config = fromJS(this.state.group).toJS()
    let _this = this
    config.fields = config.fields.map(item => {
    card.subcards[0].fields = card.subcards[0].fields.map(item => {
      item.labelwidth = 33.3
      item.span = 24
      if (['textarea','split','hint','checkcard','brafteditor'].includes(item.type)) {
@@ -337,59 +292,35 @@
    confirm({
      content: `确定切换为${type}列吗?`,
      onOk() {
        card.subcards = card.subcards.map(item => {
          if (item.uuid === config.uuid) {
            return config
          }
          return item
        })
        _this.setState({group: config, card})
        _this.props.updateConfig(card)
        _this.updateComponent(card)
      },
      onCancel() {}
    })
  }
  handleList = (list, newcard) => {
    let group = fromJS(this.state.group).toJS()
    let card = fromJS(this.state.card).toJS()
    group.fields = list
    card.subcards[0].fields = list
    card.subcards = card.subcards.map(item => {
      if (item.uuid === group.uuid) {
        return group
      }
      return item
    })
    this.setState({card, group}, () => {
    this.setState({}, () => {
      if (newcard) {
        this.handleForm(newcard)
      }
    })
    this.props.updateConfig(card)
    this.updateComponent(card)
  }
  closeForm = (cell) => {
    let group = fromJS(this.state.group).toJS()
    let card = fromJS(this.state.card).toJS()
    let _this = this
    group.fields = group.fields.filter(item => item.uuid !== cell.uuid)
    card.subcards = card.subcards.map(item => {
      if (item.uuid === group.uuid) {
        return group
      }
      return item
    })
    card.subcards[0].fields = card.subcards[0].fields.filter(item => item.uuid !== cell.uuid)
    confirm({
      content: `确定删除<<${cell.label}>>吗?`,
      onOk() {
        _this.setState({card, group})
        _this.props.updateConfig(card)
        _this.updateComponent(card)
      },
      onCancel() {}
    })
@@ -397,8 +328,8 @@
  addForm = () => {
    const { appType } = this.state
    let group = fromJS(this.state.group).toJS()
    let lastItem = group.fields[group.fields.length - 1]
    let card = fromJS(this.state.card).toJS()
    let lastItem = card.subcards[0].fields[card.subcards[0].fields.length - 1]
    let span = appType === 'mob' ? 24 : 12
    if (lastItem && lastItem.span) {
      span = lastItem.span
@@ -422,26 +353,25 @@
      focus: true
    }
    group.fields.push(newcard)
    card.subcards[0].fields.push(newcard)
    this.setState({group}, () => {
    this.setState({card}, () => {
      this.handleForm(newcard)
    })
  }
  editModalCancel = () => {
    let group = fromJS(this.state.group).toJS()
    group.fields = group.fields.filter(item => !item.focus)
    let card = fromJS(this.state.card).toJS()
    card.subcards[0].fields = card.subcards[0].fields.filter(item => !item.focus)
    this.setState({group, visible: false, editform: null})
    this.updateGroup(group)
    this.setState({card, visible: false, editform: null})
  }
  /**
   * @description 表单编辑
   */
  handleForm = (_item) => {
    const { card, group, appType } = this.state
    const { card, appType } = this.state
    let _form = fromJS(_item).toJS()
    let _inputfields = []
    let _tabfields = []
@@ -456,7 +386,7 @@
    let _inputIndex = 1
    let _tabIndex = 1
    let _linkIndex = 1
    group.fields.forEach((item, i) => {
    card.subcards[0].fields.forEach((item, i) => {
      if (_form.uuid === item.uuid) {
        index = i
      }
@@ -473,8 +403,7 @@
        })
        _inputIndex++
      }
      if (_item.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) {
      if (_form.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type)) {
        _tabfields.push({
          field: item.field,
          label: _tabIndex + '、' + label
@@ -495,13 +424,14 @@
        uniq.set(item.field, true)
        _linkableFields.push({
          field: item.field,
          label: _linkIndex + '、' + item.label + ' (表单)'
          value: item.field,
          text: _linkIndex + '、' + item.label + ' (表单)'
        })
        _linksupFields.push({
          field: item.field,
          label: _linkIndex + '、' + label
          value: item.field,
          text: _linkIndex + '、' + label
        })
        _linkIndex++
      }
    })
@@ -510,9 +440,9 @@
    if (index !== null) {
      if (index === 0) {
        standardform = group.fields[index + 1] || null
        standardform = card.subcards[0].fields[index + 1] || null
      } else {
        standardform = group.fields[index - 1] || null
        standardform = card.subcards[0].fields[index - 1] || null
      }
    }
@@ -554,10 +484,10 @@
   */
  handleSubmit = () => {
    this.formRef.handleConfirm().then(res => {
      let _config = fromJS(this.state.group).toJS()
      let _config = fromJS(this.state.card).toJS()
      let fieldrepet = false // 字段重复
      _config.fields = _config.fields.map(item => {
      _config.subcards[0].fields = _config.subcards[0].fields.map(item => {
        if (item.uuid !== res.uuid && res.field && item.field && item.field.toLowerCase() === res.field.toLowerCase()) {
          fieldrepet = true
        }
@@ -592,10 +522,10 @@
          LText: res.dataSource
        }
        param.LText = param.LText.replace(/@\$|\$@/ig, '')
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.LText = param.LText.replace(/@\$|\$@/ig, '').replace(/@(BID|ID|LoginUID|SessionUid|UserID|Appkey|time_id)@/ig, `'${param.timestamp}'`)
        
        param.LText = Utils.formatOptions(param.LText)
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
        param.secretkey = Utils.encrypt('', param.timestamp)
        if (window.GLOB.mainSystemApi && res.database === 'sso') {
@@ -609,7 +539,7 @@
              editform: null,
              visible: false
            })
            this.updateGroup(_config)
            this.updateComponent(_config)
          } else {
            this.setState({sqlVerifing: false})
            
@@ -623,16 +553,48 @@
          editform: null,
          visible: false
        })
        this.updateGroup(_config)
        this.updateComponent(_config)
      }
    })
  }
  pasteForm = (res) => {
    let _config = fromJS(this.state.group).toJS()
    let _config = fromJS(this.state.card).toJS()
    if (res.subButton) {
      let _this = this
      _config.subcards[0].setting.focus = res.focus
      _config.subcards[0].setting.cache = res.cache
      _config.subcards[0].setting.align = res.align
      _config.subcards[0].setting.enable = res.enable
      _config.subcards[0].setting.verticalSpace = res.verticalSpace || ''
      _config.wrap.focus = res.focus
      _config.wrap.cache = res.cache
      _config.wrap.align = res.align
      _config.wrap.enable = res.enable
      _config.wrap.verticalSpace = res.verticalSpace || ''
      _config.subcards[0].subButton = res.subButton
      _config.subcards[0].fields = res.fields.map(item => {
        item.uuid = Utils.getuuid()
        return item
      })
      confirm({
        content: `替换表单及按钮配置?`,
        onOk() {
          _this.updateComponent(_config)
        },
        onCancel() {}
      })
      return
    }
    let fieldrepet = false // 字段重复
    _config.fields.forEach(item => {
    _config.subcards[0].fields.forEach(item => {
      if (res.field && item.field && item.field.toLowerCase() === res.field.toLowerCase()) {
        fieldrepet = true
      }
@@ -646,9 +608,9 @@
      })
      return
    }
    _config.fields.push(res)
    _config.subcards[0].fields.push(res)
    this.updateGroup(_config)
    this.updateComponent(_config)
    this.handleForm(res)
@@ -664,7 +626,38 @@
  }
  updateWrap = (res) => {
    this.updateComponent({...this.state.card, wrap: res})
    let _card = {...this.state.card, wrap: res}
    if (res.datatype === 'static') {
      if (res.supModule && res.supModule.length > 0) {
        _card.setting.supModule = res.supModule
      } else {
        _card.setting.supModule = ''
      }
    }
    _card.subcards[0].setting.focus = _card.wrap.focus
    _card.subcards[0].setting.cache = _card.wrap.cache
    _card.subcards[0].setting.align = _card.wrap.align
    _card.subcards[0].setting.enable = _card.wrap.enable
    _card.subcards[0].setting.verticalSpace = _card.wrap.verticalSpace
    this.updateComponent(_card)
  }
  clearGroup = () => {
    let card = fromJS(this.state.card).toJS()
    let _this = this
    card.subcards[0].fields = []
    confirm({
      content: `确定清空表单吗?`,
      onOk() {
        _this.updateComponent(card)
      },
      onCancel() {}
    })
  }
  clickComponent = (e) => {
@@ -675,18 +668,18 @@
  }
  render() {
    const { card, dict, group, appType } = this.state
    const { card, dict, appType } = this.state
    return (
      <div className="menu-normal-form-edit-box" style={resetStyle(card.style)} onClick={this.clickComponent} id={card.uuid}>
      <div className="menu-simple-form-edit-box" style={resetStyle(card.style)} onClick={this.clickComponent} id={card.uuid}>
        <NormalHeader config={card} updateComponent={this.updateComponent}/>
        <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
          <div className="mk-popover-control">
            <PlusOutlined className="plus" title="添加分组" onClick={this.addCard}/>
            <NormalForm title="表单设置" width={800} update={this.updateWrap} getForms={this.getWrapForms}>
              <EditOutlined style={{color: '#1890ff'}} title="编辑"/>
            </NormalForm>
            <CopyComponent type="stepform" card={card}/>
            <PasteComponent config={card} options={['form']} updateConfig={this.pasteForm} />
            <CopyComponent type="simpleform" card={card}/>
            <PasteComponent config={card} options={['form', 'formgroup']} updateConfig={this.pasteForm} />
            <FontColorsOutlined className="style" title="调整样式" onClick={this.changeStyle}/>
            <UserComponent config={card}/>
            <DeleteOutlined className="close" title="删除组件" onClick={() => this.props.deletecomponent(card.uuid)} />
@@ -696,17 +689,10 @@
        } trigger="hover">
          <ToolOutlined />
        </Popover>
        <FormTitle
          list={card.subcards}
          selectId={group ? group.uuid : ''}
          handleList={this.changecards}
          handleGroup={this.changeGroup}
          closeGroup={this.closeGroup}
          selectGroup={this.selectGroup}
        />
        {group ? <div className="form-area">
        <div className="form-area">
          <PlusOutlined className="plus" title="添加表单" onClick={this.addForm}/>
          <FieldsComponent config={group} type="form" plusFields={this.plusFields} />
          <FieldsComponent config={card.subcards[0]} type="form" plusFields={this.plusFields} />
          <span style={{color: 'red', marginLeft: '30px', cursor: 'pointer'}} onClick={this.clearGroup}>清空</span>
          <Switch checkedChildren={dict['model.switch.open']} unCheckedChildren={dict['model.switch.close']} defaultChecked={this.state.showField} onChange={(val) => this.setState({showField: val})} />
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(1)}>1列</Button> : null}
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(2)}>2列</Button> : null}
@@ -714,24 +700,37 @@
          {appType !== 'mob' ? <Button className="mk-cols-change" onClick={() => this.changecols(4)}>4列</Button> : null}
          <div style={{clear: 'both'}}></div>
          {appType !== 'mob' ? <CardComponent
            list={group.fields}
            setting={group.setting}
            list={card.subcards[0].fields}
            setting={card.subcards[0].setting}
            showField={this.state.showField}
            placeholder={dict['header.form.modal.placeholder']}
            handleList={this.handleList}
            handleForm={this.handleForm}
            closeForm={this.closeForm}
          /> : <MobCardComponent
            list={group.fields}
            setting={group.setting}
            list={card.subcards[0].fields}
            setting={card.subcards[0].setting}
            showField={this.state.showField}
            handleList={this.handleList}
            handleForm={this.handleForm}
            closeForm={this.closeForm}
          />}
          <FormAction config={card} group={group} updateconfig={this.updateGroup}/>
        </div> : null}
        <div className="component-name"><div className="center">{card.name}</div></div>
          <FormAction config={card} group={card.subcards[0]} updateconfig={this.updateGroup}/>
        </div>
        <div className="component-name">
          <div className="center">
            <div className="title">{card.name}</div>
            <div className="content">
              {card.errors && card.errors.map((err, index) => {
                if (err.level === 0) {
                  return <span key={index} className="error">{err.detail}</span>
                } else {
                  return <span key={index} className="waring">{err.detail};</span>
                }
              })}
            </div>
          </div>
        </div>
        <Modal
          title={this.state.dict['model.edit']}
          visible={this.state.visible}
@@ -756,4 +755,4 @@
  }
}
export default PropCardEditComponent
export default SimpleFormComponent