u
This commit is contained in:
1 parent
d60be4a75b
commit
be8eaae7c5
24 files changed
+595
-232
No files matched your search
@@ -1,10 +1,8 @@
|
||||
import type { TabbarItem } from '@/components/custom/Tabbar'
|
||||
import CustomTabbar from '@/components/custom/Tabbar'
|
||||
import { useToast } from '@/utils/toast'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
export default function TabsLayout() {
|
||||
const toast = useToast()
|
||||
|
||||
const tabbarOptions: TabbarItem[] = [
|
||||
{
|
||||
name: 'user',
|
||||
|
||||
@@ -1,41 +1,39 @@
|
||||
import { Lock, UserRound } from 'lucide-react-native'
|
||||
import { useState } from 'react'
|
||||
import { Image, Text, View } from 'react-native'
|
||||
import { AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import { AButton, ACheckbox, AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import { IconQq, IconWeixin, IconZhiwen } from '@/components/iconfont'
|
||||
import { Button, ButtonText } from '@/components/ui/button'
|
||||
import {
|
||||
Checkbox,
|
||||
CheckboxIcon,
|
||||
CheckboxIndicator,
|
||||
CheckboxLabel,
|
||||
} from '@/components/ui/checkbox'
|
||||
import { Divider } from '@/components/ui/divider'
|
||||
|
||||
import { CheckIcon } from '@/components/ui/icon'
|
||||
|
||||
import useFormValidation from '@/hooks/useFormValidation'
|
||||
import alovaInstance from '@/request'
|
||||
import { useToast } from '@/utils/toast'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
interface LoginForm {
|
||||
username: string
|
||||
password: string
|
||||
rememberMe?: boolean
|
||||
rememberMe: boolean
|
||||
socialType?: 'qq' | 'weixin' | 'fingerprint'
|
||||
}
|
||||
|
||||
export default function AuthLogin() {
|
||||
const toast = useToast()
|
||||
|
||||
const [form, setForm] = useState<LoginForm>({
|
||||
username: '',
|
||||
password: '',
|
||||
rememberMe: true,
|
||||
})
|
||||
|
||||
const handleInputChange = (field: keyof LoginForm, value: string) => {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
const defaultLogin = () => {
|
||||
|
||||
// 验证规则
|
||||
const rules = {
|
||||
username: { required: true, message: '账号是必填项' },
|
||||
password: { required: true, message: '密码是必填项' },
|
||||
}
|
||||
|
||||
const { isValid } = useFormValidation(form, rules)
|
||||
|
||||
const loginDefault = () => {
|
||||
alovaInstance.Post('/auth/test', {
|
||||
title: 'foo',
|
||||
body: 'bar',
|
||||
@@ -49,6 +47,16 @@ export default function AuthLogin() {
|
||||
})
|
||||
}
|
||||
|
||||
const loginQq = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
const loginWx = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
const loginZhiwen = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="flex flex-col items-center px-6 h-full">
|
||||
<Image
|
||||
@@ -64,6 +72,7 @@ export default function AuthLogin() {
|
||||
onChange={text => handleInputChange('username', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
|
||||
<AFormItem label="密码">
|
||||
<AInput
|
||||
isPassword
|
||||
@@ -74,45 +83,34 @@ export default function AuthLogin() {
|
||||
</AForm>
|
||||
|
||||
<View className="w-full flex-row justify-between items-center mb-6">
|
||||
<Checkbox
|
||||
value="rememberMe"
|
||||
<ACheckbox
|
||||
isChecked={form.rememberMe}
|
||||
onChange={checked =>
|
||||
setForm(prev => ({ ...prev, rememberMe: checked }))}
|
||||
>
|
||||
<CheckboxIndicator>
|
||||
<CheckboxIcon as={CheckIcon} />
|
||||
</CheckboxIndicator>
|
||||
<CheckboxLabel>记住我</CheckboxLabel>
|
||||
</Checkbox>
|
||||
onChange={checked => setForm(prev => ({ ...prev, rememberMe: checked }))}
|
||||
label="记住我"
|
||||
/>
|
||||
|
||||
<Text className="text-blue-500">
|
||||
忘记密码?
|
||||
</Text>
|
||||
<Text className="text-blue-500">忘记密码?</Text>
|
||||
</View>
|
||||
|
||||
<Button className="w-full" onPress={() => defaultLogin()}>
|
||||
<ButtonText>登录</ButtonText>
|
||||
</Button>
|
||||
<AButton className="w-full" onPress={loginDefault} disabled={!isValid}>
|
||||
登录
|
||||
</AButton>
|
||||
|
||||
<View className="flex-row items-center my-8 w-full">
|
||||
<View className="flex-1">
|
||||
<Divider />
|
||||
</View>
|
||||
|
||||
<Text className="mx-3 text-gray-500 text-sm">社交账号</Text>
|
||||
|
||||
<View className="flex-1">
|
||||
<Divider />
|
||||
</View>
|
||||
</View>
|
||||
|
||||
<View className="w-full flex-row justify-between items-center">
|
||||
<IconQq size={32} />
|
||||
<IconWeixin size={32} />
|
||||
<IconZhiwen size={32} />
|
||||
<IconQq size={32} onPress={loginQq} />
|
||||
<IconWeixin size={32} onPress={loginWx} />
|
||||
<IconZhiwen size={32} onPress={loginZhiwen} />
|
||||
</View>
|
||||
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -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