From 485a0de84a6f61559f5f33f9311d226281ac9217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=B3=E7=95=94=E4=B8=80=E8=A7=92?= Date: Wed, 20 Nov 2024 20:31:50 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/src/components/Header/Header.tsx | 23 +++++------ .../admin/src/pages/console/HomeHeader.tsx | 23 +++++------ packages/admin/src/pages/login/Login.tsx | 38 +++++++++++-------- packages/admin/src/utils/request.ts | 4 -- .../home/project/components/ProjectCard.tsx | 8 ++-- packages/editor/src/pages/login/Login.tsx | 4 +- 6 files changed, 48 insertions(+), 52 deletions(-) diff --git a/packages/admin/src/components/Header/Header.tsx b/packages/admin/src/components/Header/Header.tsx index fdea11e3..9ec46932 100644 --- a/packages/admin/src/components/Header/Header.tsx +++ b/packages/admin/src/components/Header/Header.tsx @@ -66,23 +66,20 @@ const Header = memo(() => { menu={{ items: [ { - key: '1', - label: `${userName}`, + key: 'profile', + label: userName, }, { - key: '2', - label: ( -
{ - localStorage.clear(); - navigate(`/login?callback=${window.location.href}`); - }} - > - 退出 -
- ), + key: 'logout', + label: '退出', }, ], + onClick: ({ key }) => { + if (key === 'logout') { + localStorage.clear(); + navigate(`/login?callback=${window.location.href}`); + } + }, selectable: true, }} > diff --git a/packages/admin/src/pages/console/HomeHeader.tsx b/packages/admin/src/pages/console/HomeHeader.tsx index 695d3608..83a9a0c2 100644 --- a/packages/admin/src/pages/console/HomeHeader.tsx +++ b/packages/admin/src/pages/console/HomeHeader.tsx @@ -15,23 +15,20 @@ function HomeHeader() { menu={{ items: [ { - key: '1', - label: `${userInfo?.userName}`, + key: 'profile', + label: userInfo.userName, }, { - key: '2', - label: ( -
{ - localStorage.clear(); - navigate(`/login?callback=${window.location.href}`); - }} - > - 退出 -
- ), + key: 'logout', + label: '退出', }, ], + onClick: ({ key }) => { + if (key === 'logout') { + localStorage.clear(); + navigate(`/login?callback=${window.location.href}`); + } + }, selectable: true, }} > diff --git a/packages/admin/src/pages/login/Login.tsx b/packages/admin/src/pages/login/Login.tsx index 9d723fc5..03cfa112 100644 --- a/packages/admin/src/pages/login/Login.tsx +++ b/packages/admin/src/pages/login/Login.tsx @@ -6,28 +6,36 @@ import storage from '@/utils/storage'; import { usePageStore } from '@marsview/materials/stores/pageStore'; import { LockOutlined, UserOutlined } from '@ant-design/icons'; import style from './index.module.less'; +import { useState } from 'react'; type FieldType = { userName: string; userPwd: string; }; export default function Login() { const navigate = useNavigate(); + const [loading, setLoading] = useState(false); const saveUserInfo = usePageStore((state) => state.saveUserInfo); const [form] = Form.useForm(); const onFinish: FormProps['onFinish'] = async (values: FieldType) => { - const res = await login(values); - if (res.token) { - storage.set('token', res.token); - saveUserInfo(res); - if (location.search) { - const params = new URLSearchParams(location.search); - setTimeout(() => { - const url = new URL(params.get('callback') as string); - navigate(url.pathname || '/welcome'); - }); - } else { - navigate('/'); + setLoading(true); + try { + const res = await login(values); + if (res.token) { + storage.set('token', res.token); + saveUserInfo(res); + setLoading(false); + if (location.search) { + const params = new URLSearchParams(location.search); + setTimeout(() => { + const url = new URL(params.get('callback') as string); + navigate(url.pathname || '/welcome'); + }); + } else { + navigate('/'); + } } + } catch (error) { + setLoading(false); } }; return ( @@ -37,9 +45,7 @@ export default function Login() {
-
- -
+
用户登录
name="userName" rules={[{ required: true, message: '请输入邮箱' }]}> } allowClear placeholder="输入个人邮箱" /> @@ -50,7 +56,7 @@ export default function Login() { - diff --git a/packages/admin/src/utils/request.ts b/packages/admin/src/utils/request.ts index 7b829493..901380c9 100644 --- a/packages/admin/src/utils/request.ts +++ b/packages/admin/src/utils/request.ts @@ -1,6 +1,5 @@ import axios, { AxiosError } from 'axios'; import { message } from './AntdGlobal'; -import { showLoading, hideLoading } from './loading'; import router from '@/router'; import storage from './storage'; @@ -25,7 +24,6 @@ const instance = axios.create({ // 请求拦截 instance.interceptors.request.use( (config) => { - showLoading(); config.baseURL = import.meta.env.VITE_BASE_API; const token = storage.get('token'); if (token) { @@ -43,7 +41,6 @@ instance.interceptors.request.use( // 响应拦截 instance.interceptors.response.use( async (response) => { - hideLoading(); const res: IResult = await response.data; if (!res) { message.error(ErrorMsg); @@ -66,7 +63,6 @@ instance.interceptors.response.use( return res; }, (error) => { - hideLoading(); if (error.response && error.response.status === 403) { router.navigate('/403'); } else { diff --git a/packages/editor/src/pages/home/project/components/ProjectCard.tsx b/packages/editor/src/pages/home/project/components/ProjectCard.tsx index 536c7e80..0197a706 100644 --- a/packages/editor/src/pages/home/project/components/ProjectCard.tsx +++ b/packages/editor/src/pages/home/project/components/ProjectCard.tsx @@ -16,8 +16,8 @@ export default function Category({ list }: { list: Project.ProjectItem[] }) { const navigate = useNavigate(); // 单击打开项目配置 - const handleClick = () => { - navigate(`/project/${item.id}/config`); + const handleClick = (id: number) => { + navigate(`/project/${id}/config`); }; // 双击加载项目下子页面 @@ -54,7 +54,7 @@ export default function Category({ list }: { list: Project.ProjectItem[] }) { // 环境跳转 const onClick = ({ key }: { key: string }) => { - if (key === 'config') return handleClick(); + if (key === 'config') return handleClick(item.id); return window.open(`${import.meta.env.VITE_ADMIN_URL}/project/${item.id}?env=${key}`, '_blank'); }; @@ -65,7 +65,7 @@ export default function Category({ list }: { list: Project.ProjectItem[] }) { return (
handleDoubleClick(project.id)}> {/* 卡片头部 */} -
+
handleClick(project.id)}>

{project.name} diff --git a/packages/editor/src/pages/login/Login.tsx b/packages/editor/src/pages/login/Login.tsx index 16b5c3a7..cda2e772 100644 --- a/packages/editor/src/pages/login/Login.tsx +++ b/packages/editor/src/pages/login/Login.tsx @@ -105,7 +105,7 @@ export default function Login() { 登录

) : ( -
邮箱注册
+
{type === 'regist' ? '邮箱注册' : '密码找回'}
)} @@ -131,7 +131,7 @@ export default function Login() { )} - {type === 'login' && ( + {type !== 'reset' && ( style={{ marginTop: 32 }} name="userPwd" rules={[{ required: true, message: '请输入密码' }]}> } autoComplete="off" allowClear placeholder="请输入密码" />