king
2023-09-05 c9967063fa42e15d9f695220c76641cfa28669f2
src/api/index.js
@@ -5,9 +5,10 @@
import CryptoJS from 'crypto-js'
import jsSHA from 'jssha'
import moment from 'moment'
import Utils from '@/utils/utils.js'
import MKEmitter from '@/utils/events.js'
import CacheUtils from './cacheutils'
import options from '@/store/options.js'
window.GLOB.IndexDB = null
window.GLOB.OuterToken = {}
@@ -61,7 +62,7 @@
}, (error) => {
  let response = error.response || ''
  if (response && (!response.data || !response.data.errors)) { // 过滤旷视报错信息
  if (response && response.status) {
    notification.error({
      className: 'notification-custom-error',
      bottom: 0,
@@ -81,7 +82,6 @@
  
  /**
   * @description 使用dostar接口,跳过验证
   * @param {Object} param 查询及提交参数
   */
  dostarInterface (param) {
    param.userid = param.userid || ''
@@ -241,7 +241,7 @@
      Password: '',
      check_code: checkcode,
      way_no: 'sms_vcode',
      systemType: options.sysType,
      systemType: window.GLOB.sysType,
      login_city: sessionStorage.getItem('city') || '',
      login_id_address: sessionStorage.getItem('ipAddress') || '',
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
@@ -252,11 +252,11 @@
    let url = '/webapi/dologon'
    if (isCloud) {
      param.debug = 'Y'
      if (options.cloudServiceApi) {
        param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      if (window.GLOB.cloudServiceApi) {
        param.rduri = window.GLOB.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      }
    } else if (window.GLOB.mainSystemApi) {
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
      if (window.GLOB.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        param.linkurl = window.GLOB.linkurl
      }
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
@@ -277,7 +277,7 @@
    let param = {
      // func: 'webapi_login',
      UserName: username,
      systemType: options.sysType,
      systemType: window.GLOB.sysType,
      Type: 'S',
      login_city: sessionStorage.getItem('city') || '',
      login_id_address: sessionStorage.getItem('ipAddress') || '',
@@ -307,11 +307,11 @@
    if (isCloud) {
      param.debug = 'Y'
      if (options.cloudServiceApi) {
        param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      if (window.GLOB.cloudServiceApi) {
        param.rduri = window.GLOB.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      }
    } else if (window.GLOB.mainSystemApi) {
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
      if (window.GLOB.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        param.linkurl = window.GLOB.linkurl
      }
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
@@ -329,33 +329,27 @@
    CacheUtils.delIndexDBCacheConfig(date, type)
  }
  writeCacheConfig (menuid, data) {
  writeCacheConfig (menuid, data, BID = '', id = '') {
    if (!menuid) return
    let date = moment().format('YYYY-MM-DD HH:mm:ss')
    let _data = data ? JSON.stringify(data) : ''
    let userid = sessionStorage.getItem('UserID') || ''
    CacheUtils.writeCacheInIndexDB({menuid, CreateDate: date, LongParam: _data})
    CacheUtils.writeCacheInIndexDB({menuid: md5(menuid + userid + BID + id), BID: BID, id: id, CreateDate: date, LongParam: _data})
  }
  getLCacheConfig (menuid, minutes) {
  getLCacheConfig (menuid, minutes, BID = '', id = '') {
    return new Promise((resolve, reject) => {
      if (window.GLOB.IndexDB) {
        let limit = minutes ? moment().subtract(minutes, 'minutes').format('YYYY-MM-DD HH:mm:ss') : ''
        CacheUtils.getIndexDBCacheConfig(menuid, limit).then(res => {
          if (res && res.LongParam) {
            let _data = JSON.parse(res.LongParam)
            if (_data.length === 0) {
              resolve()
            } else {
              resolve(_data)
            }
          } else {
            resolve()
          }
        })
      } else {
        resolve()
      }
      let limit = minutes ? moment().subtract(minutes, 'minutes').format('YYYY-MM-DD HH:mm:ss') : ''
      let userid = sessionStorage.getItem('UserID') || ''
      CacheUtils.getIndexDBCacheConfig(md5(menuid + userid + BID + id)).then(res => {
        if (res && res.LongParam) {
          resolve({data: JSON.parse(res.LongParam), valid: !limit || res.CreateDate > limit})
        } else {
          resolve({data: null, valid: false})
        }
      })
    })
  }
@@ -375,6 +369,11 @@
        let param = {
          func: 's_get_app_version',
          modifydate: msg.createDate
        }
        if (window.GLOB.initVersion && sessionStorage.getItem('visitorUserID')) {
          param.userid = sessionStorage.getItem('visitorUserID')
          param.LoginUID = sessionStorage.getItem('visitorLoginUID')
        }
        param.TypeCharOne = ''
@@ -419,6 +418,7 @@
            let clear = false
            let _appkey = window.GLOB.appkey.substr(-10)
            let reg = new RegExp(_appkey + '$', 'i')
            let reHome = list.includes('home_page_id')
            list.forEach(mid => {
              if (reg.test(mid)) {
@@ -430,6 +430,10 @@
            }
            CacheUtils.delIndexDBConfig(list)
            this.delCacheConfig('all')
            if (reHome) {
              MKEmitter.emit('reloadMenuView', 'home_page_id')
            }
          }
          CacheUtils.updateIndexDBversion({version: res.app_version || '1.00', createDate: curTime})
@@ -463,14 +467,14 @@
   */
  getCloudConfig (param) {
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.appkey = window.GLOB.appkey || ''
    param.appkey = param.appkey || window.GLOB.appkey || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.userid = sessionStorage.getItem('CloudUserID') || ''
    param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    param.userid = param.userid || sessionStorage.getItem('CloudUserID') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('CloudLoginUID') || ''
    param = this.encryptParam(param)
    let url = options.cloudServiceApi ? options.cloudServiceApi : '/webapi/dostars'
    let url = window.GLOB.cloudServiceApi ? window.GLOB.cloudServiceApi : '/webapi/dostars'
    if (param.func) {
      url = url + '/' + param.func
    }
@@ -517,8 +521,8 @@
    param.appkey = param.appkey || window.GLOB.appkey
    let url = '/webapi/dostars'
    if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { // 编辑状态,且存在云端地址
      url = options.cloudServiceApi
    if (window.GLOB.mkHS && window.GLOB.cloudServiceApi) { // HS下,且存在云端地址
      url = window.GLOB.cloudServiceApi
      param.userid = sessionStorage.getItem('CloudUserID') || ''
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    } else if (window.GLOB.mainSystemApi) {
@@ -549,9 +553,9 @@
    param.appkey = param.appkey || window.GLOB.appkey || ''
    let url = '/webapi/dostars'
    if (sessionStorage.getItem('isEditState') === 'true') { // 编辑状态,单点登录服务器为云端
      if (options.cloudServiceApi) { // 存在云端地址时,使用云端系统参数
        url = options.cloudServiceApi
    if (window.GLOB.mkHS) {          // HS下,单点登录服务器为云端
      if (window.GLOB.cloudServiceApi) { // 存在云端地址时,使用云端系统参数
        url = window.GLOB.cloudServiceApi
        param.userid = sessionStorage.getItem('CloudUserID') || ''
        param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
      }
@@ -626,7 +630,7 @@
    if (window.GLOB.CacheMap.has(_param)) {
      return Promise.resolve(window.GLOB.CacheMap.get(_param))
    } else {
      return Promise.resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false})
      return Promise.resolve({ErrCode: 'S', LongParam: '', message: '', status: false})
    }
  }
@@ -730,7 +734,7 @@
      token = JSON.parse(window.decodeURIComponent(window.atob(token)))
    } catch (e) {
      token = null
      _resolve({status: false, ErrCode: 'E', message: '接口信息解析失败!', ErrMesg: 'token_error'})
      _resolve({status: false, ErrCode: 'token_error', message: '接口信息解析失败!'})
    }
    if (!token) return
@@ -770,7 +774,7 @@
    } else {
      let _param = {
        UserName: token.username,
        systemType: options.sysType,
        systemType: window.GLOB.sysType,
        login_city: sessionStorage.getItem('city') || '',
        device_id: token.appkey || '',
        timestamp: moment().format('YYYY-MM-DD HH:mm:ss'),
@@ -833,19 +837,14 @@
    param.appkey = window.GLOB.appkey || ''
    if (param.$token === '') {
      return Promise.resolve({status: false, ErrCode: 'E', message: '接口地址尚未设置!', ErrMesg: 'token_error'})
      return Promise.resolve({status: false, ErrCode: 'token_error', message: '接口地址尚未设置!'})
    } else if (param.$token) {
      return new Promise(resolve => this.visitOuterSystem(param, resolve))
    }
    if (['sPC_Get_TableData', 'sPC_Get_TableData_debug', 'sPC_TableData_InUpDe', 'sPC_TableData_InUpDe_debug', 'sPC_Get_structured_data'].includes(param.func)) {
      if (window.GLOB.mkHS) {
        param.username = sessionStorage.getItem('CloudUserName') || ''
        param.fullname = sessionStorage.getItem('CloudFullName') || ''
      } else {
        param.username = sessionStorage.getItem('User_Name') || ''
        param.fullname = sessionStorage.getItem('Full_Name') || ''
      }
    if (['sPC_TableData_InUpDe', 'sPC_TableData_InUpDe_debug'].includes(param.func)) {
      param.username = sessionStorage.getItem('User_Name') || ''
      param.fullname = sessionStorage.getItem('Full_Name') || ''
    }
    let login = false
@@ -877,7 +876,7 @@
      let time = +sessionStorage.getItem(rduri)
      let c_time = Math.round(new Date().getTime() / 1000)
      if (time && c_time - time <= 60) {
      if (time && c_time - time <= 1800) {
        sessionStorage.setItem(rduri, c_time)
        return axios({
          url: `${url}${param.func ? '/' + param.func : ''}`,