|
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' |
8 | 2 |
|
9 | 3 | import { ElMessage, ElMessageBox, ElNotification } from 'element-plus'
|
10 |
| -import qs from 'qs' |
11 | 4 | import { config } from '@/config/axios/config'
|
12 | 5 | import { getAccessToken, getRefreshToken, getTenantId, removeToken, setToken } from '@/utils/auth'
|
13 | 6 | import errorCode from './errorCode'
|
@@ -52,29 +45,12 @@ service.interceptors.request.use(
|
52 | 45 | }
|
53 | 46 | })
|
54 | 47 | if (getAccessToken() && !isToken) {
|
55 |
| - ;(config as Recordable).headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token |
| 48 | + config.headers.Authorization = 'Bearer ' + getAccessToken() // 让每个请求携带自定义token |
56 | 49 | }
|
57 | 50 | // 设置租户
|
58 | 51 | if (tenantEnable && tenantEnable === 'true') {
|
59 | 52 | 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 |
78 | 54 | }
|
79 | 55 | return config
|
80 | 56 | },
|
|
0 commit comments