king
2020-05-03 6def3330d1d1cf4036916ed04c8bbc4128e1e5d0
src/tabviews/commontable/index.jsx
@@ -13,8 +13,6 @@
import {refreshTabView, modifyTabview} from '@/store/action'
import MainTable from '@/tabviews/zshare/normalTable'
// import MainAction from '@/tabviews/zshare/actionList'
// import VerifyCard from '@/tabviews/zshare/verifycard'
import MainSearch from '@/tabviews/zshare/topSearch'
import NotFount from '@/components/404'
import './index.scss'
@@ -31,9 +29,10 @@
class NormalTable extends Component {
  static propTpyes = {
    param: PropTypes.any,        // 其他页面传递的搜索条件等参数
    MenuID: PropTypes.string,    // 菜单Id
    MenuNo: PropTypes.string,    // 菜单参数
    MenuName: PropTypes.string,  // 菜单参数
    MenuID: PropTypes.string     // 菜单Id
    MenuName: PropTypes.string   // 菜单名称
  }
  state = {
@@ -69,21 +68,23 @@
    tabParam: null,       // 表单标签参数
    refreshtabs: null,    // 需要刷新的标签集
    confirmLoading: false,// 自定义设置模态框加载中
    revertLoading: false, // 恢复默认设置
    settingVisible: false,// 自定义设置模态框
    triggerBtn: null      // 点击表格中或快捷键触发的按钮
    triggerBtn: null,     // 点击表格中或快捷键触发的按钮
    tabActive: null       // 标签页展开控制
  }
  /**
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { permAction } = this.props
    const { permAction, permMenus, param } = this.props
    let param = {
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: this.props.MenuID
    }
    let result = await Api.getSystemCacheConfig(param)
    let result = await Api.getSystemCacheConfig(_param)
    if (result.status) {
      let config = ''
@@ -165,6 +166,7 @@
      if (_curUserConfig) {
        config.setting = {...config.setting, ..._curUserConfig.setting}
        config.easyCode = _curUserConfig.easyCode || config.easyCode || ''
        config.action = config.action.map(item => {
          if (item.execMode) {
@@ -172,6 +174,7 @@
          }
          if (_curUserConfig.action[item.uuid]) {
            delete _curUserConfig.action[item.uuid].label
            item = {...item, ..._curUserConfig.action[item.uuid]}
          }
          
@@ -189,6 +192,13 @@
          return item
        })
      }
      let _tabActive = {} // 筛选展开的tab页
      config.tabgroups.forEach(groupId => {
        if (!config[groupId] || config[groupId].length === 0) return
        _tabActive[groupId] = config[groupId][0].uuid
      })
      let _arrField = []     // 字段集
      let _columns = []      // 显示列
@@ -211,13 +221,6 @@
        }
      })
      if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
        _columns.push({
          ...config.gridBtn,
          operations: _operations
        })
      }
      // 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
      config.columns.forEach(col => {
        if (col.field) {
@@ -234,8 +237,14 @@
      })
      // 生成显示列,处理合并列中的字段
      config.columns.forEach(col => {
      config.columns.forEach((col, index) => {
        if (_hideCol.includes(col.uuid)) return
        if (col.linkThdMenu && !permMenus[col.linkThdMenu.MenuID]) {
          col.linkThdMenu = ''
        }
        col.sort = index
        if (col.type === 'colspan' && col.sublist) {
          let _col = JSON.parse(JSON.stringify(col))
@@ -252,16 +261,30 @@
        }
      })
      let valid = true // 搜索条件必填验证
      config.search.forEach(field => {
        if (field.required === 'true' && !field.initval) {
      if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
        _columns.push({
          ...config.gridBtn,
          operations: _operations
        })
      }
      let valid = true // 搜索条件必填验证, 初始搜索条件
      let initSearch = config.search.map(item => {
        let _item = JSON.parse(JSON.stringify(item))
        if (_item.type === 'text' && param && param.searchkey === _item.field) {
          _item.initval = param.searchval
        }
        if (_item.required === 'true' && !_item.initval) {
          valid = false
        }
        return _item
      })
      if (_curUserConfig) {
        _columns = _columns.map(item => {
          if (_curUserConfig.columns[item.uuid]) {
            delete _curUserConfig.columns[item.uuid].label
            item = {...item, ..._curUserConfig.columns[item.uuid]}
          }
@@ -276,6 +299,7 @@
      this.setState({
        loadingview: false,
        config: config,
        tabActive: _tabActive,
        userConfig: userConfig,
        setting: config.setting,
        searchlist: config.search,
@@ -283,7 +307,7 @@
        columns: _columns,
        logcolumns: _logcolumns,
        arr_field: _arrField.join(','),
        search: Utils.initMainSearch(config.search) // 搜索条件初始化(含有时间格式,需要转化)
        search: Utils.initMainSearch(initSearch) // 搜索条件初始化(含有时间格式,需要转化)
      }, () => {
        this.improveSearch()
        if (config.setting.onload !== 'false' && valid) { // 初始化可加载
@@ -299,13 +323,13 @@
      notification.warning({
        top: 92,
        message: result.message,
        duration: 10
        duration: 5
      })
    }
  }
  setShortcut = () => {
    const { actions, userConfig } = this.state
    const { actions, userConfig, config } = this.state
    if (!userConfig) return
    document.onkeydown = (event) => {
@@ -359,14 +383,41 @@
            e.preventDefault()
            istrigger = true
            this.setState({
              triggerBtn: {
                uuid: new Date().getTime(),
                parentId: key,
                button: item,
                data: null
            let _groupId = ''
            let _ActiveTabId = ''
            config.tabgroups.forEach(groupId => {
              if (!config[groupId] || config[groupId].length === 0) return
              let _tab = config[groupId].filter(tab => tab.uuid === key)[0]
              if (_tab) {
                _groupId = groupId
                _ActiveTabId = _tab.uuid
              }
            })
            if (this.state.tabActive[_groupId] === _ActiveTabId) {
              this.setState({
                triggerBtn: {
                  uuid: new Date().getTime(),
                  parentId: key,
                  button: {...item, uuid: btnkey},
                  data: null
                }
              })
            } else {
              this.setState({
                tabActive: {...this.state.tabActive, [_groupId]: _ActiveTabId}
              }, () => {
                this.setState({
                  triggerBtn: {
                    uuid: new Date().getTime(),
                    parentId: key,
                    button: {...item, uuid: btnkey},
                    data: null
                  }
                })
              })
            }
          }
        })
      })
@@ -415,7 +466,7 @@
        notification.warning({
          top: 92,
          message: item.label + ': ' + this.state.dict['main.datasource.settingerror'],
          duration: 10
          duration: 5
        })
      }
    })
@@ -450,7 +501,7 @@
          notification.warning({
            top: 92,
            message: res.search.label + ':' + res.message,
            duration: 10
            duration: 5
          })
        }
      })
@@ -515,7 +566,7 @@
      notification.error({
        top: 92,
        message: result.message,
        duration: 15
        duration: 10
      })
    }
  }
@@ -538,13 +589,11 @@
    if (setting.interType === 'inner') {
      param.func = setting.innerFunc
    } else {
      if (setting.sysInterface === 'true') {
        param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi
      } else {
      if (setting.sysInterface === 'true' && window.GLOB.mainSystemApi) {
        param.rduri = window.GLOB.mainSystemApi
      } else if (setting.sysInterface !== 'true') {
        param.rduri = setting.interface
      }
      param.appkey = window.GLOB.appkey || '' // 调用外部接口增加appkey
      if (setting.outerFunc) {
        param.func = setting.outerFunc
@@ -564,7 +613,7 @@
      notification.warning({
        top: 92,
        message: '未设置显示列!',
        duration: 10
        duration: 5
      })
      return null
    }
@@ -576,8 +625,7 @@
    let param = {
      func: 'sPC_Get_TableData',
      obj_name: 'data',
      arr_field: arr_field,
      appkey: window.GLOB.appkey || ''
      arr_field: arr_field
    }
    
    let _orderBy = orderBy || setting.order
@@ -588,23 +636,14 @@
    }
    if (setting.queryType === 'statistics') { // 统计数据源,内容替换
      let fieldmap = new Map()
      let options = search.map(item => {
        let _field = item.key
      let allSearch = Utils.getAllSearchOptions(search)
        if (fieldmap.has(_field)) {
          _field = _field + '1'
        }
        fieldmap.set(item.key, true)
      let options = allSearch.map(item => {
        return {
          reg: new RegExp('@' + _field, 'ig'),
          reg: new RegExp('@' + item.key + '@', 'ig'),
          value: item.value
        }
      })
      options.reverse()
      options.forEach(item => {
        _dataresource = _dataresource.replace(item.reg, `'${item.value}'`)
@@ -981,12 +1020,72 @@
  controlCustomSetting = () => {
    this.setState({
      settingVisible: true,
      confirmLoading: false
      confirmLoading: false,
      revertLoading: false
    })
  }
  changeMenuParam = (param) => {
    this.setState({userParam: param})
  }
  linkTrigger = (menu) => {
    const { tabviews, MenuID } = this.props
    menu.selected = true
    let index = 0
    let isexit = false
    let tabs = tabviews.map((tab, i) => {
      tab.selected = false
      if (tab.MenuID === MenuID) {
        index = i
      } else if (tab.MenuID === menu.MenuID) {
        tab.param = menu.param
        tab.selected = true
        isexit = true
      }
      return tab
    })
    if (!isexit) {
      tabs.splice(index + 1, 0, menu)
    }
    this.props.modifyTabview(tabs)
  }
  settingRevert = () => {
    let param = {
      func: 's_TrdMenu_UserParam_del',
      MenuID: this.props.MenuID
    }
    this.setState({
      revertLoading: true
    })
    Api.getSystemConfig(param).then(result => {
      if (!result.status) {
        this.setState({
          revertLoading: false
        })
        notification.warning({
          top: 92,
          message: result.message,
          duration: 5
        })
        return
      }
      this.setState({
        settingVisible: false,
        revertLoading: false
      }, () => {
        window.GLOB.CacheMap = new Map()
        this.reloadview()
      })
    })
  }
  settingSubmit = () => {
@@ -999,14 +1098,17 @@
      notification.warning({
        top: 92,
        message: '编译错误',
        duration: 10
        duration: 5
      })
      return
    }
    let easyCode = userParam[this.props.MenuID] ? userParam[this.props.MenuID].easyCode : ''
    let param = {
      func: 'sPC_TrdMenu_UserParam',
      MenuID: this.props.MenuID,
      EasyCode: easyCode || '',
      LongParam: _LongParam
    }
@@ -1022,7 +1124,7 @@
        notification.warning({
          top: 92,
          message: result.message,
          duration: 10
          duration: 5
        })
        return
      }
@@ -1049,6 +1151,20 @@
        this.reloadview()
      }
      this.props.refreshTabView('')
    } else if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
      let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0]
      if (selectTab && selectTab.MenuID === this.props.MenuID) {
        this.setShortcut()
      }
    } else if (nextProps.param && !is(fromJS(this.props.param), fromJS(nextProps.param))) {
      let search = this.state.search.map(item => {
        if (item.type === 'text' && item.key === nextProps.param.searchkey) {
          item.value = nextProps.param.searchval
        }
        return item
      })
      this.refreshbysearch(search)
    }
  }
@@ -1067,7 +1183,7 @@
  }
  render() {
    const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig } = this.state
    const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig, tabActive, search } = this.state
    return (
      <div>
@@ -1121,6 +1237,7 @@
                loading={this.state.loading}
                refreshdata={this.refreshbytable}
                buttonTrigger={this.buttonTrigger}
                linkTrigger={this.linkTrigger}
                handleTableId={this.handleTableId}
              />
            </div> : null
@@ -1130,21 +1247,22 @@
              if (config[group].length === 0) return null
              return (
                <Tabs defaultActiveKey="0" key={group}>
                  {config[group].map((_tab, index) => {
                <Tabs activeKey={tabActive[group]} key={group} onChange={(key) => this.setState({tabActive: {...tabActive, [group]: key}})}>
                  {config[group].map(_tab => {
                    return (
                      <TabPane tab={
                        <span>
                          {_tab.icon ? <Icon type={_tab.icon} /> : null}
                          {_tab.label}
                        </span>
                      } key={`${index}`}>
                      } key={_tab.uuid}>
                        {_tab.type === 'SubTable' ?
                          <SubTable
                            Tab={_tab}
                            menuType="main"
                            MenuID={_tab.linkTab}
                            userConfig={userConfig ? userConfig[_tab.linkTab] : null}
                            mainSearch={_tab.searchPass === 'true' ? search : null}
                            userConfig={userConfig ? userConfig[_tab.uuid] : null}
                            triggerBtn={triggerBtn}
                            SupMenuID={this.props.MenuID}
                            refreshtabs={this.state.refreshtabs}
@@ -1217,9 +1335,12 @@
            maskClosable={false}
            width={950}
            visible={this.state.settingVisible}
            onOk={this.settingSubmit}
            onCancel={() => { this.setState({ settingVisible: false }) }}
            confirmLoading={this.state.confirmLoading}
            footer={[
              <Button key="revert" type="danger" loading={this.state.revertLoading} onClick={this.settingRevert}>{this.state.dict['main.revert.default']}</Button>,
              <Button key="cancel" onClick={() => { this.setState({ settingVisible: false }) }}>{this.state.dict['main.cancel']}</Button>,
              <Button key="confirm" type="primary" loading={this.state.confirmLoading} onClick={this.settingSubmit}>{this.state.dict['main.submit']}</Button>
            ]}
            destroyOnClose
          >
            {this.state.settingVisible ?
@@ -1248,6 +1369,7 @@
    tabviews: state.tabviews,
    refreshTab: state.refreshTab,
    permAction: state.permAction,
    permMenus: state.permMenus,
    permRoles: state.permRoles
  }
}