调整前端目录结构
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp";
|
||||
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
|
||||
import { useState, useCallback } from "react";
|
||||
import { toast } from "sonner";
|
||||
import LoginHeader from "./LoginHeader";
|
||||
import { SendCodeFormData } from "./types";
|
||||
import { Label } from "@/components/ui/label";
|
||||
|
||||
export default function EmailLoginMode({ onSendCode }: { onSendCode: (data: SendCodeFormData) => Promise<boolean> }) {
|
||||
const [email, setEmail] = useState("");
|
||||
const handleSendCode = useCallback(() => {
|
||||
if (!email.trim().match(/^[^\s@]+@[^\s@]+\.[^\s@]+$/)) {
|
||||
toast.error('请输入正确的邮箱地址');
|
||||
return;
|
||||
}
|
||||
onSendCode({
|
||||
type: 'email',
|
||||
email,
|
||||
})
|
||||
}, [email, onSendCode]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<LoginHeader />
|
||||
<div className="grid gap-3">
|
||||
<Label htmlFor="email">电子邮箱</Label>
|
||||
<Input
|
||||
id="email-login-mode-email"
|
||||
name="email"
|
||||
type="text"
|
||||
placeholder="电子邮箱"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required />
|
||||
</div>
|
||||
<div className="grid gap-3">
|
||||
<div className="flex items-center h-4">
|
||||
<Label htmlFor="code">验证码</Label>
|
||||
</div>
|
||||
<div className="flex gap-5">
|
||||
<InputOTP
|
||||
id="email-login-mode-code"
|
||||
name="code"
|
||||
maxLength={6}
|
||||
pattern={REGEXP_ONLY_DIGITS_AND_CHARS}
|
||||
required
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot index={0} />
|
||||
<InputOTPSlot index={1} />
|
||||
<InputOTPSlot index={2} />
|
||||
<InputOTPSlot index={3} />
|
||||
<InputOTPSlot index={4} />
|
||||
<InputOTPSlot index={5} />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<Button type="button" variant="secondary" onClick={handleSendCode}>获取验证码</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
注册并登录
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
12
tone-page-web/app/console/login/components/LoginHeader.tsx
Normal file
12
tone-page-web/app/console/login/components/LoginHeader.tsx
Normal file
@@ -0,0 +1,12 @@
|
||||
export default function LoginHeader() {
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-col items-center text-center">
|
||||
<h1 className="text-2xl font-bold">欢迎回来</h1>
|
||||
<p className="text-muted-foreground text-balance">
|
||||
登陆到您的账户
|
||||
</p>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import LoginHeader from "./LoginHeader";
|
||||
import { Label } from "@/components/ui/label"
|
||||
|
||||
export default function PasswordLoginMode({ forgetPassword }: { forgetPassword: () => void }) {
|
||||
return (
|
||||
<>
|
||||
<LoginHeader />
|
||||
<div className="grid gap-3">
|
||||
<Label htmlFor="email">电子邮箱/手机号/账号</Label>
|
||||
<Input
|
||||
id="password-login-mode-account"
|
||||
name="account"
|
||||
type="text"
|
||||
placeholder="电子邮箱/手机号/账号"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-3">
|
||||
<div className="flex items-center h-4">
|
||||
<Label htmlFor="password">密码</Label>
|
||||
<a
|
||||
onClick={forgetPassword}
|
||||
className="ml-auto text-sm underline-offset-2 hover:underline cursor-pointer"
|
||||
>
|
||||
忘记密码?
|
||||
</a>
|
||||
</div>
|
||||
<Input
|
||||
id="password-login-mode-password"
|
||||
name="password"
|
||||
type="password"
|
||||
required />
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
登录
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { InputOTP, InputOTPGroup, InputOTPSlot } from "@/components/ui/input-otp";
|
||||
import { REGEXP_ONLY_DIGITS_AND_CHARS } from "input-otp";
|
||||
import { useState, useCallback } from "react";
|
||||
import { toast } from "sonner";
|
||||
import LoginHeader from "./LoginHeader";
|
||||
import { SendCodeFormData } from "./types";
|
||||
import { Label } from "@/components/ui/label"
|
||||
|
||||
export default function PhoneLoginMode({ onSendCode }: { onSendCode: (data: SendCodeFormData) => Promise<boolean> }) {
|
||||
const [phone, setPhone] = useState("");
|
||||
const handleSendCode = useCallback(() => {
|
||||
if (phone.trim().length !== 11) {
|
||||
toast.error('请输入正确的手机号');
|
||||
return;
|
||||
}
|
||||
onSendCode({
|
||||
type: 'phone',
|
||||
phone,
|
||||
})
|
||||
}, [phone, onSendCode]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<LoginHeader />
|
||||
<div className="grid gap-3">
|
||||
<Label htmlFor="phone">手机号</Label>
|
||||
<Input
|
||||
id="phone-login-mode-phone"
|
||||
name="phone"
|
||||
type="text"
|
||||
placeholder="+86 手机号"
|
||||
value={phone}
|
||||
onChange={(e) => setPhone(e.target.value)}
|
||||
required />
|
||||
</div>
|
||||
<div className="grid gap-3">
|
||||
<div className="flex items-center h-4">
|
||||
<Label htmlFor="code">验证码</Label>
|
||||
</div>
|
||||
<div className="flex gap-5">
|
||||
<InputOTP
|
||||
id="phone-login-mode-code"
|
||||
name="code"
|
||||
maxLength={6}
|
||||
pattern={REGEXP_ONLY_DIGITS_AND_CHARS}
|
||||
required
|
||||
>
|
||||
<InputOTPGroup>
|
||||
<InputOTPSlot index={0} />
|
||||
<InputOTPSlot index={1} />
|
||||
<InputOTPSlot index={2} />
|
||||
<InputOTPSlot index={3} />
|
||||
<InputOTPSlot index={4} />
|
||||
<InputOTPSlot index={5} />
|
||||
</InputOTPGroup>
|
||||
</InputOTP>
|
||||
<Button type="button" variant="secondary" onClick={handleSendCode}>获取验证码</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button type="submit" className="w-full">
|
||||
注册并登录
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
}
|
||||
BIN
tone-page-web/app/console/login/components/login-bg.jpg
Normal file
BIN
tone-page-web/app/console/login/components/login-bg.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 207 KiB |
16
tone-page-web/app/console/login/components/types.ts
Normal file
16
tone-page-web/app/console/login/components/types.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
export type SubmitMode = 'password' | 'phone' | 'email';
|
||||
export type LoginFormData = {
|
||||
type: SubmitMode;
|
||||
account?: string;
|
||||
password?: string;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
code?: string;
|
||||
}
|
||||
|
||||
export type SendCodeMode = 'phone' | 'email';
|
||||
export type SendCodeFormData = {
|
||||
type: SendCodeMode;
|
||||
phone?: string;
|
||||
email?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user