king
2021-01-15 76a4300654a18d228838c3f27455dc8e7a8cd616
src/templates/treepageconfig/index.jsx
@@ -164,30 +164,6 @@
    })
  }
  getFuncNames = (data, funcNames, tableNames) => {
    data.forEach(item => {
      // if (item.subfuncs) {
      //   this.getFuncNames(item.subfuncs, funcNames, tableNames)
      //   return
      // }
      if (item.tableName) {
        tableNames.push(item.tableName)
      }
      if (item.innerFunc) {
        funcNames.push({func: item.innerFunc, label: item.label || ''})
      }
      if (item.callbackFunc) {
        funcNames.push({func: item.callbackFunc, label: item.label || ''})
      }
    })
    return {
      func: funcNames,
      table: tableNames
    }
  }
  /**
   * @description 三级菜单保存
   */
@@ -231,31 +207,6 @@
      _config.enabled = false
    }
    _config.funcs = [] // 页面及子页面存储过程集
    _config.funcs.push({
      type: 'view',
      subtype: 'view',
      uuid: menu.MenuID,
      intertype: _config.setting.interType || 'inner',
      interface: _config.setting.interface || '',
      tableName: _config.setting.tableName || '',
      innerFunc: _config.setting.innerFunc || '',
      outerFunc: _config.setting.outerFunc || ''
    })
    _config.tabgroups.forEach(group => {
      group.sublist.forEach(tab => {
        _config.funcs.push({
          type: 'tab',
          subtype: 'tab',
          uuid: tab.uuid,
          label: tab.label,
          linkTab: tab.linkTab
        })
      })
    })
    if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
      this.setState({
        menucloseloading: true
@@ -266,258 +217,224 @@
      })
    }
    new Promise(resolve => {
      // let deffers = []
      // _config.funcs.forEach(item => {
      //   if (item.type === 'tab') {
      //     let deffer = new Promise(resolve => {
      //       Api.getSystemConfig({
      //         func: 'sPC_Get_LongParam',
      //         MenuID: item.linkTab
      //       }).then(result => {
      //         if (result.status && result.LongParam) {
      //           let _LongParam = ''
      //           if (result.LongParam) {
      //             try {
      //               _LongParam = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
      //             } catch (e) {
      //               console.warn('Parse Failure')
      //               _LongParam = ''
      //             }
      //           }
    // 保存时删除配置类型,system 、user
    delete _config.type
    delete _config.isAdd
    let _LongParam = ''
    try {
      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    } catch (e) {
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 5
      })
      this.setState({
        menucloseloading: false,
        menuloading: false
      })
      return
    }
    let _sort = 0
    let btntabs = []
    
      //           if (_LongParam) {
      //             item.menuNo = _LongParam.tabNo || ''
      //             item.subfuncs = _LongParam.funcs || []
      //           }
      //         }
      //         resolve()
      //       })
      //     })
    let tabParam = { // 添加菜单tab页
      func: 'sPC_sMenusTab_AddUpt',
      MenuID: menu.MenuID
    }
      //     deffers.push(deffer)
      //   }
      // })
    let _LText = []
      // if (deffers.length === 0) {
      //   resolve()
      // } else {
      //   Promise.all(deffers).then(() => {
      //     resolve()
      //   })
      // }
      resolve()
    }).then(() => {
      // 保存时删除配置类型,system 、user
      delete _config.type
      delete _config.isAdd
      let _LongParam = ''
      try {
        _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
      } catch (e) {
        notification.warning({
          top: 92,
          message: '编译错误',
          duration: 5
        })
        this.setState({
          menucloseloading: false,
          menuloading: false
        })
        return
      }
      let _sort = 0
      let btntabs = []
      let tabParam = { // 添加菜单tab页
        func: 'sPC_sMenusTab_AddUpt',
        MenuID: menu.MenuID
      }
      let _LText = []
      btntabs.forEach(item => {
        _LText.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${item.sort * 10}' as Sort`)
    btntabs.forEach(item => {
      _LText.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${item.sort * 10}' as Sort`)
    })
    _config.tabgroups.forEach(group => {
      group.sublist.forEach(item => {
        _sort++
        _LText.push(`select '${menu.MenuID}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${_sort * 10}' as Sort`)
      })
      _config.tabgroups.forEach(group => {
        group.sublist.forEach(item => {
          _sort++
          _LText.push(`select '${menu.MenuID}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${_sort * 10}' as Sort`)
        })
      })
    })
      _LText = _LText.join(' union all ')
    _LText = _LText.join(' union all ')
      tabParam.LText = Utils.formatOptions(_LText)
      tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
    tabParam.LText = Utils.formatOptions(_LText)
    tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
      let _vals = this.getFuncNames(_config.funcs, [], [])
      let _tables = Array.from(new Set(_vals.table))
    let _funcs = []
    let _tables = []
      let param = {
        func: 'sPC_TrdMenu_AddUpt',
        FstID: _config.fstMenuId,
        SndID: _config.ParentId,
        ParentID: _config.ParentId,
        MenuID: menu.MenuID,
        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`)
      }
    if (_config.setting.tableName) {
      _tables.push(_config.setting.tableName)
    }
    if (_config.setting.innerFunc) {
      _funcs.push({func: _config.setting.innerFunc, label: _config.MenuName || ''})
    }
    if (_config.setting.outerFunc) {
      _funcs.push({func: _config.setting.outerFunc, label: _config.MenuName || ''})
    }
      if (menu.menuSort) { // 菜单新建时设置排序
        param.Sort = menu.menuSort
      }
    let param = {
      func: 'sPC_TrdMenu_AddUpt',
      FstID: _config.fstMenuId,
      SndID: _config.ParentId,
      ParentID: _config.ParentId,
      MenuID: menu.MenuID,
      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: _funcs.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`)
    }
      param.LText = param.LText.join(' union all ')
      param.LText = Utils.formatOptions(param.LText)
      param.LTexttb = param.LTexttb.join(' union all ')
      param.LTexttb = Utils.formatOptions(param.LTexttb)
      param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    if (menu.menuSort) { // 菜单新建时设置排序
      param.Sort = menu.menuSort
    }
      if (openEdition) { // 版本管理
        param.open_edition = openEdition
      }
    param.LText = param.LText.join(' union all ')
    param.LText = Utils.formatOptions(param.LText)
    param.LTexttb = param.LTexttb.join(' union all ')
    param.LTexttb = Utils.formatOptions(param.LTexttb)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
      // 有按钮或标签删除时,先进行删除操作
      // 删除成功后,保存页面配置
      new Promise(resolve => {
        if (delTabs.length > 0) {
          let deffers = delTabs.map(item => {
            let _param = {
              func: 'sPC_MainMenu_Del',
              MenuID: item.uuid
            }
    if (openEdition) { // 版本管理
      param.open_edition = openEdition
    }
            return new Promise(resolve => {
              Api.getSystemConfig(_param).then(response => {
                resolve(response)
              })
    // 有按钮或标签删除时,先进行删除操作
    // 删除成功后,保存页面配置
    new Promise(resolve => {
      if (delTabs.length > 0) {
        let deffers = delTabs.map(item => {
          let _param = {
            func: 'sPC_MainMenu_Del',
            MenuID: item.uuid
          }
          return new Promise(resolve => {
            Api.getSystemConfig(_param).then(response => {
              resolve(response)
            })
          })
          Promise.all(deffers).then(result => {
            let error = null
            result.forEach(response => {
              if (!response.status) {
                error = response
              }
            })
            if (error) {
              this.setState({
                menuloading: false,
                menucloseloading: false
              })
              notification.warning({
                top: 92,
                message: error.message,
                duration: 5
              })
              resolve(false)
            } else {
              this.setState({
                delTabs: []
              })
              resolve(true)
        })
        Promise.all(deffers).then(result => {
          let error = null
          result.forEach(response => {
            if (!response.status) {
              error = response
            }
          })
        } else if (delTabs.length === 0) {
          resolve(true)
        }
      }).then(resp => {
        if (resp === false) return
        let localParam = fromJS(param).toJS()
        localParam.func = 'sPC_TrdMenu_AddUpt_For_Local'
        delete localParam.LongParam
        delete localParam.PageParam
        delete localParam.Template
        delete localParam.Sort
        delete localParam.EasyCode
        delete localParam.open_edition
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              config: _config,
              openEdition: response.open_edition || '',
              originMenu: fromJS(_config).toJS()
            })
            // 存在标签页时
            if (tabParam.LText) {
              Api.getSystemConfig(tabParam).then(result => {
                if (result.status) {
                  notification.success({
                    top: 92,
                    message: '保存成功',
                    duration: 2
                  })
                  this.props.reloadmenu()
                  Api.getLocalConfig(localParam)
                  if (this.state.closeVisible) {
                    this.props.handleView()
                  } else {
                    this.setState({
                      menuloading: false,
                      menucloseloading: false
                    })
                  }
                } else {
                  notification.warning({
                    top: 92,
                    message: result.message,
                    duration: 5
                  })
                  this.setState({
                    menuloading: false,
                    menucloseloading: false
                  })
                }
              })
            } else {
              notification.success({
                top: 92,
                message: '保存成功',
                duration: 2
              })
              this.props.reloadmenu()
              Api.getLocalConfig(localParam)
              if (this.state.closeVisible) {
                this.props.handleView()
              } else {
                this.setState({
                  menuloading: false,
                  menucloseloading: false
                })
              }
            }
          } else {
          if (error) {
            this.setState({
              menuloading: false,
              menucloseloading: false
            })
            notification.warning({
              top: 92,
              message: response.message,
              message: error.message,
              duration: 5
            })
            resolve(false)
          } else {
            this.setState({
              delTabs: []
            })
            resolve(true)
          }
        })
      } else if (delTabs.length === 0) {
        resolve(true)
      }
    }).then(resp => {
      if (resp === false) return
      let localParam = fromJS(param).toJS()
      localParam.func = 'sPC_TrdMenu_AddUpt_For_Local'
      delete localParam.LongParam
      delete localParam.PageParam
      delete localParam.Template
      delete localParam.Sort
      delete localParam.EasyCode
      delete localParam.open_edition
      Api.getSystemConfig(param).then(response => {
        if (response.status) {
          this.setState({
            config: _config,
            openEdition: response.open_edition || '',
            originMenu: fromJS(_config).toJS()
          })
          // 存在标签页时
          if (tabParam.LText) {
            Api.getSystemConfig(tabParam).then(result => {
              if (result.status) {
                notification.success({
                  top: 92,
                  message: '保存成功',
                  duration: 2
                })
                this.props.reloadmenu()
                Api.getLocalConfig(localParam)
                if (this.state.closeVisible) {
                  this.props.handleView()
                } else {
                  this.setState({
                    menuloading: false,
                    menucloseloading: false
                  })
                }
              } else {
                notification.warning({
                  top: 92,
                  message: result.message,
                  duration: 5
                })
                this.setState({
                  menuloading: false,
                  menucloseloading: false
                })
              }
            })
          } else {
            notification.success({
              top: 92,
              message: '保存成功',
              duration: 2
            })
            this.props.reloadmenu()
            Api.getLocalConfig(localParam)
            if (this.state.closeVisible) {
              this.props.handleView()
            } else {
              this.setState({
                menuloading: false,
                menucloseloading: false
              })
            }
          }
        } else {
          this.setState({
            menuloading: false,
            menucloseloading: false
          })
          notification.warning({
            top: 92,
            message: response.message,
            duration: 5
          })
        }
      })
    })
  }