新增用户注册功能
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
import type { AxiosResponse } from "axios";
|
||||
import { apiGet, apiPost } from "./axios";
|
||||
import type { AdminUserListResponse, UserInfo, UserStatus } from "../types/api";
|
||||
|
||||
export const listPendingUsers = (status: UserStatus = "PENDING"): Promise<AxiosResponse<AdminUserListResponse>> =>
|
||||
apiGet("/api/v1/admin/users", { params: { status } });
|
||||
|
||||
export const approveUser = (userId: string): Promise<AxiosResponse<UserInfo>> =>
|
||||
apiPost(`/api/v1/admin/users/${userId}/approve`, { action: "approve" });
|
||||
|
||||
export const rejectUser = (userId: string): Promise<AxiosResponse<UserInfo>> =>
|
||||
apiPost(`/api/v1/admin/users/${userId}/reject`, { action: "reject" });
|
||||
@@ -1,10 +1,20 @@
|
||||
import type { AxiosResponse } from "axios";
|
||||
import api, { apiGet, apiPost } from "./axios";
|
||||
import type { UserMeResponse, LoginRequest, LoginResponse } from "../types/api";
|
||||
import api, { apiGet, apiPatch, apiPost } from "./axios";
|
||||
import type { UserMeResponse, LoginRequest, LoginResponse, RegisterRequest } from "../types/api";
|
||||
|
||||
export const login = (payload: LoginRequest): Promise<AxiosResponse<LoginResponse>> =>
|
||||
apiPost<LoginResponse>("/api/v1/auth/login", payload);
|
||||
|
||||
export const fetchMe = (): Promise<AxiosResponse<UserMeResponse>> => apiGet<UserMeResponse>("/api/v1/auth/me");
|
||||
|
||||
export const register = (payload: RegisterRequest): Promise<AxiosResponse<{ message: string }>> =>
|
||||
apiPost("/api/v1/auth/register", payload);
|
||||
|
||||
export const updateProfile = (payload: {
|
||||
full_name?: string;
|
||||
department?: string;
|
||||
current_password?: string;
|
||||
password?: string;
|
||||
}) => apiPatch<UserMeResponse>("/api/v1/auth/me", payload);
|
||||
|
||||
export default api;
|
||||
|
||||
@@ -27,6 +27,12 @@ instance.interceptors.response.use(
|
||||
async (error: AxiosError<ApiError>) => {
|
||||
const status = error.response?.status;
|
||||
const data = error.response?.data;
|
||||
const reqUrl = error.config?.url || "";
|
||||
const isAuthEndpoint = reqUrl.includes("/api/v1/auth/login") || reqUrl.includes("/api/v1/auth/register");
|
||||
if (isAuthEndpoint) {
|
||||
// 认证相关的错误由具体页面自行处理,避免重复提示
|
||||
return Promise.reject(error);
|
||||
}
|
||||
// 401 统一处理:同步清理本地 token,并防止重复弹窗
|
||||
const handleUnauthorized = () => {
|
||||
const auth = useAuthStore();
|
||||
|
||||
@@ -5,10 +5,19 @@ import { apiDelete } from "./axios";
|
||||
export const fetchUsers = (params?: Record<string, any>) =>
|
||||
apiGet<ApiListResponse<UserInfo>>("/api/v1/users", { params });
|
||||
|
||||
export const createUser = (payload: { username: string; password: string; role: string }) =>
|
||||
export const createUser = (payload: {
|
||||
email: string;
|
||||
password: string;
|
||||
full_name: string;
|
||||
role: string;
|
||||
department: string;
|
||||
}) =>
|
||||
apiPost<UserInfo>("/api/v1/users", payload);
|
||||
|
||||
export const updateUser = (userId: string, payload: Partial<{ role: string; is_active: boolean; password: string }>) =>
|
||||
export const updateUser = (
|
||||
userId: string,
|
||||
payload: Partial<{ role: string; status: string; password: string; full_name: string; department: string; is_active: boolean }>
|
||||
) =>
|
||||
apiPatch<UserInfo>(`/api/v1/users/${userId}`, payload);
|
||||
|
||||
export const deleteUser = (userId: string, payload: { admin_password: string }) =>
|
||||
|
||||
Reference in New Issue
Block a user