king
2019-12-12 790dfe8172be5027940a04594224531d15143389
src/templates/comtableconfig/index.jsx
@@ -37,7 +37,6 @@
  }
  state = {
    operaType: '',           // 操作类型,新建或编辑
    dict: CommonDict,        // 字典
    config: null,            // 页面配置
    visible: false,          // 搜索条件、按钮、显示列,模态框显示控制
@@ -60,7 +59,8 @@
    tables: [],              // 可用表名
    selectedTables: [],      // 已选表名
    originMenu: null,        // 原始菜单
    originActions: null
    originActions: null,
    delActions: []
  }
  /**
@@ -69,14 +69,12 @@
   * 2、设置操作类型、原始菜单信息(每次保存后重置)、已使用表及基本信息表单
   */
  UNSAFE_componentWillMount () {
    const { menu, type } = this.props
    const { menu } = this.props
    let _LongParam = menu.LongParam
    let _config = ''
    let _type = type
    if (_type === 'add' || !_LongParam) {
      _type = 'add'
    if (!_LongParam) {
      _config = JSON.parse(JSON.stringify((Source.baseConfig)))
    } else {
      let _setting = Source.baseConfig.setting
@@ -87,15 +85,28 @@
      _config = _LongParam
    }
    let _oriActions = _config.action
    if (_config.type === 'user' || _config.type === 'system') {
      _oriActions = []
    let _oriActions = []
    if (_config.type === 'user') {
      _config.action = _config.action.map(item => {
        let uuid = Utils.getuuid()
        if (item.OpenType === 'pop') { // 含有子配置项的按钮。。。
          _oriActions.push({
            prebtn: JSON.parse(JSON.stringify(item)),
            curuuid: uuid,
            Template: 'Modal'
          })
        }
        item.uuid = uuid
        return item
      })
    }
    this.setState({
      originActions: _oriActions,
      config: _config,
      operaType: _type,
      originMenu: JSON.parse(JSON.stringify(menu)),
      selectedTables: _config.tables || [],
      menuformlist: [
@@ -913,6 +924,8 @@
   * 3、添加或编辑列,保存时,如按钮位置设置为表格,则修改操作列显示状态
   */
  handleSubmit = () => {
    const { menu } = this.props
    const { card } = this.state
    let _config = JSON.parse(JSON.stringify(this.state.config))
    if (this.state.formtemp !== 'gridbtn') {
@@ -927,6 +940,35 @@
            }
            res.values.dataSourceSql = Utils.formatOptions(sql)
          }
        }
        if (res.type === 'action' && card.originCard && res.values.OpenType === 'pop') {
          Api.getSystemConfig({
            func: 'sPC_Get_LongParam',
            MenuID: card.originCard.uuid
          }).then(result => {
            if (result.status && result.LongParam) {
              let param = {
                func: 'sPC_ButtonParam_AddUpt',
                ParentID: menu.MenuID,
                MenuID: res.values.uuid,
                MenuNo: menu.MenuNo,
                Template: 'Modal',
                MenuName: res.values.label,
                PageParam: JSON.stringify({Template: 'Modal'}),
                LongParam: result.LongParam
              }
              Api.getSystemConfig(param).then(response => {
                if (!response.status) {
                  notification.warning({
                    top: 92,
                    message: response.message,
                    duration: 10
                  })
                }
              })
            }
          })
        }
  
        _config[res.type] = _config[res.type].map(item => {
@@ -995,11 +1037,14 @@
  }
  creatFunc = () => {
    // let _config = JSON.parse(JSON.stringify(this.state.config))
    let _config = JSON.parse(JSON.stringify(this.state.config))
    this.formRef.handleConfirm().then(res => {
      let btn = res.values
      let LText = ''
      let DelText = ''
      let isExit = false
      if (!btn.innerFunc) {
        notification.warning({
          top: 92,
@@ -1027,7 +1072,22 @@
            }
            if (_LongParam) {
              resolve(_LongParam)
              let fields = []
              if (_LongParam.groups.length > 0) {
                _LongParam.groups.forEach(group => {
                  fields = [...fields, ...group.sublist]
                })
              } else {
                fields = _LongParam.fields
              }
              let _param = {
                name: _config.setting.tableName || '',
                fields: fields
              }
              LText = Utils.formatOptions(Utils.getfunc(_param))
              DelText = Utils.formatOptions(Utils.dropfunc(_param.name))
              resolve(true)
            } else {
              resolve(false)
              notification.warning({
@@ -1038,21 +1098,26 @@
            }
          })
        } else {
          let _param = {
            name: _config.setting.tableName || '',
            fields: ''
          }
          LText = Utils.formatOptions(Utils.getfunc(_param))
          DelText = Utils.formatOptions(Utils.dropfunc(_param.name))
          resolve(true)
        }
      }).then(res => {
        if (!res) return
        LText = Utils.formatOptions(Utils.getfunc())
        console.log(LText)
        console.log(res)
        if (res === false) return res
        return Api.getSystemConfig({
          func: 'sPC_Get_TVP',
          TVPName: btn.innerFunc
        })
      }).then(res => {
        console.log(res)
        if (res.status) {
          return true
        } else {
        if (res === false) return res
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
@@ -1060,57 +1125,161 @@
          })
          return false
        }
        if (res.TVPText && LText === res.TVPText) {
          return 'drop'
        } else {
          if (res.TVPText) {
            isExit = true
          }
          return Api.getSystemConfig({
            func: 'sPC_TVP_InUp',
            TVPName: btn.innerFunc,
            TVPText: LText,
            TypeName: 'P'
          })
        }
      }).then(res => {
        console.log(res)
        if (res === false || res === 'drop') return res
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 10
      })
          return false
        } else if (isExit) {
          return 'drop'
        } else {
          return 'create'
        }
      }).then(res => {
        console.log(res)
        if (res === false || res === 'create') return res
      // let isupdate = false
      // _config.action = _config.action.map(item => {
      //   if (item.uuid === res.values.uuid) {
      //     isupdate = true
      //     return res.values
      //   } else {
      //     return item
      //   }
      // })
      // _config.action = _config.action.filter(item => !item.origin)
        let _param = {
          func: 'sPC_TableData_InUpDe',
          LText: DelText
        }
        _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
        _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
        return Api.getSystemConfig(_param)
      }).then(res => {
        console.log(res)
        if (res === false || res === 'create') return res
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 10
          })
          return false
        } else {
          return 'create'
        }
      }).then(res => {
        console.log(res)
        if (res === false) return res
        let _param = {
          func: 'sPC_TableData_InUpDe',
          LText: LText
        }
        _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
        _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)
        return Api.getSystemConfig(_param)
      }).then(res => {
        console.log(res)
        if (res === false) return res
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 10
          })
          return false
        } else {
          notification.success({
            top: 92,
            message: '创建成功',
            duration: 5
          })
        }
      }).then(res => {
        console.log(res)
        if (res === false) return res
        if (!res.status) {
          notification.warning({
            top: 92,
            message: res.message,
            duration: 10
          })
          return false
        } else {
          notification.success({
            top: 92,
            message: '创建成功',
            duration: 5
          })
          return true
        }
      }).then(res => {
        console.log(res)
        if (res === false) return res
        let isupdate = false
        _config.action = _config.action.map(item => {
          if (item.uuid === res.values.uuid) {
            isupdate = true
            return res.values
          } else {
            return item
          }
        })
        _config.action = _config.action.filter(item => !item.origin)
      // if (!isupdate) { // 操作不是修改,添加元素至列表
      //   _config.action.push(res.values)
      // }
        if (!isupdate) { // 操作不是修改,添加元素至列表
          _config.action.push(res.values)
        }
      // let gridbtn = _config.action.filter(act => act.position === 'grid')
      // let _display = false
        let gridbtn = _config.action.filter(act => act.position === 'grid')
        let _display = false
      // if (gridbtn.length > 0) {
      //   _display = true
      // }
        if (gridbtn.length > 0) {
          _display = true
        }
      // if (_config.gridBtn) {
      //   _config.gridBtn.display = _display
      // } else {
      //   _config.gridBtn = {
      //     display: _display,
      //     Align: 'center',
      //     IsSort: 'false',
      //     uuid: Utils.getuuid(),
      //     label: this.state.dict['header.form.column.action'],
      //     type: 'action',
      //     style: 'button',
      //     show: 'horizontal',
      //     Width: 120
      //   }
      // }
        if (_config.gridBtn) {
          _config.gridBtn.display = _display
        } else {
          _config.gridBtn = {
            display: _display,
            Align: 'center',
            IsSort: 'false',
            uuid: Utils.getuuid(),
            label: this.state.dict['header.form.column.action'],
            type: 'action',
            style: 'button',
            show: 'horizontal',
            Width: 120
          }
        }
      // this.setState({
      //   config: _config,
      //   actionloading: true
      // }, () => {
      //   this.setState({
      //     actionloading: false
      //   })
      // })
        this.setState({
          config: _config,
          actionloading: true
        }, () => {
          this.setState({
            actionloading: false
          })
        })
      })
    })
  }
@@ -1131,6 +1300,7 @@
        })
        _this.setState({
          config: _config,
          delActions: [..._this.state.delActions, element.card.uuid],
          [element.type + 'loading']: true
        }, () => {
          _this.setState({
@@ -1151,35 +1321,21 @@
   */
  submitConfig = () => {
    const { menu } = this.props
    const { config, originMenu } = this.state
    const { originMenu } = this.state
    let config = JSON.parse(JSON.stringify(this.state.config))
    this.menuformRef.handleConfirm().then(res => {
      if (config.search[0] && config.search[0].origin) {
      config.search = config.search.filter(item => !item.origin)
      }
      if (config.action[0] && config.action[0].origin) {
      config.action = config.action.filter(item => !item.origin)
      }
      if (config.columns[0] && config.columns[0].origin) {
      config.columns = config.columns.filter(item => !item.origin)
      // if (config.search[0] && config.search[0].origin) {
      //   notification.warning({
      //     top: 92,
      //     message: '请设置搜索条件',
      //     duration: 10
      //   })
      //   return
      // }
      // if (config.action[0] && config.action[0].origin) {
      //   notification.warning({
      //     top: 92,
      //     message: '请设置按钮',
      //     duration: 10
      //   })
      //   return
      // }
      // if (config.columns[0] && config.columns[0].origin) {
      //   notification.warning({
      //     top: 92,
      //     message: '请设置显示列',
      //     duration: 10
      //   })
      //   return
      // }
      }
      let _LongParam = ''
      let _config = {...config, tables: this.state.selectedTables}
@@ -1216,14 +1372,14 @@
      btnParam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
      btnParam.secretkey = Utils.encrypt(btnParam.LText, btnParam.timestamp)
      if (this.state.operaType === 'add') { // 新建菜单
        let param = {
          func: 'sPC_TrdMenu_Add',
        func: 'sPC_TrdMenu_AddUpt',
          ParentID: res.parentId,
          MenuID: menu.MenuID,
          MenuNo: res.menuNo,
          Template: menu.PageParam.Template || '',
          MenuName: res.menuName,
        Sort: (this.props.supMenuList.length + 1) * 10,
          PageParam: JSON.stringify(_pageParam),
          LongParam: _LongParam
        }
@@ -1241,7 +1397,7 @@
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              operaType: 'edit',
            config: _config,
              originMenu: {
                ...originMenu,
                LongParam: _config,
@@ -1249,8 +1405,18 @@
                MenuName: res.menuName,
                MenuNo: res.menuNo,
                ParentID: res.parentId
              }
            },
            searchloading: true,
            actionloading: true,
            columnsloading: true
          }, () => {
            this.setState({
              searchloading: false,
              actionloading: false,
              columnsloading: false
            })
          })
            this.submitAction(btnParam)
          } else {
            this.setState({
@@ -1264,54 +1430,6 @@
            })
          }
        })
      } else { // 修改菜单
        let param = {
          func: 'sPC_TrdMenu_Upt',
          ParentID: res.parentId,
          MenuID: menu.MenuID,
          MenuNo: res.menuNo,
          Template: menu.PageParam.Template || '',
          MenuName: res.menuName,
          PageParam: JSON.stringify(_pageParam),
          LongParam: _LongParam
        }
        if (this.state.closeVisible) { // 显示关闭对话框时,模态框中保存按钮,显示保存中状态
          this.setState({
            menucloseloading: true
          })
        } else {
          this.setState({
            menuloading: true
          })
        }
        Api.getSystemConfig(param).then(response => {
          if (response.status) {
            this.setState({
              originMenu: {
                ...originMenu,
                LongParam: _config,
                PageParam: _pageParam,
                MenuName: res.menuName,
                MenuNo: res.menuNo,
                ParentID: res.parentId
              }
            })
            this.submitAction(btnParam)
          } else {
            this.setState({
              menuloading: false,
              menucloseloading: false
            })
            notification.warning({
              top: 92,
              message: response.message,
              duration: 10
            })
          }
        })
      }
    }, () => {
      notification.warning({
        top: 92,
@@ -1325,8 +1443,117 @@
   * @description 保存或修改菜单按钮
   */
  submitAction = (param) => {
    const { config } = this.state
    new Promise(resolve => {
      // 内部请求
    Api.getSystemConfig(param).then(response => {
      if (response.status) {
          resolve('true')
        } else {
          resolve(response)
        }
      })
    }).then(res => {
      console.log(res)
      if (res === 'true' && this.state.delActions.length > 0) {
        let deffers = this.state.delActions.map(item => {
          let param = {
            func: 'sPC_MainMenu_Del',
            MenuID: item
          }
          return new Promise(resolve => {
            Api.getSystemConfig(param).then(res => {
              resolve(res)
            })
          })
        })
        return Promise.all(deffers)
      } else if (res === 'true' && this.state.delActions.length === 0) {
        return 'copy'
      } else if (!res.status) {
        notification.warning({
          top: 92,
          message: res.message,
          duration: 10
        })
        return false
      }
    }).then(response => {
      console.log(response)
      if (response === false || response === 'copy') return response
      let res = 'copy'
      if (Array.isArray(response)) {
        response.forEach(result => {
          if (!result.status) {
            res = result
          }
        })
      }
      if (res === 'copy') return 'copy'
      notification.warning({
        top: 92,
        message: res.message,
        duration: 10
      })
      return false
    }).then(response => {
      console.log(response)
      if (response === false) return response
      let oriActions = []
      this.state.originActions.forEach(item => {
        let curBtn = config.action.filter(cell => item.curuuid === cell.uuid)[0] // 查看初始化按钮是否存在
        if (!curBtn) return
        if (curBtn.OpenType !== item.prebtn.OpenType) return
        oriActions.push({
          prebtn: item.prebtn,
          curBtn: item.curBtn
        })
      })
      if (oriActions.length === 0) return 'true'
      oriActions.forEach(action => {
        Api.getSystemConfig({
          func: 'sPC_Get_LongParam',
          MenuID: action.prebtn ? action.prebtn.uuid : ''
        }).then(result => {
          if (result.status && result.LongParam) {
            let _LongParam = ''
            if (result.LongParam) {
              _LongParam = window.decodeURIComponent(window.atob(result.LongParam))
              try {
                _LongParam = JSON.parse(_LongParam)
              } catch (e) {
                _LongParam = ''
              }
            }
            if (_LongParam) {
              let param = {
                func: 'sPC_ButtonParam_AddUpt',
                ParentID: this.props.menu.MenuID,
                MenuID: action.curBtn.uuid,
                MenuNo: this.props.menu.MenuNo,
                Template: _LongParam.type,
                MenuName: action.curBtn.label,
                PageParam: JSON.stringify({Template: _LongParam.type}),
                LongParam: result.LongParam
              }
              Api.getSystemConfig(param).then(() => {})
            }
          }
        })
      })
      return 'true'
    }).then(response => {
      console.log(response)
      if (response === 'true') {
        notification.success({
          top: 92,
          message: '保存成功',
@@ -1345,11 +1572,6 @@
          menuloading: false,
          menucloseloading: false
        })
        notification.warning({
          top: 92,
          message: response.message,
          duration: 10
        })
      }
    })
  }
@@ -1357,9 +1579,19 @@
  cancelConfig = () => {
    const { menu } = this.props
    const { config, originMenu } = this.state
    let _this = this
    if (this.state.operaType === 'add') {
    let _this = this
    let isAdd = false
    if (
      (config.search[0] && config.search[0].origin) ||
      (config.action[0] && config.action[0].origin) ||
      (config.columns[0] && config.columns[0].origin)
    ) {
      isAdd = true
    }
    if (isAdd) {
      confirm({
        content: '菜单尚未提交,确定放弃保存吗?',
        okText: this.state.dict['header.confirm'],
@@ -1590,11 +1822,14 @@
    }
    this.setState({
      tableVisible: false,
      [addType + 'loading']: true,
      addType: '',
      config: {...config, [addType]: items}
    }, () => {
      notification.success({
        top: 92,
        message: '操作成功',
        duration: 5
      })
      this.setState({
        [addType + 'loading']: false
      })
@@ -1693,7 +1928,17 @@
    const { menu } = this.props
    const { config, originMenu } = this.state
    if (this.state.operaType === 'add') {
    let isAdd = false
    if (
      (config.search[0] && config.search[0].origin) ||
      (config.action[0] && config.action[0].origin) ||
      (config.columns[0] && config.columns[0].origin)
    ) {
      isAdd = true
    }
    if (isAdd) {
      notification.warning({
        top: 92,
        message: '菜单尚未保存,请保存菜单配置!',
@@ -1739,7 +1984,7 @@
                  _LongParam = ''
                }
              }
              console.log(_LongParam)
              this.props.handleSubConfig(btn, originMenu, _LongParam)
            } else {
              this.setState({
@@ -1946,7 +2191,7 @@
          onOk={this.handleSubmit}
          footer={[
            this.state.formtemp === 'action' ?
            <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.delete']}</Button> : null,
            <Button key="delete" className="mk-btn mk-purple" onClick={this.creatFunc} loading={this.state.confirmLoading}>{this.state.dict['header.menu.func.create']}</Button> : null,
            <Button key="cancel" onClick={() => { this.setState({ visible: false }) }}>{this.state.dict['header.cancel']}</Button>,
            <Button key="confirm" type="primary" onClick={this.handleSubmit}>{this.state.dict['header.confirm']}</Button>
          ]}
@@ -1999,6 +2244,7 @@
          visible={this.state.tableVisible}
          width={'65vw'}
          style={{minWidth: '900px', maxWidth: '1200px'}}
          cancelText={this.state.dict['header.close']}
          onOk={this.addFieldSubmit}
          onCancel={() => { // 取消添加
            this.setState({
@@ -2009,7 +2255,7 @@
          destroyOnClose
        >
          {this.state.addType && this.state.fields.length > 0 ?
            <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} /> : null
            <EditCard data={this.state.fields} ref="searchcard" type={this.state.addType} dict={this.state.dict} /> : null
          }
          {(!this.state.fields || this.state.fields.length === 0) &&
            <Empty />