king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/views/tabledesign/index.jsx
@@ -63,8 +63,16 @@
  }
  UNSAFE_componentWillMount() {
    if (!sessionStorage.getItem('UserID')) {
      sessionStorage.removeItem('isEditState')
      sessionStorage.removeItem('appType')
      this.props.history.replace('/login')
      return
    }
    sessionStorage.setItem('editMenuType', 'menu') // 编辑菜单类型
    window.GLOB.curDate = moment().format('YYYY-MM-DD')
    window.GLOB.UserComponentMap = new Map() // 缓存用户自定义组件
    window.GLOB.TabsMap = new Map()          // 缓存用户操作的标签页
    window.GLOB.urlFields = []               // url变量
@@ -95,6 +103,8 @@
  }
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    setTimeout(() => {
@@ -235,6 +245,26 @@
      _btn.config.MenuID = _btn.uuid
      _btn.config.ParentId = card.uuid
      _btn.config.MenuName = _btn.label
      _btn.config.components = _btn.config.components || []
      _btn.config.components.forEach(item => {
        if (item.type === 'tabs') {
          item.subtabs.forEach(tab => {
            tab.components[0].cols = tab.components[0].cols.map(col => {
              if (col.type === 'action') {
                col.type = 'custom'
              }
              return col
            })
          })
        } else if (item.cols) {
          item.cols = item.cols.map(col => {
            if (col.type === 'action') {
              col.type = 'custom'
            }
            return col
          })
        }
      })
    } else {
      _btn.config = {
        uuid: _btn.uuid,
@@ -263,6 +293,21 @@
  submitPopConfig = (btnconfig) => {
    let config = fromJS(this.state.config).toJS()
    let loopCol = (cols) => {
      cols.forEach(col => {
        if (col.type === 'colspan') {
          loopCol(col.subcols)
        } else if (col.type === 'custom') {
          col.elements.forEach(cell => {
            if (cell.eleType !== 'button') return
            if (cell.OpenType === 'popview' && cell.uuid === btnconfig.uuid) {
              cell.config = btnconfig
            }
          })
        }
      })
    }
    config.components.forEach(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
@@ -273,14 +318,8 @@
              btn.config = btnconfig
            }
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
                btn.config = btnconfig
              }
            })
          })
          loopCol(tab.components[0].cols)
          tab.components[0].$tables = getTables(tab.components[0])
        })
@@ -290,14 +329,8 @@
            btn.config = btnconfig
          }
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          col.elements.forEach(btn => {
            if (btn.OpenType === 'popview' && btn.uuid === btnconfig.uuid) {
              btn.config = btnconfig
            }
          })
        })
        loopCol(item.cols)
        item.$tables = getTables(item)
      }
@@ -407,8 +440,20 @@
            if (item.type === 'tabs') {
              item.subtabs.forEach(tab => {
                tab.components[0].name = tab.label
                tab.components[0].cols = tab.components[0].cols.map(col => {
                  if (col.type === 'action') {
                    col.type = 'custom'
                  }
                  return col
                })
              })
            } else {
              item.cols = item.cols.map(col => {
                if (col.type === 'action') {
                  col.type = 'custom'
                }
                return col
              })
              item.name = '主表'
            }
          })
@@ -457,15 +502,22 @@
            buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
            _s++
          })
          tab.components[0].cols.forEach(col => {
            if (col.type !== 'action') return
            col.elements.forEach(btn => {
              if (btn.hidden === 'true') return
              buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
              _s++
          let loopCol = (cols) => {
            cols.forEach(col => {
              if (col.type === 'colspan') {
                loopCol(col.subcols)
              } else if (col.type === 'custom') {
                col.elements.forEach(cell => {
                  if (cell.eleType !== 'button' || cell.hidden === 'true') return
                  buttons.push(`select '${cell.uuid}' as menuid, '${cell.label}' as menuname, '${_s * 10}' as Sort, '${tab.components[0].uuid}' as parentid, 60 as Type`)
                  _s++
                })
              }
            })
          })
          }
          loopCol(tab.components[0].cols)
        })
      } else {
        if (item.$tables) {
@@ -477,15 +529,22 @@
          buttons.push(`select '${btn.uuid}' as menuid, '${btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
          _sort++
        })
        item.cols.forEach(col => {
          if (col.type !== 'action') return
          col.elements.forEach(btn => {
            if (btn.hidden === 'true') return
            buttons.push(`select '${btn.uuid}' as menuid,  '${btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
            _sort++
        let loopCol = (cols) => {
          cols.forEach(col => {
            if (col.type === 'colspan') {
              loopCol(col.subcols)
            } else if (col.type === 'custom') {
              col.elements.forEach(cell => {
                if (cell.eleType !== 'button' || cell.hidden === 'true') return
                buttons.push(`select '${cell.uuid}' as menuid,  '${cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
                _sort++
              })
            }
          })
        })
        }
        loopCol(item.cols)
      }
    })
@@ -517,9 +576,17 @@
      menuloading: true
    })
    window.GLOB.saving = true
    setTimeout(() => {
      if (config.enabled && this.verifyConfig()) {
      let _pass = this.verifyConfig(config)
      if (config.enabled && !_pass) {
        config.enabled = false
        config.force = true
      } else if (!config.enabled && config.force && _pass) {
        config.enabled = true
        delete config.force
      }
      let tbs = []
@@ -613,6 +680,8 @@
          menuloading: false
        })
        window.GLOB.saving = false
        if (!res) return
        if (res.status) {
@@ -637,6 +706,9 @@
    this.setState({
      menuloading: false
    })
    window.GLOB.saving = false
    if (!error) {
      notification.warning({
        top: 92,
@@ -681,17 +753,22 @@
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    let _config = {...config, enabled: !config.enabled}
    this.setState({
      config: {...config, enabled: !config.enabled}
    })
    delete _config.force
    if (!_config.enabled) {
      this.setState({
        config: _config
      })
    } else if (this.verifyConfig(_config)) {
      this.setState({
        config: _config
      })
    }
  }
  verifyConfig = (show) => {
    const { config } = this.state
  verifyConfig = (config) => {
    let error = ''
    config.components.forEach(item => {
@@ -725,7 +802,7 @@
      }
    }
    if (show && error) {
    if (config.enabled && error) {
      notification.warning({
        top: 92,
        message: error,
@@ -733,7 +810,7 @@
      })
    }
    return error
    return error === ''
  }
  // 更新配置信息
@@ -843,7 +920,7 @@
                    <TableNodes config={config} />
                    <ReplaceField type="custom" config={config} updateConfig={this.resetConfig}/>
                    <PasteBaseTable type="page" insert={this.insert}/>
                    <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config && config.enabled} onChange={this.onEnabledChange} />
                    {config ? <Switch className="big" checkedChildren="启" unCheckedChildren="停" checked={config.enabled} onChange={this.onEnabledChange} /> : null}
                    <Button type="primary" id="save-config" onClick={this.submitConfig} loading={menuloading}>保存</Button>
                    <Button type="default" onClick={this.closeView}>关闭</Button>
                  </div>