refactor(http): 重构登录和请求基础URL处理逻辑
移除loginAction的sparkBaseUrl参数,改为通过请求拦截器统一处理 优化设备地址显示逻辑,优先使用非IPv6地址
This commit is contained in:
@@ -6,8 +6,7 @@ import { encryptPassword } from '@/utils/crypto.js';
|
||||
export const getHealthAction = () => getAction(url.health);
|
||||
|
||||
// 用户登录
|
||||
export const loginAction = (data, sparkBaseUrl) =>
|
||||
postAction(url.user.login, { email: data.email, password: encryptPassword(data.password) }, {}, sparkBaseUrl);
|
||||
export const loginAction = (data) => postAction(url.user.login, { email: data.email, password: encryptPassword(data.password) });
|
||||
|
||||
// 会话
|
||||
export const createSessionAction = (data) => postAction(url.session.create, data);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import axios from 'axios';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { getBaseUrl } from './url.js';
|
||||
import { useSparkStore } from '@/stores/spark';
|
||||
|
||||
// baseURL 由主进程动态分配端口,通过 getBaseUrl() 运行时获取
|
||||
const axiosInstance = axios.create({
|
||||
@@ -12,9 +13,10 @@ const axiosInstance = axios.create({
|
||||
responseType: 'json',
|
||||
});
|
||||
|
||||
// 每次请求前动态更新 baseURL,确保服务启动后端口变更能被感知
|
||||
// 每次请求前动态更新 baseURL:优先用选中的 spark 设备地址,否则回退到 opencode 地址
|
||||
axiosInstance.interceptors.request.use((config) => {
|
||||
config.baseURL = getBaseUrl();
|
||||
const sparkStore = useSparkStore();
|
||||
config.baseURL = sparkStore.selectedDeviceUrl || getBaseUrl();
|
||||
return config;
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user