Skip to content

Let's use AI to Earn!

调试

daoyian4c2a93f56186
diff --git a/src/api/apiReq.ts b/src/api/apiReq.ts
new file mode 100644
index 00000000..03659534
--- /dev/null
+++ b/src/api/apiReq.ts
@@ -0,0 +1,37 @@
+import sxRequest from "@/utils/request";
+
+export interface ResponseType<T> {
+ code: string | number;
+ data: T;
+ msg: string;
+ url: string;
+}
+
+export interface LoginResponse {
+ type: 'regist' | 'login'; // 登录类型:regist-需要注册,login-直接登录
+ token?: string;
+ registUrl?: string;
+}
+
+export const getMoneyStampApi = () => {
+ return sxRequest.get<any>("cfg/money/stamp");
+};
+
+export const fluxSchnellApi = (data: any) => {
+ return sxRequest.post<any>("experience-ai/text2image/flux_schnell", data);
+};
+
+// 邮箱登录接口
+export const loginWithMailApi = (data: { mail: string; password: string }) => {
+ return sxRequest.post<LoginResponse>("user/login/mail", data);
+};
+
+// 获取注册链接
+export const getRegistUrlApi = (mail: string) => {
+ return sxRequest.get<LoginResponse>(`user/login/mail/regist/url?mail=${mail}`);
+};
+
+// 检查注册状态
+export const checkRegistStatusApi = (mail: string) => {
+ return sxRequest.get<LoginResponse>(`user/login/mail/regist/back?mail=${mail}`);
+};
diff --git a/src/api/config.ts b/src/api/config.ts
deleted file mode 100644
index 597fb610..00000000
--- a/src/api/config.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import sxRequest from "@/utils/request";
-
-export const getMoneyStampApi = () => {
- return sxRequest.get<any>("cfg/money/stamp");
-};
-
-export const fluxSchnellApi = (data: any) => {
- return sxRequest.post<any>("experience-ai/text2image/flux_schnell", data);
-};
diff --git a/src/app/login/login.module.css b/src/app/login/login.module.css
index d5b7ffe3..48cd9d21 100644
--- a/src/app/login/login.module.css
+++ b/src/app/login/login.module.css
@@ -130,6 +130,21 @@
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;
+}
+
/* 移动端适配 */
@media (max-width: 480px) {
.loginBox {
diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx
index cbfda46b..4b4ebd59 100644
--- a/src/app/login/page.tsx
+++ b/src/app/login/page.tsx
@@ -1,21 +1,82 @@
"use client";
-import { useState } from "react";
+import { useState, useEffect } from "react";
import Link from "next/link";
import { FcGoogle } from "react-icons/fc";
import { GoogleLogin } from "@react-oauth/google";
+import { message } from "antd";
+import { useRouter } from "next/navigation";
import styles from "./login.module.css";
+import { loginWithMailApi, getRegistUrlApi, checkRegistStatusApi, LoginResponse } from "@/api/apiReq";
export default function LoginPage() {
+ const router = useRouter();
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
+ const [isChecking, setIsChecking] = useState(false);
+ const [registUrl, setRegistUrl] = useState("");
- const handleSubmit = (e: React.FormEvent) => {
+ const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
- // TODO: 实现登录逻辑
- console.log("登录:", { email, password });
+ try {
+ const response = await loginWithMailApi({ mail: email, password });
+ if (!response) return;
+
+ if (response.code === 0) {
+ if (response.data.type === 'regist') {
+ // 用户未注册,获取注册链接
+ const registResponse = await getRegistUrlApi(email);
+ if (!registResponse) return;
+
+ if (registResponse.code === 0 && registResponse.data.registUrl) {
+ setRegistUrl(registResponse.data.registUrl);
+ setIsChecking(true);
+ message.info('请完成注册后继续');
+ }
+ } else if (response.data.type === 'login' && response.data.token) {
+ // 登录成功
+ localStorage.setItem('token', response.data.token);
+ message.success('登录成功');
+ router.push('/');
+ }
+ } else {
+ message.error(response.msg || '登录失败');
+ }
+ } catch (error) {
+ message.error('登录失败,请稍后重试');
+ }
};
+ // 检查注册状态
+ useEffect(() => {
+ let timer: NodeJS.Timeout;
+
+ if (isChecking && registUrl) {
+ timer = setInterval(async () => {
+ try {
+ const response = await checkRegistStatusApi(email);
+ if (!response) return;
+
+ if (response.code === 0 && response.data.type === 'login' && response.data.token) {
+ clearInterval(timer);
+ setIsChecking(false);
+ localStorage.setItem('token', response.data.token);
+ message.success('注册成功,已自动登录');
+ router.push('/');
+ }
+ } catch (error) {
+ console.error('检查注册状态失败:', error);
+ }
+ }, 3000);
+ }
+
+ return () => {
+ if (timer) {
+ clearInterval(timer);
+ }
+ };
+ }, [isChecking, registUrl, email, router]);
+
const handleGoogleSuccess = (credentialResponse: any) => {
console.log("Google 登录成功:", credentialResponse);
// TODO: 将 credential 发送到后端验证
@@ -55,6 +116,14 @@ export default function LoginPage() {
</button>
</form>
+ {registUrl && (
+ <div className={styles.registLink}>
+ <a href={registUrl} target="_blank" rel="noopener noreferrer">
+ 点击这里完成注册
+ </a>
+ </div>
+ )}
+
<div className={styles.divider}>
<span>或 </span>
</div>
diff --git a/src/app/providers.tsx b/src/app/providers.tsx
index 032cd856..8416d5e3 100644
--- a/src/app/providers.tsx
+++ b/src/app/providers.tsx
@@ -8,7 +8,7 @@ import { Suspense } from "react";
export function Providers({ children }: { children: React.ReactNode }) {
return (
- <GoogleOAuthProvider clientId="YOUR_GOOGLE_CLIENT_ID">
+ <GoogleOAuthProvider clientId="471394506793-t2g4mg90vr8qgpq5stbua0b22pofqrne.apps.googleusercontent.com">
<ConfigProvider
locale={zh_CN}
theme={{
diff --git a/src/constant.ts b/src/constant.ts
index 02e6fad6..8f186025 100644
--- a/src/constant.ts
+++ b/src/constant.ts
@@ -2,4 +2,5 @@
export const APP_TITLE = "哎呦赚Web端";
// api url
-export const API_BASE_URL = "https://api.yikart.cn/api/";
+// export const API_BASE_URL = "https://api.yikart.cn/api/";
+export const API_BASE_URL = "http://localhost:3000/api/";