king
2020-08-20 3683e1475e8d74f690172a468518d88d91a69ccc
src/tabviews/subtabtable/index.jsx
@@ -2,7 +2,7 @@
import PropTypes from 'prop-types'
import {connect} from 'react-redux'
import { is, fromJS } from 'immutable'
import { notification, Spin, Col, Icon, Tabs} from 'antd'
import { notification, Spin, Col, Row, Icon, Tabs} from 'antd'
import moment from 'moment'
import Api from '@/api'
@@ -26,11 +26,15 @@
class SubTabModalTable extends Component {
  static propTpyes = {
    type: PropTypes.any,             // 类型,calendar需特殊处理
    Tab: PropTypes.any,              // 日历标签信息
    BID: PropTypes.string,           // 上级数据ID
    BData: PropTypes.any,            // 上级数据
    MenuID: PropTypes.string,        // 菜单Id
    mainSearch: PropTypes.any,       // 主表搜索条件
    SupMenuID: PropTypes.string,     // 上级菜单Id
    refreshSupView: PropTypes.any    // 刷新上级菜单
    refreshSupView: PropTypes.any,   // 刷新上级菜单
    closeModalView: PropTypes.any    // 关闭模态框
  }
  state = {
@@ -62,13 +66,13 @@
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { permAction } = this.props
    const { permAction, type } = this.props
    let param = {
      func: 'sPC_Get_LongParam',
      MenuID: this.props.MenuID
    }
    let result = await Api.getSystemCacheConfig(param)
    let result = await Api.getCacheConfig(param)
    if (result.status) {
      let config = ''
@@ -104,90 +108,107 @@
      let _hideCol = []      // 隐藏及合并列中字段的uuid集
      let colMap = new Map()
      // 兼容图表
      let chartId = ''
      if (!config.charts) {
        config.expand = true
        config.charts = [{
          uuid: Utils.getuuid(),
          label: '',
          title: '',
          chartType: 'table',
          icon: 'table',
          Hide: 'false',
          blacklist: []
        }]
      } else if (config.charts.length === 1) {
        config.expand = true
      // 旧版本兼容
      if (!config.version || config.version < '1.0') {
        // 兼容图表
        if (!config.charts) {
          config.expand = true
          config.charts = [{ uuid: Utils.getuuid(), label: '', title: '', chartType: 'table', icon: 'table', Hide: 'false', blacklist: [] }]
        } else {
          config.charts.forEach(card => {
            if (card.chartType === 'card') {
              card.details = card.details.map(_cell => {
                _cell.fontSize = _cell.fontSize || 14
                if (!_cell.width) {
                  _cell.width = 100
                } else if (_cell.width === 'helf') {
                  _cell.width = 50
                } else if (_cell.width === 'third') {
                  _cell.width = 33
                }
                if (!_cell.fontWeight && _cell.bold === 'true') {
                  _cell.fontWeight = 'normal'
                }
                _cell.height = _cell.height || 1
                return _cell
              })
            }
          })
        }
      }
      chartId = config.charts[0].uuid
      // 仅支持exec、prompt、pop 三种类型按钮
      config.action = config.action.filter(item => ['exec', 'prompt', 'pop'].includes(item.OpenType))
      if (type === 'calendar') {
        config.action = config.action.filter(item => ['exec', 'prompt', 'pop', 'tab', 'excelIn', 'excelOut'].includes(item.OpenType))
      } else {
        config.action = config.action.filter(item => ['exec', 'prompt', 'pop'].includes(item.OpenType))
      }
      // 权限过滤
      if (this.props.menuType !== 'HS') {
        config.action = config.action.filter(item => permAction[item.uuid])
        // 字段权限黑名单
        config.search = config.search.filter(item => {
          if (!item.blacklist || item.blacklist.length === 0) return true
          let _black = item.blacklist.filter(v => {
            return this.props.permRoles.indexOf(v) !== -1
          })
          if (_black.length > 0) {
            return false
          } else {
            return true
          }
        })
        config.columns = config.columns.filter(col => {
          if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return true
          let _black = col.blacklist.filter(v => {
            return this.props.permRoles.indexOf(v) !== -1
          })
          if (_black.length > 0) {
            return false
          } else {
            return true
          }
        })
        // 视图权限
        config.charts = config.charts.filter(item => {
          if (item.Hide === 'true') return false
          if (!item.blacklist || item.blacklist.length === 0) return true
          let _black = item.blacklist.filter(v => {
            return this.props.permRoles.indexOf(v) !== -1
          })
          if (_black.length > 0 || item.Hide === 'true') {
            return false
          } else {
            return true
          }
        })
      } else {
        // 隐藏视图
        config.charts = config.charts.filter(item => item.Hide !== 'true')
      }
      // 字段权限黑名单
      config.search = config.search.filter(item => {
        item.oriInitval = item.initval
        if (!item.blacklist || item.blacklist.length === 0) return item
        let _black = item.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0) {
          item.Hide = 'true'
        }
        return item
      })
      config.columns = config.columns.filter(col => {
        if (!col.field || !col.blacklist || col.blacklist.length === 0 || config.setting.primaryKey === col.field) return col
        let _black = col.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0) {
          col.Hide = 'true'
        }
        return col
      })
      // 视图权限
      config.charts = config.charts.filter(item => {
        if (item.Hide === 'true') return false
        if (!item.blacklist || item.blacklist.length === 0) return true
        let _black = item.blacklist.filter(v => {
          return this.props.permRoles.indexOf(v) !== -1
        })
        if (_black.length > 0 || item.Hide === 'true') {
          return false
        } else {
          return true
        }
      })
      if (config.charts.length <= 1) {
        config.expand = true
      }
      let chartId = config.charts[0] ? config.charts[0].uuid : ''
      // 1、筛选字段集,2、过滤隐藏列及合并列中的字段uuid
      config.columns.forEach(col => {
        if (col.field) {
          _arrField.push(col.field)
          _logcolumns.push(col)
          col.nameField && _arrField.push(col.nameField) // 链接名字段
        }
        if (col.type === 'colspan' && col.sublist) { // 筛选隐藏列
          _hideCol = _hideCol.concat(col.sublist)
@@ -261,8 +282,6 @@
        arr_field: _arrField.join(','),
        search: Utils.initMainSearch(config.search) // 搜索条件初始化(含有时间格式,需要转化)
      }, () => {
        this.improveSearch()
        if (config.setting.onload !== 'false' && valid) { // 初始化可加载
          this.loadmaindata()
        }
@@ -278,94 +297,6 @@
        duration: 5
      })
    }
  }
  /**
   * @description 搜索条件下拉选项预加载
   */
  improveSearch = () => {
    let searchlist = JSON.parse(JSON.stringify(this.state.searchlist))
    let deffers = []
    searchlist.forEach(item => {
      if (item.type !== 'multiselect' && item.type !== 'select' && item.type !== 'link') return
      if (item.setAll === 'true') {
        item.options.unshift({
          key: Utils.getuuid(),
          Value: '',
          Text: this.state.dict['main.all']
        })
      }
      if (item.resourceType === '1' && item.dataSource) {
        let _option = Utils.getSelectQueryOptions(item)
        let _sql = Utils.formatOptions(_option.sql)
        let isSSO = item.database === 'sso'
        let param = {
          func: 'sPC_Get_SelectedList',
          LText: _sql,
          obj_name: 'data',
          arr_field: _option.field
        }
        if (this.props.BID) {
          param.BID = this.props.BID
        }
        if (this.props.dataManager) { // 数据权限
          param.LText = param.LText.replace(/\$@/ig, '/*')
          param.LText = param.LText.replace(/@\$/ig, '*/')
        } else {
          param.LText = param.LText.replace(/@\$|\$@/ig, '')
        }
        param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
        param.secretkey = Utils.encrypt(param.LText, param.timestamp)
        let defer = new Promise(resolve => {
          Api.getSystemCacheConfig(param, isSSO).then(res => {
            res.search = item
            resolve(res)
          })
        })
        deffers.push(defer)
      } else if (item.resourceType === '1' && !item.dataSource) {
        notification.warning({
          top: 92,
          message: item.label + ': ' + this.state.dict['main.datasource.settingerror'],
          duration: 5
        })
      }
    })
    this.setState({searchlist: JSON.parse(JSON.stringify(searchlist))})
    if (deffers.length === 0) return
    Promise.all(deffers).then(result => {
      result.forEach(res => {
        if (res.status) {
          searchlist = searchlist.map(item => {
            if (item.uuid === res.search.uuid) {
              res.data.forEach(cell => {
                item.options.push({
                  key: Utils.getuuid(),
                  Value: cell[res.search.valueField],
                  Text: cell[res.search.valueText]
                })
              })
            }
            return item
          })
        } else {
          notification.warning({
            top: 92,
            message: res.search.label + ':' + res.message,
            duration: 5
          })
        }
      })
      this.setState({searchlist})
    })
  }
  /**
@@ -399,6 +330,11 @@
      param = this.getDefaultParam()
    }
    // 数据管理权限
    if (this.props.dataManager) {
      param.dataM = 'Y'
    }
    let result = await Api.genericInterface(param)
    if (result.status) {
      this.setState({
@@ -425,13 +361,18 @@
   * @description 获取用户自定义存储过程传参
   */
  getCustomParam = () => {
    const { mainSearch } = this.props
    const { pageIndex, pageSize, orderBy, search, setting } = this.state
    let _search = Utils.formatCustomMainSearch(search)
    let searches = search
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...search]
    }
    let _search = Utils.formatCustomMainSearch(searches)
    let param = {
      OrderCol: orderBy || setting.order,
      dataM: this.props.dataManager ? 'Y' : '',
      ..._search
    }
@@ -469,9 +410,15 @@
   * @description 获取系统存储过程 sPC_Get_TableData 的参数
   */
  getDefaultParam = () => {
    const { mainSearch } = this.props
    const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state
    let _search = Utils.joinMainSearchkey(search)
    let searches = search
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...search]
    }
    let _search = Utils.joinMainSearchkey(searches)
    _search = _search ? 'where ' + _search : ''
    let param = {
@@ -480,8 +427,7 @@
      arr_field: arr_field,
      BID: this.props.BID,
      custom_script: setting.customScript || '',
      default_sql: setting.default || 'true',
      dataM: this.props.dataManager ? 'Y' : ''
      default_sql: setting.default || 'true'
    }
    let _orderBy = orderBy || setting.order
@@ -503,7 +449,7 @@
    let regoptions = null
    if (setting.queryType === 'statistics' || param.custom_script) {
      let allSearch = Utils.getAllSearchOptions(search)
      let allSearch = Utils.getAllSearchOptions(searches)
      regoptions = allSearch.map(item => {
        return {
@@ -524,10 +470,10 @@
    let DateCount = ''
    if (setting.default !== 'false' && setting.laypage !== 'false') {
      LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
      LText = ` select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows `
      DateCount = `select count(1) as total from ${_dataresource} ${_search}`
    } else if (setting.default !== 'false') {
      LText = `select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows`
      LText = ` select ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows `
      DateCount = ''
    }
@@ -554,7 +500,7 @@
        LText += `
          aaa:
          if @ErrorCode!=''
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
        `
      } else {
        param.custom_script += `
@@ -563,14 +509,23 @@
            insert into tmp_err_retmsg (ID, ErrorCode, retmsg, CreateUserID) select @time_id@,@ErrorCode, @retmsg,@UserID@
        `
      }
      param.custom_script = Utils.formatOptions(param.custom_script)
    }
    // 测试系统打印查询语句
    if ((options.sysType === 'local' && !window.GLOB.systemType) || window.debugger === true) {
      param.custom_script &&  console.log(`${LText ? '' : '/*不执行默认sql*/\n'}${param.custom_script}`)
      LText &&  console.log(LText)
    }
    param.custom_script = Utils.formatOptions(param.custom_script)
    param.LText = Utils.formatOptions(LText)
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
    param.DateCount = Utils.formatOptions(DateCount)
    if (this.props.menuType === 'HS') { // 云端数据验证
      param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true)
    }
    return param
  }
@@ -648,12 +603,14 @@
   * @description 按钮操作完成后(成功或失败),页面刷新,重置页码及选择项
   */
  refreshbyaction = (position) => {
    if (position === 'grid') {
    if (position === 'grid' || position === 'maingrid') {
      this.reloadtable()
      this.props.refreshSupView()
    } else if (position === 'view') {
      this.reloadview()
      this.props.refreshSupView()
    } else if (position === 'trigger') { // 日历子表触发标签点击事件
      this.props.closeModalView && this.props.closeModalView()
    }
  }
@@ -664,11 +621,31 @@
    this.setState({
      triggerBtn: {
        uuid: new Date().getTime(),
        parentId: this.props.MenuID,
        parentId: this.props.SupMenuID,
        button: btn,
        data: record
      }
    })
  }
  /**
   * @description 导出Excel时,获取页面搜索排序等参数
   */
  getexceloutparam = () => {
    const { Tab, mainSearch } = this.props
    const { arr_field, orderBy, search, setting} = this.state
    let searches = search
    if (mainSearch && mainSearch.length > 0) { // 主表搜索条件
      searches = [...mainSearch, ...search]
    }
    return {
      arr_field: arr_field,
      orderBy: orderBy || setting.order,
      search: searches,
      menuName: Tab.label
    }
  }
  /**
@@ -704,12 +681,15 @@
        {loadingview && <Spin />}
        {searchlist && searchlist.length > 0 ?
          <SubSearch
            refreshdata={this.refreshbysearch}
            searchlist={searchlist}
            BID={this.props.BID}
            dict={this.state.dict}
            searchlist={searchlist}
            menuType={this.props.menuType}
            dataManager={this.props.dataManager}
            refreshdata={this.refreshbysearch}
          /> : null
        }
        {config ? <div className="chart-view">
        {config ? <Row className="chart-view" gutter={16}>
          {/* 视图组 */}
          {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
            {config.charts.map(item => (
@@ -736,6 +716,7 @@
                      logcolumns={this.state.logcolumns}
                      operations={config.gridBtn.operations || []}
                      refreshdata={this.refreshbyaction}
                      getexceloutparam={this.getexceloutparam}
                    />
                  </div>
                  <SubTable
@@ -764,9 +745,13 @@
                    tableId=""
                    plot={item}
                    config={config}
                    BID={this.props.BID}
                    BData={this.props.BData}
                    data={this.state.data}
                    loading={this.state.loading}
                    logcolumns={this.state.logcolumns}
                    buttonTrigger={this.buttonTrigger}
                    refreshdata={this.refreshbyaction}
                    handleTableId={() => {}}
                  />
                </Col>
@@ -784,7 +769,7 @@
              )
            }
          })}
        </div> : null }
        </Row> : null }
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )