king
2021-12-30 09e0de52a398dd08a0dc3f4b43e4589d211e9c27
src/mob/searchconfig/index.jsx
@@ -4,7 +4,8 @@
import { DndProvider } from 'react-dnd'
import HTML5Backend from 'react-dnd-html5-backend'
import moment from 'moment'
import { Button, Modal, Collapse, notification, Switch, Icon } from 'antd'
import { Button, Modal, Collapse, notification, Switch } from 'antd'
import { SettingOutlined, LeftOutlined, SearchOutlined, PlusOutlined } from '@ant-design/icons'
import Api from '@/api'
import Utils from '@/utils/utils.js'
@@ -15,6 +16,7 @@
import SettingForm from './settingform'
import asyncComponent from '@/utils/asyncComponent'
import { SearchItems } from './source'
import MKEmitter from '@/utils/events.js'
import './index.scss'
const { Panel } = Collapse
@@ -43,7 +45,8 @@
    sqlVerifing: false,    // sql验证
    showField: false,      // 显示表单字段值
    group: null,
    editGroup: null
    editGroup: null,
    saving: false
  }
  /**
@@ -59,6 +62,10 @@
    })
  }
  componentDidMount () {
    MKEmitter.addListener('completeSave', this.completeSave)
  }
  /**
   * @description 组件销毁,清除state更新
   */
@@ -66,6 +73,11 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('completeSave', this.completeSave)
  }
  completeSave = () => {
    this.setState({saving: false})
  }
  /**
@@ -132,12 +144,25 @@
   * @description 表单编辑
   */
  handleForm = (_card) => {
    const { group } = this.state
    let card = fromJS(_card).toJS()
    let linkableFields = []
    group.fields.forEach(item => {
      if (item.uuid === card.uuid) return
      if (!['select', 'link', 'checkcard'].includes(item.type)) return
      if (item.type === 'checkcard' && item.multiple === 'true') return
      linkableFields.push({
        value: item.field,
        text: item.label
      })
    })
    this.setState({
      visible: true,
      card: card,
      formlist: getSearchForm(card, [])
      formlist: getSearchForm(card, linkableFields)
    })
  }
@@ -148,20 +173,49 @@
   * 3、通过loading刷新
   */
  handleSubmit = () => {
    const { config } = this.state
    this.formRef.handleConfirm().then(res => {
      let _group = fromJS(this.state.group).toJS()
      let fieldrepet = false // 字段重复
      _group.fields = _group.fields.map(item => {
        if (item.uuid !== res.uuid && item.field.toLowerCase() === res.field.toLowerCase()) {
          fieldrepet = true
        }
        if (item.uuid === res.uuid) {
          return res
        } else {
          return item
        }
      })
      let fieldrepet = false // 字段重复
      let lowerField = res.field.toLowerCase()
      if (config.setting.field) {
        let m = config.setting.field.toLowerCase().split(',')
        if (m.includes(lowerField)) {
          fieldrepet = true
        }
      }
      config.fields.forEach(item => {
        if (item.uuid === res.uuid) return
        if (res.type === 'date' && item.type === 'date') return
        if (item.field.toLowerCase() === lowerField) {
          fieldrepet = true
        }
      })
      config.groups.forEach(group => {
        if (group.setting.field) {
          let m = group.setting.field.toLowerCase().split(',')
          if (m.includes(lowerField)) {
            fieldrepet = true
          }
        }
        group.fields.forEach(item => {
          if (item.uuid === res.uuid) return
          if (res.type === 'date' && item.type === 'date') return
          if (item.field.toLowerCase() === lowerField) {
            fieldrepet = true
          }
        })
      })
      if (fieldrepet) {
@@ -246,13 +300,12 @@
  submitConfig = () => {
    const { config } = this.state
    this.setState({originConfig: fromJS(config).toJS()})
    this.setState({originConfig: fromJS(config).toJS(), saving: true})
    this.props.handleSave(config)
    notification.success({
      top: 92,
      message: '保存成功。',
      duration: 2
    })
    setTimeout(() => {
      MKEmitter.emit('triggerMenuSave')
    }, 100)
  }
  cancelConfig = () => {
@@ -285,8 +338,54 @@
   * @description 保存分组设置
   */
  settingSave = () => {
    const { config } = this.state
    this.settingRef.handleConfirm().then(res => {
      let _group = {...this.state.group, setting: res}
      let lowers = _group.setting.field ? _group.setting.field.toLowerCase() : ''
      if (lowers) {
        let fieldrepet = false // 字段重复
        lowers = lowers.split(',')
        let length = lowers.length
        if (_group.floor !== 1 && config.setting.field) {
          let m = config.setting.field.toLowerCase().split(',')
          if (Array.from(new Set([...m, ...lowers])).length < m.length + length) {
            fieldrepet = true
          }
        }
        config.fields.forEach(item => {
          if (lowers.includes(item.field.toLowerCase())) {
            fieldrepet = true
          }
        })
        config.groups.forEach(group => {
          if (_group.uuid === group.uuid) return
          if (group.setting.field) {
            let m = group.setting.field.toLowerCase().split(',')
            if (Array.from(new Set([...m, ...lowers])).length < m.length + length) {
              fieldrepet = true
            }
          }
          group.fields.forEach(item => {
            if (lowers.includes(item.field.toLowerCase())) {
              fieldrepet = true
            }
          })
        })
        if (fieldrepet) {
          notification.warning({
            top: 92,
            message: '字段已存在!',
            duration: 10
          })
          return
        }
      }
      this.setState({
        group: _group,
        settingVisible: false
@@ -321,7 +420,7 @@
    let _g = {
      uuid: Utils.getuuid(),
      wrap: { name: 'name', icon: '' },
      setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden' },
      setting: { type: 'title', field: '', title: '', focus: 'true', btn: 'hidden', backgroundColor: sessionStorage.getItem('sysBgColor') },
      fields: []
    }
@@ -386,7 +485,7 @@
  }
  render () {
    const { dict, group, editGroup } = this.state
    const { dict, group, editGroup, saving } = this.state
    return (
      <div className="mob-search-board">
        <DndProvider backend={HTML5Backend}>
@@ -402,7 +501,7 @@
            </Collapse>
          </div>
          <div className="modal-control">
            <Button type="primary" onClick={this.submitConfig}>保存</Button>
            <Button type="primary" loading={saving} onClick={this.submitConfig}>保存</Button>
            <Button onClick={this.cancelConfig}>关闭</Button>
            {!group.floor ? <Button onClick={this.returnUp}>返回上级</Button> : null}
            <PasteComponent insert={this.insert} />
@@ -410,16 +509,17 @@
          </div>
          <div className="setting">
            <div className="mob-shell" style={{width: window.GLOB.shellWidth, height: window.GLOB.shellHeight}}>
              <div className="mob-shell-inner">
                <Icon className="setting-group" onClick={this.changeSetting} type="setting" />
              <div className="mob-shell-inner" style={{backgroundColor: group.setting.backgroundColor || '#ffffff'}}>
                <SettingOutlined className="setting-group" onClick={this.changeSetting}/>
                {group.setting.type === 'title' ? <div className="am-navbar">
                  <Icon type="close" />
                  <LeftOutlined />
                  <div className="am-navbar-title">{group.setting.title}</div>
                </div> : <div className="am-navbar">
                  <Icon type="left" />
                  <div className="search-bar"><Icon type="search" /></div>
                  {/* <LeftOutlined /> */}
                  <div className="search-bar"><SearchOutlined /></div>
                  <Button >取消</Button>
                </div>}
                {group.floor === 1 ? <Icon className="plus-group" type="plus" onClick={this.plusGroup} /> : null}
                {group.floor === 1 ? <PlusOutlined className="plus-group" onClick={this.plusGroup} /> : null}
                <div style={{minHeight: 'calc(100% - 100px)'}}>
                  {group.floor === 1 && group.groups.length > 0 ? <GDragElement
                    list={group.groups}