feat: 完成TikTok短剧管理后台基础功能开发
本次提交搭建了完整的后台管理系统,包含: 1. 登录认证与权限校验体系 2. 工作台、短剧、用户、角色、人员、日志等全业务模块 3. 响应式布局与通用样式组件 4. 菜单动态过滤与路由权限控制 5. 移除了README中冗余的权限管理菜单项
This commit is contained in:
30
src/api/client.ts
Normal file
30
src/api/client.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import axios, { AxiosError } from 'axios';
|
||||
import { Message } from '@arco-design/web-react';
|
||||
import type { ApiResponse, PageData } from './types';
|
||||
|
||||
export const API_BASE_URL = import.meta.env.VITE_API_BASE_URL || 'http://localhost:3000';
|
||||
export const TOKEN_KEY = 'cth_tk_admin_token';
|
||||
|
||||
export const api = axios.create({ baseURL: API_BASE_URL });
|
||||
|
||||
api.interceptors.request.use((config) => {
|
||||
const token = localStorage.getItem(TOKEN_KEY);
|
||||
if (token) {
|
||||
config.headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
return config;
|
||||
});
|
||||
|
||||
api.interceptors.response.use(
|
||||
(response) => response,
|
||||
(error: AxiosError<ApiResponse<unknown>>) => {
|
||||
const message = error.response?.data?.message || error.message || '请求失败';
|
||||
Message.error(message);
|
||||
return Promise.reject(error);
|
||||
},
|
||||
);
|
||||
|
||||
export async function fetchPage<T>(url: string): Promise<PageData<T>> {
|
||||
const response = await api.get<ApiResponse<PageData<T>>>(url);
|
||||
return response.data.data;
|
||||
}
|
||||
Reference in New Issue
Block a user