feat: 1. 将大部分的请求从fetch改成axios方便管理。
2. 给文档类型添加入口模块和相关数据的渲染。并且给文档类型进行功能上的角色权限区分 3. 新增角色权限管理页面
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import { API_BASE_URL } from "~/config/api-config";
|
||||
import axios from 'axios';
|
||||
|
||||
/**
|
||||
* 登录请求参数(OAuth 方式)
|
||||
@@ -64,30 +65,26 @@ export async function loginWithOAuth(loginData: LoginRequest): Promise<LoginResp
|
||||
console.log("📝 [Login Client] 调用后端 OAuth 登录接口:", loginUrl);
|
||||
|
||||
try {
|
||||
const response = await fetch(loginUrl, {
|
||||
method: "POST",
|
||||
const response = await axios.post(loginUrl, loginData, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
},
|
||||
body: JSON.stringify(loginData)
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
console.error("❌ [Login Client] OAuth 登录请求失败:", response.status, errorData);
|
||||
console.log("✅ [Login Client] OAuth 登录成功");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const errorData = error.response?.data || {};
|
||||
console.error("❌ [Login Client] OAuth 登录请求失败:", error.response?.status, errorData);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: errorData.error || errorData.message || `登录失败: ${response.status}`
|
||||
error: errorData.error || errorData.message || `登录失败: ${error.response?.status || 'Unknown'}`
|
||||
};
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("✅ [Login Client] OAuth 登录成功");
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("❌ [Login Client] OAuth 登录请求异常:", error);
|
||||
return {
|
||||
success: false,
|
||||
@@ -120,33 +117,29 @@ export async function loginWithPassword(
|
||||
console.log("📝 [Login Client] 调用后端密码登录接口:", loginUrl);
|
||||
|
||||
try {
|
||||
const response = await fetch(loginUrl, {
|
||||
method: "POST",
|
||||
const response = await axios.post(loginUrl, {
|
||||
username,
|
||||
password
|
||||
}, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
},
|
||||
body: JSON.stringify({
|
||||
username,
|
||||
password
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
const errorData = await response.json().catch(() => ({}));
|
||||
console.error("❌ [Login Client] 密码登录请求失败:", response.status, errorData);
|
||||
console.log("✅ [Login Client] 密码登录成功");
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
const errorData = error.response?.data || {};
|
||||
console.error("❌ [Login Client] 密码登录请求失败:", error.response?.status, errorData);
|
||||
|
||||
return {
|
||||
success: false,
|
||||
error: errorData.error || errorData.message || `登录失败: ${response.status}`
|
||||
error: errorData.error || errorData.message || `登录失败: ${error.response?.status || 'Unknown'}`
|
||||
};
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
console.log("✅ [Login Client] 密码登录成功");
|
||||
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error("❌ [Login Client] 密码登录请求异常:", error);
|
||||
return {
|
||||
success: false,
|
||||
|
||||
Reference in New Issue
Block a user