king
2020-08-22 835b48025a582b1c19c4de128906aff6a5e63612
src/templates/treepageconfig/index.jsx
@@ -11,11 +11,10 @@
import Utils from '@/utils/utils.js'
import zhCN from '@/locales/zh-CN/model.js'
import enUS from '@/locales/en-US/model.js'
import { getMainMenuForm } from '@/templates/zshare/formconfig'
import asyncComponent from '@/utils/asyncComponent'
import MenuForm from '@/templates/zshare/menuform'
import MenuForm from '@/templates/comtableconfig/menuform'
import EditComponent from '@/templates/zshare/editcomponent'
import SourceElement from '@/templates/zshare/dragsource'
import Source from './source'
@@ -38,7 +37,6 @@
  state = {
    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    config: null,            // 页面配置
    menuformlist: null,      // 基本信息表单字段
    formlist: null,          // 搜索条件、按钮、显示列表单字段
    menuloading: false,      // 菜单保存中
    menucloseloading: false, // 菜单关闭时,选择保存
@@ -72,6 +70,13 @@
      _config = _LongParam
    }
    // 页面配置中保留菜单信息,只用于数据传递
    _config.ParentId = menu.ParentId
    _config.fstMenuId = menu.fstMenuId
    _config.MenuName = menu.MenuName || ''
    _config.MenuNo = menu.MenuNo || ''
    _config.OpenType = menu.PageParam ? menu.PageParam.OpenType : ''
    // 配置默认值,兼容
    _config.Template = 'TreePage'
    _config.easyCode = _config.easyCode || ''
@@ -96,8 +101,7 @@
      openEdition: menu.open_edition || '',
      activeKey: menu.activeKey || '0',
      optionLibs: optionLibs,
      originMenu: fromJS(menu).toJS(),
      menuformlist: getMainMenuForm(menu, _config)
      originMenu: fromJS(_config).toJS()
    })
  }
@@ -189,17 +193,28 @@
   */
  submitConfig = () => {
    const { menu } = this.props
    const { originMenu, delTabs, openEdition } = this.state
    const { delTabs, openEdition } = this.state
    let config = fromJS(this.state.config).toJS()
    let _config = fromJS(this.state.config).toJS()
    this.menuformRef.handleConfirm().then(res => {
      if (config.isAdd) {
        config.tabgroups[0].sublist = config.tabgroups[0].sublist.filter(item => !item.origin)
    // 基本信息验证
    if (!_config.fstMenuId || !_config.ParentId || !_config.MenuName || !_config.MenuNo) {
      notification.warning({
        top: 92,
        message: this.state.dict['model.menu.basemsg'],
        duration: 5
      })
      return
      }
      if (config.type === 'user') { // 使用已有菜单时,默认添加关联标签id
        config.tabgroups.forEach(group => {
    // 新建验证
    if (_config.isAdd) {
      _config.tabgroups[0].sublist = _config.tabgroups[0].sublist.filter(item => !item.origin)
    }
    // 使用已有菜单时,默认添加关联标签id
    if (_config.type === 'user') {
      _config.tabgroups.forEach(group => {
          group.sublist = group.sublist.map(tab => {
            if (!tab.linkTab) {
              tab.linkTab = Utils.getuuid()
@@ -208,10 +223,6 @@
          })
        })
      }
      let _LongParam = ''
      let _config = {...config, easyCode: res.easyCode}
      let _pageParam = {...menu.PageParam, OpenType: res.opentype}
      // 未设置数据源或标签不合法时,启用状态为false
      let vresult = this.verifyconfig(_config)
@@ -300,6 +311,8 @@
        delete _config.type
        delete _config.isAdd
  
      let _LongParam = ''
        try {
          _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
        } catch (e) {
@@ -346,15 +359,15 @@
        let param = {
          func: 'sPC_TrdMenu_AddUpt',
          FstID: res.fstMenuId,
          SndID: res.parentId,
          ParentID: res.parentId,
        FstID: _config.fstMenuId,
        SndID: _config.ParentId,
        ParentID: _config.ParentId,
          MenuID: menu.MenuID,
          MenuNo: res.MenuNo,
          EasyCode: res.easyCode,
          Template: menu.PageParam.Template || '',
          MenuName: res.MenuName,
          PageParam: JSON.stringify(_pageParam),
        MenuNo: _config.MenuNo,
        EasyCode: _config.easyCode,
        Template: _config.Template,
        MenuName: _config.MenuName,
        PageParam: JSON.stringify({...menu.PageParam, Template: _config.Template, OpenType: _config.OpenType}),
          LongParam: _LongParam,
          LText: _vals.func.map(item => `select '${menu.MenuID}' as MenuID,'${item.func}' as ProcName,'${item.label}' as MenuName`),
          LTexttb: _tables.map(item => `select '${menu.MenuID}' as MenuID,'${item}' as tbName`)
@@ -426,25 +439,10 @@
          Api.getSystemConfig(param).then(response => {
            if (response.status) {
              let _FMenu = originMenu.fstMenuList.filter(fstM => fstM.MenuID === res.fstMenuId)[0]
              let _supMenuList = []
              if (_FMenu) {
                _supMenuList = _FMenu.options
              }
              this.setState({
                config: _config,
                openEdition: response.open_edition || '',
                originMenu: {
                  ...originMenu,
                  LongParam: _config,
                  PageParam: _pageParam,
                  MenuName: res.MenuName,
                  MenuNo: res.MenuNo,
                  ParentID: res.parentId,
                  fstMenuId: res.fstMenuId,
                  supMenuList: _supMenuList
                }
              originMenu: fromJS(_config).toJS()
              })
              this.props.reloadmenu()
@@ -517,22 +515,13 @@
          })
        })
      })
    }, () => {
      notification.warning({
        top: 92,
        message: this.state.dict['model.menu.basemsg'],
        duration: 5
      })
    })
  }
  /**
   * @description 点击返回时,判断配置保存状态
   */
  cancelConfig = () => {
    const { menu } = this.props
    const { config, originMenu } = this.state
    let _this = this
    if (config.isAdd) {
@@ -546,62 +535,42 @@
        onCancel() {}
      })
    } else {
      this.menuformRef.handleConfirm().then(res => {
        let _config = {...config, easyCode: res.easyCode}
        let _pageParam = {...menu.PageParam, OpenType: res.opentype}
        let _originMenu = {
          ...originMenu,
          LongParam: _config,
          PageParam: _pageParam,
          MenuName: res.MenuName,
          MenuNo: res.MenuNo,
          ParentID: res.parentId,
          fstMenuId: res.fstMenuId
        }
        if (!is(fromJS(originMenu), fromJS(_originMenu))) {
      if (!is(fromJS(originMenu), fromJS(config))) {
          this.setState({
            closeVisible: true
          })
        } else {
          this.props.handleView()
        }
      }, () => {
        this.setState({
          closeVisible: true
        })
      })
    }
  }
  /**
   * @description 设置可配置按钮
   */
  setSubConfig = (item, type) => {
  setSubConfig = (item) => {
    const { menu } = this.props
    const { config, originMenu, optionLibs, activeKey, openEdition } = this.state
    if (!originMenu.MenuID) { // menuID不存在时,为新建菜单,提示菜单尚未保存
    if (config.isAdd) { // menuID不存在时,为新建菜单,提示菜单尚未保存
      notification.warning({
        top: 92,
        message: this.state.dict['header.menu.config.notsave'],
        duration: 5
      })
    } else {
      this.menuformRef.handleConfirm().then(res => {
        let _config = {...config, easyCode: res.easyCode}
        let _pageParam = {...menu.PageParam, OpenType: res.opentype}
        let _originMenu = {
          ...originMenu,
          LongParam: _config,
          PageParam: _pageParam,
          MenuName: res.MenuName,
          MenuNo: res.MenuNo,
          ParentID: res.parentId,
          fstMenuId: res.fstMenuId
      // 基本信息验证
      if (!config.fstMenuId || !config.ParentId || !config.MenuName || !config.MenuNo) {
        notification.warning({
          top: 92,
          message: this.state.dict['model.menu.basemsg'],
          duration: 5
        })
        return
        }
        if (!is(fromJS(originMenu), fromJS(_originMenu))) { // 菜单信息变化时,提示保存
      // 菜单信息变化时,提示保存
      if (!is(fromJS(originMenu), fromJS(config))) {
          notification.warning({
            top: 92,
            message: this.state.dict['header.menu.config.update'],
@@ -610,12 +579,24 @@
          return
        }
        _originMenu.activeKey = activeKey       // 保存当前打开页签
        _originMenu.open_edition = openEdition  // 更新版本号
      let submenu = menu.fstMenuList.filter(item => item.MenuID === config.fstMenuId)[0]
      let _Menu = {
        ...menu,
        LongParam: config,
        PageParam: {...menu.PageParam, Template: config.Template, OpenType: config.OpenType},
        MenuName: config.MenuName,
        MenuNo: config.MenuNo,
        ParentId: config.ParentId,
        fstMenuId: config.fstMenuId,
        supMenuList: submenu ? submenu.options : []
      }
      _Menu.activeKey = activeKey       // 保存当前打开页签
      _Menu.open_edition = openEdition  // 更新版本号
        let param = {
          optionLibs: optionLibs,
          editMenu: _originMenu,
        editMenu: _Menu,
          editTab: item,
          tabConfig: null,
          editSubTab: null,
@@ -668,13 +649,6 @@
              duration: 5
            })
          }
        })
      }, () => {
        notification.warning({
          top: 92,
          message: this.state.dict['header.menu.config.update'],
          duration: 5
        })
      })
    }
  }
@@ -767,6 +741,7 @@
  }
  render () {
    const { menu } = this.props
    const { activeKey, config } = this.state
    let configTabs = []
@@ -784,9 +759,10 @@
              <Panel forceRender={true} header={this.state.dict['header.menu.basedata']} key="0" id="main-basedata">
                {/* 菜单信息 */}
                <MenuForm
                  menu={menu}
                  config={config}
                  dict={this.state.dict}
                  formlist={this.state.menuformlist}
                  wrappedComponentRef={(inst) => this.menuformRef = inst}
                  updatemenu={this.updateconfig}
                />
              </Panel>
              {/* 添加标签 */}
@@ -811,7 +787,7 @@
                        className="config-button"
                        icon={item.icon}
                        style={{marginBottom: '10px'}}
                        onClick={() => this.setSubConfig(item, 'tab')}
                        onClick={() => this.setSubConfig(item)}
                      >{item.label}</Button>
                    </div>
                  )
@@ -838,7 +814,6 @@
                  <TreeSettingComponent
                    config={config}
                    MenuID={this.props.menu.MenuID}
                    menuformRef={this.menuformRef}
                    permFuncField={this.props.permFuncField}
                    updatesetting={this.updateconfig}
                  />
@@ -876,7 +851,7 @@
                  <TabsComponent
                    config={config}
                    tabs={this.state.tabviews}
                    setSubConfig={(item) => this.setSubConfig(item, 'tab')}
                    setSubConfig={(item) => this.setSubConfig(item)}
                    updatetabs={this.updatetabs}
                  />
                </Col>