Skip to content

Commit

Permalink
fix: 修复问题
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft authored and jianbing.chen committed Dec 18, 2024
1 parent bf5a180 commit 485a0de
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 52 deletions.
23 changes: 10 additions & 13 deletions packages/admin/src/components/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,23 +66,20 @@ const Header = memo(() => {
menu={{
items: [
{
key: '1',
label: `${userName}`,
key: 'profile',
label: userName,
},
{
key: '2',
label: (
<div
onClick={(e) => {
localStorage.clear();
navigate(`/login?callback=${window.location.href}`);
}}
>
退出
</div>
),
key: 'logout',
label: '退出',
},
],
onClick: ({ key }) => {
if (key === 'logout') {
localStorage.clear();
navigate(`/login?callback=${window.location.href}`);
}
},
selectable: true,
}}
>
Expand Down
23 changes: 10 additions & 13 deletions packages/admin/src/pages/console/HomeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,20 @@ function HomeHeader() {
menu={{
items: [
{
key: '1',
label: `${userInfo?.userName}`,
key: 'profile',
label: userInfo.userName,
},
{
key: '2',
label: (
<div
onClick={(e) => {
localStorage.clear();
navigate(`/login?callback=${window.location.href}`);
}}
>
退出
</div>
),
key: 'logout',
label: '退出',
},
],
onClick: ({ key }) => {
if (key === 'logout') {
localStorage.clear();
navigate(`/login?callback=${window.location.href}`);
}
},
selectable: true,
}}
>
Expand Down
38 changes: 22 additions & 16 deletions packages/admin/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FieldType>['onFinish'] = async (values: FieldType) => {
const res = await login<FieldType>(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<FieldType>(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 (
Expand All @@ -37,9 +45,7 @@ export default function Login() {
<img src="/imgs/login-bg.png" />
</div>
<div className={style.form}>
<div className={style.title}>
<img src={`${import.meta.env.VITE_CDN_URL}/mars-logo.png`} width={45} />
</div>
<div className={style.title}>用户登录</div>
<Form name="basic" layout="vertical" className={style.form} onFinish={onFinish} autoComplete="off" size="large" form={form}>
<Form.Item<FieldType> name="userName" rules={[{ required: true, message: '请输入邮箱' }]}>
<Input prefix={<UserOutlined />} allowClear placeholder="输入个人邮箱" />
Expand All @@ -50,7 +56,7 @@ export default function Login() {
</Form.Item>

<Form.Item style={{ marginTop: 40 }}>
<Button type="primary" block htmlType="submit">
<Button type="primary" block htmlType="submit" loading={loading}>
登录
</Button>
</Form.Item>
Expand Down
4 changes: 0 additions & 4 deletions packages/admin/src/utils/request.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -66,7 +63,6 @@ instance.interceptors.response.use(
return res;
},
(error) => {
hideLoading();
if (error.response && error.response.status === 403) {
router.navigate('/403');
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
};

// 双击加载项目下子页面
Expand Down Expand Up @@ -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');
};

Expand All @@ -65,7 +65,7 @@ export default function Category({ list }: { list: Project.ProjectItem[] }) {
return (
<div className={styles.projectCard} key={project.id} onDoubleClick={() => handleDoubleClick(project.id)}>
{/* 卡片头部 */}
<div className={styles.cardHeader} onClick={handleClick}>
<div className={styles.cardHeader} onClick={() => handleClick(project.id)}>
<h3 className={styles.cardTitle}>
<GlobalOutlined className={styles.cardIcon} />
{project.name}
Expand Down
4 changes: 2 additions & 2 deletions packages/editor/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default function Login() {
<span>登录</span>
</div>
) : (
<div className={style.title}>邮箱注册</div>
<div className={style.title}>{type === 'regist' ? '邮箱注册' : '密码找回'}</div>
)}
<Form name="basic" layout="vertical" className={style.form} onFinish={onFinish} size="large" form={form}>
<Form.Item<FieldType>
Expand All @@ -131,7 +131,7 @@ export default function Login() {
</Form.Item>
)}

{type === 'login' && (
{type !== 'reset' && (
<Form.Item<FieldType> style={{ marginTop: 32 }} name="userPwd" rules={[{ required: true, message: '请输入密码' }]}>
<Input.Password prefix={<LockOutlined />} autoComplete="off" allowClear placeholder="请输入密码" />
</Form.Item>
Expand Down

0 comments on commit 485a0de

Please sign in to comment.