feat(react-web-next): 新增.editorconfig和.prettierrc配置文件,添加public/.gitkeep占位文件

This commit is contained in:
2025-09-23 10:32:35 +08:00
parent 10ddfd6f75
commit 408b500b6a
199 changed files with 16850 additions and 34874 deletions
+61
View File
@@ -0,0 +1,61 @@
// 避免类型耦合,使用 any 降级
import './global.less';
import React from 'react';
import { ThemeProvider } from './theme';
import { history } from 'umi';
export function rootContainer(container: React.ReactNode, _args?: any) {
return React.createElement(ThemeProvider, null, container);
}
// 使用简化的 request 配置,避免与类型强绑定(兼容 umi 3)
export const request: any = {
errorConfig: {
errorHandler(error: any) {
// 可在此处统一处理错误,如通知等
throw error;
},
},
requestInterceptors: [
(url: string, options: any) => {
const token = sessionStorage.getItem('access_token');
const headers: Record<string, string> = { ...(options?.headers as any) };
if (token) headers['Authorization'] = `Bearer ${token}`;
return { url, options: { ...options, headers } };
},
],
responseInterceptors: [
async (response: Response) => {
// 兼容后端 Result 结构
try {
const cloned = response.clone();
const data = await cloned.json();
if (data && typeof (data as any).resp_code !== 'undefined') {
const mapped = {
success: (data as any).resp_code === 0,
code: (data as any).resp_code,
msg: (data as any).resp_msg,
data: (data as any).data,
} as any;
(response as any).data = mapped;
}
} catch (e) {
// 静默处理解析错误
}
return response;
},
],
};
// 简单路由守卫:未登录访问受保护路由时跳回登录;已登录访问登录页时跳到欢迎页
export function onRouteChange({ location }: any) {
try {
const token = sessionStorage.getItem('access_token');
const isLoginPath = String(location?.pathname || '').startsWith('/user/login');
if (!token && !isLoginPath) {
history.push('/user/login');
} else if (token && isLoginPath) {
history.push('/welcome');
}
} catch {}
}