king
2023-08-27 da64ab0923bf8817fc8599a6e37b953ce38f64c8
src/tabviews/basetable/index.jsx
@@ -4,8 +4,6 @@
import { notification, Spin, Row, Col } from 'antd'
import Api from '@/api'
import zhCN from '@/locales/zh-CN/main.js'
import enUS from '@/locales/en-US/main.js'
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
import MKEmitter from '@/utils/events.js'
@@ -25,22 +23,18 @@
    param: PropTypes.any,        // 其他页面传递的参数
    Tab: PropTypes.string,       // 弹窗标签
    MenuID: PropTypes.string,    // 菜单Id
    MenuNo: PropTypes.string,    // 菜单参数
    MenuName: PropTypes.string,  // 菜单名称
    changeTemp: PropTypes.func
  }
  state = {
    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
    ContainerId: Utils.getuuid(), // 菜单外层html Id
    BID: '',              // 页面跳转时携带ID
    loadingview: true,    // 页面加载中
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: null,         // 页面配置信息,包括组件等
    mainSearch: null,     // 主搜索
    userConfig: null,     // 用户自定义设置
    data: null,           // 列表数据集
    loading: false,       // 列表数据加载中
    visible: false,       // 标签页控制
    shortcuts: null,      // 快捷键
@@ -51,12 +45,13 @@
   * @description 获取页面配置信息
   */
  async loadconfig () {
    const { MenuID } = this.props
    const { MenuID, MenuName } = this.props
    let _param = {
      func: 'sPC_Get_LongParam',
      MenuID: MenuID
    }
    let result = await Api.getCacheConfig(_param)
    if (result.status) {
@@ -67,6 +62,8 @@
        config = window.decodeURIComponent(window.atob(result.LongParam))
        config = config.replace(/@mywebsite@\//ig, window.GLOB.baseurl)
        config = JSON.parse(config)
        config.MenuID = MenuID
        config.MenuName = MenuName || config.MenuName
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
@@ -86,7 +83,7 @@
        this.setState({
          viewlost: true,
          loadingview: false,
          lostmsg: this.state.dict['main.view.unenabled']
          lostmsg: '抱歉,您访问的页面未启用,请联系管理员。'
        })
        return
      }
@@ -130,11 +127,6 @@
      let userName = sessionStorage.getItem('User_Name') || ''
      let fullName = sessionStorage.getItem('Full_Name') || ''
      if (sessionStorage.getItem('isEditState') === 'true') {
        userName = sessionStorage.getItem('CloudUserName') || ''
        fullName = sessionStorage.getItem('CloudFullName') || ''
      }
      let regs = [
        { reg: /@userName@/ig, value: `'${userName}'` },
        { reg: /@fullName@/ig, value: `'${fullName}'` }
@@ -156,7 +148,7 @@
        })
      }
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, skip, param, MenuID)
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, skip, param, MenuID, config.MenuName)
      let autoMatic = null
      if (config.autoMatic && config.autoMatic.enable === 'true') {
@@ -173,32 +165,41 @@
      }
      
      // 获取主搜索条件
      let mainSearch = []
      config.components.forEach(component => {
        if (component.type === 'tabs') return
        component.search = component.search.map(item => {
          item.oriInitval = item.initval
          if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) {
            item.initval = param.$searchval
        if (param.$searchkey) {
          component.search = component.search.map(item => {
            if (['text', 'select', 'link'].includes(item.type) && param.$searchkey === item.field) {
              item.initval = param.$searchval
            }
            return item
          })
          component.$searches = Utils.initMainSearch(component.search)
        }
        if (component.$searches.length) {
          component.$main = true
          window.GLOB.SearchBox.set(MenuID, component.$searches)
          if (component.$s_req) {
            window.GLOB.SearchBox.set(MenuID + 'required', true)
          }
          return item
        })
        mainSearch = Utils.initMainSearch(component.search)
        }
      })
      let BID = param.$BID || ''
      config.components = this.formatSetting(config.components, mainSearch, regs)
      config.components = this.formatSetting(config.components, regs)
      this.setState({
        BID: BID,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        config,
        autoMatic,
        mainSearch
        autoMatic
      }, () => {
        setTimeout(() => { // 延时加载状态
          this.setState({
@@ -244,7 +245,6 @@
      let _shortcut = `${preKey}+${keyCode}`
      if (window.GLOB.breakpoint && _shortcut === 'ctrl+67') {
        window.debugger = false
        window.GLOB.breakpoint = false
        sessionStorage.removeItem('breakpoint')
        
@@ -263,11 +263,12 @@
    }
  }
  filterComponent = (components, roleId, permAction, skip, urlparam, pageId) => {
  filterComponent = (components, roleId, permAction, skip, urlparam, pageId, MenuName) => {
    return components.filter(item => {
      item.$pageId = pageId
      item.$searchId = pageId
      item.$menuname = (this.props.MenuName || '') + '-' + (item.name || '主表')
      item.$menuname = (MenuName || '') + '-' + (item.name || '主表')
      if (item.type === 'tabs') {
        item.subtabs = item.subtabs.filter(tab => {
@@ -286,19 +287,19 @@
          if (tab.permission !== 'true') { // 权限未开启不做权限控制
            skip = true
          }
          tab.components = this.filterComponent(tab.components, roleId, permAction, skip, urlparam, pageId)
          tab.components = this.filterComponent(tab.components, roleId, permAction, skip, urlparam, pageId, MenuName)
          return tab
        })
        return true
      } else {
        item.name = (this.props.MenuName || '')
        item.name = (MenuName || '')
      }
      // 搜索条件初始化
      if (item.search && item.search.length > 0) {
        item.search = Utils.initSearchVal(item.search)
      }
      Utils.initSearchVal(item)
      item.$searches = Utils.initMainSearch(item.search)
      if (item.setting.supModule) {
        let pid = item.setting.supModule.pop()
@@ -340,50 +341,10 @@
              if (cell.eleType === 'button') {
                if (cell.hidden === 'true') return false
          
                cell.logLabel = item.$menuname + '-' + cell.label
                cell.Ot = cell.Ot || 'requiredSgl'
                cell.ContainerId = this.state.ContainerId
                cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
                cell.$menuId = item.uuid
                cell.$MenuID = this.props.MenuID
                cell.$view = 'popview'
                if (cell.syncComponentId) {
                  if (cell.syncComponentId === item.setting.supModule) {
                    cell.syncComponentId = ''
                    if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                      cell.execSuccess = 'mainline'
                    }
                  } else if (cell.syncComponentId === 'multiComponent') {
                    let ids = cell.syncComponents.map(m => {
                      return m.syncComId.pop() || ''
                    })
                    if (item.setting.supModule && ids.includes(item.setting.supModule)) {
                      if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                        cell.execSuccess = 'mainline'
                      }
                      ids = ids.filter(id => id !== item.setting.supModule)
                    }
                    if (ids.length === 0) {
                      cell.syncComponentId = ''
                    } else {
                      cell.syncComponentIds = ids
                    }
                  }
                }
                cell = this.resetButton(item, cell)
                if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                  cell = this.getPrinter(cell, item.uuid)
                }
                if (cell.controlField) {
                  if (/,/ig.test(cell.controlVal)) {
                    cell.controlVals = cell.controlVal.split(',')
                  } else {
                    cell.controlVals = [(cell.controlVal || '')]
                  }
                }
                return skip || permAction[cell.uuid]
@@ -425,50 +386,12 @@
        item.action = item.action.filter(cell => {
          if (cell.hidden === 'true') return false
          cell.logLabel = item.$menuname + '-' + cell.label
          cell.ContainerId = this.state.ContainerId
          cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
          cell.$menuId = item.uuid
          cell.$MenuID = this.props.MenuID
          cell.$view = 'popview'
          cell.$toolbtn = true
          cell = this.resetButton(item, cell)
          if (cell.syncComponentId) {
            if (cell.syncComponentId === item.setting.supModule) {
              cell.syncComponentId = ''
              if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                cell.execSuccess = 'mainline'
              }
            } else if (cell.syncComponentId === 'multiComponent') {
              let ids = cell.syncComponents.map(m => {
                return m.syncComId.pop() || ''
              })
              if (item.setting.supModule && ids.includes(item.setting.supModule)) {
                if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                  cell.execSuccess = 'mainline'
                }
                ids = ids.filter(id => id !== item.setting.supModule)
              }
              if (ids.length === 0) {
                cell.syncComponentId = ''
              } else {
                cell.syncComponentIds = ids
              }
            }
          }
          cell.$toolbtn = true
          if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
            cell = this.getPrinter(cell, item.uuid)
          }
          if (cell.controlField) {
            if (/,/ig.test(cell.controlVal)) {
              cell.controlVals = cell.controlVal.split(',')
            } else {
              cell.controlVals = [(cell.controlVal || '')]
            }
          }
          return skip || permAction[cell.uuid]
@@ -477,6 +400,62 @@
      
      return true
    })
  }
  resetButton = (item, cell) => {
    cell.logLabel = item.$menuname + '-' + cell.label
    cell.Ot = cell.Ot || 'requiredSgl'
    cell.ContainerId = this.state.ContainerId
    cell.syncComponentId = cell.syncComponent ? (cell.syncComponent.pop() || '') : ''
    cell.$menuId = item.uuid
    cell.$MenuID = this.props.MenuID
    cell.$view = 'popview'
    if (cell.controlField) {
      if (/,/ig.test(cell.controlVal)) {
        cell.controlVals = cell.controlVal.split(',')
      } else {
        cell.controlVals = [(cell.controlVal || '')]
      }
    }
    if (cell.OpenType === 'excelOut') { // 导出
      cell.$menuName = item.name
      if (!cell.verify || !cell.verify.columns || cell.verify.columns.length === 0) {
        cell.errorType = 'error1'
      } else if (cell.intertype === 'system' && cell.verify.dataType !== 'custom' && item.setting.interType !== 'system') {
        cell.errorType = 'error2'
      }
    }
    if (cell.syncComponentId) {
      if (cell.syncComponentId === item.setting.supModule) {
        cell.syncComponentId = ''
        if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
          cell.execSuccess = 'mainline'
        }
      } else if (cell.syncComponentId === 'multiComponent') {
        let ids = cell.syncComponents.map(m => {
          return m.syncComId.pop() || ''
        })
        if (item.setting.supModule && ids.includes(item.setting.supModule)) {
          if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
            cell.execSuccess = 'mainline'
          }
          ids = ids.filter(id => id !== item.setting.supModule)
        }
        if (ids.length === 0) {
          cell.syncComponentId = ''
        } else {
          cell.syncComponentIds = ids
        }
      }
    }
    return cell
  }
  getPrinter = (item, parentId) => {
@@ -509,7 +488,15 @@
        return component
      }
      component.setting.arr_field = component.columns.map(col => col.field).join(',')
      component.setting.useMSearch = component.setting.useMSearch === 'true'
      if (component.setting.useMSearch) {
        if (!window.GLOB.SearchBox.has(component.$searchId)) {
          component.setting.useMSearch = false
        } else if (window.GLOB.SearchBox.has(component.$searchId + 'required')) {
          component.$s_req = true
        }
      }
      if (component.setting.interType !== 'system') { // 不使用系统函数时
        component.setting.sync = 'false'
@@ -518,9 +505,15 @@
      }
      let _customScript = ''
      let _tailScript = ''
      component.scripts && component.scripts.forEach(script => {
        if (script.status !== 'false') {
        if (script.status === 'false') return
        if (script.position !== 'back') {
          _customScript += `
          ${script.sql}
          `
        } else {
          _tailScript += `
          ${script.sql}
          `
        }
@@ -538,22 +531,30 @@
      }
  
      if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
        component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
        component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/')
        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
        _customScript = _customScript.replace(/@\$/ig, '*/')
        component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
        _tailScript = _tailScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      } else {
        component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _tailScript = _tailScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
      }
      regs.forEach(cell => {
        component.setting.dataresource = component.setting.dataresource.replace(cell.reg, cell.value)
        _customScript = _customScript.replace(cell.reg, cell.value)
        _tailScript = _tailScript.replace(cell.reg, cell.value)
      })
      component.setting.customScript = _customScript // 整理后自定义脚本
      component.setting.tailScript = _tailScript     // 后置自定义脚本
      component.setting.custompage = /@pageSize@|@orderBy@/i.test(component.setting.dataresource + component.setting.customScript)
      if (!component.setting.execute || component.setting.custompage) {
        component.forbidLine = true
      }
      component.setting.delay = delay
      delay += 20
@@ -622,6 +623,9 @@
      } else {
        window.GLOB.CacheData.delete(item.uuid)
      }
      if (item.type !== 'tabs' && item.$main) {
        window.GLOB.SearchBox.delete(item.$searchId)
      }
    })
  }
@@ -638,20 +642,13 @@
      config: null,         // 页面配置信息,包括组件等
      loading: false,       // 列表数据加载中
      shortcuts: null,
      data: ''
    }, () => {
      this.loadconfig()
    })
  }
  resetSearch = (search) => {
    this.setState({mainSearch: null}, () => {
      this.setState({mainSearch: search})
    })
  }
  getComponents = () => {
    const { config, data, mainSearch } = this.state
    const { config } = this.state
    if (!config || !config.components) return
@@ -659,13 +656,13 @@
      if (item.type === 'tabs') {
        return (
          <Col span={item.width} key={item.uuid}>
            <AntvTabs config={item} mainSearch={mainSearch} />
            <AntvTabs config={item}/>
          </Col>
        )
      } else {
        return (
          <Col span={item.width} key={item.uuid}>
            <MkBaseTable config={item} data={data}/>
            <MkBaseTable config={item}/>
          </Col>
        )
      }
@@ -680,9 +677,9 @@
        {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
        <Row className="component-wrap">{this.getComponents()}</Row>
        {config && window.GLOB.breakpoint ? <DebugTable /> : null}
        {!window.GLOB.mkHS && config && autoMatic ? <AutoMatic autoMatic={autoMatic} config={config.components[0]} /> : null}
        {!window.GLOB.mkHS && config && autoMatic ? <AutoMatic autoMatic={autoMatic} tabId={config.MenuID} config={config.components[0]} /> : null}
        {!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <TableNodes config={config} /> : null}
        {!window.GLOB.mkHS && config ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts || []}/> : null}
        {!window.GLOB.mkHS && config ? <SettingComponent config={config} shortcuts={shortcuts || []}/> : null}
        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
      </div>
    )