Skip to content

Commit ba2cdcc

Browse files
YunaiVgitee-org
authored andcommitted
!587 【修复】修复对 axios 的处理
Merge pull request !587 from 半栈幼儿员/hoxfix/axios
2 parents 1c23298 + c119e91 commit ba2cdcc

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

src/api/login/oauth2/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const authorize = (
2727
return request.post({
2828
url: '/system/oauth2/authorize',
2929
headers: {
30-
'Content-type': 'application/x-www-form-urlencoded'
30+
'Content-Type': 'application/x-www-form-urlencoded'
3131
},
3232
params: {
3333
response_type: responseType,

src/config/axios/index.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ import { config } from './config'
55
const { default_headers } = config
66

77
const request = (option: any) => {
8-
const { url, method, params, data, headersType, responseType, ...config } = option
8+
const { headersType, headers, ...otherOption } = option
99
return service({
10-
url: url,
11-
method,
12-
params,
13-
data,
14-
...config,
15-
responseType: responseType,
10+
...otherOption,
1611
headers: {
17-
'Content-Type': headersType || default_headers
12+
'Content-Type': headersType || default_headers,
13+
...headers
1814
}
1915
})
2016
}

src/config/axios/service.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
import axios, {
2-
AxiosError,
3-
AxiosInstance,
4-
AxiosRequestHeaders,
5-
AxiosResponse,
6-
InternalAxiosRequestConfig
7-
} from 'axios'
1+
import axios, { AxiosError, AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios'
82

93
import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
10-
import qs from 'qs'
114
import { config } from '@/config/axios/config'
125
import { getAccessToken, getRefreshToken, getTenantId, removeToken, setToken } from '@/utils/auth'
136
import errorCode from './errorCode'
@@ -52,29 +45,12 @@ service.interceptors.request.use(
5245
}
5346
})
5447
if (getAccessToken() && !isToken) {
55-
;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token
48+
config.headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token
5649
}
5750
// 设置租户
5851
if (tenantEnable && tenantEnable === 'true') {
5952
const tenantId = getTenantId()
60-
if (tenantId) (config as Recordable).headers['tenant-id'] = tenantId
61-
}
62-
const params = config.params || {}
63-
const data = config.data || false
64-
if (
65-
config.method?.toUpperCase() === 'POST' &&
66-
(config.headers as AxiosRequestHeaders)['Content-Type'] ===
67-
'application/x-www-form-urlencoded'
68-
) {
69-
config.data = qs.stringify(data)
70-
}
71-
// get参数编码
72-
if (config.method?.toUpperCase() === 'GET' && params) {
73-
config.params = {}
74-
const paramsStr = qs.stringify(params, { allowDots: true })
75-
if (paramsStr) {
76-
config.url = config.url + '?' + paramsStr
77-
}
53+
if (tenantId) config.headers['tenant-id'] = tenantId
7854
}
7955
return config
8056
},

0 commit comments

Comments
 (0)