u
This commit is contained in:
1 parent
d60be4a75b
commit
be8eaae7c5
24 files changed
+595
-232
No files matched your search
@@ -1,11 +1,12 @@
|
||||
import type { AFormRef } from '@/components/common/ao'
|
||||
import { useRouter } from 'expo-router'
|
||||
import { Lock, UserRound } from 'lucide-react-native'
|
||||
import { useRef, useState } from 'react'
|
||||
import { Image, ScrollView, View } from 'react-native'
|
||||
|
||||
import { AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import { Button, ButtonSpinner, ButtonText } from '@/components/ui/button'
|
||||
import { useToast } from '@/utils/toast'
|
||||
import { Image, ScrollView, View } from 'react-native'
|
||||
import { AButton, AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import { registerDefaultApi } from '@/request/api/auth'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
interface RegisterForm {
|
||||
username: string
|
||||
@@ -14,8 +15,8 @@ interface RegisterForm {
|
||||
}
|
||||
|
||||
export default function AuthRegister() {
|
||||
const router = useRouter()
|
||||
const scrollRef = useRef<ScrollView>(null)
|
||||
const toast = useToast()
|
||||
|
||||
const [form, setForm] = useState<RegisterForm>({
|
||||
username: '',
|
||||
@@ -29,14 +30,30 @@ export default function AuthRegister() {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
const handleRegister = () => {
|
||||
const handleRegister = async () => {
|
||||
if (formRef.current?.validate()) {
|
||||
setLoading(true)
|
||||
toast.show({ title: '校验通过,开始注册', action: 'success' })
|
||||
// 模拟注册过程
|
||||
setTimeout(() => {
|
||||
|
||||
await registerDefaultApi({
|
||||
account: form.username,
|
||||
password: form.password,
|
||||
}).then((res) => {
|
||||
if (res.isSuccess) {
|
||||
console.log(res)
|
||||
toast.show({
|
||||
title: '注册成功',
|
||||
})
|
||||
// router.replace('/auth/login')
|
||||
}
|
||||
else {
|
||||
toast.show({
|
||||
title: res.message || '注册失败',
|
||||
})
|
||||
}
|
||||
}).catch((_err) => {
|
||||
}).finally(() => {
|
||||
setLoading(false)
|
||||
}, 2000)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,10 +83,7 @@ export default function AuthRegister() {
|
||||
<AFormItem
|
||||
name="password"
|
||||
label="密码"
|
||||
rules={[
|
||||
{ required: true, message: '密码是必填项' },
|
||||
{ pattern: /^\d{6}$/, message: '请输入6位数字密码' },
|
||||
]}
|
||||
isRequired
|
||||
>
|
||||
<AInput
|
||||
placeholder="请输入密码"
|
||||
@@ -83,8 +97,8 @@ export default function AuthRegister() {
|
||||
<AFormItem
|
||||
name="confirmPassword"
|
||||
label="确认密码"
|
||||
isRequired
|
||||
rules={[
|
||||
{ required: true, message: '确认密码是必填项' },
|
||||
{
|
||||
validator: val => val === form.password,
|
||||
message: '两次密码不一致',
|
||||
@@ -101,18 +115,10 @@ export default function AuthRegister() {
|
||||
</AFormItem>
|
||||
</AForm>
|
||||
|
||||
<Button className="w-full mb-4" onPress={handleRegister} disabled={loading}>
|
||||
{loading
|
||||
? (
|
||||
<>
|
||||
<ButtonSpinner color="gray" />
|
||||
<ButtonText>请稍等 . . .</ButtonText>
|
||||
</>
|
||||
)
|
||||
: (
|
||||
<ButtonText>注册</ButtonText>
|
||||
)}
|
||||
</Button>
|
||||
<AButton className="w-full mb-4" onPress={handleRegister} loading={loading}>
|
||||
|
||||
注册
|
||||
</AButton>
|
||||
</View>
|
||||
</ScrollView>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user