king
2023-05-15 3672b83182a648733ff245bd690f170d68cc80a9
src/tabviews/custom/index.jsx
@@ -21,6 +21,7 @@
const AntvScatter = asyncComponent(() => import('./components/chart/antv-scatter'))
const DataCard = asyncComponent(() => import('./components/card/data-card'))
const PropCard = asyncComponent(() => import('./components/card/prop-card'))
const DoubleDataCard = asyncComponent(() => import('./components/card/double-data-card'))
const SimpleForm = asyncComponent(() => import('./components/form/simple-form'))
const StepForm = asyncComponent(() => import('./components/form/step-form'))
const TabForm = asyncComponent(() => import('./components/form/tab-form'))
@@ -40,6 +41,7 @@
const TimeLine = asyncComponent(() => import('./components/timeline/normal-timeline'))
const AntvG6 = asyncComponent(() => import('./components/chart/antv-G6'))
const Voucher = asyncComponent(() => import('./components/module/voucher'))
const Account = asyncComponent(() => import('./components/module/account'))
const Iframe = asyncComponent(() => import('./components/iframe'))
const DebugTable = asyncComponent(() => import('@/tabviews/debugtable'))
const TableNodes = asyncComponent(() => import('@/tabviews/zshare/tablenodes'))
@@ -68,8 +70,11 @@
    data: null,           // 列表数据集
    loading: false,       // 列表数据加载中
    visible: false,       // 标签页控制
    shortcuts: null       // 快捷键
    shortcuts: null,      // 快捷键
    loadinginter: false
  }
  stepInter = null
  /**
   * @description 获取页面配置信息
@@ -91,6 +96,7 @@
        config = window.decodeURIComponent(window.atob(result.LongParam))
        config = config.replace(/@mywebsite@\//ig, window.GLOB.baseurl)
        config = JSON.parse(config)
        config.MenuID = MenuID
      } catch (e) {
        console.warn('Parse Failure')
        config = ''
@@ -196,9 +202,12 @@
        popview = 'popview'
      }
      config.interfaces = this.formatInterSetting(config.interfaces, regs)
      config.$cache = config.cacheLocal === 'true'
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces, popview)
      let initInters = []
      config.interfaces = this.formatInterSetting(config.interfaces, regs, MenuID, initInters)
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces, popview, config.$cache)
      
      // 获取主搜索条件
      let mainSearch = []
@@ -233,13 +242,34 @@
        config.components = this.filterBalcony(config.components, balMap)
      }
      if (initInters.length > 0) {
        this.stepInter = {
          MenuID: MenuID,
          inters: initInters,
          params: params
        }
      }
      this.setState({
        BID: BID,
        loadinginter: this.stepInter !== null,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        config,
        mainSearch
      }, () => {
        if (params.length === 0) {
        if (config.normalcss) {
          let node = document.getElementById(config.uuid)
          node && node.remove()
          let ele = document.createElement('style')
          ele.id = config.uuid
          ele.innerHTML = config.normalcss
          document.getElementsByTagName('head')[0].appendChild(ele)
        }
        if (this.stepInter) {
        } else if (params.length === 0) {
          setTimeout(() => { // 延时加载状态
            this.setState({
              loadingview: false
@@ -306,9 +336,10 @@
    }
  }
  filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview) => {
  filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache) => {
    return components.filter(item => {
      item.$pageId = pageId
      item.$cache = cache
      
      if (item.style && item.style.boxShadow) {
        delete item.style.hShadow
@@ -392,7 +423,7 @@
        item.subtabs = item.subtabs.map(tab => {
          tab.$pageId = pageId
          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview)
          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache)
          return tab
        })
@@ -405,7 +436,7 @@
          return false
        }
        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview)
        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache)
        return true
      } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart'].includes(item.type)) {
@@ -469,17 +500,7 @@
              }
            } else if (col.type === 'custom') {
              col.elements = col.elements.map(cell => {
                if (['text', 'number', 'formula'].includes(cell.eleType)) {
                  if (!cell.height) {
                    cell.innerHeight = 'auto'
                  }
                  if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                    cell.round = Math.pow(10, cell.decimal)
                    if (cell.format === 'percent') {
                      cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                    }
                  }
                }
                cell = this.resetElement(cell)
                return cell
              })
            }
@@ -503,7 +524,7 @@
      if (item.wrap && item.wrap.supType === 'multi') { // 数据卡多上级组件
        mutil = true
        item.setting.supModule = item.supNodes[0].componentId
      } else if (item.setting && item.setting.supModule) {
      } else if (item.setting && item.setting.supModule && typeof(item.setting.supModule) !== 'string') {
        let pid = item.setting.supModule.pop()
        if (pid && pid !== 'empty') {
          item.setting.supModule = pid
@@ -517,25 +538,19 @@
        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 = this.resetButton(item, cell, popview)
          cell.$toolbtn = true
          if (!mutil && cell.syncComponentId === item.setting.supModule) {
            cell.syncComponentId = ''
            if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
              cell.execSuccess = 'mainline'
            }
          }
          if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
            cell = this.getPrinter(cell, item.uuid)
          }
          if (cell.btnstyle) { // 兼容
            cell.style = cell.style || {}
            cell.style = {...cell.style, ...cell.btnstyle}
          }
          return skip || permAction[cell.uuid]
@@ -555,35 +570,20 @@
            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
              cell = this.resetButton(item, cell, popview)
              if (!mutil && cell.syncComponentId === item.setting.supModule) {
                cell.syncComponentId = ''
                if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                  cell.execSuccess = 'mainline'
                }
              }
              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                cell = this.getPrinter(cell, item.uuid)
              }
              if (card.btnstyle) { // 兼容
                card.style = card.style || {}
                card.style = {...card.style, ...card.btnstyle}
              }
            } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
              if (!cell.height) {
                cell.innerHeight = 'auto'
              }
              if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                cell.round = Math.pow(10, cell.decimal)
                if (cell.format === 'percent') {
                  cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                }
              }
            } else {
              cell = this.resetElement(cell)
            }
            return cell.eleType !== 'button' || skip || permAction[cell.uuid]
@@ -595,35 +595,20 @@
            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
              cell = this.resetButton(item, cell, popview)
              if (!mutil && cell.syncComponentId === item.setting.supModule) {
                cell.syncComponentId = ''
                if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                  cell.execSuccess = 'mainline'
                }
              }
              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
                cell = this.getPrinter(cell, item.uuid)
              }
              if (card.btnstyle) { // 兼容
                card.style = card.style || {}
                card.style = {...card.style, ...card.btnstyle}
              }
            } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
              if (!cell.height) {
                cell.innerHeight = 'auto'
              }
              if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
                cell.round = Math.pow(10, cell.decimal)
                if (cell.format === 'percent') {
                  cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
                }
              }
            } else {
              cell = this.resetElement(cell)
            }
            return cell.eleType !== 'button' || skip || permAction[cell.uuid]
@@ -641,30 +626,20 @@
          if (cell.eleType === 'button') {
            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 = this.resetButton(item, cell, popview)
            if (cell.syncComponentId === item.wrap.supModule) {
              cell.syncComponentId = ''
              if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                cell.execSuccess = 'mainline'
              }
            }
            if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
              cell = this.getPrinter(cell, item.uuid)
            }
          } else if (['text', 'number', 'formula'].includes(cell.eleType)) {
            if (!cell.height) {
              cell.innerHeight = 'auto'
            }
            if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
              cell.round = Math.pow(10, cell.decimal)
              if (cell.format === 'percent') {
                cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
              }
            }
          } else {
            cell = this.resetElement(cell)
          }
          return cell.eleType !== 'button' || skip || permAction[cell.uuid]
@@ -674,26 +649,18 @@
          if (col.type !== 'action') return true
          col.elements = col.elements.filter(cell => {
            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
            cell = this.resetButton(item, cell, popview)
            if (cell.syncComponentId === item.setting.supModule) {
              cell.syncComponentId = ''
              if (cell.execSuccess === 'line' || cell.execSuccess === 'grid') {
                cell.execSuccess = 'mainline'
              }
            }
            if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 打印机设置
              cell = this.getPrinter(cell, item.uuid)
            }
            if (cell.btnstyle) { // 兼容
              cell.style = cell.style || {}
              cell.style = {...cell.style, ...cell.btnstyle}
            }
            return skip || permAction[cell.uuid]
@@ -723,26 +690,17 @@
          if (group.subButton.syncComponentId === item.setting.supModule) {
            group.subButton.syncComponentId = ''
            if (group.subButton.execSuccess === 'grid') {
              group.subButton.execSuccess = 'mainline'
            }
          }
          let _sql = `Declare @mk_organization nvarchar(512)  select @mk_organization='${sessionStorage.getItem('organization') || ''}'\n`
          let _sso = _sql
          let _local = _sql
          group.fields = group.fields.map(cell => {
            // 数据源sql语句,预处理,权限黑名单字段设置为隐藏表单
            if (['select', 'link', 'multiselect', 'radio', 'checkbox', 'checkcard'].includes(cell.type) && cell.resourceType === '1') {
              let _option = Utils.getSelectQueryOptions(cell)
              if (cell.database === 'sso') {
                cell.data_sql = Utils.formatOptions(_sso + _option.sql)
                _sso = ''
              } else {
                cell.data_sql = Utils.formatOptions(_local + _option.sql)
                _local = ''
              }
              cell.base_sql = window.btoa(window.encodeURIComponent(_sql + _option.sql))
              cell.base_sql = _option.sql
              cell.arr_field = _option.field
            }
      
@@ -757,6 +715,12 @@
          return group
        })
      } else if (item.subtype === 'voucher') {
        if (item.wrap.supModule && item.wrap.supModule.length > 0) {
          item.wrap.supModule = item.wrap.supModule.pop()
        } else {
          item.wrap.supModule = ''
        }
      }
      
      return true
@@ -799,6 +763,66 @@
      
      return true
    })
  }
  resetButton = (item, cell, popview) => {
    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.btnstyle) { // 兼容
      cell.style = cell.style || {}
      cell.style = {...cell.style, ...cell.btnstyle}
    }
    if (cell.controlField) {
      if (/,/ig.test(cell.controlVal)) {
        cell.controlVals = cell.controlVal.split(',')
      } else {
        cell.controlVals = [(cell.controlVal || '')]
      }
    }
    return cell
  }
  resetElement = (cell) => {
    cell.style = cell.style || {}
    if (['text', 'number', 'formula'].includes(cell.eleType)) {
      if (!cell.height) {
        cell.innerHeight = 'auto'
      }
      cell.innerHeight = cell.innerHeight || 'auto'
      cell.alignItems = cell.height > 1 ? cell.alignItems : ''
      if (cell.eleType === 'number' && typeof(cell.decimal) === 'number') {
        cell.round = Math.pow(10, cell.decimal)
        if (cell.format === 'percent') {
          cell.decimal = cell.decimal > 2 ? cell.decimal - 2 : 0
        }
      }
    } else if (cell.eleType === 'icon') {
      if (!cell.innerHeight) { // 兼容
        let fontSize = 14
        let lineHeight = 1.5
        if (cell.style.fontSize) {
          fontSize = parseInt(cell.style.fontSize)
        }
        if (cell.style.lineHeight) {
          lineHeight = parseFloat(cell.style.lineHeight)
        }
        cell.innerHeight = fontSize * lineHeight
      }
    }
    return cell
  }
  getPrinter = (item, parentId) => {
@@ -850,6 +874,10 @@
      component.setting.useMSearch = component.setting.useMSearch === 'true'
      if (component.wrap && component.wrap.goback === 'true') {
        component.setting.sync = 'false'
      }
      if (component.setting.interType !== 'system') { // 不使用系统函数时
        component.setting.sync = 'false'
        component.setting.laypage = component.setting.laypage === 'true'
@@ -895,7 +923,7 @@
      // dataName 系统生成的数据源名称
      if (component.setting.sync === 'true') {
        component.dataName = Utils.getdataName()
        component.dataName = 'mk' + component.uuid.slice(-18)
      }
      // floor    组件的层级
@@ -937,15 +965,39 @@
  }
  // 格式化默认设置
  formatInterSetting = (inters, regs) => {
  formatInterSetting = (inters, regs, MenuID, initInters) => {
    if (!inters) return []
    let interfaces = inters.filter(m => m.status === 'true')
    let initlimit = false
    let interfaces = inters.filter(m => {
      if (m.status !== 'true') return false
      if (m.setting.loadlevel === 'init') {
        initlimit = true
        initInters.push(m.uuid)
      }
      return true
    })
    let delay = 15
    return interfaces.map(inter => {
      inter.MenuID = MenuID
      inter.setting.delay = delay
      delay += 15
      if (inter.setting.supModule) {
        let pid = inter.setting.supModule.pop()
        if (pid && pid !== 'empty') {
          inter.setting.supModule = pid
        } else {
          inter.setting.supModule = ''
        }
      }
      if (initlimit && inter.setting.loadlevel !== 'init') {
        inter.setting.onload = 'false'
      }
      if (inter.setting.interType !== 'system') return inter
@@ -995,7 +1047,8 @@
   * @description 主表数据加载
   */ 
  loadmaindata = (params) => {
    let param = getStructuredParams(params, this.state.config, this.state.BID || '')
    const { config } = this.state
    let param = getStructuredParams(params, config, this.state.BID || '')
    this.setState({loading: true, loadingview: false})
@@ -1005,6 +1058,16 @@
        delete result.message
        delete result.ErrMesg
        delete result.ErrCode
        if (config.$cache) {
          params.forEach((item) => {
            let _data = result[item.name] || ''
            if (_data && !Array.isArray(_data)) {
              _data = [_data]
            }
            Api.writeCacheConfig(item.uuid, _data)
          })
        }
        this.setState({
          data: result,
@@ -1050,6 +1113,7 @@
  }
  componentDidMount () {
    MKEmitter.addListener('interFinish', this.interFinish)
    MKEmitter.addListener('debugChange', this.debugChange)
    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
@@ -1062,6 +1126,7 @@
    this.setState = () => {
      return
    }
    MKEmitter.removeListener('interFinish', this.interFinish)
    MKEmitter.removeListener('debugChange', this.debugChange)
    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
@@ -1072,6 +1137,30 @@
      this.state.config.interfaces.forEach(m => {
        window.GLOB.CacheData.delete(m.uuid)
      })
    }
  }
  interFinish = (MenuID, interId) => {
    if (!this.stepInter || this.stepInter.MenuID !== MenuID) return
    this.stepInter.inters = this.stepInter.inters.filter(item => item !== interId)
    if (this.stepInter.inters.length === 0) {
      this.setState({loadinginter: false})
      if (this.stepInter.params.length === 0) {
        setTimeout(() => { // 延时加载状态
          this.setState({
            loadingview: false
          })
        }, 1000)
      } else {
        this.loadmaindata(this.stepInter.params)
      }
      MKEmitter.emit('initFinish', this.stepInter.MenuID)
      this.stepInter = null
    }
  }
@@ -1103,6 +1192,8 @@
      })
    }
    this.stepInter = null
    this.setState({
      BID: '',              // 页面跳转时携带ID
      loadingview: true,    // 页面加载中
@@ -1123,9 +1214,9 @@
  }
  getComponents = () => {
    const { config, BID, data, mainSearch } = this.state
    const { config, BID, data, mainSearch, loadinginter } = this.state
    if (!config || !config.components) return
    if (!config || !config.components || loadinginter) return
    return config.components.map(item => {
      let style = null
@@ -1144,6 +1235,12 @@
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <PropCard config={item} data={data} mainSearch={mainSearch}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'dualdatacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DoubleDataCard config={item} mainSearch={mainSearch}/>
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'normaltable') {
@@ -1284,6 +1381,12 @@
            <Voucher config={item}/>
          </Col>
        )
      } else if (item.type === 'module' && item.subtype === 'account') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <Account config={item}/>
          </Col>
        )
      } else if (item.type === 'iframe') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
@@ -1300,9 +1403,9 @@
    const { loadingview, viewlost, config, loading, shortcuts, BID } = this.state
    return (
      <div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}>
        {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
        <Row className="component-wrap">{this.getComponents()}</Row>
      <div className={`custom-page-wrap ${config && config.minWidth ? 'mk-scroll' : ''} ${loadingview || loading ? 'loading' : ''}`} id={this.state.ContainerId} style={config ? config.style : null}>
        {(loadingview || (loading && !config.$cache)) ? <Spin className="view-spin" size="large" /> : null}
        <Row id={config ? 'menu' + config.uuid : ''} style={config && config.minWidth ? {minWidth: config.minWidth} : null} className="component-wrap">{this.getComponents()}</Row>
        {config && config.interfaces.length > 0 ? <MkInterfaces BID={BID} interfaces={config.interfaces}/> : null}
        {config && window.GLOB.breakpoint ? <DebugTable /> : null}
        {!window.GLOB.mkHS && window.GLOB.systemType !== 'production' ? <TableNodes config={config} /> : null}