GuLiMmo
2024-08-28 8797b388e93ec37721df22382d10595160a0e12c
no message
1 files modified
40 ■■■■■ changed files
src/api/http/request.ts 40 ●●●●● patch | view | raw | blame | history
src/api/http/request.ts
@@ -2,7 +2,7 @@
 * @Author: GuLiMmo 2820890765@qq.com
 * @Date: 2024-03-12 18:01:28
 * @LastEditors: GuLiMmo 2820890765@qq.com
 * @LastEditTime: 2024-08-27 16:16:55
 * @LastEditTime: 2024-08-28 15:03:34
 * @FilePath: /drone-web/src/api/http/request.ts
 * @Description: axios配置
 * Copyright (c) 2024 by GuLiMmo, All Rights Reserved.
@@ -11,7 +11,7 @@
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
import { uuidv4 } from '/@/utils/uuid'
import { CURRENT_CONFIG } from './config'
import { useMyStore } from '/@/store'
import store from '/@/store/'
import { getToken } from '/@/utils/auth'
import { serialize } from '/@/utils/common'
import { message as Message, MessageArgsProps } from 'ant-design-vue'
@@ -113,20 +113,13 @@
instance.interceptors.response.use(
  (res: { data: { code: any; msg: any; message: any; error_description: any }; status: any; config: { url: string; meta: { noCookie: boolean } } }) => {
    const status = res.data.code || res.status
    const statusWhiteList = website.statusWhiteList || []
    const message = res.data.msg || res.data.message || res.data.error_description || '未知错误'
    // 如果在白名单里则自行catch逻辑处理
    if ((statusWhiteList as any).includes(status)) return Promise.reject(res)
    // 洪水预警接口地址放开
    const hsyjWhiteList = [
      '/fh-admin/skkr/getFuture',
      'https://sk.hubeishuiyi.cn/hsybApi/api/fh-admin/skkr/getFuture',
      '/hsybApi/api/fh-admin/skkr/getFuture',
    ]
    if (hsyjWhiteList.includes(res.config.url)) return Promise.resolve(res)
    // 如果是401则跳转到登录页面
    const store = useMyStore()
    if (status === 401) store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }))
    // const store = useMyStore()
    if (status === 401) {
      store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }))
      // return
    }
    // 如果请求为非200否者默认统一处理
    if (status !== 200) {
      // 排除海康 code 为 0  情况
@@ -201,15 +194,16 @@
    // }
    if (err.response?.status === 401) {
      console.error(err.response)
      const flag: number = Number(localStorage.getItem(ELocalStorageKey.Flag))
      switch (flag) {
        case EUserType.Web:
          router.push(ERouterName.PROJECT_LIST)
          break
        case EUserType.Pilot:
          router.push(ERouterName.PILOT)
          break
      }
      store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }))
      // const flag: number = Number(localStorage.getItem(ELocalStorageKey.Flag))
      // switch (flag) {
      //   case EUserType.Web:
      //     router.push(ERouterName.PROJECT_LIST)
      //     break
      //   case EUserType.Pilot:
      //     router.push(ERouterName.PILOT)
      //     break
      // }
    }
    return Promise.reject(err)
  },