From 044c5c3b8a42a5d7e40f45dc75027e13470d69f4 Mon Sep 17 00:00:00 2001 From: Jimmy Liow <18777396951@163.com> Date: Mon, 8 May 2023 16:41:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=99=BB=E9=99=86=E6=88=90=E5=8A=9F=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E5=88=B0=E5=9B=A2=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/stores/Auth.js | 8 ++------ src/views/Login.jsx | 33 +++++++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/stores/Auth.js b/src/stores/Auth.js index 1ad725a..d8cac0a 100644 --- a/src/stores/Auth.js +++ b/src/stores/Auth.js @@ -19,12 +19,7 @@ class Auth { return fetchJSON(fetchUrl) .then(json => { if (json.errcode == 0) { - runInAction(() => { - this.login = { - userId: json.Result.WU_LMI_SN, - username: json.Result.WU_UserName, - } - }); + return json.Result.WU_LMI_SN; } else { throw new Error(json.errmsg + ': ' + json.errcode); } @@ -48,6 +43,7 @@ class Auth { cityId: json.Result.citysn } }); + return json.Result.LoginName; } else { throw new Error(json.errmsg + ': ' + json.errcode); } diff --git a/src/views/Login.jsx b/src/views/Login.jsx index 794b571..f28c6e2 100644 --- a/src/views/Login.jsx +++ b/src/views/Login.jsx @@ -1,20 +1,44 @@ +import { useNavigate } from "react-router-dom"; import { Button, Checkbox, Form, Input, Row, App } from 'antd'; import { useStore } from '@/stores/StoreContext.js'; function Login() { const { authStore } = useStore(); + const navigate = useNavigate(); const { notification } = App.useApp(); const onFinish = (values) => { - console.log('Success:', values); - authStore.valdateUserPassword(values.username, values.password); + authStore.valdateUserPassword(values.username, values.password) + .then((userId) => { + authStore.fetchUserDetail(userId) + .then((user) => { + // navigate(-1) is equivalent to hitting the back button. + navigate("/reservation/newest"); + }) + .catch(ex => { + notification.error({ + message: `Notification`, + description: ex.message, + placement: 'top', + duration: 4, + }); + }); + }) + .catch(ex => { + notification.error({ + message: `Notification`, + description: ex.message, + placement: 'top', + duration: 4, + }); + }); }; const onFinishFailed = (errorInfo) => { console.log('Failed:', errorInfo); }; - + return (
- - Remember me -