king
2023-06-14 08cce3334a2dc81d690b518136b0aaea64e48b0b
src/views/menudesign/index.jsx
@@ -73,8 +73,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变量
@@ -106,6 +114,8 @@
  }
  componentDidMount () {
    if (!sessionStorage.getItem('UserID')) return
    MKEmitter.addListener('changePopview', this.initPopview)
    MKEmitter.addListener('triggerMenuSave', this.triggerMenuSave)
    MKEmitter.addListener('updateCustomComponent', this.updateCustomComponent)
@@ -370,6 +380,8 @@
      _btn.config.MenuID = _btn.uuid
      _btn.config.ParentId = card.uuid
      _btn.config.MenuName = _btn.label
      _btn.config.components = this.updateComponents(_btn.config.components || [])
    } else {
      _btn.config = {
        uuid: _btn.uuid,
@@ -485,6 +497,7 @@
          })
          this.updatePage(config)
        } else {
          config.components = this.updateComponents(config.components)
          this.setState({
            oriConfig: fromJS(config).toJS(),
            config: config
@@ -498,6 +511,27 @@
          duration: 5
        })
      }
    })
  }
  updateComponents = (components) => { // 兼容性升级 table
    return components.map(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          tab.components = this.updateComponents(tab.components)
        })
      } else if (item.type === 'group') {
        item.components = this.updateComponents(item.components)
      } else if (item.type === 'table') {
        item.cols = item.cols.map(col => {
          if (col.type === 'action') {
            col.type = 'custom'
          }
          return col
        })
      }
      return item
    })
  }
@@ -519,6 +553,13 @@
      if (item.subtype === 'tablecard') { // 兼容
        item.type = 'card'
      } else if (item.type === 'table') {
        item.cols = item.cols.map(col => {
          if (col.type === 'action') {
            col.type = 'custom'
          }
          return col
        })
      }
      delete item.tabId
@@ -556,15 +597,23 @@
      })
    })
    config.cols && config.cols.forEach(col => {
      if (col.type === 'action') {
    if (config.cols) {
      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' && popbtns[cell.uuid]) {
            cell.config = popbtns[cell.uuid]
          }
        })
      }
    })
      }
      loopCol(config.cols)
    }
    config.elements && config.elements.forEach(cell => {
      if (cell.eleType !== 'button') return
@@ -684,6 +733,11 @@
        if (item.$tables) {
          tbs.push(...item.$tables)
        }
        if (item.wrap && item.wrap.permission === 'false') {
          return
        }
        if (item.action && item.action.length > 0) {
          item.action.forEach(btn => {
            if (btn.hidden === 'true') return
@@ -720,14 +774,20 @@
            _sort++
          })
        } else if (item.type === 'table') {
          item.cols && 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, '${item.name + '-' + btn.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
          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, '${item.name + '-' + cell.label}' as menuname, '${_sort * 10}' as Sort, '${config.uuid}' as parentid, 40 as Type`)
              _sort++
            })
              }
          })
          }
          loopCol(item.cols)
        }
      })
    }
@@ -758,6 +818,35 @@
    return true
  }
  resetSyncQuery = (components) => {
    return components.map(item => {
      if (item.type === 'tabs') {
        item.subtabs.forEach(tab => {
          tab.components = this.resetSyncQuery(tab.components)
        })
      } else if (item.type === 'group') {
        item.components = this.resetSyncQuery(item.components)
      } else if (item.setting && item.setting.interType === 'system' && item.setting.sync === 'true') {
        let sql = ''
        if (item.setting.execute !== 'false' && item.setting.dataresource) {
          sql = item.setting.dataresource
        }
        item.scripts && item.scripts.forEach(script => {
          if (script.status === 'false') return
          sql += script.sql
        })
        if (sql.length > 8000) {
          item.setting.sync = 'false'
        }
      }
      return item
    })
  }
  submitConfig = () => {
    const { MenuType } = this.state
    let config = fromJS(this.state.config).toJS()
@@ -775,9 +864,21 @@
      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
      }
      if (config.cacheUseful !== 'true') {
        config.components = this.resetSyncQuery(config.components)
      }
      let tbs = []
@@ -928,6 +1029,8 @@
          menuloading: false
        })
        window.GLOB.saving = false
        if (!res) return
        if (res.status) {
@@ -952,6 +1055,9 @@
    this.setState({
      menuloading: false
    })
    window.GLOB.saving = false
    if (!error) {
      notification.warning({
        top: 92,
@@ -997,17 +1103,23 @@
  onEnabledChange = () => {
    const { config } = this.state
    if (!config || (!config.enabled && this.verifyConfig(true))) {
      return
    }
    let _config = {...config, enabled: !config.enabled}
    delete _config.force
    if (!_config.enabled) {
    this.setState({
      config: {...config, enabled: !config.enabled}
        config: _config
      })
    } else if (this.verifyConfig(_config)) {
      this.setState({
        config: _config
    })
  }
  }
  verifyConfig = (show) => {
    const { config, MenuType } = this.state
  verifyConfig = (config) => {
    const { MenuType } = this.state
    let error = ''
    let check = (components) => {
@@ -1035,7 +1147,7 @@
    check(config.components)
    if (show && error) {
    if (config.enabled && error) {
      notification.warning({
        top: 92,
        message: error,
@@ -1051,7 +1163,7 @@
        carousel: '轮播',
        tree: '树形列表',
        chart: '自定义图表',
        editor: '富文本',
        // editor: '富文本',
        group: '分组',
        iframe: 'iframe'
      }
@@ -1069,7 +1181,7 @@
        }
      })
      if (show && error) {
      if (config.enabled && error) {
        notification.warning({
          top: 92,
          message: error,
@@ -1078,7 +1190,7 @@
      }
    }
    return error
    return error === ''
  }
  // 更新配置信息
@@ -1193,7 +1305,7 @@
                    <PictureController/>
                    <StyleCombControlButton menu={config} />
                    <PasteController 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" className={needUpdate ? 'update-tip' : ''} onClick={this.submitConfig} loading={menuloading}>保存</Button>
                    <Button type="default" onClick={this.closeView}>关闭</Button>
                  </div>