Skip to content

Let's use AI to Earn!

yes

daoyian7770f4638d30
diff --git a/package.json b/package.json
index f9093f32..2e6afd65 100644
--- a/package.json
+++ b/package.json
@@ -24,6 +24,7 @@
"i18next-browser-languagedetector": "8.0.4",
"i18next-resources-to-backend": "1.2.1",
"idb-keyval": "^6.2.2",
+ "lodash": "^4.17.21",
"next": "14.2.29",
"react": "^18",
"react-dom": "^18",
diff --git a/src/api/apiReq.ts b/src/api/apiReq.ts
index d917f7aa..2daf8919 100644
--- a/src/api/apiReq.ts
+++ b/src/api/apiReq.ts
@@ -1,4 +1,5 @@
import sxRequest from "@/utils/request";
+import { UserInfo } from "@/store/user";
export interface ResponseType<T> {
code: string | number;
@@ -12,6 +13,7 @@ export interface LoginResponse {
token?: string;
registUrl?: string;
code?: string; // 注册码
+ userInfo?: UserInfo; // 用户信息
}
export interface RegistCheckParams {
@@ -41,5 +43,5 @@ export const getRegistUrlApi = (mail: string) => {
// 检查注册状态
export const checkRegistStatusApi = (data: RegistCheckParams) => {
- return sxRequest.get<LoginResponse>(`user/login/mail/regist/back`, data);
+ return sxRequest.post<LoginResponse>(`user/login/mail/regist/back`, data);
};
diff --git a/src/app/[lng]/login/login.module.css b/src/app/[lng]/login/login.module.css
index 48cd9d21..a499518f 100644
--- a/src/app/[lng]/login/login.module.css
+++ b/src/app/[lng]/login/login.module.css
@@ -3,164 +3,124 @@
display: flex;
justify-content: center;
align-items: center;
- background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
+ background-color: var(--background-color);
padding: 20px;
}
.loginBox {
- background: rgba(255, 255, 255, 0.95);
- padding: 2.5rem;
- border-radius: 16px;
- box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 420px;
- backdrop-filter: blur(10px);
+ padding: 32px;
+ background: var(--card-background);
+ border-radius: 8px;
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.title {
+ font-size: 28px;
+ color: var(--text-color);
text-align: center;
- color: #1a1a1a;
- margin-bottom: 2rem;
- font-size: 2rem;
+ margin-bottom: 32px;
font-weight: 600;
}
.form {
display: flex;
flex-direction: column;
- gap: 1.2rem;
+ gap: 20px;
}
.inputGroup {
- display: flex;
- flex-direction: column;
- gap: 0.5rem;
+ position: relative;
}
.input {
- padding: 1rem;
- border: 2px solid #e1e1e1;
- border-radius: 8px;
- font-size: 1rem;
- transition: all 0.3s ease;
- background: rgba(255, 255, 255, 0.9);
+ width: 100%;
+ padding: 12px 16px;
+ border: 1px solid var(--border-color);
+ border-radius: 6px;
+ font-size: 16px;
+ transition: all 0.3s;
+ background: var(--card-background);
}
.input:focus {
outline: none;
- border-color: #4285f4;
- box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
+ border-color: var(--primary-color);
+ box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
}
-.submitButton {
- background-color: #4285f4;
- color: white;
- padding: 1rem;
- border: none;
- border-radius: 8px;
- font-size: 1rem;
- font-weight: 500;
- cursor: pointer;
- transition: all 0.3s ease;
- margin-top: 0.5rem;
+.input::placeholder {
+ color: #999;
}
-.submitButton:hover {
- background-color: #3367d6;
- transform: translateY(-1px);
- box-shadow: 0 4px 12px rgba(66, 133, 244, 0.2);
+.submitButton {
+ width: 100%;
+ margin-top: 8px;
}
.divider {
display: flex;
align-items: center;
- text-align: center;
- margin: 1.5rem 0;
- color: #666;
+ margin: 24px 0;
+ color: #999;
}
.divider::before,
.divider::after {
content: '';
flex: 1;
- border-bottom: 1px solid #e1e1e1;
+ height: 1px;
+ background: var(--border-color);
}
.divider span {
- padding: 0 1rem;
- font-size: 0.9rem;
+ padding: 0 12px;
}
.googleButtonWrapper {
- display: flex;
- justify-content: center;
- margin: 1rem 0;
width: 100%;
-}
-
-/* 确保 Google 按钮容器有正确的尺寸 */
-.googleButtonWrapper > div {
- width: 100% !important;
- display: flex !important;
- justify-content: center !important;
-}
-
-/* 确保 Google 按钮本身有正确的尺寸 */
-.googleButtonWrapper iframe {
- width: 100% !important;
- height: 40px !important;
+ margin-bottom: 24px;
}
.links {
display: flex;
justify-content: space-between;
- margin-top: 1.5rem;
- font-size: 0.9rem;
+ margin-top: 16px;
}
.link {
- color: #4285f4;
+ color: var(--primary-color);
text-decoration: none;
+ font-size: 14px;
transition: color 0.3s;
- font-weight: 500;
}
.link:hover {
- color: #3367d6;
- text-decoration: underline;
-}
-
-.registLink {
- margin: 16px 0;
- text-align: center;
-}
-
-.registLink a {
- color: #1890ff;
- text-decoration: none;
- font-size: 14px;
-}
-
-.registLink a:hover {
- text-decoration: underline;
+ color: var(--primary-hover);
}
/* 移动端适配 */
@media (max-width: 480px) {
.loginBox {
- padding: 1.5rem;
- margin: 1rem;
+ padding: 24px 16px;
+ box-shadow: none;
+ background: transparent;
}
.title {
- font-size: 1.75rem;
+ font-size: 24px;
+ margin-bottom: 24px;
}
.input {
- padding: 0.9rem;
+ padding: 10px 14px;
+ font-size: 15px;
}
- .submitButton {
- padding: 0.9rem;
+ .links {
+ flex-direction: column;
+ align-items: center;
+ gap: 12px;
}
}
\ No newline at end of file
diff --git a/src/app/[lng]/login/page.tsx b/src/app/[lng]/login/page.tsx
index 5c254286..53b30734 100644
--- a/src/app/[lng]/login/page.tsx
+++ b/src/app/[lng]/login/page.tsx
@@ -8,9 +8,11 @@ import { message, Modal, Form, Input, Button } from "antd";
import { useRouter } from "next/navigation";
import styles from "./login.module.css";
import { loginWithMailApi, checkRegistStatusApi, LoginResponse } from "@/api/apiReq";
+import { useUserStore } from "@/store/user";
export default function LoginPage() {
const router = useRouter();
+ const { setToken, setUserInfo } = useUserStore();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [isChecking, setIsChecking] = useState(false);
@@ -30,9 +32,12 @@ export default function LoginPage() {
setRegistCode(response.data.code || '');
setIsModalOpen(true);
setIsChecking(true);
- } else if (response.data.type === 'login' && response.data.token) {
+ } else if (response.data.token) {
// 登录成功
- localStorage.setItem('token', response.data.token);
+ setToken(response.data.token);
+ if (response.data.userInfo) {
+ setUserInfo(response.data.userInfo);
+ }
message.success('登录成功');
router.push('/');
}
@@ -55,10 +60,13 @@ export default function LoginPage() {
if (!response) return;
- if (response.code === 0 && response.data.type === 'login' && response.data.token) {
+ if (response.code === 0 && response.data.token) {
setIsChecking(false);
setIsModalOpen(false);
- localStorage.setItem('token', response.data.token);
+ setToken(response.data.token);
+ if (response.data.userInfo) {
+ setUserInfo(response.data.userInfo);
+ }
message.success('注册成功,已自动登录');
router.push('/');
} else {
@@ -79,17 +87,20 @@ export default function LoginPage() {
const response = await checkRegistStatusApi({
code: registCode,
mail: email,
- password: form.getFieldValue('password') || '',
+ password: form.getFieldValue('password'),
inviteCode: form.getFieldValue('inviteCode') || ''
});
if (!response) return;
- if (response.code === 0 && response.data.type === 'login' && response.data.token) {
+ if (response.code === 0 && response.data.token) {
clearInterval(timer);
setIsChecking(false);
setIsModalOpen(false);
- localStorage.setItem('token', response.data.token);
+ setToken(response.data.token);
+ if (response.data.userInfo) {
+ setUserInfo(response.data.userInfo);
+ }
message.success('注册成功,已自动登录');
router.push('/');
}
@@ -104,7 +115,7 @@ export default function LoginPage() {
clearInterval(timer);
}
};
- }, [isChecking, isModalOpen, email, router, registCode, form]);
+ }, [isChecking, isModalOpen, email, router, registCode, form, setToken, setUserInfo]);
const handleGoogleSuccess = (credentialResponse: any) => {
console.log("Google 登录成功:", credentialResponse);
@@ -140,7 +151,7 @@ export default function LoginPage() {
required
/>
</div>
- <button type="submit" className={styles.submitButton}>
+ <button type="submit" >
登录
</button>
</form>
diff --git a/src/app/[lng]/page.tsx b/src/app/[lng]/page.tsx
index d2f4ed3d..0787249e 100644
--- a/src/app/[lng]/page.tsx
+++ b/src/app/[lng]/page.tsx
@@ -12,9 +12,15 @@ export default function Home() {
router.push("/login");
};
+ const handleProfile = () => {
+ router.push("/profile");
+ };
+
+
return (
<div className={styles.page}>
<Button onClick={handleLogin}>登录页面</Button>
+ <Button onClick={handleProfile}>个人中心</Button>
</div>
);
}
diff --git a/src/app/[lng]/profile/page.tsx b/src/app/[lng]/profile/page.tsx
new file mode 100644
index 00000000..52800ed5
--- /dev/null
+++ b/src/app/[lng]/profile/page.tsx
@@ -0,0 +1,61 @@
+"use client";
+
+import { useEffect, useState } from "react";
+import { Card, Descriptions, Button, message } from "antd";
+import { useRouter } from "next/navigation";
+import { useUserStore } from "@/store/user";
+import styles from "./profile.module.css";
+
+export default function ProfilePage() {
+ const router = useRouter();
+ const { userInfo, clearLoginStatus } = useUserStore();
+ const [loading, setLoading] = useState(true);
+
+ useEffect(() => {
+ if (!userInfo) {
+ message.error('请先登录');
+ router.push('/login');
+ return;
+ }
+ setLoading(false);
+ }, [userInfo, router]);
+
+ const handleLogout = () => {
+ clearLoginStatus();
+ message.success('退出登录成功');
+ router.push('/login');
+ };
+
+ if (loading) {
+ return null;
+ }
+
+ return (
+ <div className={styles.container}>
+ <Card
+ title="个人信息"
+ className={styles.card}
+ extra={
+ <Button type="primary" danger onClick={handleLogout}>
+ 退出登录
+ </Button>
+ }
+ >
+ <Descriptions bordered column={1}>
+ <Descriptions.Item label="用户ID">{userInfo?.id}</Descriptions.Item>
+ <Descriptions.Item label="用户名">{userInfo?.name}</Descriptions.Item>
+ <Descriptions.Item label="邮箱">{userInfo?.phone}</Descriptions.Item>
+ <Descriptions.Item label="账号状态">
+ {userInfo?.status === 1 ? '正常' : '禁用'}
+ </Descriptions.Item>
+ <Descriptions.Item label="创建时间">
+ {new Date(userInfo?.createTime || '').toLocaleString()}
+ </Descriptions.Item>
+ <Descriptions.Item label="最后更新">
+ {new Date(userInfo?.updateTime || '').toLocaleString()}
+ </Descriptions.Item>
+ </Descriptions>
+ </Card>
+ </div>
+ );
+}
\ No newline at end of file
diff --git a/src/app/[lng]/profile/profile.module.css b/src/app/[lng]/profile/profile.module.css
new file mode 100644
index 00000000..ba8dd410
--- /dev/null
+++ b/src/app/[lng]/profile/profile.module.css
@@ -0,0 +1,25 @@
+.container {
+ min-height: 100vh;
+ padding: 24px;
+ background-color: #f5f5f5;
+ display: flex;
+ justify-content: center;
+ align-items: flex-start;
+}
+
+.card {
+ width: 100%;
+ max-width: 800px;
+ margin-top: 24px;
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
+}
+
+@media (max-width: 768px) {
+ .container {
+ padding: 16px;
+ }
+
+ .card {
+ margin-top: 16px;
+ }
+}
\ No newline at end of file
diff --git a/src/app/globals.css b/src/app/globals.css
index 9925df3f..ad6396c6 100644
--- a/src/app/globals.css
+++ b/src/app/globals.css
@@ -1,6 +1,27 @@
:root {
- --background: #ffffff;
- --foreground: #171717;
+ --primary-color: #D8B5F5;
+ --primary-hover: #D7B4F5;
+ --text-color: #1f2937;
+ --border-color: #e5e7eb;
+ --background-color: #f9fafb;
+ --card-background: #fff;
+ --error-color: #ef4444;
+ --success-color: #10b981;
+}
+
+/* 全局样式重置 */
+* {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+}
+
+body {
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
+ 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
+ 'Noto Color Emoji';
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
}
html,
@@ -10,20 +31,14 @@ body {
}
body {
- color: var(--foreground);
- background: var(--background);
- font-family: Arial, Helvetica, sans-serif;
+ color: var(--text-color);
+ background: var(--background-color);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
-* {
- box-sizing: border-box;
- padding: 0;
- margin: 0;
-}
-
a {
color: inherit;
text-decoration: none;
}
+
diff --git a/src/store/user.ts b/src/store/user.ts
index 5359994a..530ba54b 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -1,15 +1,43 @@
import { createPersistStore } from "@/utils/createPersistStore";
-export interface IUserStore {}
+export interface UserInfo {
+ createTime: string;
+ id: string;
+ name: string;
+ password: string;
+ phone: string;
+ salt: string;
+ status: number;
+ updateTime: string;
+ _id: string;
+}
-const state: IUserStore = {};
+export interface IUserStore {
+ token?: string;
+ userInfo?: UserInfo;
+}
+
+const state: IUserStore = {
+ token: undefined,
+ userInfo: undefined,
+};
export const useUserStore = createPersistStore(
{
...state,
},
(set, _get) => {
- return {};
+ return {
+ setToken: (token: string) => {
+ set({ token });
+ },
+ setUserInfo: (userInfo: UserInfo) => {
+ set({ userInfo });
+ },
+ clearLoginStatus: () => {
+ set({ token: undefined, userInfo: undefined });
+ },
+ };
},
{
name: "User",