From 12aef3fcea068ad59635ca124e2819993c4807b8 Mon Sep 17 00:00:00 2001
From: 1708-huayu <57060237+1708-huayu@users.noreply.github.com>
Date: Fri, 13 Dec 2024 18:50:46 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=AE=8C=E6=88=90=E5=90=8E=E6=B8=B2=E6=9F=93?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/app/layout.tsx | 34 ++--
src/app/loading.tsx | 3 +
src/app/login/loading.tsx | 3 +
src/app/login/page.tsx | 371 ++------------------------------------
src/ui/login/Page.tsx | 364 +++++++++++++++++++++++++++++++++++++
5 files changed, 398 insertions(+), 377 deletions(-)
create mode 100644 src/app/loading.tsx
create mode 100644 src/app/login/loading.tsx
create mode 100644 src/ui/login/Page.tsx
diff --git a/src/app/layout.tsx b/src/app/layout.tsx
index 57403f7..13c5e74 100644
--- a/src/app/layout.tsx
+++ b/src/app/layout.tsx
@@ -1,10 +1,10 @@
-import type { Metadata } from "next";
+import type {Metadata} from "next";
import "@/ui/globals.css";
import Script from "next/script";
export const metadata: Metadata = {
- title: "任务管理",
- description: "任务管理小助手",
+ title: "任务管理",
+ description: "任务管理小助手",
};
/**
* Root Layout (Required)
@@ -12,19 +12,19 @@ export const metadata: Metadata = {
* @constructor
*/
export default function RootLayout({
- children,
-}: Readonly<{
- children: React.ReactNode;
+ children,
+ }: Readonly<{
+ children: React.ReactNode;
}>) {
- return (
-
-
-
-
- 任务管理
-
-
- {children}
-
- );
+ return (
+
+
+
+
+ 任务管理
+
+
+ {children}
+
+ );
}
diff --git a/src/app/loading.tsx b/src/app/loading.tsx
new file mode 100644
index 0000000..438d658
--- /dev/null
+++ b/src/app/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return /Loading...
;
+}
\ No newline at end of file
diff --git a/src/app/login/loading.tsx b/src/app/login/loading.tsx
new file mode 100644
index 0000000..eeef040
--- /dev/null
+++ b/src/app/login/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return /login/Loading...
;
+}
\ No newline at end of file
diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx
index 0ccdb2e..4818bd2 100644
--- a/src/app/login/page.tsx
+++ b/src/app/login/page.tsx
@@ -1,365 +1,16 @@
'use client'
-import {
- AlipayOutlined,
- LockOutlined, MailOutlined,
- MobileOutlined,
- TaobaoOutlined,
- UserOutlined,
- WeiboOutlined,
-} from '@ant-design/icons';
-import {
- LoginForm,
- LoginFormPage,
- ProConfigProvider,
- ProFormCaptcha,
- ProFormCheckbox,
- ProFormText,
-} from '@ant-design/pro-components';
-import {Divider, Space, Tabs, message, theme, Modal, Button} from 'antd';
-import {CSSProperties, useCallback} from 'react';
-import {useState} from 'react';
-import {CaptchaLoginSuccess, LoginObject} from "@/lib/login/definitions";
-import {httpReq} from "@/utils/axiosReq";
-import {useRouter} from 'next/navigation'
-
-type LoginType = 'email' | 'account';
-
-const iconStyles: CSSProperties = {
- color: 'rgba(0, 0, 0, 0.2)',
- fontSize: '18px',
- verticalAlign: 'middle',
- cursor: 'pointer',
-};
-
-
-const Page = () => {
- const [loginType, setLoginType] = useState('account');
- const {token} = theme.useToken();
- const router = useRouter()
- const [messageApi, contextHolder] = message.useMessage();
- const [loading, setLoading] = useState(false);
- const [open, setOpen] = useState(false);
- const [captchaLoginSuccessList, setCaptchaLoginSuccessList] = useState([]);
- const captchaUserNameConfirm = (captchaLoginSuccess:CaptchaLoginSuccess)=>{
- messageApi.open({
- type: 'info',
- content: "使用帐号"+captchaLoginSuccess.username+"登录成功"
- })
- localStorage.setItem('platform-security', captchaLoginSuccess.token)
- router.push('/task/project')
- setOpen(false)
- setLoading(false)
- }
- return (
-
- {contextHolder}
-
(
- captchaUserNameConfirm(label)}>
- {label.username}
-
- ))
- }
- >
-
-
{
- console.log("登录信息:" + formData.username + ";" + formData.password)
- if (loginType === "account") {
- httpReq.post(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/stateless/login/username", {
- username: formData.username,
- password: formData.password
- }).then(response => {
- console.log(response);
- if (response.data.status.code === 200) {
- // localStorage.removeItem("platform-security")
- localStorage.setItem('platform-security', response.data.data)
- // 删除名为 'platform-security' 的Cookie
- // Cookies.remove('platform-security');
- // 设置一个有效期为7天的Cookie
- // Cookies.set('platform-security', response.data.data, { expires: 7 });
- // 登录成功,跳转到首页或者回调
- router.push('/task/project')
- } else {
- messageApi.open({
- type: 'error',
- content: response.data.status.message,
- })
- }
- ;
- })
- } else if (loginType === "email") {
- httpReq.post(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/stateless/login/email", {
- email: formData.email,
- captcha: formData.captcha
- }).then(response => {
- console.log(response);
- if (response.data.status.code === 200) {
- // localStorage.removeItem("platform-security")
- if (response.data.data.length > 1) {
- setCaptchaLoginSuccessList(response.data.data)
- setOpen(true)
- } else {
- localStorage.setItem('platform-security', response.data.data)
- // 删除名为 'platform-security' 的Cookie
- // Cookies.remove('platform-security');
- // 设置一个有效期为7天的Cookie
- // Cookies.set('platform-security', response.data.data, { expires: 7 });
- // 登录成功,跳转到首页或者回调
- router.push('/task/project')
- }
- } else {
- messageApi.open({
- type: 'error',
- content: response.data.status.message,
- })
- }
- ;
- })
- }
-
- }}
- // actions={
- //
- //
- //
- // 其他登录方式
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- //
- // }
- >
- setLoginType(activeKey as LoginType)}
- >
-
-
-
- {loginType === 'account' && (
- <>
-
- ),
- }}
- placeholder={'用户名: test'}
- rules={[
- {
- required: true,
- message: '请输入用户名!',
- },
- ]}
- />
-
- ),
- }}
- placeholder={'密码: 123456'}
- rules={[
- {
- required: true,
- message: '请输入密码!',
- },
- ]}
- />
- >
- )}
- {loginType === 'email' && (
- <>
-
- ),
- }}
- name="email"
- placeholder={'邮箱帐号'}
- rules={[
- {
- required: true,
- message: '请输入邮箱帐号!',
- },
- {
- pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
- message: '邮箱格式错误!',
- },
- ]}
- />
-
- ),
- }}
- captchaProps={{
- size: 'large',
- }}
- placeholder={'请输入验证码'}
- captchaTextRender={(timing, count) => {
- if (timing) {
- return `${count} ${'获取验证码'}`;
- }
- return '获取验证码';
- }}
- phoneName="email"
- name="captcha"
- rules={[
- {
- required: true,
- message: '请输入验证码!',
- },
- ]}
- onGetCaptcha={async (email) => {
- // 请求后端服务器发送密码
- httpReq.get(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/common/email/captcha/" + email)
- .then(response => {
- if (response.data.status.code === 200) {
- message.success(`${email},获取验证码成功,请及时查看!`);
- } else {
- messageApi.open({
- type: 'error',
- content: response.data.status.message,
- })
- }
- })
- }}
- />
- >
- )}
-
-
-
- );
-};
-
+import {ProConfigProvider} from "@ant-design/pro-components";
+import React, {lazy, Suspense} from "react";
+// import Page from "@/ui/login/Page";
+import Loading from "@/app/loading";
+const Page = lazy(() => import('@/ui/login/Page'));
export default function Login() {
+
return (
-
-
-
+ }>
+
+
+
+
);
};
\ No newline at end of file
diff --git a/src/ui/login/Page.tsx b/src/ui/login/Page.tsx
new file mode 100644
index 0000000..45c67d6
--- /dev/null
+++ b/src/ui/login/Page.tsx
@@ -0,0 +1,364 @@
+'use client'
+import {
+ AlipayOutlined,
+ LockOutlined, MailOutlined,
+ MobileOutlined,
+ TaobaoOutlined,
+ UserOutlined,
+ WeiboOutlined,
+} from '@ant-design/icons';
+import {
+ LoginForm,
+ LoginFormPage,
+ ProConfigProvider,
+ ProFormCaptcha,
+ ProFormCheckbox,
+ ProFormText,
+} from '@ant-design/pro-components';
+
+import {Divider, Space, Tabs, message, theme, Modal, Button} from 'antd';
+import React, {CSSProperties, Suspense, useCallback, useEffect, useLayoutEffect} from 'react';
+import {useState} from 'react';
+import {CaptchaLoginSuccess, LoginObject} from "@/lib/login/definitions";
+import {httpReq} from "@/utils/axiosReq";
+import {useRouter} from 'next/navigation'
+import {use} from 'react';
+import Loading from "@/app/loading";
+
+type LoginType = 'email' | 'account';
+
+const iconStyles: CSSProperties = {
+ color: 'rgba(0, 0, 0, 0.2)',
+ fontSize: '18px',
+ verticalAlign: 'middle',
+ cursor: 'pointer',
+};
+
+export default function Page() {
+ const [loaded, setLoaded] = useState(false);
+ useLayoutEffect(() => {
+ console.log('页面所有资源加载完毕');
+ setLoaded(true);
+ })
+ const [loginType, setLoginType] = useState('account');
+ const {token} = theme.useToken();
+ const router = useRouter()
+ const [messageApi, contextHolder] = message.useMessage();
+ const [loading, setLoading] = useState(false);
+ const [open, setOpen] = useState(false);
+ const [captchaLoginSuccessList, setCaptchaLoginSuccessList] = useState([]);
+ const captchaUserNameConfirm = (captchaLoginSuccess: CaptchaLoginSuccess) => {
+ messageApi.open({
+ type: 'info',
+ content: "使用帐号" + captchaLoginSuccess.username + "登录成功"
+ })
+ localStorage.setItem('platform-security', captchaLoginSuccess.token)
+ router.push('/task/project')
+ setOpen(false)
+ setLoading(false)
+ }
+ return (
+
+ {contextHolder}
+
(
+ captchaUserNameConfirm(label)}>
+ {label.username}
+
+ ))
+ }
+ >
+
+ {loaded?
{
+ console.log("登录信息:" + formData.username + ";" + formData.password)
+ if (loginType === "account") {
+ httpReq.post(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/stateless/login/username", {
+ username: formData.username,
+ password: formData.password
+ }).then(response => {
+ console.log(response);
+ if (response.data.status.code === 200) {
+ // localStorage.removeItem("platform-security")
+ localStorage.setItem('platform-security', response.data.data)
+ // 删除名为 'platform-security' 的Cookie
+ // Cookies.remove('platform-security');
+ // 设置一个有效期为7天的Cookie
+ // Cookies.set('platform-security', response.data.data, { expires: 7 });
+ // 登录成功,跳转到首页或者回调
+ router.push('/task/project')
+ } else {
+ messageApi.open({
+ type: 'error',
+ content: response.data.status.message,
+ })
+ }
+ ;
+ })
+ } else if (loginType === "email") {
+ httpReq.post(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/stateless/login/email", {
+ email: formData.email,
+ captcha: formData.captcha
+ }).then(response => {
+ console.log(response);
+ if (response.data.status.code === 200) {
+ // localStorage.removeItem("platform-security")
+ if (response.data.data.length > 1) {
+ setCaptchaLoginSuccessList(response.data.data)
+ setOpen(true)
+ } else {
+ localStorage.setItem('platform-security', response.data.data)
+ // 删除名为 'platform-security' 的Cookie
+ // Cookies.remove('platform-security');
+ // 设置一个有效期为7天的Cookie
+ // Cookies.set('platform-security', response.data.data, { expires: 7 });
+ // 登录成功,跳转到首页或者回调
+ router.push('/task/project')
+ }
+ } else {
+ messageApi.open({
+ type: 'error',
+ content: response.data.status.message,
+ })
+ }
+ ;
+ })
+ }
+
+ }}
+ // actions={
+ //
+ //
+ //
+ // 其他登录方式
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // }
+ >
+ setLoginType(activeKey as LoginType)}
+ >
+
+
+
+ {loginType === 'account' && (
+ <>
+
+ ),
+ }}
+ placeholder={'用户名: test'}
+ rules={[
+ {
+ required: true,
+ message: '请输入用户名!',
+ },
+ ]}
+ />
+
+ ),
+ }}
+ placeholder={'密码: 123456'}
+ rules={[
+ {
+ required: true,
+ message: '请输入密码!',
+ },
+ ]}
+ />
+ >
+ )}
+ {loginType === 'email' && (
+ <>
+
+ ),
+ }}
+ name="email"
+ placeholder={'邮箱帐号'}
+ rules={[
+ {
+ required: true,
+ message: '请输入邮箱帐号!',
+ },
+ {
+ pattern: /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/,
+ message: '邮箱格式错误!',
+ },
+ ]}
+ />
+
+ ),
+ }}
+ captchaProps={{
+ size: 'large',
+ }}
+ placeholder={'请输入验证码'}
+ captchaTextRender={(timing, count) => {
+ if (timing) {
+ return `${count} ${'获取验证码'}`;
+ }
+ return '获取验证码';
+ }}
+ phoneName="email"
+ name="captcha"
+ rules={[
+ {
+ required: true,
+ message: '请输入验证码!',
+ },
+ ]}
+ onGetCaptcha={async (email) => {
+ // 请求后端服务器发送密码
+ httpReq.get(process.env.NEXT_PUBLIC_SECURITY_REQUEST_URL + "/common/email/captcha/" + email)
+ .then(response => {
+ if (response.data.status.code === 200) {
+ message.success(`${email},获取验证码成功,请及时查看!`);
+ } else {
+ messageApi.open({
+ type: 'error',
+ content: response.data.status.message,
+ })
+ }
+ })
+ }}
+ />
+ >
+ )}
+
+ :
}
+
+ );
+};
\ No newline at end of file