Skip to content

Let's use AI to Earn!

重置密码

daoyian4cccec53420b
diff --git a/src/api/apiReq.ts b/src/api/apiReq.ts
index 544c449a..f41be268 100644
--- a/src/api/apiReq.ts
+++ b/src/api/apiReq.ts
@@ -55,3 +55,55 @@ export const getRegistUrlApi = (mail: string) => {
export const checkRegistStatusApi = (data: RegistCheckParams) => {
return sxRequest.get<LoginResponse>(`user/login/mail/regist/back`, data);
};
+
+// 发送重置密码邮件
+export const sendResetPasswordMailApi = (data: { mail: string }) => {
+ return sxRequest.post<LoginResponse>("user/login/repassword/mail", data);
+};
+
+// 重置密码
+export const resetPasswordApi = (data: { code: string; mail: string; password: string }) => {
+ return sxRequest.post<LoginResponse>("user/login/repassword/mail/back", data);
+};
+
+// 三方账户类型定义
+export interface SocialAccount {
+ id: number;
+ type: string;
+ loginCookie: string;
+ loginTime: string;
+ uid: string;
+ account: string;
+ avatar: string;
+ nickname: string;
+ fansCount: number;
+ readCount: number;
+ likeCount: number;
+ collectCount: number;
+ forwardCount: number;
+ commentCount: number;
+ lastStatsTime: string;
+ workCount: number;
+ income: number;
+ status: number;
+}
+
+// 创建或更新账户
+export const createOrUpdateAccountApi = (data: Omit<SocialAccount, 'id'>) => {
+ return sxRequest.post<SocialAccount>("account/login", data);
+};
+
+// 更新账户状态
+export const updateAccountStatusApi = (data: { id: number; status: number }) => {
+ return sxRequest.post<SocialAccount>("account/status", data);
+};
+
+// 获取账户列表
+export const getAccountListApi = () => {
+ return sxRequest.post<SocialAccount[]>("account/list/ids");
+};
+
+// 获取账户详情
+export const getAccountDetailApi = (id: number) => {
+ return sxRequest.get<SocialAccount>(`account/${id}`);
+};
diff --git a/src/app/[lng]/accounts/accounts.module.css b/src/app/[lng]/accounts/accounts.module.css
new file mode 100644
index 00000000..051f1394
--- /dev/null
+++ b/src/app/[lng]/accounts/accounts.module.css
@@ -0,0 +1,22 @@
+.container {
+ min-height: 100vh;
+ padding: 24px;
+ background-color: var(--background-color);
+}
+
+.card {
+ max-width: 1200px;
+ margin: 0 auto;
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
+ border-radius: 8px;
+}
+
+@media (max-width: 768px) {
+ .container {
+ padding: 16px;
+ }
+
+ .card {
+ margin: 0;
+ }
+}
\ No newline at end of file
diff --git a/src/app/[lng]/accounts/page.tsx b/src/app/[lng]/accounts/page.tsx
new file mode 100644
index 00000000..8b6f740f
--- /dev/null
+++ b/src/app/[lng]/accounts/page.tsx
@@ -0,0 +1,266 @@
+"use client";
+
+import { useEffect, useState } from "react";
+import { Card, Table, Button, message, Modal, Form, Input, Select, InputNumber, Space, Tag } from "antd";
+import { useRouter } from "next/navigation";
+import { useUserStore } from "@/store/user";
+import {
+ SocialAccount,
+ createOrUpdateAccountApi,
+ updateAccountStatusApi,
+ getAccountListApi
+} from "@/api/apiReq";
+import styles from "./accounts.module.css";
+
+const { Option } = Select;
+
+const PLATFORM_TYPES = [
+ { value: 'douyin', label: '抖音', color: '#000000' },
+ { value: 'xiaohongshu', label: '小红书', color: '#FF2442' },
+ { value: 'bilibili', label: 'Bilibili', color: '#FB7299' },
+ { value: 'kuaishou', label: '快手', color: '#FFC300' },
+ { value: 'facebook', label: 'Facebook', color: '#1877F2' },
+ { value: 'twitter', label: 'Twitter', color: '#1DA1F2' },
+];
+
+export default function AccountsPage() {
+ const router = useRouter();
+ const { token } = useUserStore();
+ const [loading, setLoading] = useState(true);
+ const [accounts, setAccounts] = useState<SocialAccount[]>([]);
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const [form] = Form.useForm();
+
+ // 获取账户列表
+ const fetchAccounts = async () => {
+ try {
+ const response: any = await getAccountListApi();
+ if (!response) {
+ message.error('获取账户列表失败');
+ return;
+ }
+
+ if (response.code === 0 && response.data) {
+ setAccounts(response.data);
+ } else {
+ message.error(response.msg || '获取账户列表失败');
+ }
+ } catch (error) {
+ message.error('获取账户列表失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ useEffect(() => {
+ if (!token) {
+ message.error('请先登录');
+ router.push('/login');
+ return;
+ }
+ fetchAccounts();
+ }, [token, router]);
+
+ // 处理账户状态更新
+ const handleStatusChange = async (id: number, status: number) => {
+ try {
+ const response: any = await updateAccountStatusApi({ id, status });
+ if (!response) {
+ message.error('更新状态失败');
+ return;
+ }
+
+ if (response.code === 0) {
+ message.success('更新状态成功');
+ fetchAccounts();
+ } else {
+ message.error(response.msg || '更新状态失败');
+ }
+ } catch (error) {
+ message.error('更新状态失败');
+ }
+ };
+
+ // 处理账户创建/更新
+ const handleSubmit = async (values: any) => {
+ try {
+ const response: any = await createOrUpdateAccountApi(values);
+ if (!response) {
+ message.error('操作失败');
+ return;
+ }
+
+ if (response.code === 0) {
+ message.success('操作成功');
+ setIsModalOpen(false);
+ form.resetFields();
+ fetchAccounts();
+ } else {
+ message.error(response.msg || '操作失败');
+ }
+ } catch (error) {
+ message.error('操作失败');
+ }
+ };
+
+ const columns = [
+ {
+ title: '平台',
+ dataIndex: 'type',
+ key: 'type',
+ render: (type: string) => {
+ const platform = PLATFORM_TYPES.find(p => p.value === type);
+ return platform ? (
+ <Tag color={platform.color}>{platform.label}</Tag>
+ ) : type;
+ }
+ },
+ {
+ title: '账号',
+ dataIndex: 'account',
+ key: 'account',
+ },
+ {
+ title: '昵称',
+ dataIndex: 'nickname',
+ key: 'nickname',
+ },
+ {
+ title: '粉丝数',
+ dataIndex: 'fansCount',
+ key: 'fansCount',
+ },
+ {
+ title: '作品数',
+ dataIndex: 'workCount',
+ key: 'workCount',
+ },
+ {
+ title: '收入',
+ dataIndex: 'income',
+ key: 'income',
+ render: (income: number) => `¥${income.toFixed(2)}`,
+ },
+ {
+ title: '状态',
+ dataIndex: 'status',
+ key: 'status',
+ render: (status: number) => (
+ <Tag color={status === 1 ? 'success' : 'error'}>
+ {status === 1 ? '正常' : '禁用'}
+ </Tag>
+ ),
+ },
+ {
+ title: '操作',
+ key: 'action',
+ render: (_: any, record: SocialAccount) => (
+ <Space>
+ <Button
+ type="link"
+ onClick={() => handleStatusChange(record.id, record.status === 1 ? 0 : 1)}
+ >
+ {record.status === 1 ? '禁用' : '启用'}
+ </Button>
+ </Space>
+ ),
+ },
+ ];
+
+ return (
+ <div className={styles.container}>
+ <Card
+ title="三方账户管理"
+ className={styles.card}
+ extra={
+ <Button type="primary" onClick={() => setIsModalOpen(true)}>
+ 添加账户
+ </Button>
+ }
+ >
+ <Table
+ columns={columns}
+ dataSource={accounts}
+ rowKey="id"
+ loading={loading}
+ />
+ </Card>
+
+ <Modal
+ title="添加账户"
+ open={isModalOpen}
+ onCancel={() => {
+ setIsModalOpen(false);
+ form.resetFields();
+ }}
+ footer={null}
+ >
+ <Form
+ form={form}
+ onFinish={handleSubmit}
+ layout="vertical"
+ >
+ <Form.Item
+ name="type"
+ label="平台"
+ rules={[{ required: true, message: '请选择平台' }]}
+ >
+ <Select placeholder="请选择平台">
+ {PLATFORM_TYPES.map(platform => (
+ <Option key={platform.value} value={platform.value}>
+ {platform.label}
+ </Option>
+ ))}
+ </Select>
+ </Form.Item>
+
+ <Form.Item
+ name="account"
+ label="账号"
+ rules={[{ required: true, message: '请输入账号' }]}
+ >
+ <Input placeholder="请输入账号" />
+ </Form.Item>
+
+ <Form.Item
+ name="nickname"
+ label="昵称"
+ rules={[{ required: true, message: '请输入昵称' }]}
+ >
+ <Input placeholder="请输入昵称" />
+ </Form.Item>
+
+ <Form.Item
+ name="loginCookie"
+ label="登录Cookie"
+ rules={[{ required: true, message: '请输入登录Cookie' }]}
+ >
+ <Input.TextArea rows={4} placeholder="请输入登录Cookie" />
+ </Form.Item>
+
+ <Form.Item
+ name="uid"
+ label="用户ID"
+ rules={[{ required: true, message: '请输入用户ID' }]}
+ >
+ <Input placeholder="请输入用户ID" />
+ </Form.Item>
+
+ <Form.Item
+ name="avatar"
+ label="头像URL"
+ rules={[{ required: true, message: '请输入头像URL' }]}
+ >
+ <Input placeholder="请输入头像URL" />
+ </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]/forgot-password/forgot-password.module.css b/src/app/[lng]/forgot-password/forgot-password.module.css
index 4ee53b4f..6bf24f8d 100644
--- a/src/app/[lng]/forgot-password/forgot-password.module.css
+++ b/src/app/[lng]/forgot-password/forgot-password.module.css
@@ -3,24 +3,25 @@
display: flex;
justify-content: center;
align-items: center;
- background-color: #f5f5f5;
+ background-color: var(--background-color);
padding: 20px;
}
.box {
- background: white;
- padding: 2rem;
- border-radius: 8px;
- box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 100%;
max-width: 400px;
+ padding: 32px;
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}
.title {
text-align: center;
- color: #333;
- margin-bottom: 2rem;
- font-size: 1.8rem;
+ margin-bottom: 24px;
+ color: var(--text-color);
+ font-size: 24px;
+ font-weight: 500;
}
.form {
@@ -49,15 +50,16 @@
}
.submitButton {
+ margin-top: 24px;
+ height: 40px;
+ font-size: 16px;
background-color: #0070f3;
color: white;
padding: 0.8rem;
border: none;
border-radius: 4px;
- font-size: 1rem;
cursor: pointer;
transition: background-color 0.3s;
- margin-top: 1rem;
}
.submitButton:hover {
@@ -65,31 +67,29 @@
}
.links {
- display: flex;
- justify-content: center;
- margin-top: 1.5rem;
+ margin-top: 16px;
+ text-align: center;
font-size: 0.9rem;
}
.link {
- color: #0070f3;
+ color: var(--primary-color);
text-decoration: none;
- transition: color 0.3s;
}
.link:hover {
- color: #0051a2;
text-decoration: underline;
}
/* 移动端适配 */
@media (max-width: 480px) {
.box {
- padding: 1.5rem;
+ padding: 24px;
}
-
+
.title {
- font-size: 1.5rem;
+ font-size: 20px;
+ margin-bottom: 20px;
}
.input {
diff --git a/src/app/[lng]/forgot-password/page.tsx b/src/app/[lng]/forgot-password/page.tsx
index 2b1e6a4e..9bed76ab 100644
--- a/src/app/[lng]/forgot-password/page.tsx
+++ b/src/app/[lng]/forgot-password/page.tsx
@@ -1,43 +1,170 @@
"use client";
import { useState } from "react";
+import { Form, Input, Button, message, Modal } from "antd";
+import { useRouter } from "next/navigation";
import Link from "next/link";
+import { sendResetPasswordMailApi, resetPasswordApi } from "@/api/apiReq";
import styles from "./forgot-password.module.css";
export default function ForgotPasswordPage() {
- const [email, setEmail] = useState("");
+ const router = useRouter();
+ const [form] = Form.useForm();
+ const [loading, setLoading] = useState(false);
+ const [isModalOpen, setIsModalOpen] = useState(false);
+ const [resetForm] = Form.useForm();
+ const [resetCode, setResetCode] = useState<string>('');
- const handleSubmit = (e: React.FormEvent) => {
- e.preventDefault();
- // TODO: 实现忘记密码逻辑
- console.log("重置密码:", { email });
+ // 处理发送重置密码邮件
+ const handleSubmit = async (values: { mail: string }) => {
+ try {
+ setLoading(true);
+ const response: any = await sendResetPasswordMailApi(values);
+ if (!response) {
+ message.error('发送失败');
+ return;
+ }
+
+ if (response.code === 0 && response.data) {
+ setResetCode(response.data);
+ setIsModalOpen(true);
+ } else {
+ message.error(response.msg || '发送失败');
+ }
+ } catch (error) {
+ message.error('发送失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ // 处理重置密码
+ const handleResetPassword = async (values: { password: string }) => {
+ if (!resetCode) {
+ message.error('无效的重置码');
+ return;
+ }
+
+ try {
+ setLoading(true);
+ const response: any = await resetPasswordApi({
+ code: resetCode,
+ mail: form.getFieldValue('mail'),
+ password: values.password
+ });
+
+ if (!response) {
+ message.error('重置失败');
+ return;
+ }
+
+ if (response.code === 0) {
+ message.success('密码重置成功');
+ router.push('/login');
+ } else {
+ message.error(response.msg || '重置失败');
+ }
+ } catch (error) {
+ message.error('重置失败');
+ } finally {
+ setLoading(false);
+ }
};
return (
<div className={styles.container}>
<div className={styles.box}>
<h1 className={styles.title}>重置密码</h1>
- <form onSubmit={handleSubmit} className={styles.form}>
- <div className={styles.inputGroup}>
- <input
- type="email"
- placeholder="请输入注册邮箱"
- value={email}
- onChange={(e) => setEmail(e.target.value)}
- className={styles.input}
- required
- />
- </div>
- <button type="submit" className={styles.submitButton}>
- 发送重置链接
- </button>
- </form>
+ <Form
+ form={form}
+ onFinish={handleSubmit}
+ layout="vertical"
+ >
+ <Form.Item
+ name="mail"
+ label="邮箱"
+ rules={[
+ { required: true, message: '请输入邮箱' },
+ { type: 'email', message: '请输入有效的邮箱地址' }
+ ]}
+ >
+ <Input placeholder="请输入注册邮箱" />
+ </Form.Item>
+
+ <Form.Item>
+ <Button
+ type="primary"
+ htmlType="submit"
+ block
+ loading={loading}
+ className={styles.submitButton}
+ >
+ 发送重置链接
+ </Button>
+ </Form.Item>
+ </Form>
+
<div className={styles.links}>
<Link href="/login" className={styles.link}>
返回登录
</Link>
</div>
</div>
+
+ <Modal
+ title="重置密码"
+ open={isModalOpen}
+ onCancel={() => setIsModalOpen(false)}
+ footer={null}
+ >
+ <Form
+ form={resetForm}
+ onFinish={handleResetPassword}
+ layout="vertical"
+ >
+ <Form.Item
+ name="password"
+ label="新密码"
+ rules={[
+ { required: true, message: '请输入新密码' },
+ { min: 6, message: '密码长度不能小于6个字符' }
+ ]}
+ >
+ <Input.Password placeholder="请输入新密码" />
+ </Form.Item>
+
+ <Form.Item
+ name="confirmPassword"
+ label="确认密码"
+ dependencies={['password']}
+ rules={[
+ { required: true, message: '请确认密码' },
+ ({ getFieldValue }) => ({
+ validator(_, value) {
+ if (!value || getFieldValue('password') === value) {
+ return Promise.resolve();
+ }
+ return Promise.reject(new Error('两次输入的密码不一致'));
+ },
+ }),
+ ]}
+ >
+ <Input.Password placeholder="请确认密码" />
+ </Form.Item>
+
+ <Form.Item>
+ <Button
+ type="primary"
+ htmlType="submit"
+ block
+ loading={loading}
+ className={styles.submitButton}
+ >
+ 确认重置
+ </Button>
+ </Form.Item>
+ </Form>
+ </Modal>
</div>
);
}
\ No newline at end of file
diff --git a/src/app/[lng]/page.tsx b/src/app/[lng]/page.tsx
index 0787249e..af09422c 100644
--- a/src/app/[lng]/page.tsx
+++ b/src/app/[lng]/page.tsx
@@ -17,10 +17,16 @@ export default function Home() {
};
+ const handleAccounts = () => {
+ router.push("/accounts");
+ };
+
return (
<div className={styles.page}>
<Button onClick={handleLogin}>登录页面</Button>
<Button onClick={handleProfile}>个人中心</Button>
+ <Button onClick={handleAccounts}>账户中心</Button>
+
</div>
);
}