import { useEffect, useState } from 'react' import { Tabs, Form, Input, Button } from 'antd' import type { TabsProps } from 'antd' import sso from '@src/lib/http/sso' import type { modalType, LoginTypeProps, RegisterType } from './types' import router from '@src/router/router' import styles from './index.module.css' import { debounce } from 'lodash' import { useSearchParams } from 'react-router-dom' const imgUrl = new URL('@assets/images/login_bg.png', import.meta.url).href export default function Login() { const [loginType, setLoginType] = useState('login') const [activeTab, setActiveTab] = useState('1') const [searchParams] = useSearchParams() function login() { if (searchParams.has('redirectUrl')) { router.navigate(decodeURIComponent(searchParams.get('redirectUrl') as string)) }else{ sessionStorage.removeItem('advertiserId') router.navigate('/') } } function editPassword() { setLoginType('register') } function backToLogin() { setLoginType('login') } function tabChange(tab: string) { setActiveTab(tab) } const items: TabsProps['items'] = [ { key: '1', label: '账号登录', children: }, // { // key: '2', // label: '短信登录', // children: // } ] return (
AD | 优量圈
{loginType === 'login' && } {loginType === 'register' && }
{/*

客服电话 0731-85679198、18974809627 | 客服邮箱:piaoquankefu@piaoquantv.com

ICP备案:湘B2-20180063 | window.open('https://beian.miit.gov.cn/')}>湘ICP备16013107-06号 | window.open('https://beian.mps.gov.cn/#/query/webSearch')}>湘公网安备:43019002001624

*/}
) } // 密码登录 function AccountLogin({ onLogin, activeTab }: LoginTypeProps) { const [form] = Form.useForm() useEffect(() => { form.resetFields() }, [activeTab]) function login() { form.validateFields().then(res => { const { account, password } = res fetchLogin(account, password) }) } function validator() { const account = form.getFieldValue('account') if (!account) return Promise.resolve() const phoneRegx = /^1[3456789]\d{9}$/ const emailRegx = /^\w+@\w+(\.\w+)+$/ if (phoneRegx.test(account) || emailRegx.test(account)) return Promise.resolve() return Promise.reject('请输入合法账号') } const fetchLogin = debounce((account, password) => { sso.login(account, password).then(res => { res && onLogin() }) }, 500) return (
{/*

忘记密码?

*/}
) } // 短信登录 // function SMSlogin({ onLogin, onEditPassword, activeTab }: LoginTypeProps) { // const [smsText, setSmsText] = useState('获取验证码') // const [verificationDisabled, setVerificationDisabled] = useState(false) // const [form] = Form.useForm() // useEffect(() => { // form.resetFields() // }, [activeTab]) // function login() { // form.validateFields().then(res => { // const { verificationCode, phone } = res // fetchLogin(phone, verificationCode) // }) // } // const fetchLogin = debounce((phone, verificationCode) => { // sso.loginBySendCode(phone, verificationCode).then(res => { // res && onLogin() // }) // }, 500) // function verificationCode() { // form.validateFields(['phone']).then(res => { // const { phone } = res // sso.sendCode(phone).then(res => { // res && countdown() // }) // }) // } // function countdown() { // let count = 59 // setVerificationDisabled(true) // setSmsText(`${count--}`) // const interval = setInterval(() => { // setSmsText(`${count--}`) // if (interval && count === 0) { // clearInterval(interval) // setVerificationDisabled(false) // setSmsText('获取验证码') // } // }, 1000) // } // function validator() { // const phone = form.getFieldValue('phone') // if (!phone) // return Promise.resolve() // const phoneRegx = /^1[3456789]\d{9}$/ // if (phoneRegx.test(phone)) // return Promise.resolve() // return Promise.reject('请输入合法手机号') // } // return ( //
//
// // // // //
// // //
//
// // // //
//

忘记密码?

//
// ) // } // 忘记密码 function Register({ backToLogin }: RegisterType) { const [smsText, setSmsText] = useState('获取验证码') const [verificationDisabled, setVerificationDisabled] = useState(false) const [form] = Form.useForm() useEffect(() => { form.resetFields() }, []) function submit() { form.validateFields().then(res => { const { phone, verificationCode, newPassword } = res fetchSubmit(phone, verificationCode, newPassword) }) } const fetchSubmit = debounce((phone, verificationCode, newPassword) => { sso.forgotLoginPassword(phone, verificationCode, newPassword).then(res => { res && backToLogin() }) }, 500) function verificationCode() { form.validateFields(['phone']).then(res => { const { phone } = res sso.sendCode(phone).then(res => { res && countdown() }) }) } function countdown() { let count = 59 setVerificationDisabled(true) setSmsText(`${count--}`) const interval = setInterval(() => { setSmsText(`${count--}`) if (interval && count === 0) { clearInterval(interval) setVerificationDisabled(false) setSmsText('获取验证码') } }, 1000) } function validator() { const phone = form.getFieldValue('phone') if (!phone) return Promise.resolve() const phoneRegx = /^1[3456789]\d{9}$/ const emailRegx = /^\w+@\w+(\.\w+)+$/ if (phoneRegx.test(phone) || emailRegx.test(phone)) return Promise.resolve() return Promise.reject('请输入合法手机号') } return (
忘记密码
) }