king
2023-07-21 71e3da644eca32a5aa40503e903efb0640748093
src/tabviews/custom/index.jsx
@@ -66,9 +66,7 @@
    viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
    lostmsg: '',          // 页面丢失时的提示信息
    config: null,         // 页面配置信息,包括组件等
    mainSearch: null,     // 主搜索
    userConfig: null,     // 用户自定义设置
    data: null,           // 列表数据集
    loading: false,       // 列表数据加载中
    visible: false,       // 标签页控制
    shortcuts: null,      // 快捷键
@@ -210,24 +208,7 @@
      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, config.MenuName)
      // 获取主搜索条件
      let mainSearch = []
      config.components.forEach(component => {
        if (component.type !== 'search') 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
          }
          return item
        })
        mainSearch = Utils.initMainSearch(component.search)
      })
      config.components = this.filterComponent(config.components, roleId, window.GLOB.mkActions, balMap, skip, param, MenuID, config.interfaces, popview, config.$cache, config.MenuName, MenuID, MenuID)
      let params = []
      let BID = param.$BID || ''
@@ -239,7 +220,30 @@
        inherit.cacheTime = config.cacheTime
      }
      config.components = this.formatSetting(config.components, params, mainSearch, inherit, regs, balMap)
      // 字段透视
      config.components.forEach(component => {
        if (component.type !== 'search') return
        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)
        }
        window.GLOB.SearchBox.set(MenuID, component.$searches)
        if (component.$s_req) {
          window.GLOB.SearchBox.set(MenuID + 'required', true)
        }
      })
      config.components = this.formatSetting(config.components, params, inherit, regs, balMap)
      if ([...balMap.keys()].length > 0) {
        config.components = this.filterBalcony(config.components, balMap)
@@ -257,8 +261,7 @@
        BID: BID,
        loadinginter: this.stepInter !== null,
        shortcuts: shortcuts.length > 0 ? shortcuts : null,
        config,
        mainSearch
        config
      }, () => {
        if (config.normalcss) {
          let node = document.getElementById(config.uuid)
@@ -339,10 +342,12 @@
    }
  }
  filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName) => {
  filterComponent = (components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, searchId, syncId) => {
    return components.filter(item => {
      item.$pageId = pageId
      item.$cache = cache
      item.$searchId = searchId
      item.$syncId = syncId
      
      if (item.style && item.style.boxShadow) {
        delete item.style.hShadow
@@ -435,7 +440,18 @@
        item.subtabs = item.subtabs.map(tab => {
          tab.$pageId = pageId
          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName)
          let _searchId = searchId
          tab.components.forEach(cell => {
            if (cell.type !== 'search') return
            _searchId = cell.uuid
            window.GLOB.SearchBox.set(cell.uuid, cell.$searches)
            if (cell.$s_req) {
              window.GLOB.SearchBox.set(cell.uuid + 'required', true)
            }
          })
          tab.components = this.filterComponent(tab.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, _searchId, tab.uuid)
          return tab
        })
@@ -448,7 +464,7 @@
          return false
        }
        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName)
        item.components = this.filterComponent(item.components, roleId, permAction, balMap, skip, urlparam, pageId, interfaces, popview, cache, MenuName, searchId, syncId)
        return true
      } else if (['pie', 'bar', 'line', 'dashboard', 'scatter', 'chart', 'antvG6', 'antvX6'].includes(item.type)) {
@@ -481,8 +497,12 @@
      }
      // 搜索条件初始化
      if (item.search && item.search.length > 0) {
        item.search = Utils.initSearchVal(item.search)
      if (item.type === 'search' && item.search.length === 0) {
        return false
      } else if (item.search) {
        Utils.initSearchVal(item)
        item.$searches = Utils.initMainSearch(item.search)
      }
      if (item.wrap && item.wrap.supType === 'multi') { // 数据卡多上级组件
@@ -889,28 +909,30 @@
  }
  // 格式化默认设置
  formatSetting = (components, params, mainSearch, inherit, regs, balMap) => {
  formatSetting = (components, params, inherit, regs, balMap) => {
    let delay = 20
    return components.map(component => {
      if (component.type === 'tabs') {
        component.subtabs = component.subtabs.map(tab => {
          tab.components = this.formatSetting(tab.components, null, null, inherit, regs, balMap)
          tab.components = this.formatSetting(tab.components, null, inherit, regs, balMap)
          tab = {...tab, ...inherit}
          return tab
        })
        return component
      } else if (component.type === 'group') {
        component.components = this.formatSetting(component.components, null, null, inherit, regs, balMap)
        component.components = this.formatSetting(component.components, params, inherit, regs, balMap)
        component = {...component, ...inherit}
        return component
      } else if (component.wrap && component.wrap.datatype === 'public') {
        component.setting.useMSearch = false
        component.setting.sync = 'false'
        return component
      } else if (component.wrap && component.wrap.datatype === 'static') {
        component.format = ''
        component.setting = component.setting || {}
        component.setting.useMSearch = false
        component.setting.sync = 'false'
        return component
      } else if (!component.setting || !component.format) {
@@ -918,6 +940,13 @@
      }
      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.wrap && component.wrap.goback === 'true') {
        component.setting.sync = 'false'
@@ -950,10 +979,8 @@
      }
  
      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\'')
      } else {
        component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
@@ -966,35 +993,39 @@
      component.setting.customScript = _customScript // 整理后自定义脚本
      if (component.setting.sync === 'true') {
        // pageable 是否分页,组件属性,不分页的组件才可以统一查询
        if ((!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true') {
        } else {
          component.setting.sync = 'false'
        }
      }
      // dataName 系统生成的数据源名称
      if (component.setting.sync === 'true') {
        component.dataName = 'mk' + component.uuid.slice(-18)
      }
      // floor    组件的层级
      // pageable 是否分页,组件属性,不分页的组件才可以统一查询
      if (params && (!component.pageable || (component.pageable && !component.setting.laypage)) && component.setting.onload === 'true' && component.setting.sync === 'true') {
        let searchlist = []
        if (component.search && component.search.length > 0) {
          searchlist = Utils.initMainSearch(component.search)
        }
        if (component.setting.useMSearch) {
          let keys = searchlist.map(item => item.key)
          mainSearch.forEach(item => {
            if (!keys.includes(item.key)) {
        if (params) {
          let searchlist = component.$searches || []
          if (component.setting.useMSearch) {
            let mainSearch = window.GLOB.SearchBox.get(component.$searchId)
            let keys = component.$s_keys || []
            mainSearch.forEach(item => {
              if (keys.includes(item.key.toLowerCase())) return
              searchlist.push(item)
            }
          })
            })
          }
          if (component.$s_req && searchlist.filter(item => item.required && item.value === '').length > 0) {
            component.setting.sync = 'false'
            component.setting.onload = 'false'
          } else {
            params.push(getStructDefaultParam(component, searchlist, params.length === 0))
          }
        }
        if (searchlist.filter(item => item.required && item.value === '').length > 0) {
          component.setting.sync = 'false'
          component.setting.onload = 'false'
        } else {
          params.push(getStructDefaultParam(component, searchlist, params.length === 0))
        }
      } else if (params) {
        component.setting.sync = 'false'
      }
      
      component.setting.delay = delay
@@ -1068,10 +1099,8 @@
      }
  
      if (sessionStorage.getItem('dataM') === 'true') { // 数据权限
        inter.setting.dataresource = inter.setting.dataresource.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
        inter.setting.dataresource = inter.setting.dataresource.replace(/@\$/ig, '*/')
        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@datam@/ig, '\'Y\'')
        _customScript = _customScript.replace(/@\$/ig, '*/')
        inter.setting.dataresource = inter.setting.dataresource.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
        _customScript = _customScript.replace(/\$@/ig, '/*').replace(/@\$/ig, '*/').replace(/@datam@/ig, '\'Y\'')
      } else {
        inter.setting.dataresource = inter.setting.dataresource.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
        _customScript = _customScript.replace(/@\$|\$@/ig, '').replace(/@datam@/ig, '\'\'')
@@ -1098,6 +1127,10 @@
    this.setState({loading: true, loadingview: false})
    Api.genericInterface(param).then(result => {
      this.setState({
        loading: false
      })
      if (result.status) {
        if (result.message) {
          if (result.ErrCode === 'Y') {
@@ -1113,31 +1146,18 @@
          }
        }
        delete result.status
        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,
          loading: false
        params.forEach((item) => {
          let _data = result[item.name] || ''
          if (_data && !Array.isArray(_data)) {
            _data = [_data]
          }
          window.GLOB.SyncData.set(item.name, _data)
        })
        MKEmitter.emit('transferSyncData', config.MenuID)
      } else {
        this.setState({
          data: '',
          loading: false
        })
        MKEmitter.emit('transferSyncData', config.MenuID)
        if (!result.message) return
        if (result.ErrCode === 'N') {
          Modal.error({
@@ -1243,8 +1263,13 @@
        })
      } else if (item.type === 'group') {
        this.deleteCache(item.components)
      } else if (item.type === 'search') {
        window.GLOB.SearchBox.delete(item.$searchId)
      } else {
        window.GLOB.CacheData.delete(item.uuid)
      }
      if (item.dataName) {
        window.GLOB.SyncData.delete(item.dataName)
      }
    })
  }
@@ -1267,21 +1292,14 @@
      viewlost: false,      // 页面丢失:1、未获取到配置-页面丢失;2、页面未启用
      config: null,         // 页面配置信息,包括组件等
      loading: false,       // 列表数据加载中
      shortcuts: null,
      data: ''
      shortcuts: null
    }, () => {
      this.loadconfig()
    })
  }
  resetSearch = (search) => {
    this.setState({mainSearch: null}, () => {
      this.setState({mainSearch: search})
    })
  }
  getComponents = () => {
    const { config, BID, data, mainSearch, loadinginter } = this.state
    const { config, BID, loadinginter } = this.state
    if (!config || !config.components || loadinginter) return
@@ -1297,157 +1315,157 @@
      if (item.type === 'card' && item.subtype === 'datacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DataCard config={item} data={data} mainSearch={mainSearch}/>
            <DataCard config={item}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'propcard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <PropCard config={item} data={data} mainSearch={mainSearch}/>
            <PropCard config={item}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'dualdatacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <DoubleDataCard config={item} mainSearch={mainSearch}/>
            <DoubleDataCard config={item}/>
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'normaltable') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <NormalTable config={item} data={data} mainSearch={mainSearch}/>
            <NormalTable config={item}/>
          </Col>
        )
      } else if (item.type === 'bar' || item.type === 'line') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvBarAndLine config={item} data={data} mainSearch={mainSearch}/>
            <AntvBarAndLine config={item}/>
          </Col>
        )
      } else if (item.type === 'pie') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvPie config={item} data={data} mainSearch={mainSearch}/>
            <AntvPie config={item}/>
          </Col>
        )
      } else if (item.type === 'scatter') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvScatter config={item} data={data} mainSearch={mainSearch}/>
            <AntvScatter config={item}/>
          </Col>
        )
      } else if (item.type === 'dashboard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvDashboard config={item} data={data} mainSearch={mainSearch}/>
            <AntvDashboard config={item}/>
          </Col>
        )
      } else if (item.type === 'form' && item.subtype === 'simpleform') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <SimpleForm config={item} data={data} mainSearch={mainSearch}/>
            <SimpleForm config={item}/>
          </Col>
        )
      } else if (item.type === 'form' && item.subtype === 'stepform') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <StepForm config={item} data={data} mainSearch={mainSearch}/>
            <StepForm config={item}/>
          </Col>
        )
      } else if (item.type === 'form' && item.subtype === 'tabform') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <TabForm config={item} data={data} mainSearch={mainSearch}/>
            <TabForm config={item}/>
          </Col>
        )
      } else if (item.type === 'search') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <MainSearch config={item} BID={BID} refreshdata={this.resetSearch} />
            <MainSearch config={item} BID={BID}/>
          </Col>
        )
      } else if (item.type === 'tabs') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvTabs config={item} mainSearch={mainSearch} />
            <AntvTabs config={item}/>
          </Col>
        )
      } else if (item.type === 'balcony') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <Balcony config={item} data={data}/>
            <Balcony config={item}/>
          </Col>
        )
      } else if (item.type === 'timeline') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <TimeLine config={item} data={data} mainSearch={mainSearch}/>
            <TimeLine config={item}/>
          </Col>
        )
      } else if (item.type === 'carousel' && item.subtype === 'datacard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <CarouselDataCard config={item} data={data} mainSearch={mainSearch}/>
            <CarouselDataCard config={item}/>
          </Col>
        )
      } else if (item.type === 'carousel' && item.subtype === 'propcard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <CarouselPropCard config={item} data={data} mainSearch={mainSearch}/>
            <CarouselPropCard config={item}/>
          </Col>
        )
      } else if (item.type === 'card' && item.subtype === 'tablecard') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <TableCard config={item} data={data} mainSearch={mainSearch}/>
            <TableCard config={item}/>
          </Col>
        )
      } else if (item.type === 'table' && item.subtype === 'editable') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <EditTable config={item} mainSearch={mainSearch}/>
            <EditTable config={item}/>
          </Col>
        )
      } else if (item.type === 'group' && item.subtype === 'normalgroup') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <NormalGroup config={item} mainSearch={mainSearch}/>
            <NormalGroup config={item}/>
          </Col>
        )
      } else if (item.type === 'editor') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <BraftEditor config={item} data={data} mainSearch={mainSearch}/>
            <BraftEditor config={item}/>
          </Col>
        )
      } else if (item.type === 'tree') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <NormalTree config={item} data={data} mainSearch={mainSearch}/>
            <NormalTree config={item}/>
          </Col>
        )
      } else if (item.type === 'calendar') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <Calendar config={item} mainSearch={mainSearch}/>
            <Calendar config={item}/>
          </Col>
        )
      } else if (item.type === 'code') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <SandBox config={item} data={data} mainSearch={mainSearch}/>
            <SandBox config={item}/>
          </Col>
        )
      } else if (item.type === 'chart') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <CustomChart config={item} data={data} mainSearch={mainSearch}/>
            <CustomChart config={item}/>
          </Col>
        )
      } else if (item.type === 'antvG6') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <AntvG6 config={item} data={data} mainSearch={mainSearch}/>
            <AntvG6 config={item}/>
          </Col>
        )
      } else if (item.type === 'antvX6') {
@@ -1471,7 +1489,7 @@
      } else if (item.type === 'iframe') {
        return (
          <Col span={item.width} style={style} key={item.uuid}>
            <Iframe config={item} data={data} mainSearch={mainSearch}/>
            <Iframe config={item}/>
          </Col>
        )
      } else {