From 51b0418fa925bcfeb5d7806f6b32cf8ae9d6b18a Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 23 Mar 2021 14:32:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=80=80=E5=87=BA=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/auth.ts | 2 +- back/loaders/express.ts | 2 +- src/layouts/index.tsx | 15 +++++++++++++++ src/pages/login/index.tsx | 2 +- src/pages/setting/index.tsx | 6 +++--- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/back/api/auth.ts b/back/api/auth.ts index d31f2679..62cebabd 100644 --- a/back/api/auth.ts +++ b/back/api/auth.ts @@ -10,7 +10,7 @@ const route = Router(); export default (app: Router) => { app.use('/', route); route.post( - '/auth', + '/login', async (req: Request, res: Response, next: NextFunction) => { const logger: Logger = Container.get('logger'); try { diff --git a/back/loaders/express.ts b/back/loaders/express.ts index c521371c..204b6ce0 100644 --- a/back/loaders/express.ts +++ b/back/loaders/express.ts @@ -13,7 +13,7 @@ export default ({ app }: { app: Application }) => { app.use(bodyParser.urlencoded({ extended: true })); app.use( jwt({ secret: config.secret as string, algorithms: ['HS384'] }).unless({ - path: ['/api/auth'], + path: ['/api/login'], }), ); app.use(config.api.prefix, routes()); diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index c3512de2..51608df2 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -8,11 +8,16 @@ import { } from 'darkreader'; import defaultProps from './defaultProps'; import { Link, history } from 'umi'; +import { LogoutOutlined } from '@ant-design/icons'; import config from '@/utils/config'; import 'codemirror/mode/shell/shell.js'; import './index.less'; export default function (props: any) { + const logout = () => { + localStorage.removeItem(config.authKey); + }; + useEffect(() => { const isAuth = localStorage.getItem(config.authKey); if (!isAuth) { @@ -55,6 +60,16 @@ export default function (props: any) { } return {defaultDom}; }} + postMenuData={(menuData) => { + return [ + ...(menuData || []), + { + icon: , + name: '退出登录', + onTitleClick: () => logout(), + }, + ]; + }} {...defaultProps} > {props.children} diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 442fb993..1df59ccb 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -11,7 +11,7 @@ const FormItem = Form.Item; const Login = () => { const handleOk = (values: any) => { request - .post(`${config.apiPrefix}auth`, { + .post(`${config.apiPrefix}login`, { data: { username: values.username, password: values.password, diff --git a/src/pages/setting/index.tsx b/src/pages/setting/index.tsx index a22148e2..0cf32464 100644 --- a/src/pages/setting/index.tsx +++ b/src/pages/setting/index.tsx @@ -9,6 +9,7 @@ import { auto as followSystemColorScheme, setFetchMethod, } from 'darkreader'; +import { history } from 'umi'; const optionsWithDisabled = [ { label: '亮色', value: 'light' }, @@ -34,9 +35,8 @@ const Password = () => { }, }) .then((data: any) => { - notification.success({ - message: data.msg, - }); + localStorage.removeItem(config.authKey); + history.push('/login'); }) .catch((error: any) => { console.log(error);