From be8c270a8b0e77e7224fe297593226118ae39c7f Mon Sep 17 00:00:00 2001
From: powersir <1576775122@qq.com>
Date: Tue, 12 Sep 2023 10:54:36 +0800
Subject: [PATCH] add login function
---
src/layout/header/index.tsx | 13 ++++---------
src/models/index.ts | 13 +++++++++++++
src/pages/login/index.tsx | 32 ++++++++++++++++++++++----------
src/request/service/home.ts | 8 ++++++++
src/request/service/login.ts | 2 +-
src/store/global/index.ts | 10 ----------
src/store/global/user.ts | 2 +-
7 files changed, 49 insertions(+), 31 deletions(-)
create mode 100644 src/request/service/home.ts
diff --git a/src/layout/header/index.tsx b/src/layout/header/index.tsx
index 0f6f498..2a4576b 100644
--- a/src/layout/header/index.tsx
+++ b/src/layout/header/index.tsx
@@ -32,11 +32,6 @@ const Header = () => {
const logout = async () => {
const [error] = await runAsync();
if (error) return;
-
- useGlobalStore.setState({
- token: '',
- refreshToken: ''
- });
}
return (
@@ -140,13 +135,13 @@ const Header = () => {
>
- {currentUser?.nickName}
+ {currentUser?.userName}
{currentUser?.phoneNumber}
- {currentUser?.email}
+ {currentUser?.emailAddress}
@@ -158,8 +153,8 @@ const Header = () => {
}}
>
- {currentUser?.avatarPath ? (
-
+ {currentUser?.avatarUrl ? (
+
) : (
} />
)}
diff --git a/src/models/index.ts b/src/models/index.ts
index a864daa..b421474 100644
--- a/src/models/index.ts
+++ b/src/models/index.ts
@@ -4,3 +4,16 @@ export interface PageData
{
data: T[];
total: number;
}
+
+
+export interface Announcement {
+ id: number,
+ name: string,
+ detail: string,
+ expiryTime: string,
+ roleId: number,
+ flag: number,
+ createTime: string,
+ createOperId: number,
+ top: number
+}
diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx
index fd2c6d2..60c1930 100644
--- a/src/pages/login/index.tsx
+++ b/src/pages/login/index.tsx
@@ -1,14 +1,26 @@
import { t } from '@/utils/i18n';
-import { IconBuguang } from '@/assets/icons/buguang'
+import { IconBuguang } from '@/assets/icons/buguang';
import { LockOutlined, UserOutlined } from '@ant-design/icons';
import { Button, Form, Input, Carousel } from 'antd';
import { useNavigate } from 'react-router-dom';
+import { useRequest } from '@/hooks/use-request';
+import { useUserStore } from '@/store/global/user';
+import loginService from '@/request/service/login';
+import { LoginDTO } from '@/models';
import './index.css'
const Login = () => {
const navigate = useNavigate();
- const onFinish = async () => {
+ const { runAsync: login, loading } = useRequest(loginService.login, { manual: true });
+ const { setCurrentUser } = useUserStore();
+ const onFinish = async (values: LoginDTO) => {
+ const [loginError, data] = await login(values);
+ if (loginError) {
+ return;
+ }
+ data.data.avatarUrl = 'https://test.vogocm.com:9010/eshop/eshop_img/2023/5/24/43853633d16749bfb291f81bebb73451_20230524150631A001.jpg'
+ setCurrentUser(data.data);
navigate('/');
};
@@ -22,7 +34,7 @@ const Login = () => {
旺嘉-ERP Admin
- {t("wbTMzvDM" /* 一个高颜值后台管理系统 */)}
+ {t("wbTMzvDM" /* 旺嘉-ERP后台管理系统 */)}