u
This commit is contained in:
1 parent
5a79414319
commit
8663cb2e3d
28 files changed
+744
-756
No files matched your search
@@ -1,152 +0,0 @@
|
||||
import { useRouter } from 'expo-router'
|
||||
import { useState } from 'react'
|
||||
import { Image, Text, View } from 'react-native'
|
||||
import { AButton, ACheckbox, AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import CustomHeader from '@/components/custom/Header'
|
||||
import { IconQq, IconWeixin, IconZhiwen } from '@/components/iconfont'
|
||||
import { Divider } from '@/components/ui/divider'
|
||||
import useFormValidation from '@/hooks/useFormValidation'
|
||||
import { loginDefaultApi } from '@/request/api/auth'
|
||||
import { useAppStore } from '@/store/app'
|
||||
import { useUserStore } from '@/store/user'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
interface LoginForm {
|
||||
account: string
|
||||
password: string
|
||||
rememberMe: boolean
|
||||
socialType?: 'qq' | 'weixin' | 'fingerprint'
|
||||
}
|
||||
|
||||
export default function AuthLogin() {
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
const appStore = useAppStore()
|
||||
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [form, setForm] = useState<LoginForm>({
|
||||
account: userStore.userInfo?.account || '',
|
||||
password: '',
|
||||
rememberMe: true,
|
||||
})
|
||||
|
||||
const handleInputChange = (field: keyof LoginForm, value: string) => {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
const rules = {
|
||||
account: { required: true, message: '账号是必填项' },
|
||||
password: { required: true, message: '密码是必填项' },
|
||||
}
|
||||
|
||||
const { isValid } = useFormValidation(form, rules)
|
||||
|
||||
const loginDefault = () => {
|
||||
setLoading(true)
|
||||
loginDefaultApi({
|
||||
account: form.account,
|
||||
password: form.password,
|
||||
}).then((res) => {
|
||||
if (res.isSuccess) {
|
||||
toast.show({
|
||||
title: '登录成功',
|
||||
})
|
||||
|
||||
userStore.setUserInfo({
|
||||
account: form.account,
|
||||
id: res.data.userId,
|
||||
seqNo: res.data.seqNo,
|
||||
username: res.data.username,
|
||||
gender: res.data.gender,
|
||||
token: res.data.token,
|
||||
refreshToken: res.data.refreshToken,
|
||||
rememberMe: form.rememberMe,
|
||||
})
|
||||
|
||||
appStore.init()
|
||||
|
||||
router.replace('/money')
|
||||
}
|
||||
else {
|
||||
toast.show({
|
||||
title: res.message || '登录失败',
|
||||
})
|
||||
}
|
||||
}).catch((_err) => {
|
||||
|
||||
}).finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
}
|
||||
|
||||
const loginQq = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
const loginWx = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
const loginZhiwen = () => {
|
||||
toast.show({ title: '功能待开发,请稍等. . .' })
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<CustomHeader title="登录" />
|
||||
<View className="flex flex-col items-center px-6 h-full">
|
||||
<Image
|
||||
source={require('@/static/images/logo.png')}
|
||||
style={{ width: 120, height: 120 }}
|
||||
className="my-12"
|
||||
/>
|
||||
|
||||
<AForm form={form}>
|
||||
<AFormItem label="账号">
|
||||
<AInput
|
||||
value={form.account}
|
||||
onChangeText={text => handleInputChange('account', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
|
||||
<AFormItem label="密码">
|
||||
<AInput
|
||||
isPassword
|
||||
value={form.password}
|
||||
onChangeText={text => handleInputChange('password', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
</AForm>
|
||||
|
||||
<View className="w-full flex-row justify-between items-center mb-6">
|
||||
<ACheckbox
|
||||
isChecked={form.rememberMe}
|
||||
onChange={checked => setForm(prev => ({ ...prev, rememberMe: checked }))}
|
||||
label="记住我"
|
||||
/>
|
||||
|
||||
<Text className="text-blue-500">忘记密码?</Text>
|
||||
</View>
|
||||
|
||||
<AButton className="w-full" onPress={loginDefault} disabled={!isValid} loading={loading}>
|
||||
登录
|
||||
</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} onPress={loginQq} />
|
||||
<IconWeixin size={32} onPress={loginWx} />
|
||||
<IconZhiwen size={32} onPress={loginZhiwen} />
|
||||
</View>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
)
|
||||
}
|
||||
@@ -1,129 +0,0 @@
|
||||
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 { AButton, AForm, AFormItem, AInput } from '@/components/common/ao'
|
||||
import CustomHeader from '@/components/custom/Header'
|
||||
import { registerDefaultApi } from '@/request/api/auth'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
interface RegisterForm {
|
||||
username: string
|
||||
password: string
|
||||
confirmPassword: string
|
||||
}
|
||||
|
||||
export default function AuthRegister() {
|
||||
const router = useRouter()
|
||||
const scrollRef = useRef<ScrollView>(null)
|
||||
|
||||
const [form, setForm] = useState<RegisterForm>({
|
||||
username: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
})
|
||||
const [loading, setLoading] = useState(false)
|
||||
const formRef = useRef<AFormRef>(null)
|
||||
|
||||
const handleInputChange = (field: keyof RegisterForm, value: string) => {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
const handleRegister = async () => {
|
||||
if (formRef.current?.validate()) {
|
||||
setLoading(true)
|
||||
|
||||
await registerDefaultApi({
|
||||
account: form.username,
|
||||
password: form.password,
|
||||
}).then((res) => {
|
||||
if (res.isSuccess) {
|
||||
toast.show({
|
||||
title: '注册成功',
|
||||
})
|
||||
router.replace('/auth/login')
|
||||
}
|
||||
else {
|
||||
toast.show({
|
||||
title: res.message || '注册失败',
|
||||
})
|
||||
}
|
||||
}).catch((_err) => {
|
||||
}).finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<CustomHeader title="注册" />
|
||||
<ScrollView ref={scrollRef} style={{ flex: 1 }}>
|
||||
<View className="flex flex-col items-center px-6 bg-white ">
|
||||
<Image
|
||||
source={require('@/static/images/logo.png')}
|
||||
style={{ width: 120, height: 120 }}
|
||||
className="my-12"
|
||||
/>
|
||||
|
||||
<AForm ref={formRef} form={form} scrollRef={scrollRef}>
|
||||
<AFormItem
|
||||
name="username"
|
||||
label="账号"
|
||||
isRequired
|
||||
>
|
||||
<AInput
|
||||
placeholder="请输入账号"
|
||||
leftIcon={UserRound}
|
||||
value={form.username}
|
||||
onChangeText={text => handleInputChange('username', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
|
||||
<AFormItem
|
||||
name="password"
|
||||
label="密码"
|
||||
isRequired
|
||||
>
|
||||
<AInput
|
||||
placeholder="请输入密码"
|
||||
leftIcon={Lock}
|
||||
isPassword
|
||||
value={form.password}
|
||||
onChangeText={text => handleInputChange('password', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
|
||||
<AFormItem
|
||||
name="confirmPassword"
|
||||
label="确认密码"
|
||||
isRequired
|
||||
rules={[
|
||||
{
|
||||
validator: val => val === form.password,
|
||||
message: '两次密码不一致',
|
||||
},
|
||||
]}
|
||||
>
|
||||
<AInput
|
||||
placeholder="请再次输入密码"
|
||||
leftIcon={Lock}
|
||||
isPassword
|
||||
value={form.confirmPassword}
|
||||
onChangeText={text => handleInputChange('confirmPassword', text)}
|
||||
/>
|
||||
</AFormItem>
|
||||
</AForm>
|
||||
|
||||
<AButton className="w-full mb-4" onPress={handleRegister} loading={loading}>
|
||||
|
||||
注册
|
||||
</AButton>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</View>
|
||||
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user