diff --git a/nkebao/src/pages/login/login.module.scss b/nkebao/src/pages/login/login.module.scss index 0f9408ea..45527883 100644 --- a/nkebao/src/pages/login/login.module.scss +++ b/nkebao/src/pages/login/login.module.scss @@ -1,6 +1,6 @@ .login-page { min-height: 100vh; - background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%); + background: var(--primary-gradient); display: flex; align-items: center; justify-content: center; @@ -63,7 +63,7 @@ .login-container { width: 100%; max-width: 420px; - background: rgba(255, 255, 255, 0.95); + background: #ffffff; backdrop-filter: blur(20px); border-radius: 24px; padding: 32px 24px; @@ -89,20 +89,20 @@ .logo-icon { width: 40px; height: 40px; - background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%); + background: var(--primary-gradient); border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; - box-shadow: 0 6px 12px rgba(24, 144, 255, 0.3); + box-shadow: 0 6px 12px var(--primary-shadow); } .app-name { font-size: 24px; font-weight: 800; - background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%); + background: var(--primary-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; @@ -150,26 +150,15 @@ z-index: 2; &.active { - color: #1890ff; + color: var(--primary-color); font-weight: 600; + background: white; + box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); } } .tab-indicator { - position: absolute; - top: 3px; - left: 3px; - width: calc(50% - 3px); - height: calc(100% - 6px); - background: white; - border-radius: 7px; - box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1); - transition: transform 0.3s ease; - z-index: 1; - - &.slide { - transform: translateX(100%); - } + display: none; // 隐藏分割线指示器 } // 表单样式 @@ -201,9 +190,9 @@ transition: all 0.3s ease; &:focus-within { - border-color: #1890ff; + border-color: var(--primary-color); background: white; - box-shadow: 0 0 0 3px rgba(24, 144, 255, 0.1); + box-shadow: 0 0 0 3px var(--primary-shadow-light); } } @@ -241,14 +230,14 @@ transition: color 0.3s ease; &:hover { - color: #1890ff; + color: var(--primary-color); } } .send-code-btn { padding: 6px 12px; margin-right: 6px; - background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%); + background: var(--primary-gradient); color: white; border: none; border-radius: 6px; @@ -259,7 +248,7 @@ &:hover:not(.disabled) { transform: translateY(-1px); - box-shadow: 0 3px 8px rgba(24, 144, 255, 0.3); + box-shadow: 0 3px 8px var(--primary-shadow); } &.disabled { @@ -305,7 +294,7 @@ } .agreement-link { - color: #1890ff; + color: var(--primary-color); cursor: pointer; text-decoration: none; white-space: nowrap; @@ -320,14 +309,14 @@ font-size: 15px; font-weight: 600; border-radius: 10px; - background: linear-gradient(135deg, #1890ff 0%, #096dd9 100%); + background: var(--primary-gradient); border: none; - box-shadow: 0 6px 12px rgba(24, 144, 255, 0.3); + box-shadow: 0 6px 12px var(--primary-shadow); transition: all 0.3s ease; &:hover:not(:disabled) { transform: translateY(-1px); - box-shadow: 0 8px 16px rgba(24, 144, 255, 0.4); + box-shadow: 0 8px 16px var(--primary-shadow-dark); } &:disabled { diff --git a/nkebao/src/pages/login/login.tsx b/nkebao/src/pages/login/login.tsx index 52720f7c..25beeead 100644 --- a/nkebao/src/pages/login/login.tsx +++ b/nkebao/src/pages/login/login.tsx @@ -1,362 +1,362 @@ -import React, { useState, useEffect } from "react"; -import { useNavigate, useSearchParams } from "react-router-dom"; -import { Form, Input, Button, Toast, Tabs, Checkbox } from "antd-mobile"; -import { - EyeInvisibleOutline, - EyeOutline, - UserOutline, -} from "antd-mobile-icons"; -import { useUserStore } from "@/store/module/user"; -import { loginWithPassword, loginWithCode, sendVerificationCode } from "./api"; -import style from "./login.module.scss"; - -const Login: React.FC = () => { - const [form] = Form.useForm(); - const [activeTab, setActiveTab] = useState("password"); - const [loading, setLoading] = useState(false); - const [countdown, setCountdown] = useState(0); - const [showPassword, setShowPassword] = useState(false); - const [agreeToTerms, setAgreeToTerms] = useState(false); - - const navigate = useNavigate(); - const [searchParams] = useSearchParams(); - const { login } = useUserStore(); - - // 倒计时效果 - useEffect(() => { - if (countdown > 0) { - const timer = setTimeout(() => setCountdown(countdown - 1), 1000); - return () => clearTimeout(timer); - } - }, [countdown]); - - // 检查URL是否为登录页面 - const isLoginPage = (url: string) => { - try { - const urlObj = new URL(url, window.location.origin); - return urlObj.pathname === "/login" || urlObj.pathname.endsWith("/login"); - } catch { - return false; - } - }; - - // 手机号格式验证 - const validatePhone = (phone: string) => { - const phoneRegex = /^1[3-9]\d{9}$/; - return phoneRegex.test(phone); - }; - - // 发送验证码 - const handleSendVerificationCode = async () => { - const phone = form.getFieldValue("phone"); - - if (!phone) { - Toast.show({ content: "请输入手机号", position: "top" }); - return; - } - - if (!validatePhone(phone)) { - Toast.show({ content: "请输入正确的11位手机号", position: "top" }); - return; - } - - try { - setLoading(true); - const response = await sendVerificationCode(phone); - - if (response.code === 200) { - Toast.show({ content: "验证码已发送", position: "top" }); - setCountdown(60); - } else { - Toast.show({ content: response.msg || "发送失败", position: "top" }); - } - } catch (error) { - Toast.show({ content: "发送失败,请稍后重试", position: "top" }); - } finally { - setLoading(false); - } - }; - - // 表单验证 - const validateForm = async () => { - try { - const values = await form.validateFields(); - - if (!agreeToTerms) { - Toast.show({ content: "请同意用户协议和隐私政策", position: "top" }); - return false; - } - - if (!validatePhone(values.phone)) { - Toast.show({ content: "请输入正确的11位手机号", position: "top" }); - return false; - } - - if (activeTab === "password" && !values.password) { - Toast.show({ content: "请输入密码", position: "top" }); - return false; - } - - if (activeTab === "verification" && !values.verificationCode) { - Toast.show({ content: "请输入验证码", position: "top" }); - return false; - } - - return values; - } catch (error) { - return false; - } - }; - - // 登录处理 - const handleLogin = async () => { - const values = await validateForm(); - if (!values) return; - - setLoading(true); - try { - let response; - - if (activeTab === "password") { - response = await loginWithPassword(values.phone, values.password); - } else { - response = await loginWithCode(values.phone, values.verificationCode); - } - - if (response.code === 200 && response.data) { - // 保存登录信息到localStorage - localStorage.setItem("token", response.data.token); - localStorage.setItem("token_expired", response.data.token_expired); - localStorage.setItem("s2_accountId", response.data.member.s2_accountId); - localStorage.setItem("userInfo", JSON.stringify(response.data.member)); - - // 更新状态管理 - login(response.data.token, response.data.member); - - Toast.show({ content: "登录成功", position: "top" }); - - // 跳转到首页或重定向URL - const returnUrl = searchParams.get("returnUrl"); - if (returnUrl) { - const decodedUrl = decodeURIComponent(returnUrl); - if (isLoginPage(decodedUrl)) { - navigate("/"); - } else { - window.location.href = decodedUrl; - } - } else { - navigate("/"); - } - } else { - Toast.show({ content: response.msg || "登录失败", position: "top" }); - } - } catch (error: any) { - Toast.show({ - content: error?.message || "登录失败,请稍后重试", - position: "top", - }); - } finally { - setLoading(false); - } - }; - - // 第三方登录处理 - const handleWechatLogin = () => { - Toast.show({ content: "微信登录功能开发中", position: "top" }); - }; - - const handleAppleLogin = () => { - Toast.show({ content: "Apple登录功能开发中", position: "top" }); - }; - - return ( -
欢迎回来
-登录您的账户继续使用
-欢迎回来
+登录您的账户继续使用
+