flat: 暂存

This commit is contained in:
史典卓
2025-03-28 15:30:35 +08:00
parent 2bf8cf55ac
commit b3238e5c2b
50 changed files with 3302 additions and 416 deletions

View File

@@ -1,18 +1,21 @@
import { Footer, Question, SelectLang, AvatarDropdown, AvatarName } from '@/components';
import { LinkOutlined } from '@ant-design/icons';
import { AvatarDropdown, AvatarName, Footer, SelectLang } from '@/components';
import type { Settings as LayoutSettings } from '@ant-design/pro-components';
import { SettingDrawer } from '@ant-design/pro-components';
import type { RunTimeLayoutConfig } from '@umijs/max';
import { history, Link } from '@umijs/max';
import { history } from '@umijs/max';
import defaultSettings from '../config/defaultSettings';
import { errorConfig } from './requestErrorConfig';
import { clearSessionToken, getAccessToken, getRefreshToken, getTokenExpireTime } from './access';
import { getRemoteMenu, getRoutersInfo, getUserInfo, patchRouteWithRemoteMenus, setRemoteMenu } from './services/session';
import {
getRemoteMenu,
getRoutersInfo,
getUserInfo,
patchRouteWithRemoteMenus,
setRemoteMenu,
} from './services/session';
import { PageEnum } from './enums/pagesEnums';
import {logout} from "@/services/system/auth";
import { stringify } from 'querystring';
import { message } from 'antd'
import { createRef } from 'react';
import { message } from 'antd';
const isDev = process.env.NODE_ENV === 'development';
const loginOut = async () => {
@@ -23,7 +26,7 @@ const loginOut = async () => {
/** 此方法会跳转到 redirect 参数所在的位置 */
const redirect = urlParams.get('redirect');
// Note: There may be security issues, please note
console.log('redirect', window.location.pathname, redirect)
console.log('redirect', window.location.pathname, redirect);
if (window.location.pathname !== '/qingdao/user/login' && !redirect) {
history.replace({
pathname: '/user/login',
@@ -34,7 +37,6 @@ const loginOut = async () => {
}
};
/**
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */
@@ -79,12 +81,12 @@ 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" />],
actionsRender: () => [<SelectLang key="SelectLang" />],
avatarProps: {
src: initialState?.currentUser?.avatar,
title: <AvatarName />,
@@ -106,7 +108,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
if (!initialState?.currentUser?.userId) {
return [];
}
return getRemoteMenu()
return getRemoteMenu();
},
},
footerRender: () => <Footer />,
@@ -137,6 +139,7 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
width: '331px',
},
],
pure: false,
// links: isDev
// ? [
// <Link key="openapi" to="/umi/plugin/openapi" target="_blank">
@@ -174,9 +177,9 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
export async function onRouteChange({ clientRoutes, location }) {
const menus = getRemoteMenu();
// console.log('onRouteChange', clientRoutes, location, menus);
if(menus === null && location.pathname !== PageEnum.LOGIN) {
console.log('refresh')
// console.log('onRouteChange', clientRoutes, location, menus);
if (menus === null && location.pathname !== PageEnum.LOGIN) {
console.log('refresh');
// history.go(0);
}
}
@@ -185,24 +188,23 @@ export async function onRouteChange({ clientRoutes, location }) {
// console.log('patchRoutes', routes, routeComponents);
// }
export async function patchClientRoutes({ routes }) {
// console.log('patchClientRoutes', routes);
patchRouteWithRemoteMenus(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) {
if (!token || token?.length === 0) {
oldRender();
return;
}
await getRoutersInfo().then(res => {
console.log('render get routers', 123)
await getRoutersInfo().then((res) => {
console.log('render get routers', 123);
setRemoteMenu(res);
oldRender()
oldRender();
});
}
@@ -241,7 +243,7 @@ export const request = {
clearSessionToken();
}
}
if(process.env.NODE_ENV !== 'development') {
if (process.env.NODE_ENV !== 'development') {
if (url.startsWith('/api')) {
url = url.replace(/^\/api/, '');
}
@@ -255,15 +257,15 @@ export const request = {
const { data = {} as any, config } = response;
switch (data.code) {
case 401:
loginOut()
break
loginOut();
break;
}
if(data.code !== 200 && data.msg) {
message.info(data.msg)
if (data.code !== 200 && data.msg) {
message.info(data.msg);
}
console.log('data: ', data)
// console.log('data: ', data)
// console.log('config: ', config)
return response
return response;
},
],
};