From 4ff3eee77b41466d08117970970d01be6e48ffe1 Mon Sep 17 00:00:00 2001
From: zhongrj <646384940@qq.com>
Date: Fri, 28 Mar 2025 19:02:30 +0800
Subject: [PATCH] Merge branch 'master' of http://139.196.74.78:10010/r/drone/pilot-h5
---
src/api/http/request.ts | 71 +++++++++++------------------------
1 files changed, 22 insertions(+), 49 deletions(-)
diff --git a/src/api/http/request.ts b/src/api/http/request.ts
index 5186bda..153b0a9 100644
--- a/src/api/http/request.ts
+++ b/src/api/http/request.ts
@@ -6,11 +6,12 @@
* isToken是否需要token
*/
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
-import store from '@/store/user'
+// import store from '@/store/user'
+import { useMyStore } from '@/store'
import router from '@/router';
import { serialize } from '@/utils/common'
import { getToken } from '@/utils/auth';
-import { ElMessage } from 'element-plus';
+import { showNotify } from 'vant';
import website from '@/config/website';
import { Base64 } from 'js-base64'
// import NProgress from 'nprogress';
@@ -66,10 +67,8 @@
url: string
authorization: boolean
}) => {
- if(config.url.includes('h5')) {
- config.url = '/drone-h5' + config.url
- } else if (!config.url.includes('/blade-') && !config.url.includes('https://') && !config.url.includes('http://')) {
- config.url = '/drone-yw' + config.url
+ if (!config.url.includes('/blade-') && !config.url.includes('https://') && !config.url.includes('http://')) {
+ config.url = '/drone-device-core' + config.url
}
const authorization = config.authorization === false
if (!authorization) {
@@ -80,6 +79,9 @@
const isToken = meta.isToken === false
if (getToken() && !isToken) {
config.headers[website.tokenHeader] = 'bearer ' + getToken()
+ } else {
+ // 为了兼容分享页面
+ config.headers[website.tokenHeader] = 'bearer ' + getAuthToken()
}
if (meta.noCookie) {
delete config.headers.cookie
@@ -100,9 +102,6 @@
if (config.method === 'post' && meta.isSerialize === true) {
config.data = serialize(config.data)
}
- // config.headers[ELocalStorageKey.Token] = localStorage.getItem(ELocalStorageKey.Token)
- // config.headers[REQUEST_ID] = uuidv4()
- // config.baseURL = CURRENT_CONFIG.baseURL
return config
},
(error: any) => {
@@ -115,10 +114,8 @@
const status = res.data.code || res.status
const message = res.data.msg || res.data.message || res.data.error_description || '未知错误'
// 如果是401则跳转到登录页面
- // const store = useMyStore()
- if (status === 401) {
- store.dispatch('FedLogOut').then(() => router.push({ path: '/login' }))
- // return
+ if (status == 401) {
+ router.push({ path: '/login' })
}
// 如果请求为非200否者默认统一处理
if (status !== 200) {
@@ -130,11 +127,7 @@
return Promise.reject(new Error(message))
}
if (message === '缺失令牌,鉴权失败') {
- // message({
- // message: '登录信息已过期,请重新登录',
- // type: 'warning',
- // })
- ElMessage.warning('登录信息已过期,请重新登录')
+ showNotify({ type: 'warning', message: '登录信息已过期,请重新登录' })
}
if (
![
@@ -146,22 +139,10 @@
'缺失令牌,鉴权失败',
].includes(message)
) {
- ElMessage.warning(message)
+ showNotify({ type: 'warning', message: message })
}
return Promise.reject(new Error(message))
}
- // console.info('URL: ' + response.config.baseURL + response.config.url, '\nData: ', response.data, '\nResponse:', response)
- // const whiteList = ['/manage/api/v1/live/streams/stop']
- // if (whiteList.includes(response.config.url)) {
- // return Promise.reject(response.data)
- // }
- // 处理消息返回
- // if (response.data.code && !response.data.success) {
- // message.error(response.data.message)
- // }
- // if (response.data.code && response.data.code !== 0) {
- // message.error(response.data.message)
- // }
return res
},
(err: {
@@ -181,29 +162,21 @@
if (err.response?.data && err.response.data.result) {
description = err.response.data.result.message
}
- // @See: https://github.com/axios/axios/issues/383
if (!err.response || !err.response.status) {
- ElMessage.error('网络异常,请检查后端服务后重试')
+ showNotify({ type: 'danger', message: '网络异常,请检查后端服务后重试' })
return
}
if (err.response?.status !== 200) {
- ElMessage.error(`错误码: ${err.response?.status}`)
+ if (err.response.data?.msg) {
+ showNotify({ type: 'danger', message: err.response.data?.msg })
+ } else if (err.response.data?.error_description) {
+ showNotify({ type: 'danger', message: err.response.data?.error_description })
+ } else {
+ showNotify({ type: 'danger', message: `错误码: ${err.response?.status}` })
+ }
}
- // if (err.response?.status === 403) {
- // // window.location.href = '/'
- // }
- if (err.response?.status === 401) {
- console.error(err.response)
- 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
- // }
+ if (err.response?.status == 401) {
+ router.push({ path: '/login' })
}
return Promise.reject(err)
},
--
Gitblit v1.9.3