flat: 暂存
This commit is contained in:
30
src/app.tsx
30
src/app.tsx
@@ -12,11 +12,10 @@ import { PageEnum } from './enums/pagesEnums';
|
||||
import {logout} from "@/services/system/auth";
|
||||
import { stringify } from 'querystring';
|
||||
import { message } from 'antd'
|
||||
import { createRef } from 'react';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const loginOut = async () => {
|
||||
await logout();
|
||||
clearSessionToken();
|
||||
setRemoteMenu(null);
|
||||
const { search, pathname } = window.location;
|
||||
@@ -24,11 +23,12 @@ const loginOut = async () => {
|
||||
/** 此方法会跳转到 redirect 参数所在的位置 */
|
||||
const redirect = urlParams.get('redirect');
|
||||
// Note: There may be security issues, please note
|
||||
if (window.location.pathname !== '/user/login' && !redirect) {
|
||||
console.log('redirect', window.location.pathname, redirect)
|
||||
if (window.location.pathname !== '/qingdao/user/login' && !redirect) {
|
||||
history.replace({
|
||||
pathname: '/user/login',
|
||||
search: stringify({
|
||||
redirect: pathname + search,
|
||||
redirect: pathname.replace('/qingdao', '') + search,
|
||||
}),
|
||||
});
|
||||
}
|
||||
@@ -79,9 +79,9 @@ export async function getInitialState(): Promise<{
|
||||
settings: defaultSettings as Partial<LayoutSettings>,
|
||||
};
|
||||
}
|
||||
|
||||
// ProLayout 支持的api https://procomponents.ant.design/components/layout
|
||||
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
|
||||
|
||||
return {
|
||||
// actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
|
||||
actionsRender: () => [ <SelectLang key="SelectLang" />],
|
||||
@@ -95,9 +95,10 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
||||
waterMarkProps: {
|
||||
// content: initialState?.currentUser?.nickName,
|
||||
},
|
||||
// actionRef: layoutActionRef,
|
||||
menu: {
|
||||
locale: false,
|
||||
// 每当 initialState?.currentUser?.userid 发生修改时重新执行 request
|
||||
// // 每当 initialState?.currentUser?.userid 发生修改时重新执行 request
|
||||
params: {
|
||||
userId: initialState?.currentUser?.userId,
|
||||
},
|
||||
@@ -105,7 +106,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
|
||||
if (!initialState?.currentUser?.userId) {
|
||||
return [];
|
||||
}
|
||||
return getRemoteMenu();
|
||||
return getRemoteMenu()
|
||||
},
|
||||
},
|
||||
footerRender: () => <Footer />,
|
||||
@@ -176,7 +177,7 @@ export async function onRouteChange({ clientRoutes, location }) {
|
||||
// console.log('onRouteChange', clientRoutes, location, menus);
|
||||
if(menus === null && location.pathname !== PageEnum.LOGIN) {
|
||||
console.log('refresh')
|
||||
history.go(0);
|
||||
// history.go(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,13 +192,15 @@ export async function patchClientRoutes({ routes }) {
|
||||
}
|
||||
|
||||
export async function render(oldRender: () => void) {
|
||||
// console.log('render get routers', oldRender)
|
||||
console.log('render get routers', oldRender)
|
||||
const token = getAccessToken();
|
||||
if(!token || token?.length === 0) {
|
||||
oldRender();
|
||||
return;
|
||||
}
|
||||
await getRoutersInfo().then(res => {
|
||||
console.log('render get routers', 123)
|
||||
|
||||
setRemoteMenu(res);
|
||||
oldRender()
|
||||
});
|
||||
@@ -209,9 +212,10 @@ export async function render(oldRender: () => void) {
|
||||
* @doc https://umijs.org/docs/max/request#配置
|
||||
*/
|
||||
const checkRegion = 5 * 60 * 1000;
|
||||
|
||||
export const request = {
|
||||
...errorConfig,
|
||||
baseURL: process.env.NODE_ENV === 'development' ? '' : 'http://39.98.44.136:8080',
|
||||
// baseURL: 'http://39.98.44.136:8080',
|
||||
requestInterceptors: [
|
||||
(url: any, options: { headers: any }) => {
|
||||
const headers = options.headers ? options.headers : [];
|
||||
@@ -237,6 +241,11 @@ export const request = {
|
||||
clearSessionToken();
|
||||
}
|
||||
}
|
||||
if(process.env.NODE_ENV !== 'development') {
|
||||
if (url.startsWith('/api')) {
|
||||
url = url.replace(/^\/api/, '');
|
||||
}
|
||||
}
|
||||
return { url, options };
|
||||
},
|
||||
],
|
||||
@@ -247,6 +256,7 @@ export const request = {
|
||||
switch (data.code) {
|
||||
case 401:
|
||||
loginOut()
|
||||
break
|
||||
}
|
||||
if(data.code !== 200 && data.msg) {
|
||||
message.info(data.msg)
|
||||
|
||||
Reference in New Issue
Block a user