修改登陆api

This commit is contained in:
2025-06-04 23:50:46 +08:00
parent 4f5e971cb6
commit 60667511b4
4 changed files with 349 additions and 218 deletions

View File

@@ -50,39 +50,45 @@ import { loginSuccess } from '../utils/jwt';
// }
// )
export const userLogin = async (username, password, server, token) => {
// 获取验证码
export const getCaptcha = async () => {
try {
const response = await axiosInstance.get('/captcha');
return response.data;
} catch (error) {
throw error;
}
};
// 用户登录
export const userLogin = async (username, password, token, captcha) => {
try {
// console.log('登录请求参数:', { username, password, server, token }); // 保留此调试日志以备将来使用,或按需移除
const response = await axiosInstance.post('/user/login', {
username,
password,
server,
token
token,
captcha
});
if (response.data.access_token) {
loginSuccess(response.data.access_token, username); // 使用 username 作为 userId
loginSuccess(response.data.access_token);
}
return response.data;
} catch (error) {
// 错误将由响应拦截器统一处理和记录,这里可以直接抛出
throw error;
}
};
export const userRegister = async (qq_code, password, server, token) => {
// 用户注册
export const userRegister = async (qq_code, password, token, captcha) => {
try {
const requestData = {
const response = await axiosInstance.post('/user/register', {
qq_code,
password,
server,
token
};
// console.log('注册请求参数:', requestData); // 保留此调试日志以备将来使用,或按需移除
const response = await axiosInstance.post('/user/register', requestData);
// console.log('注册响应数据:', response.data); // 保留此调试日志以备将来使用,或按需移除
token,
captcha
});
return response.data;
} catch (error) {
throw error;