flat: 初始化
This commit is contained in:
64
src/app.tsx
64
src/app.tsx
@@ -9,10 +9,29 @@ import { errorConfig } from './requestErrorConfig';
|
||||
import { clearSessionToken, getAccessToken, getRefreshToken, getTokenExpireTime } from './access';
|
||||
import { getRemoteMenu, getRoutersInfo, getUserInfo, patchRouteWithRemoteMenus, setRemoteMenu } from './services/session';
|
||||
import { PageEnum } from './enums/pagesEnums';
|
||||
|
||||
import {logout} from "@/services/system/auth";
|
||||
import { stringify } from 'querystring';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const loginOut = async () => {
|
||||
await logout();
|
||||
clearSessionToken();
|
||||
setRemoteMenu(null);
|
||||
const { search, pathname } = window.location;
|
||||
const urlParams = new URL(window.location.href).searchParams;
|
||||
/** 此方法会跳转到 redirect 参数所在的位置 */
|
||||
const redirect = urlParams.get('redirect');
|
||||
// Note: There may be security issues, please note
|
||||
if (window.location.pathname !== '/user/login' && !redirect) {
|
||||
history.replace({
|
||||
pathname: '/user/login',
|
||||
search: stringify({
|
||||
redirect: pathname + search,
|
||||
}),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
@@ -63,7 +82,8 @@ export async function getInitialState(): Promise<{
|
||||
// ProLayout 支持的api https://procomponents.ant.design/components/layout
|
||||
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
|
||||
return {
|
||||
actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
|
||||
// actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
|
||||
actionsRender: () => [ <SelectLang key="SelectLang" />],
|
||||
avatarProps: {
|
||||
src: initialState?.currentUser?.avatar,
|
||||
title: <AvatarName />,
|
||||
@@ -115,14 +135,14 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
||||
width: '331px',
|
||||
},
|
||||
],
|
||||
links: isDev
|
||||
? [
|
||||
<Link key="openapi" to="/umi/plugin/openapi" target="_blank">
|
||||
<LinkOutlined />
|
||||
<span>OpenAPI 文档</span>
|
||||
</Link>,
|
||||
]
|
||||
: [],
|
||||
// links: isDev
|
||||
// ? [
|
||||
// <Link key="openapi" to="/umi/plugin/openapi" target="_blank">
|
||||
// <LinkOutlined />
|
||||
// <span>OpenAPI 文档</span>
|
||||
// </Link>,
|
||||
// ]
|
||||
// : [],
|
||||
menuHeaderRender: undefined,
|
||||
// 自定义 403 页面
|
||||
// unAccessible: <div>unAccessible</div>,
|
||||
@@ -169,14 +189,14 @@ export async function patchClientRoutes({ routes }) {
|
||||
patchRouteWithRemoteMenus(routes);
|
||||
}
|
||||
|
||||
export function render(oldRender: () => void) {
|
||||
export async function render(oldRender: () => void) {
|
||||
// console.log('render get routers', oldRender)
|
||||
const token = getAccessToken();
|
||||
if(!token || token?.length === 0) {
|
||||
oldRender();
|
||||
return;
|
||||
}
|
||||
getRoutersInfo().then(res => {
|
||||
await getRoutersInfo().then(res => {
|
||||
setRemoteMenu(res);
|
||||
oldRender()
|
||||
});
|
||||
@@ -220,14 +240,16 @@ export const request = {
|
||||
},
|
||||
],
|
||||
responseInterceptors: [
|
||||
// (response) =>
|
||||
// {
|
||||
// // // 不再需要异步处理读取返回体内容,可直接在data中读出,部分字段可在 config 中找到
|
||||
// // const { data = {} as any, config } = response;
|
||||
// // // do something
|
||||
// // console.log('data: ', data)
|
||||
// // console.log('config: ', config)
|
||||
// return response
|
||||
// },
|
||||
(response) => {
|
||||
// 不再需要异步处理读取返回体内容,可直接在data中读出,部分字段可在 config 中找到
|
||||
const { data = {} as any, config } = response;
|
||||
switch (data.code) {
|
||||
case 401:
|
||||
loginOut()
|
||||
}
|
||||
// console.log('data: ', data)
|
||||
// console.log('config: ', config)
|
||||
return response
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user