king
2025-01-10 dfdcdcb3dbd0b711bc0b77bb00fd1d39af91bd0b
src/api/index.js
@@ -15,7 +15,8 @@
window.GLOB.$error = false
let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : ''
let lang = sessionStorage.getItem('lang') !== 'zh-CN' ? sessionStorage.getItem('lang') : ''
let lang = sessionStorage.getItem('lang') || 'zh-CN'
lang = lang !== 'zh-CN' ? lang : ''
let db = `mkdb${service + lang}`
if (window.indexedDB) {
@@ -74,6 +75,32 @@
      placement: 'bottomRight',
      duration: 15
    })
    if ([500, 504].includes(response.status) && error.config && error.config.url && error.config.data) {
      window.mkInfo(error.config.url)
      window.mkInfo(error.config.data)
      if (window.GLOB.errorLog && !sessionStorage.getItem('local_error')) {
        let urlReg = new RegExp('^(' + window.GLOB.baseurl + '|/)webapi/(exstars|dostars)', 'ig')
        if (urlReg.test(error.config.url) && !/s_special_error_note_log/.test(error.config.url)) {
          let res = null
          try {
            let data = JSON.parse(error.config.data)
            if (!data.rduri) {
              res = {
                api_url: error.config.url,
                error_code: response.status,
                error_time: moment().format('YYYY-MM-DD HH:mm:ss'),
                api_param: error.config.data
              }
            }
          } catch (e) {
            res = null
          }
          if (res) {
            sessionStorage.setItem('local_error', JSON.stringify(res))
          }
        }
      }
    }
  }
  return Promise.reject(response)
@@ -175,12 +202,7 @@
   * @description 游客登录
   */
  getTouristMsg (binding_type, appid, openid, memberid, scanId) {
    let _SessionUid = localStorage.getItem('SessionUid')
    if (!_SessionUid) { // 手动清除SessionUid时,实时生成
      _SessionUid = Utils.getuuid()
      localStorage.setItem('SessionUid', _SessionUid)
    }
    let _SessionUid = localStorage.getItem('SessionUid') || ''
    let param = {
      func: 's_visitor_login',
@@ -434,7 +456,7 @@
            CacheUtils.delIndexDBConfig(list)
            this.delCacheConfig('all')
            if (reHome) {
            if (reHome && reload !== 'home_page_id') {
              MKEmitter.emit('reloadMenuView', 'home_page_id')
            }
          }
@@ -492,26 +514,26 @@
  /**
   * @description 获取或修改系统配置,增加appkey
   */
  getSystemFuncs (time) {
    let param = {
      func: 's_get_func_base_sso',
      update_date: time,
      userid: sessionStorage.getItem('UserID') || '',
      lang: sessionStorage.getItem('lang') || '',
      SessionUid: localStorage.getItem('SessionUid') || '',
      LoginUID: sessionStorage.getItem('LoginUID') || '',
      appkey: window.GLOB.appkey
    }
  // getSystemFuncs (time) {
  //   let param = {
  //     func: 's_get_func_base_sso',
  //     update_date: time,
  //     userid: sessionStorage.getItem('UserID') || '',
  //     lang: sessionStorage.getItem('lang') || '',
  //     SessionUid: localStorage.getItem('SessionUid') || '',
  //     LoginUID: sessionStorage.getItem('LoginUID') || '',
  //     appkey: window.GLOB.appkey
  //   }
    let url = window.GLOB.mainSystemApi || '/webapi/dostars'
    param = this.encryptParam(param)
  //   let url = window.GLOB.mainSystemApi || '/webapi/dostars'
  //   param = this.encryptParam(param)
    return axios({
      url: `${url}/${param.func}`,
      method: 'post',
      data: JSON.stringify(param)
    })
  }
  //   return axios({
  //     url: `${url}/${param.func}`,
  //     method: 'post',
  //     data: JSON.stringify(param)
  //   })
  // }
  /**
   * @description 获取或修改系统配置,增加appkey
@@ -670,6 +692,70 @@
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    if (param.$backend) {
      delete param.$backend
      let id = ''
      if (cache) {
        id = param.data[0].id
        if (window.GLOB.CacheMap.has(id)) {
          return Promise.resolve(window.GLOB.CacheMap.get(id))
        }
      }
      param.username = sessionStorage.getItem('User_Name') || ''
      param.fullname = sessionStorage.getItem('Full_Name') || ''
      param.s_debug = window.GLOB.debugger ? 'Y' : ''
      param.data_md5 = param.data_md5 || ''
      param.time_limit = param.time_limit || 0
      let url = '/webapi/exstars'
      if (param.rduri) {
        param.rduri = param.rduri.replace(/dostars/ig, 'exstars')
        if (!window.GLOB.transfer) {
          url = param.rduri
          delete param.rduri
        }
      }
      if (param.$type) {
        url += '/' + param.$type
      }
      delete param.$type
      param = this.encryptParam(param)
      return new Promise((resolve) => {
        axios({
          url: url,
          method: 'post',
          data: JSON.stringify(param)
        }).then(res => {
          if (res.mksqls) {
            res.mksqls.forEach(n => {
              n = n.replace(/(UNION ALL\s+)?SELECT obj_name='[\S\s]+sub_field=''\s+/ig, '')
              if (!res.status) {
                window.mkInfo('%c' + n, 'color: #f5222d')
              } else {
                window.mkInfo(n)
              }
            })
          }
          delete res.mksqls
          if (res.ErrCode === 'version_error') {
            res.ErrCode = '-2'
            MKEmitter.emit('reloadTabs')
          }
          if (res.status && id) {
            window.GLOB.CacheMap.set(id, res)
          }
          resolve(res)
        })
      })
    }
    let url = '/webapi/dostars'
    if (param.rduri && !window.GLOB.transfer) {
@@ -938,6 +1024,62 @@
          }
        })
      })
    } else if (param.$backend) {
      delete param.$backend
      let url = '/webapi/exstars'
      if (param.rduri) {
        param.rduri = param.rduri.replace(/dostars/ig, 'exstars')
        if (!window.GLOB.transfer) {
          url = param.rduri
          delete param.rduri
        }
      }
      if (param.$type) {
        url += '/' + param.$type
      }
      delete param.$type
      param.username = sessionStorage.getItem('User_Name') || ''
      param.fullname = sessionStorage.getItem('Full_Name') || ''
      param.s_debug = window.GLOB.debugger ? 'Y' : ''
      param.data_md5 = param.data_md5 || ''
      param.time_limit = param.time_limit || 0
      param = this.encryptParam(param)
      return new Promise((resolve) => {
        axios({
          url: url,
          method: 'post',
          data: JSON.stringify(param),
          requestId
        }).then(res => {
          if (res.mksqls) {
            res.mksqls.forEach(n => {
              n = n.replace(/(UNION ALL\s+)?SELECT obj_name='[\S\s]+sub_field=''\s+/ig, '')
              if (!res.status) {
                window.mkInfo('%c' + n, 'color: #f5222d')
              } else {
                window.mkInfo(n)
              }
            })
          }
          delete res.mksqls
          if (!res.status) {
            if (res.ErrCode === 'version_error') {
              res.ErrCode = '-2'
              MKEmitter.emit('reloadTabs')
            } else if (res.message === 'permission deny') {
              res.message = window.GLOB.dict['permission_deny'] || '无当前菜单或按钮的访问权限,请联系管理员!'
              res.ErrMesg = window.GLOB.dict['permission_deny'] || '无当前菜单或按钮的访问权限,请联系管理员!'
            }
          }
          resolve(res)
        })
      })
    } else {
      let url = '/webapi/dostars'
      if (param.rduri && (!window.GLOB.transfer || /https:\/\/sso.mk9h.cn/.test(param.rduri)) && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
@@ -954,6 +1096,29 @@
        requestId
      })
    }
  }
  /**
   * @description 清空后端缓存
   */
  cacheInterface (param) {
    param.appkey = window.GLOB.appkey || ''
    param.userid = param.userid || sessionStorage.getItem('UserID') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    let url = '/webapi/excache'
    if (param.rduri && !window.GLOB.transfer) {
      url = param.rduri
      delete param.rduri
    }
    param = this.encryptParam(param)
    return axios({
      url: url,
      method: 'post',
      data: JSON.stringify(param),
    })
  }
  /**
@@ -1095,7 +1260,7 @@
  /**
   * @description sql检验
   */
  sDebug (sql) {
  sDebug (sql, skip = false) {
    let param = {
      func: 's_debug_sql',
      exec_type: window.GLOB.execType || 'y',
@@ -1123,6 +1288,8 @@
    window.mkInfo(`/* sql 验证 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`)
    if (skip) return
    sql = sql.replace(/\n/ig, ' ')
    param.LText = Utils.formatOptions(sql, param.exec_type)