flat: 初始化

This commit is contained in:
史典卓
2024-11-19 16:16:30 +08:00
parent f1acec18f1
commit 47a8edcf60
7 changed files with 74 additions and 65 deletions

View File

@@ -76,9 +76,9 @@ export default defineConfig({
* @name layout 插件 * @name layout 插件
* @doc https://umijs.org/docs/max/layout-menu * @doc https://umijs.org/docs/max/layout-menu
*/ */
title: 'Ant Design Pro', title: '青岛智慧就业服务系统',
layout: { layout: {
locale: true, locale: false,
...defaultSettings, ...defaultSettings,
}, },
/** /**
@@ -97,9 +97,9 @@ export default defineConfig({
locale: { locale: {
// default zh-CN // default zh-CN
default: 'zh-CN', default: 'zh-CN',
antd: true, antd: false,
// default true, when it is true, will use `navigator.language` overwrite default // default true, when it is true, will use `navigator.language` overwrite default
baseNavigator: true, baseNavigator: false,
}, },
/** /**
* @name antd 插件 * @name antd 插件

View File

@@ -15,7 +15,7 @@ const Settings: ProLayoutProps & {
fixedHeader: false, fixedHeader: false,
fixSiderbar: true, fixSiderbar: true,
colorWeak: false, colorWeak: false,
title: 'Ant Design Pro', title: '青岛智慧就业服务系统',
pwa: true, pwa: true,
logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg', logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg',
iconfontUrl: '', iconfontUrl: '',

View File

@@ -9,10 +9,29 @@ import { errorConfig } from './requestErrorConfig';
import { clearSessionToken, getAccessToken, getRefreshToken, getTokenExpireTime } from './access'; 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 { PageEnum } from './enums/pagesEnums';
import {logout} from "@/services/system/auth";
import { stringify } from 'querystring';
const isDev = process.env.NODE_ENV === 'development'; 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 // ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => { export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
return { return {
actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />], // actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />],
actionsRender: () => [ <SelectLang key="SelectLang" />],
avatarProps: { avatarProps: {
src: initialState?.currentUser?.avatar, src: initialState?.currentUser?.avatar,
title: <AvatarName />, title: <AvatarName />,
@@ -115,14 +135,14 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) =
width: '331px', width: '331px',
}, },
], ],
links: isDev // links: isDev
? [ // ? [
<Link key="openapi" to="/umi/plugin/openapi" target="_blank"> // <Link key="openapi" to="/umi/plugin/openapi" target="_blank">
<LinkOutlined /> // <LinkOutlined />
<span>OpenAPI </span> // <span>OpenAPI 文档</span>
</Link>, // </Link>,
] // ]
: [], // : [],
menuHeaderRender: undefined, menuHeaderRender: undefined,
// 自定义 403 页面 // 自定义 403 页面
// unAccessible: <div>unAccessible</div>, // unAccessible: <div>unAccessible</div>,
@@ -169,14 +189,14 @@ export async function patchClientRoutes({ routes }) {
patchRouteWithRemoteMenus(routes); patchRouteWithRemoteMenus(routes);
} }
export function render(oldRender: () => void) { export async function render(oldRender: () => void) {
// console.log('render get routers', oldRender) // console.log('render get routers', oldRender)
const token = getAccessToken(); const token = getAccessToken();
if(!token || token?.length === 0) { if(!token || token?.length === 0) {
oldRender(); oldRender();
return; return;
} }
getRoutersInfo().then(res => { await getRoutersInfo().then(res => {
setRemoteMenu(res); setRemoteMenu(res);
oldRender() oldRender()
}); });
@@ -220,14 +240,16 @@ export const request = {
}, },
], ],
responseInterceptors: [ responseInterceptors: [
// (response) => (response) => {
// { // 不再需要异步处理读取返回体内容可直接在data中读出部分字段可在 config 中找到
// // // 不再需要异步处理读取返回体内容可直接在data中读出部分字段可在 config 中找到 const { data = {} as any, config } = response;
// // const { data = {} as any, config } = response; switch (data.code) {
// // // do something case 401:
// // console.log('data: ', data) loginOut()
// // console.log('config: ', config) }
// return response // console.log('data: ', data)
// }, // console.log('config: ', config)
return response
},
], ],
}; };

View File

@@ -10,22 +10,9 @@ const Footer: React.FC = () => {
}} }}
links={[ links={[
{ {
key: 'Ant Design Pro', key: '青岛智慧就业服务系统',
title: 'Ant Design Pro', title: '青岛智慧就业服务系统',
href: 'https://pro.ant.design', href: 'http://localhost:8000/',
blankTarget: true,
},
{
key: 'github',
title: <GithubOutlined />,
href: 'https://github.com/ant-design/ant-design-pro',
blankTarget: true,
},
{
key: 'Ant Design',
title: 'Ant Design',
href: 'https://ant.design',
blankTarget: true,
}, },
]} ]}
/> />

View File

@@ -135,7 +135,6 @@ const Login: React.FC = () => {
}); });
const current = new Date(); const current = new Date();
const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60); const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60);
console.log('login response: ', response);
setSessionToken(response?.token, response?.token, expireTime); setSessionToken(response?.token, response?.token, expireTime);
message.success(defaultLoginSuccessMessage); message.success(defaultLoginSuccessMessage);
await fetchUserInfo(); await fetchUserInfo();
@@ -144,18 +143,19 @@ const Login: React.FC = () => {
history.push(urlParams.get('redirect') || '/'); history.push(urlParams.get('redirect') || '/');
return; return;
} else { } else {
console.log(response.msg); message.error(response.msg);
clearSessionToken(); clearSessionToken();
// 如果失败去设置用户错误信息 // 如果失败去设置用户错误信息
setUserLoginState({ ...response, type }); setUserLoginState({ ...response, type });
getCaptchaCode(); getCaptchaCode();
} }
} catch (error) { } catch (error) {
// message.error(response.msg);
const defaultLoginFailureMessage = intl.formatMessage({ const defaultLoginFailureMessage = intl.formatMessage({
id: 'pages.login.failure', id: 'pages.login.failure',
defaultMessage: '登录失败,请重试!', defaultMessage: '登录失败,请重试!',
}); });
console.log(error); // console.log(error);
message.error(defaultLoginFailureMessage); message.error(defaultLoginFailureMessage);
} }
}; };
@@ -190,19 +190,19 @@ const Login: React.FC = () => {
maxWidth: '75vw', maxWidth: '75vw',
}} }}
logo={<img alt="logo" src="/logo.svg" />} logo={<img alt="logo" src="/logo.svg" />}
title="Ant Design" title="青岛智慧就业服务系统"
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })} // subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })}
initialValues={{ initialValues={{
autoLogin: true, autoLogin: true,
}} }}
actions={[ // actions={[
<FormattedMessage // <FormattedMessage
key="loginWith" // key="loginWith"
id="pages.login.loginWith" // id="pages.login.loginWith"
defaultMessage="其他登录方式" // defaultMessage="其他登录方式"
/>, // />,
<ActionIcons key="icons" />, // <ActionIcons key="icons" />,
]} // ]}
onFinish={async (values) => { onFinish={async (values) => {
await handleSubmit(values as API.LoginParams); await handleSubmit(values as API.LoginParams);
}} }}
@@ -229,14 +229,14 @@ const Login: React.FC = () => {
]} ]}
/> />
{code !== 200 && loginType === 'account' && ( {/*{code !== 200 && loginType === 'account' && (*/}
<LoginMessage {/* <LoginMessage*/}
content={intl.formatMessage({ {/* content={intl.formatMessage({*/}
id: 'pages.login.accountLogin.errorMessage', {/* id: 'pages.login.accountLogin.errorMessage',*/}
defaultMessage: '账户或密码错误(admin/admin123)', {/* defaultMessage: '账户或密码错误(admin/admin123)',*/}
})} {/* })}*/}
/> {/* />*/}
)} {/*)}*/}
{type === 'account' && ( {type === 'account' && (
<> <>
<ProFormText <ProFormText

View File

@@ -29,6 +29,7 @@ export const errorConfig: RequestConfig = {
errorConfig: { errorConfig: {
// 错误抛出 // 错误抛出
errorThrower: (res) => { errorThrower: (res) => {
console.log('errorThrower')
const { success, data, errorCode, errorMessage, showType } = const { success, data, errorCode, errorMessage, showType } =
res as unknown as ResponseStructure; res as unknown as ResponseStructure;
if (!success) { if (!success) {
@@ -99,7 +100,6 @@ export const errorConfig: RequestConfig = {
(response) => { (response) => {
// 拦截响应数据,进行个性化处理 // 拦截响应数据,进行个性化处理
const { data } = response as unknown as ResponseStructure; const { data } = response as unknown as ResponseStructure;
console.log(data)
if (data?.success === false) { if (data?.success === false) {
message.error('请求失败!'); message.error('请求失败!');
} }