king
2020-12-23 e9640ccdc9fe57f91919e3f51462c780e44fadb0
src/templates/subtableconfig/index.jsx
@@ -275,50 +275,6 @@
      _config.enabled = false
    }
    // _config.funcs = []
    // _config.funcs.push({
    //   type: 'view',
    //   subtype: 'view',
    //   uuid: _config.uuid,
    //   intertype: _config.setting.interType || 'system',
    //   interface: _config.setting.interface || '',
    //   tableName: _config.setting.tableName || '',
    //   innerFunc: _config.setting.innerFunc || '',
    //   outerFunc: _config.setting.outerFunc || ''
    // })
    // _config.action.forEach(item => {
    //   let tablename = item.OpenType === 'excelIn' ? (item.sheet || '') : (item.sql || '')
    //   if (item.OpenType === 'excelOut' && item.intertype === 'system') {
    //     tablename = _config.setting.tableName || ''
    //   }
    //   if (item.OpenType === 'popview') {
    //     _config.funcs.push({
    //       type: 'tab',
    //       subtype: 'btn',
    //       uuid: item.uuid,
    //       label: item.label,
    //       linkTab: item.linkTab
    //     })
    //   } else {
    //     _config.funcs.push({
    //       type: 'button',
    //       subtype: 'btn',
    //       uuid: item.uuid,
    //       label: item.label,
    //       tableName: tablename,
    //       intertype: item.intertype,
    //       interface: item.interface || '',
    //       innerFunc: item.innerFunc || '',
    //       outerFunc: item.outerFunc || '',
    //       callbackFunc: item.callbackFunc || ''
    //     })
    //   }
    // })
    if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
      this.setState({
        menucloseloading: true
@@ -329,251 +285,206 @@
      })
    }
    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 = ''
      //             }
      //           }
      //           if (_LongParam) {
      //             item.menuNo = _LongParam.tabNo
      //             item.subfuncs = _LongParam.funcs || []
      //           }
      //         }
      //         resolve()
      //       })
      //     })
    // 保存时删除配置类型,system 、user
    delete _config.type
    delete _config.isAdd
      //     deffers.push(deffer)
      //   }
      // })
    let _LongParam = ''
      // 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 btnParam = {
        func: 'sPC_Button_AddUpt',
        Type: 40,
        ParentID: _config.uuid,
        MenuNo: _config.tabNo,
        Template: 'SubTable',
        PageParam: '',
        LongParam: '',
        LText: []
      }
      let btntabs = []
      _config.action.forEach((item, index) => {
        if (item.OpenType === 'popview') {
          btntabs.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${(index + 1) * 10}' as Sort`)
        }
        btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${(index + 1) * 10}' as Sort`)
    try {
      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(_config)))
    } catch (e) {
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 5
      })
      btnParam.LText = btnParam.LText.join(' union all ')
      btnParam.LText = Utils.formatOptions(btnParam.LText)
      btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      this.setState({
        menucloseloading: false,
        menuloading: false
      })
      return
    }
      let tabParam = { // 添加标签按钮tab页
        func: 'sPC_sMenusTab_AddUpt',
        MenuID: _config.uuid,
        LText: btntabs.join(' union all ')
    let btnParam = {
      func: 'sPC_Button_AddUpt',
      Type: 40,
      ParentID: _config.uuid,
      MenuNo: _config.tabNo,
      Template: 'SubTable',
      PageParam: '',
      LongParam: '',
      LText: []
    }
    let btntabs = []
    _config.action.forEach((item, index) => {
      if (item.OpenType === 'popview') {
        btntabs.push(`select '${item.uuid}' as MenuID ,'${item.linkTab}' as Tabid,'${item.label}' as TabName ,'${(index + 1) * 10}' as Sort`)
      }
      btnParam.LText.push(`select '${item.uuid}' as menuid, '${item.label}' as menuname, '${(index + 1) * 10}' as Sort`)
    })
      tabParam.LText = Utils.formatOptions(tabParam.LText)
      tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
      tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
    btnParam.LText = btnParam.LText.join(' union all ')
    btnParam.LText = Utils.formatOptions(btnParam.LText)
    btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      let param = {
        func: 'sPC_Tab_AddUpt',
        MenuID: _config.uuid,
        MenuNo: _config.tabNo,
        Template: 'SubTable',
        MenuName: _config.tabName,
        Remark: _config.Remark,
        Sort: 0,
        PageParam: JSON.stringify({Template: 'SubTable'}),
        LongParam: _LongParam
      }
    let tabParam = { // 添加标签按钮tab页
      func: 'sPC_sMenusTab_AddUpt',
      MenuID: _config.uuid,
      LText: btntabs.join(' union all ')
    }
      if (openEdition) {
        param.open_edition = openEdition
      }
    tabParam.LText = Utils.formatOptions(tabParam.LText)
    tabParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
    tabParam.secretkey = Utils.encrypt(tabParam.LText, tabParam.timestamp)
      // 有按钮或标签删除时,先进行删除操作
      // 删除成功后,保存页面配置
      new Promise(resolve => {
        if (delActions.length > 0) {
          let deffers = delActions.map(item => {
            let _param = {
              func: 'sPC_MainMenu_Del',
              MenuID: item.card.uuid
            }
    let param = {
      func: 'sPC_Tab_AddUpt',
      MenuID: _config.uuid,
      MenuNo: _config.tabNo,
      Template: 'SubTable',
      MenuName: _config.tabName,
      Remark: _config.Remark,
      Sort: 0,
      PageParam: JSON.stringify({Template: 'SubTable'}),
      LongParam: _LongParam
    }
            let _ParentParam = null
    if (openEdition) {
      param.open_edition = openEdition
    }
            try {
              _ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
            } catch (e) {
              console.warn('Stringify Failure')
              _ParentParam = null
            }
    // 有按钮或标签删除时,先进行删除操作
    // 删除成功后,保存页面配置
    new Promise(resolve => {
      if (delActions.length > 0) {
        let deffers = delActions.map(item => {
          let _param = {
            func: 'sPC_MainMenu_Del',
            MenuID: item.card.uuid
          }
            if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
              _param.ParentParam = _ParentParam
            }
          let _ParentParam = null
            return new Promise(resolve => {
              Api.getSystemConfig(_param).then(response => {
                resolve(response)
              })
          try {
            _ParentParam = window.btoa(window.encodeURIComponent(JSON.stringify(item.card)))
          } catch (e) {
            console.warn('Stringify Failure')
            _ParentParam = null
          }
          if (_ParentParam) { // 删除按钮时,保存按钮配置信息,用于恢复按钮
            _param.ParentParam = _ParentParam
          }
          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({
                delActions: []
              })
              resolve(true)
        })
        Promise.all(deffers).then(result => {
          let error = null
          result.forEach(response => {
            if (!response.status) {
              error = response
            }
          })
        } else if (delActions.length === 0) {
          resolve(true)
        }
      }).then(resp => {
        if (resp === false) return
        if (thawButtons.length > 0) {
          let defers = thawButtons.map(item => {
            return new Promise((resolve) => {
              Api.getSystemConfig({
                func: 'sPC_MainMenu_ReDel',
                MenuID: item
              }).then(res => {
                if (res.status) {
                  resolve('')
                } else {
                  resolve(res.message)
                }
              })
            })
          })
          return Promise.all(defers)
        } else {
          return true
        }
      }).then(res => {
        if (res === true || res === false) return res
        let msg = res.filter(Boolean)[0]
        if (msg) {
          notification.warning({
            top: 92,
            message: msg,
            duration: 5
          })
          return false
        } else {
          this.setState({
            thawButtons: []
          })
          return true
        }
      }).then(resp => {
        if (resp === false) return
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              openEdition: response.open_edition || '',
              config: _config,
              originConfig: fromJS(_config).toJS()
            }, () => {
              this.setState({
                menuloading: false,
                menucloseloading: false
              })
              this.submitAction(btnParam, tabParam)
            })
          } 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({
              delActions: []
            })
            resolve(true)
          }
        })
      } else if (delActions.length === 0) {
        resolve(true)
      }
    }).then(resp => {
      if (resp === false) return
      if (thawButtons.length > 0) {
        let defers = thawButtons.map(item => {
          return new Promise((resolve) => {
            Api.getSystemConfig({
              func: 'sPC_MainMenu_ReDel',
              MenuID: item
            }).then(res => {
              if (res.status) {
                resolve('')
              } else {
                resolve(res.message)
              }
            })
          })
        })
        return Promise.all(defers)
      } else {
        return true
      }
    }).then(res => {
      if (res === true || res === false) return res
      let msg = res.filter(Boolean)[0]
      if (msg) {
        notification.warning({
          top: 92,
          message: msg,
          duration: 5
        })
        return false
      } else {
        this.setState({
          thawButtons: []
        })
        return true
      }
    }).then(resp => {
      if (resp === false) return
      Api.getSystemConfig(param).then(response => {
        if (response.status) {
          this.setState({
            openEdition: response.open_edition || '',
            config: _config,
            originConfig: fromJS(_config).toJS()
          }, () => {
            this.setState({
              menuloading: false,
              menucloseloading: false
            })
            this.submitAction(btnParam, tabParam)
          })
        } else {
          this.setState({
            menuloading: false,
            menucloseloading: false
          })
          notification.warning({
            top: 92,
            message: response.message,
            duration: 5
          })
        }
      })
    })
  }
  /**