|
1 | 1 | import axios from 'axios' |
2 | 2 | import {Message, MessageBox, Notification} from 'element-ui' |
3 | 3 | import store from '@/store' |
4 | | -import {getAccessToken, getRefreshToken, getTenantId, setToken} from '@/utils/auth' |
| 4 | +import {getAccessToken, getRefreshToken, getTenantId, setToken, getVisitTenantId} from '@/utils/auth' |
5 | 5 | import errorCode from '@/utils/errorCode' |
6 | 6 | import {getPath, getTenantEnable} from "@/utils/ruoyi"; |
7 | 7 | import {refreshToken} from "@/api/login"; |
@@ -43,6 +43,11 @@ service.interceptors.request.use(config => { |
43 | 43 | if (tenantId) { |
44 | 44 | config.headers['tenant-id'] = tenantId; |
45 | 45 | } |
| 46 | + // 只有登录时,才设置 visit-tenant-id 访问租户 |
| 47 | + const visitTenantId = getVisitTenantId() |
| 48 | + if (config.headers.Authorization && visitTenantId) { |
| 49 | + config.headers['visit-tenant-id'] = visitTenantId |
| 50 | + } |
46 | 51 | } |
47 | 52 | // get请求映射params参数 |
48 | 53 | if (config.method === 'get' && config.params) { |
@@ -183,10 +188,17 @@ service.interceptors.response.use(async res => { |
183 | 188 | ) |
184 | 189 |
|
185 | 190 | export function getBaseHeader() { |
186 | | - return { |
| 191 | + const headers = { |
187 | 192 | 'Authorization': "Bearer " + getAccessToken(), |
188 | 193 | 'tenant-id': getTenantId(), |
189 | 194 | } |
| 195 | + // 如果已登录且存在访问租户ID,添加 visit-tenant-id 请求头 |
| 196 | + const visitTenantId = getVisitTenantId() |
| 197 | + if (getAccessToken() && visitTenantId) { |
| 198 | + headers['visit-tenant-id'] = visitTenantId |
| 199 | + } |
| 200 | + |
| 201 | + return headers |
190 | 202 | } |
191 | 203 |
|
192 | 204 | function handleAuthorized() { |
|
0 commit comments