Skip to content

Let's use AI to Earn!

1

daoyian659d4a3bd102
diff --git a/src/api/apiReq.ts b/src/api/apiReq.ts
index 2daf8919..544c449a 100644
--- a/src/api/apiReq.ts
+++ b/src/api/apiReq.ts
@@ -23,6 +23,16 @@ export interface RegistCheckParams {
inviteCode: string;
}
+// 获取用户信息
+export const getUserInfoApi = () => {
+ return sxRequest.get<UserInfo>("user/mine");
+};
+
+// 更新用户信息
+export const updateUserInfoApi = (data: { name: string }) => {
+ return sxRequest.put<UserInfo>("user/info/update", data);
+};
+
export const getMoneyStampApi = () => {
return sxRequest.get<any>("cfg/money/stamp");
};
@@ -43,5 +53,5 @@ export const getRegistUrlApi = (mail: string) => {
// 检查注册状态
export const checkRegistStatusApi = (data: RegistCheckParams) => {
- return sxRequest.post<LoginResponse>(`user/login/mail/regist/back`, data);
+ return sxRequest.get<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 a499518f..4ac7baa7 100644
--- a/src/app/[lng]/login/login.module.css
+++ b/src/app/[lng]/login/login.module.css
@@ -12,8 +12,8 @@
max-width: 420px;
padding: 32px;
background: var(--card-background);
- border-radius: 8px;
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
+ border-radius: 16px;
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}
.title {
@@ -38,7 +38,7 @@
width: 100%;
padding: 12px 16px;
border: 1px solid var(--border-color);
- border-radius: 6px;
+ border-radius: 8px;
font-size: 16px;
transition: all 0.3s;
background: var(--card-background);
@@ -47,7 +47,7 @@
.input:focus {
outline: none;
border-color: var(--primary-color);
- box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.1);
+ box-shadow: 0 0 0 2px rgba(216, 181, 245, 0.1);
}
.input::placeholder {
@@ -55,8 +55,24 @@
}
.submitButton {
- width: 100%;
- margin-top: 8px;
+ height: 44px !important;
+ font-size: 16px !important;
+ font-weight: 500 !important;
+ border-radius: 8px !important;
+ background: var(--primary-color) !important;
+ border-color: var(--primary-color) !important;
+ transition: all 0.3s !important;
+}
+
+.submitButton:hover {
+ background: var(--primary-hover) !important;
+ border-color: var(--primary-hover) !important;
+ transform: translateY(-1px);
+ box-shadow: 0 4px 12px rgba(216, 181, 245, 0.2);
+}
+
+.submitButton:active {
+ transform: scale(0.98);
}
.divider {
diff --git a/src/app/[lng]/login/page.tsx b/src/app/[lng]/login/page.tsx
index 53b30734..9b65ba99 100644
--- a/src/app/[lng]/login/page.tsx
+++ b/src/app/[lng]/login/page.tsx
@@ -151,9 +151,9 @@ export default function LoginPage() {
required
/>
</div>
- <button type="submit" >
+ <Button type="primary" htmlType="submit" block className={styles.submitButton}>
登录
- </button>
+ </Button>
</form>
<div className={styles.divider}>
@@ -178,9 +178,7 @@ export default function LoginPage() {
<Link href="/forgot-password" className={styles.link}>
忘记密码?
</Link>
- <Link href="/register" className={styles.link}>
- 注册账号
- </Link>
+
</div>
</div>
diff --git a/src/app/[lng]/profile/page.tsx b/src/app/[lng]/profile/page.tsx
index 52800ed5..07653f3c 100644
--- a/src/app/[lng]/profile/page.tsx
+++ b/src/app/[lng]/profile/page.tsx
@@ -1,24 +1,48 @@
"use client";
import { useEffect, useState } from "react";
-import { Card, Descriptions, Button, message } from "antd";
+import { Card, Descriptions, Button, message, Modal, Form, Input } from "antd";
import { useRouter } from "next/navigation";
import { useUserStore } from "@/store/user";
+import { getUserInfoApi, updateUserInfoApi } from "@/api/apiReq";
import styles from "./profile.module.css";
export default function ProfilePage() {
const router = useRouter();
- const { userInfo, clearLoginStatus } = useUserStore();
+ const { userInfo, setUserInfo, clearLoginStatus, token } = useUserStore();
const [loading, setLoading] = useState(true);
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const [form] = Form.useForm();
+
+ // 获取用户信息
+ const fetchUserInfo = async () => {
+ try {
+ const response: any = await getUserInfoApi();
+ if (!response) {
+ message.error('获取用户信息失败');
+ return;
+ }
+
+ if (response.code === 0 && response.data) {
+ setUserInfo(response.data);
+ } else {
+ message.error(response.msg || '获取用户信息失败');
+ }
+ } catch (error) {
+ message.error('获取用户信息失败');
+ } finally {
+ setLoading(false);
+ }
+ };
useEffect(() => {
- if (!userInfo) {
+ if (!token) {
message.error('请先登录');
router.push('/login');
return;
}
- setLoading(false);
- }, [userInfo, router]);
+ fetchUserInfo();
+ }, [token, router]);
const handleLogout = () => {
clearLoginStatus();
@@ -26,6 +50,26 @@ export default function ProfilePage() {
router.push('/login');
};
+ const handleUpdateName = async (values: { name: string }) => {
+ try {
+ const response: any = await updateUserInfoApi(values);
+ if (!response) {
+ message.error('更新失败');
+ return;
+ }
+
+ if (response.code === 0 && response.data) {
+ setUserInfo(response.data);
+ message.success('更新成功');
+ setIsModalOpen(false);
+ } else {
+ message.error(response.msg || '更新失败');
+ }
+ } catch (error) {
+ message.error('更新失败');
+ }
+ };
+
if (loading) {
return null;
}
@@ -36,15 +80,20 @@ export default function ProfilePage() {
title="个人信息"
className={styles.card}
extra={
- <Button type="primary" danger onClick={handleLogout}>
- 退出登录
- </Button>
+ <div className={styles.actions}>
+ <Button type="primary" onClick={() => setIsModalOpen(true)}>
+ 修改用户名
+ </Button>
+ <Button type="primary" danger onClick={handleLogout}>
+ 退出登录
+ </Button>
+ </div>
}
>
<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?.mail}</Descriptions.Item>
<Descriptions.Item label="账号状态">
{userInfo?.status === 1 ? '正常' : '禁用'}
</Descriptions.Item>
@@ -56,6 +105,37 @@ export default function ProfilePage() {
</Descriptions.Item>
</Descriptions>
</Card>
+
+ <Modal
+ title="修改用户名"
+ open={isModalOpen}
+ onCancel={() => setIsModalOpen(false)}
+ footer={null}
+ >
+ <Form
+ form={form}
+ onFinish={handleUpdateName}
+ initialValues={{ name: userInfo?.name }}
+ layout="vertical"
+ >
+ <Form.Item
+ name="name"
+ label="用户名"
+ rules={[
+ { required: true, message: '请输入用户名' },
+ { min: 2, message: '用户名长度不能小于2个字符' },
+ { max: 20, message: '用户名长度不能超过20个字符' }
+ ]}
+ >
+ <Input placeholder="请输入用户名" />
+ </Form.Item>
+ <Form.Item>
+ <Button type="primary" htmlType="submit" block>
+ 确认修改
+ </Button>
+ </Form.Item>
+ </Form>
+ </Modal>
</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
index ba8dd410..4864b27f 100644
--- a/src/app/[lng]/profile/profile.module.css
+++ b/src/app/[lng]/profile/profile.module.css
@@ -1,7 +1,7 @@
.container {
min-height: 100vh;
padding: 24px;
- background-color: #f5f5f5;
+ background-color: var(--background-color);
display: flex;
justify-content: center;
align-items: flex-start;
@@ -11,9 +11,16 @@
width: 100%;
max-width: 800px;
margin-top: 24px;
- box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
+ border-radius: 16px;
}
+.actions {
+ display: flex;
+ gap: 12px;
+}
+
+/* 移动端适配 */
@media (max-width: 768px) {
.container {
padding: 16px;
@@ -22,4 +29,9 @@
.card {
margin-top: 16px;
}
+
+ .actions {
+ flex-direction: column;
+ gap: 8px;
+ }
}
\ No newline at end of file
diff --git a/src/store/user.ts b/src/store/user.ts
index 530ba54b..79576925 100644
--- a/src/store/user.ts
+++ b/src/store/user.ts
@@ -5,7 +5,8 @@ export interface UserInfo {
id: string;
name: string;
password: string;
- phone: string;
+ phone?: string;
+ mail: string;
salt: string;
status: number;
updateTime: string;
diff --git a/src/utils/request.ts b/src/utils/request.ts
index d00bd1dd..a1ef78bc 100644
--- a/src/utils/request.ts
+++ b/src/utils/request.ts
@@ -1,7 +1,7 @@
import FetchService from "@/utils/FetchService/FetchService";
import { RequestParams } from "@/utils/FetchService/types";
import { API_BASE_URL } from "@/constant";
-// import { useUserStore } from "@/store/user";
+import { useUserStore } from "@/store/user";
type ResponseType<T> = {
code: string | number;
@@ -13,11 +13,11 @@ type ResponseType<T> = {
export const fetchService = new FetchService({
baseURL: API_BASE_URL,
requestInterceptor(requestParams) {
- // const token = useUserStore.getState().token;
-
+ const token = useUserStore.getState().token;
+
requestParams.headers = {
...(requestParams["headers"] || {}),
- // Authorization: token,
+ Authorization: token ? `Bearer ${token}` : '',
};
return requestParams;
@@ -33,7 +33,7 @@ export async function request<T>(params: RequestParams) {
const data: ResponseType<T> = await res.json();
if (data.code === "Unauthorized") {
- // useUserStore.getState().clearLoginStatus();
+ useUserStore.getState().clearLoginStatus();
return null;
}