新增go服务token

This commit is contained in:
Teo
2025-07-29 16:24:08 +08:00
parent 7e7e51853d
commit c069b53636
9 changed files with 61 additions and 14 deletions

19
src/utils/request-go.ts Normal file
View File

@ -0,0 +1,19 @@
import $cache from '@/plugins/cache';
// src/utils/request-go.ts
import request from '@/utils/request';
const BASE_GO_URL = import.meta.env.VITE_APP_BASE_API_GO;
/**
* 包装 request 请求,统一使用 Go 服务地址作为 baseURL
* @param config 原始请求配置
*/
export default function requestGo(config: any) {
return request({
baseURL: BASE_GO_URL,
...config,
headers: {
'Authorization': `Bearer ${$cache.local.get('goToken') || ''}`
}
});
}

View File

@ -45,7 +45,7 @@ service.interceptors.request.use(
// 是否需要加密
const isEncrypt = config.headers?.isEncrypt === 'true';
if (getToken() && !isToken) {
if (getToken() && !isToken && !config.headers?.Authorization) {
config.headers['Authorization'] = 'Bearer ' + getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改
}
// get请求映射params参数