feat: add Tailwind CSS and Skeleton UI integration, implement authentication flow, and configure API requests

This commit is contained in:
ethan.chen
2025-05-19 18:25:20 +08:00
parent 803f0d93ed
commit 811ed03a05
9 changed files with 1899 additions and 62 deletions

47
src/lib/request.ts Normal file
View File

@@ -0,0 +1,47 @@
/*
* @Date: 2025-05-19 18:10:10
* @LastEditors: 陈子健
* @LastEditTime: 2025-05-19 18:23:05
* @FilePath: /my-score/frontend/src/lib/request.ts
*/
import axios from 'axios';
const request = axios.create({
baseURL: '/api',
timeout: 5000,
headers: {
'Content-Type': 'application/json',
}
});
// 请求拦截器
request.interceptors.request.use(
(config) => {
// 从 localStorage 获取认证信息
const auth = localStorage.getItem('auth');
if (auth) {
config.headers.Authorization = `Basic ${auth}`;
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
// 响应拦截器
request.interceptors.response.use(
(response) => {
return response.data;
},
(error) => {
if (error.response?.status === 401) {
// 清除认证信息
localStorage.removeItem('auth');
return
}
return Promise.reject(error.response?.data || error);
}
);
export default request;