diff --git a/config/config.ts b/config/config.ts index f0004a8..eeed263 100644 --- a/config/config.ts +++ b/config/config.ts @@ -76,9 +76,9 @@ export default defineConfig({ * @name layout 插件 * @doc https://umijs.org/docs/max/layout-menu */ - title: 'Ant Design Pro', + title: '青岛智慧就业服务系统', layout: { - locale: true, + locale: false, ...defaultSettings, }, /** @@ -97,9 +97,9 @@ export default defineConfig({ locale: { // default zh-CN default: 'zh-CN', - antd: true, + antd: false, // default true, when it is true, will use `navigator.language` overwrite default - baseNavigator: true, + baseNavigator: false, }, /** * @name antd 插件 diff --git a/config/defaultSettings.ts b/config/defaultSettings.ts index 2796a7e..f4c8439 100644 --- a/config/defaultSettings.ts +++ b/config/defaultSettings.ts @@ -15,7 +15,7 @@ const Settings: ProLayoutProps & { fixedHeader: false, fixSiderbar: true, colorWeak: false, - title: 'Ant Design Pro', + title: '青岛智慧就业服务系统', pwa: true, logo: 'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg', iconfontUrl: '', diff --git a/src/access.ts b/src/access.ts index 8c11f31..e1f2065 100644 --- a/src/access.ts +++ b/src/access.ts @@ -21,7 +21,7 @@ export function setSessionToken( access_token: string | undefined, refresh_token: string | undefined, expireTime: number, -): void { +): void{ if (access_token) { localStorage.setItem('access_token', access_token); } else { diff --git a/src/app.tsx b/src/app.tsx index 38f76b4..9397980 100644 --- a/src/app.tsx +++ b/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: () => [, ], + // actionsRender: () => [, ], + actionsRender: () => [ ], avatarProps: { src: initialState?.currentUser?.avatar, title: , @@ -115,14 +135,14 @@ export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) = width: '331px', }, ], - links: isDev - ? [ - - - OpenAPI 文档 - , - ] - : [], + // links: isDev + // ? [ + // + // + // OpenAPI 文档 + // , + // ] + // : [], menuHeaderRender: undefined, // 自定义 403 页面 // unAccessible:
unAccessible
, @@ -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 + }, ], }; diff --git a/src/components/Footer/index.tsx b/src/components/Footer/index.tsx index f204ac2..76b5016 100644 --- a/src/components/Footer/index.tsx +++ b/src/components/Footer/index.tsx @@ -10,22 +10,9 @@ const Footer: React.FC = () => { }} links={[ { - key: 'Ant Design Pro', - title: 'Ant Design Pro', - href: 'https://pro.ant.design', - blankTarget: true, - }, - { - key: 'github', - title: , - href: 'https://github.com/ant-design/ant-design-pro', - blankTarget: true, - }, - { - key: 'Ant Design', - title: 'Ant Design', - href: 'https://ant.design', - blankTarget: true, + key: '青岛智慧就业服务系统', + title: '青岛智慧就业服务系统', + href: 'http://localhost:8000/', }, ]} /> diff --git a/src/pages/User/Login/index.tsx b/src/pages/User/Login/index.tsx index a18f785..2371726 100644 --- a/src/pages/User/Login/index.tsx +++ b/src/pages/User/Login/index.tsx @@ -135,7 +135,6 @@ const Login: React.FC = () => { }); const current = new Date(); const expireTime = current.setTime(current.getTime() + 1000 * 12 * 60 * 60); - console.log('login response: ', response); setSessionToken(response?.token, response?.token, expireTime); message.success(defaultLoginSuccessMessage); await fetchUserInfo(); @@ -144,18 +143,19 @@ const Login: React.FC = () => { history.push(urlParams.get('redirect') || '/'); return; } else { - console.log(response.msg); + message.error(response.msg); clearSessionToken(); // 如果失败去设置用户错误信息 setUserLoginState({ ...response, type }); getCaptchaCode(); } } catch (error) { + // message.error(response.msg); const defaultLoginFailureMessage = intl.formatMessage({ id: 'pages.login.failure', defaultMessage: '登录失败,请重试!', }); - console.log(error); + // console.log(error); message.error(defaultLoginFailureMessage); } }; @@ -190,19 +190,19 @@ const Login: React.FC = () => { maxWidth: '75vw', }} logo={logo} - title="Ant Design" - subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })} + title="青岛智慧就业服务系统" + // subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })} initialValues={{ autoLogin: true, }} - actions={[ - , - , - ]} + // actions={[ + // , + // , + // ]} onFinish={async (values) => { await handleSubmit(values as API.LoginParams); }} @@ -229,14 +229,14 @@ const Login: React.FC = () => { ]} /> - {code !== 200 && loginType === 'account' && ( - - )} + {/*{code !== 200 && loginType === 'account' && (*/} + {/* */} + {/*)}*/} {type === 'account' && ( <> { + console.log('errorThrower') const { success, data, errorCode, errorMessage, showType } = res as unknown as ResponseStructure; if (!success) { @@ -99,7 +100,6 @@ export const errorConfig: RequestConfig = { (response) => { // 拦截响应数据,进行个性化处理 const { data } = response as unknown as ResponseStructure; - console.log(data) if (data?.success === false) { message.error('请求失败!'); }