完成顶部导航条
> 添加左侧logo
> 添加右侧用户信息展示
> 修复一些登录注册的跳转问题
> 修复axios拦截器错误的头设置
> 修复authApi错误的接口路径
> 组织api文件结构
Change-Id: Ifaec7e9a78ad6862ce7d0ce76be5181185186edd
diff --git a/src/api/authApi.ts b/src/api/Auth/AuthApi.ts
similarity index 63%
rename from src/api/authApi.ts
rename to src/api/Auth/AuthApi.ts
index 4a08c2d..9eae3fb 100644
--- a/src/api/authApi.ts
+++ b/src/api/Auth/AuthApi.ts
@@ -1,29 +1,30 @@
import axios, { type AxiosResponse } from 'axios';
-import type { RejisterRequest , CommonResponse, ResetPasswordRequest} from './type';
+import type { RejisterRequest , ResetPasswordRequest} from './type';
import type{ LoginRequest } from './type';
+import type { CommonResponse } from '../type';
-class authAPI {
+class AuthAPI {
static sendVerificationCode(email: string): Promise<AxiosResponse<CommonResponse>> {
- return axios.post('/api/sendVerification', { email });
+ return axios.post('/api/auth/sendVerification', { email });
}
static register(request: RejisterRequest): Promise<AxiosResponse<CommonResponse>> {
- return axios.post('/api/register', request);
+ return axios.post('/api/auth/register', request);
}
static sendResetCode(email: string):Promise<AxiosResponse<CommonResponse>> {
- return axios.post('/api/sendResetCode', { email });
+ return axios.post('/api/auth/sendResetCode', { email });
}
static resetPassword( request: ResetPasswordRequest ):Promise<AxiosResponse<CommonResponse>> {
- return axios.post('/api/resetPassword', request);
+ return axios.post('/api/auth/resetPassword', request);
}
static refreshToken(oldToken : string): Promise<AxiosResponse<CommonResponse<string>>> {
return axios.post(
- '/api/refreshToken',
+ '/api/auth/refreshToken',
{}, // 请求体空
{
headers: {
@@ -35,10 +36,10 @@
static login(loginRequest: LoginRequest): Promise<AxiosResponse<CommonResponse<string>>> {
- return axios.post('/api/login', loginRequest);
+ return axios.post('/api/auth/login', loginRequest);
}
}
-export default authAPI;
+export default AuthAPI;
diff --git a/src/api/Auth/type.ts b/src/api/Auth/type.ts
new file mode 100644
index 0000000..fd6f87d
--- /dev/null
+++ b/src/api/Auth/type.ts
@@ -0,0 +1,19 @@
+export interface LoginRequest {
+ email: string;
+ password: string;
+}
+
+export interface RejisterRequest {
+ username: string,
+ email: string,
+ verificationCode: string,
+ password: string,
+}
+
+export interface ResetPasswordRequest {
+ email: string,
+ code: string,
+ newPassword: string,
+}
+
+
diff --git a/src/api/User/UserApi.ts b/src/api/User/UserApi.ts
new file mode 100644
index 0000000..44a0ae9
--- /dev/null
+++ b/src/api/User/UserApi.ts
@@ -0,0 +1,12 @@
+import type { AxiosResponse } from "axios";
+import axios from "axios";
+import type { UserInfo } from "./type";
+import type { CommonResponse } from "../type";
+
+class UserAPi {
+ static getMe() :Promise<AxiosResponse<CommonResponse<UserInfo>>> {
+ return axios.get('/api/me');
+ }
+}
+
+export default UserAPi;
\ No newline at end of file
diff --git a/src/api/User/type.ts b/src/api/User/type.ts
new file mode 100644
index 0000000..a7a1503
--- /dev/null
+++ b/src/api/User/type.ts
@@ -0,0 +1,10 @@
+export interface UserInfo {
+ userid: string,
+ username: string
+}
+
+export interface UserDetailInfo {
+ userid: string,
+ username: string,
+ // ...
+}
\ No newline at end of file
diff --git a/src/api/interceptors.ts b/src/api/interceptors.ts
index 3945bc3..bc2e566 100644
--- a/src/api/interceptors.ts
+++ b/src/api/interceptors.ts
@@ -7,7 +7,8 @@
config.url = requestUrl.replace("/auth/","/");
} else {
const token = localStorage.getItem('token');
- config.headers['Authorization'] = `Bearer ${token}`;
+ console.log(token);
+ config.headers['token'] = `${token}`;
}
return config;
}, (error) => {
diff --git a/src/api/type.ts b/src/api/type.ts
index c1acc22..8714ae7 100644
--- a/src/api/type.ts
+++ b/src/api/type.ts
@@ -1,23 +1,5 @@
-export interface LoginRequest {
- email: string;
- password: string;
-}
-
-export interface RejisterRequest {
- username: string,
- email: string,
- verificationCode: string,
- password: string,
-}
-
-export interface ResetPasswordRequest {
- email: string,
- code: string,
- newPassword: string,
-}
-
export interface CommonResponse<T= null> {
code: number;
message: string;
data: T;
- }
+}
\ No newline at end of file