king
2024-09-12 ffa0d7a5e06556c358bf8bbb1af30082214d4376
src/tabviews/zshare/topSearch/index.jsx
@@ -48,6 +48,8 @@
    let fieldMap = new Map()
    let mainItems = []  // 云端或单点数据
    let localItems = [] // 本地数据
    let backMItems = [] // 云端或单点数据
    let backLItems = [] // 本地数据
    let deForms = []    // 测试系统,单个请求
    let advanceValues = []
    let linkFields = {}
@@ -55,6 +57,22 @@
    let forbid = false // header中不设置高级搜索
    let _setting = {showAdv: false, show: false, style: null}
    let BID = this.props.BID
    let sysvals = {}
    if (window.backend) {
      sysvals = {
        mk_departmentcode: sessionStorage.getItem('departmentcode') || '',
        mk_organization: sessionStorage.getItem('organization') || '',
        mk_user_type: sessionStorage.getItem('mk_user_type') || '',
        bid: BID || '',
        datam: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
        datam_begin: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
        datam_end: sessionStorage.getItem('dataM') === 'true' ? 'Y' : '',
      }
      if (window.GLOB.externalDatabase !== null) {
        sysvals.db = window.GLOB.externalDatabase
      }
    }
    
    if (config.wrap) {
      _setting.show = config.wrap.show !== 'false'
@@ -188,43 +206,77 @@
        // 数据源查询语句
        if (item.resourceType === '1' && item.dataSource) {
          let _option = Utils.getSelectQueryOptions(item)
          let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
          if (window.backend && window.GLOB.CacheData.has('sql_' + item.uuid)) {
            let ex = window.GLOB.CacheData.get('sql_' + item.uuid)
            let exps = []
          let exec = true
          if (item.checkBid) {
            item.sql = _declare + _option.sql
            item.arr_field = _option.field
            ex.reps.forEach(n => {
              let key = n.toLowerCase()
              if (sysvals.hasOwnProperty(key)) {
                exps.push({
                  key: n,
                  value: sysvals[key]
                })
              }
            })
            exec = !!BID
          }
            let cell = {
              id: ex.id,
              exps: exps,
              menuname: item.label + '(搜索)',
              md5_id: ''
            }
            if (item.checkBid) {
              item.sqlId = ex.id
              item.exps = exps
            }
          if (exec) {
            let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
            if (item.checkBid && !BID) {
            } else if (item.database === 'sso' && window.GLOB.mainSystemApi) {
              backMItems.push(cell)
            } else {
              backLItems.push(cell)
            }
          } else {
            let _option = Utils.getSelectQueryOptions(item)
            let _declare = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
  
            if (window.GLOB.debugger === true) {
              window.mkInfo(_declare + _sql)
            let exec = true
            if (item.checkBid) {
              item.sql = _declare + _option.sql
              item.arr_field = _option.field
              exec = !!BID
            }
  
            // 测试系统单个请求
            if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
              deForms.push({
                ...item,
                arr_field: _option.field,
                data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
              })
            } else { // 合并请求,区分本地及系统
              _sql = _sql.replace(/%/ig, ' mpercent ')
              if (item.database === 'sso') {
                if (mainItems.length === 0) {
                  _sql = _declare + _sql
            if (exec) {
              let _sql = _option.sql.replace(/@BID@/ig, `'${BID || ''}'`)
              if (window.GLOB.debugger === true) {
                window.mkInfo(_declare + _sql)
              }
              // 测试系统单个请求
              if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && !window.GLOB.systemType) {
                deForms.push({
                  ...item,
                  arr_field: _option.field,
                  data_sql: Utils.formatOptions(_declare + _sql, window.GLOB.execType)
                })
              } else { // 合并请求,区分本地及系统
                _sql = _sql.replace(/%/ig, ' mpercent ')
                if (item.database === 'sso') {
                  if (mainItems.length === 0) {
                    _sql = _declare + _sql
                  }
                  mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
                } else {
                  if (localItems.length === 0) {
                    _sql = _declare + _sql
                  }
                  localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
                }
                mainItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
              } else {
                if (localItems.length === 0) {
                  _sql = _declare + _sql
                }
                localItems.push(`select '${item.field}' as obj_name,'${_option.field}' as arr_field,'${window.btoa(window.encodeURIComponent(_sql))}' as LText`)
              }
            }
          }
@@ -296,7 +348,9 @@
      advanceValues,
      searchlist: _list
    }, () => {
      if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
      if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
        this.improveBackSearch(backMItems, backLItems, false)
      } else if (!window.GLOB.mkHS && window.GLOB.sysType === 'local' && window.GLOB.systemType !== 'production') {
        this.improveSimpleSearch(deForms, false, null, BID)
      } else if (mainItems.length > 0 || localItems.length > 0) {
        this.improveSearch(mainItems, localItems, BID)
@@ -337,19 +391,41 @@
  resetOptions = (BID) => {
    let deForms = []
    let backMItems = [] // 云端或单点数据
    let backLItems = [] // 本地数据
    let searchlist = fromJS(this.state.searchlist).toJS().map(item => {
      if (item.checkBid) {
        let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
        if (window.GLOB.debugger === true) {
          window.mkInfo(sql)
        }
        if (window.backend && item.sqlId) {
          let cell = {
            id: item.sqlId,
            menuname: item.label + '(搜索)',
            md5_id: '',
            exps: item.exps.map(n => {
              if (n.key === 'BID') {
                n.value = BID
              }
              return n
            })
          }
        deForms.push({
          ...item,
          arr_field: item.arr_field,
          data_sql: Utils.formatOptions(sql, window.GLOB.execType)
        })
          if (item.database === 'sso' && window.GLOB.mainSystemApi) {
            backMItems.push(cell)
          } else {
            backLItems.push(cell)
          }
        } else {
          let sql = item.sql.replace(/@BID@/ig, `'${BID || ''}'`)
          if (window.GLOB.debugger === true) {
            window.mkInfo(sql)
          }
          deForms.push({
            ...item,
            arr_field: item.arr_field,
            data_sql: Utils.formatOptions(sql, window.GLOB.execType)
          })
        }
      } else if (item.checkShift) {
        let d = ''
        if (window.GLOB.CacheData.has(item.$supId)) {
@@ -387,7 +463,9 @@
      return item
    })
    if (deForms.length > 0) {
    if (window.backend && (backMItems.length > 0 || backLItems.length > 0)) {
      this.improveBackSearch(backMItems, backLItems, true, searchlist)
    } else if (deForms.length > 0) {
      this.improveSimpleSearch(deForms, true, searchlist, BID)
    } else {
      this.setState({
@@ -532,6 +610,54 @@
      delete result.status
      this.resetSearch(result, false)
    })
  }
  // 查询下拉菜单
  improveBackSearch = (mainItems, localItems, trigger, searchlist) => {
    let deffers = []
    if (localItems.length) {
      deffers.push({
        $backend: true,
        $type: 's_Get_SelectedList',
        data: localItems
      })
    }
    if (mainItems.length) {
      deffers.push({
        $backend: true,
        $type: 's_Get_SelectedList',
        data: mainItems,
        rduri: window.GLOB.mainSystemApi
      })
    }
    deffers = deffers.map(item => {
      return new Promise(resolve => {
        Api.getSystemCacheConfig(item).then(res => {
          if (!res.status) {
            notification.warning({
              top: 92,
              message: res.message,
              duration: 5
            })
          }
          resolve(res)
        })
      })
    })
    Promise.all(deffers).then(response => {
      let result = {...response[0], ...(response[1] || {})}
      delete result.ErrCode
      delete result.ErrMesg
      delete result.message
      delete result.status
      this.resetSearch(result, trigger, searchlist)
    })
  }
@@ -1049,7 +1175,7 @@
        }
        if (typeof(val) === 'string') {
          val = val.replace(/(^\s*|\s*$)/ig, '')
          val = val.replace(/(^\s+|\s+$)/ig, '').replace(/\t+|\v+/g, '')
        }
        search.push({