| | |
| | | * @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. |
| | |
| | | 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' |
| | |
| | | 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 情况 |
| | |
| | | // } |
| | | 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) |
| | | }, |