修改登录页面链接对应的登录页和点击登录页的蓝狐代理跳转首页,未登录点击菜单栏产品订购里的导航页面校验

This commit is contained in:
Eamon-meng
2025-08-13 14:26:40 +08:00
parent 2242275e84
commit 13708483fc
3 changed files with 28 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
'use client' 'use client'
import {useState, useCallback, useRef} from 'react' import {useState, useCallback, useRef, useEffect} from 'react'
import {Input} from '@/components/ui/input' import {Input} from '@/components/ui/input'
import {Button} from '@/components/ui/button' import {Button} from '@/components/ui/button'
import {Checkbox} from '@/components/ui/checkbox' import {Checkbox} from '@/components/ui/checkbox'
@@ -50,13 +50,24 @@ type FormValues = zod.infer<typeof smsSchema>
export default function LoginPage(props: LoginPageProps) { export default function LoginPage(props: LoginPageProps) {
const router = useRouter() const router = useRouter()
const params = useSearchParams()
const [submitting, setSubmitting] = useState(false) const [submitting, setSubmitting] = useState(false)
const [countdown, setCountdown] = useState(0) const [countdown, setCountdown] = useState(0)
const [showCaptcha, setShowCaptcha] = useState(false) const [showCaptcha, setShowCaptcha] = useState(false)
const [loginMode, setLoginMode] = useState<'sms' | 'password'>('sms') const [loginMode, setLoginMode] = useState<'sms' | 'password'>('password')
const [showPwd, setShowPwd] = useState(false) const [showPwd, setShowPwd] = useState(false)
const timerRef = useRef<NodeJS.Timeout>(undefined) const timerRef = useRef<NodeJS.Timeout>(undefined)
useEffect(() => {
const type = params.get('type')
if (type === 'sms') {
setLoginMode('sms')
}
else {
setLoginMode('password')
}
}, [params])
const form = useForm<FormValues>({ const form = useForm<FormValues>({
resolver: zodResolver(loginMode === 'sms' ? smsSchema : pwdSchema), resolver: zodResolver(loginMode === 'sms' ? smsSchema : pwdSchema),
defaultValues: { defaultValues: {
@@ -218,7 +229,6 @@ export default function LoginPage(props: LoginPageProps) {
// 重定向 // 重定向
// ====================== // ======================
const params = useSearchParams()
const redirect = params.get('redirect') const redirect = params.get('redirect')
const refreshProfile = useProfileStore(store => store.refreshProfile) const refreshProfile = useProfileStore(store => store.refreshProfile)
@@ -234,15 +244,15 @@ export default function LoginPage(props: LoginPageProps) {
)}> )}>
<Image src={bg} alt="背景图" fill priority className="absolute -z-20 object-cover"/> <Image src={bg} alt="背景图" fill priority className="absolute -z-20 object-cover"/>
<Link href="/"> <Link href="/">
<Image src={logo} alt="logo" priority height={64} className="absolute top-8 left-8 -z-10"/> <Image src={logo} alt="logo" priority height={64} className="absolute top-8 left-8 z-10"/>
</Link> </Link>
{/* 登录表单 */} {/* 登录表单 */}
<Card className="w-96 mx-4 shadow-lg"> <Card className="w-110 mx-4 shadow-lg">
<CardHeader className="text-center"> {/* <CardHeader className="text-center">
<CardTitle className="text-2xl">登录/注册</CardTitle> <CardTitle className="text-2xl">登录/注册</CardTitle>
</CardHeader> </CardHeader> */}
<CardContent className="px-8"> <CardContent className="px-12 py-12">
{/* 登录方式切换 */} {/* 登录方式切换 */}
<Tabs <Tabs
value={loginMode} value={loginMode}
@@ -252,22 +262,22 @@ export default function LoginPage(props: LoginPageProps) {
}} }}
className="mb-6"> className="mb-6">
<TabsList className="w-full h-10 flex justify-center gap-2"> <TabsList className="w-full h-10 flex justify-center gap-2">
<TabsTrigger value="sms" className="flex-1">
</TabsTrigger>
<TabsTrigger value="password" className="flex-1"> <TabsTrigger value="password" className="flex-1">
</TabsTrigger> </TabsTrigger>
<TabsTrigger value="sms" className="flex-1">
</TabsTrigger>
</TabsList> </TabsList>
</Tabs> </Tabs>
<Form<FormValues> className="space-y-6" onSubmit={onSubmit} form={form}> <Form<FormValues> className="space-y-6" onSubmit={onSubmit} form={form}>
<FormField name="username" label="手机号码"> <FormField name="username" label={loginMode === 'sms' ? '手机号' : '用户名'}>
{({id, field}) => ( {({id, field}) => (
<Input <Input
{...field} {...field}
id={id} id={id}
type="tel" type="tel"
placeholder="请输入手机号" placeholder="请输入手机号"
autoComplete="tel-national" autoComplete="tel-national"
/> />
)} )}
@@ -341,7 +351,7 @@ export default function LoginPage(props: LoginPageProps) {
theme="gradient" theme="gradient"
disabled={submitting} disabled={submitting}
> >
{submitting ? '登录中...' : (loginMode === 'sms' ? '注册 / 登录' : '登录')} {submitting ? '登录中...' : (loginMode === 'sms' ? '首次登录即注册' : '立即登录')}
</Button> </Button>
<p className="text-xs text-center text-gray-500"> <p className="text-xs text-center text-gray-500">

View File

@@ -173,7 +173,7 @@ export default function Page(props: ProviderProps) {
<span></span> <span></span>
</Link> </Link>
<Link <Link
href="/login" href="/login?type=sms"
className={[ className={[
`w-20 lg:w-24 h-10 lg:h-12 bg-gradient-to-r rounded-sm flex items-center justify-center lg:text-lg text-white`, `w-20 lg:w-24 h-10 lg:h-12 bg-gradient-to-r rounded-sm flex items-center justify-center lg:text-lg text-white`,
`transition-colors duration-200 ease-in-out`, `transition-colors duration-200 ease-in-out`,

View File

@@ -18,9 +18,9 @@ export default function Purchase(props: PurchaseProps) {
const router = useRouter() const router = useRouter()
useEffect(() => { useEffect(() => {
setCurrentTab(props.defaultType) setCurrentTab(props.defaultType)
if (!profile) { // if (!profile) {
router.push('/login?redirect=/admin/purchase') // 未登录用户重定向到登录页 // router.push('/login?redirect=/admin/purchase') // 未登录用户重定向到登录页
} // }
}, [props.defaultType, profile, router]) }, [props.defaultType, profile, router])
return ( return (