Files
schisandra-cloud-storage-fr…/src/views/User/Register/index.tsx
2024-04-22 00:02:42 +08:00

261 lines
12 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { BarcodeOutlined, LockOutlined, MobileOutlined, WechatOutlined } from '@ant-design/icons'
import { ProFormCaptcha, ProFormText } from '@ant-design/pro-components'
import { Space, Tabs, message, Image, Alert, Form, Button } from 'antd'
import { useState } from 'react'
import logo from '@/assets/icons/schisandra.svg'
// import background from '@/assets/images/background.png'
import qrCode from '@/assets/images/login_qrcode-landaiqing.jpg'
import styles from './index.module.less'
import { observer } from 'mobx-react'
import FooterComponent from '@/components/Footer'
// import useStore from '@/utils/store/useStore.tsx'
type LoginType = 'phone'
export default observer(() => {
// @ts-expect-error
const [generateMpRegCodeData, setGenerateMpRegCodeData] = useState<API.GenerateMpRegCode>({})
const [form] = Form.useForm()
// @ts-ignore
const [base64Code, setBase64Code] = useState<API.GenerateBase64Code>({ data: '' })
const clickGetBase64CodeMethod = async () => {
await getBase64CodeMethod()
}
const CodeImg = (
<img
src={'data:image/jpg;base64,' + base64Code.data}
onClick={clickGetBase64CodeMethod}
title='点击刷新'
style={{ cursor: 'pointer', height: 40, width: 90 }}
/>
)
const getBase64CodeMethod = async () => {}
const items = [
{
key: 'phone',
label: (
<span>
<MobileOutlined />
</span>
),
},
]
const [loginType, setLoginType] = useState<LoginType>('phone')
const onSubmit = async (formData: object) => {
console.log(formData)
}
return (
<div className={styles.container}>
<div className={styles.content}>
<Space>
<Space className={styles.login_content}>
<Space align='center' className={styles.mp_code}>
<Space direction='vertical' align='center'>
<span className={styles.mp_code_title}></span>
<Image
preview={false}
height={210}
width={200}
className={styles.mp_code_img}
// src={generateMpRegCodeData.data?.qrCodeUrl}
src={qrCode}
/>
<Alert
// message={(<span>微信扫码<span>关注公众号</span></span>)}
description={
<div>
<span>
<span className={styles.mp_tips}></span>
</span>
<br />
</div>
}
// type="success"
showIcon={true}
className={styles.alert}
icon={<WechatOutlined />}
/>
</Space>
</Space>
<Form
form={form}
className={styles.login_form}
initialValues={{
autoLogin: true,
}}>
<Space direction='vertical' align='center'>
<Space className={styles.logo}>
<img
alt='logo'
src={logo}
style={{ width: '44px', height: '44px' }}
/>
<span></span>
</Space>
<div className={styles.subTitle}></div>
</Space>
<Tabs
centered={true}
items={items}
activeKey={loginType}
onChange={(activeKey) =>
setLoginType(activeKey as LoginType)
}></Tabs>
<>
<ProFormText
fieldProps={{
size: 'large',
prefix: <MobileOutlined className={'prefixIcon'} />,
autoComplete: 'off',
}}
name='phone'
placeholder='请输入手机号!'
rules={[
{
required: true,
message: '请输入手机号!',
},
{
pattern: /^1\d{10}$/,
message: '手机号格式错误!',
},
]}
/>
<ProFormText.Password
name='password'
fieldProps={{
size: 'large',
prefix: <LockOutlined className={'prefixIcon'} />,
}}
placeholder='请输入密码'
rules={[
{
required: true,
message: '请输入密码!',
},
{
pattern:
/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z\\W]{6,18}$/,
message:
'密码长度需在6~18位字符且必须包含字母和数字',
},
]}
/>
<ProFormText.Password
name='confirmPassword'
dependencies={['password']}
fieldProps={{
size: 'large',
prefix: <LockOutlined className={'prefixIcon'} />,
}}
placeholder='请再次确认密码'
rules={[
{
required: true,
message: '请再次确认密码!',
},
({ getFieldValue }) => ({
validator(_, value) {
if (!value || getFieldValue('password') === value) {
return Promise.resolve()
}
return Promise.reject(
new Error('两次输入的密码不一致!'),
)
},
}),
]}
/>
<ProFormText
addonAfter={CodeImg}
name='code'
fieldProps={{
size: 'large',
prefix: <BarcodeOutlined className={'prefixIcon'} />,
autoComplete: 'off',
}}
placeholder='请输入图形验证码'
rules={[
{
required: true,
message: '请输入图形验证码!',
},
{
pattern: /^[a-zA-Z0-9]{5}$/,
message: '图形验证码格式不正确!',
},
]}
/>
<ProFormCaptcha
fieldProps={{
size: 'large',
prefix: <LockOutlined className={'prefixIcon'} />,
}}
captchaProps={{
size: 'large',
}}
placeholder={'请输入验证码'}
captchaTextRender={(timing, count) => {
if (timing) {
return `${count} ${'获取验证码'}`
}
return '获取验证码'
}}
name='captcha'
rules={[
{
required: true,
message: '请输入验证码!',
},
]}
onGetCaptcha={async () => {
message.success('获取验证码成功验证码为1234')
}}
/>
</>
<Button
type='primary'
block
size='large'
onClick={async () => {
const validateFields = [
'phone',
'username',
'password',
'captcha',
'code',
'confirmPassword',
]
await form
.validateFields(validateFields)
.then(async (values) => {
await onSubmit(values as API.PhoneRegisterRequest)
})
.catch((errorInfo) => {
console.error(errorInfo)
})
}}>
</Button>
</Form>
<a href='/login' className={styles.go_to_register}>
<span></span>
</a>
</Space>
</Space>
</div>
<FooterComponent />
</div>
)
})