u
This commit is contained in:
1 parent
be8eaae7c5
commit
d6dd5b032d
11 files changed
+202
-112
No files matched your search
@@ -1,10 +1,11 @@
|
||||
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 { IconQq, IconWeixin, IconZhiwen } from '@/components/iconfont'
|
||||
import { Divider } from '@/components/ui/divider'
|
||||
import useFormValidation from '@/hooks/useFormValidation'
|
||||
import alovaInstance from '@/request'
|
||||
import { loginDefaultApi } from '@/request/api/auth'
|
||||
import { toast } from '@/utils/toast'
|
||||
|
||||
interface LoginForm {
|
||||
@@ -15,6 +16,9 @@ interface LoginForm {
|
||||
}
|
||||
|
||||
export default function AuthLogin() {
|
||||
const router = useRouter()
|
||||
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
const [form, setForm] = useState<LoginForm>({
|
||||
username: '',
|
||||
password: '',
|
||||
@@ -25,7 +29,6 @@ export default function AuthLogin() {
|
||||
setForm(prev => ({ ...prev, [field]: value }))
|
||||
}
|
||||
|
||||
// 验证规则
|
||||
const rules = {
|
||||
username: { required: true, message: '账号是必填项' },
|
||||
password: { required: true, message: '密码是必填项' },
|
||||
@@ -34,17 +37,24 @@ export default function AuthLogin() {
|
||||
const { isValid } = useFormValidation(form, rules)
|
||||
|
||||
const loginDefault = () => {
|
||||
alovaInstance.Post('/auth/test', {
|
||||
title: 'foo',
|
||||
body: 'bar',
|
||||
userId: 1,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log('成功返回:', res)
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('请求失败或未授权:', err)
|
||||
})
|
||||
setLoading(true)
|
||||
// loginDefaultApi({
|
||||
// account: form.username,
|
||||
// password: form.password,
|
||||
// }).then((res) => {
|
||||
// if (res.isSuccess) {
|
||||
// router.replace('/')
|
||||
// }
|
||||
// else {
|
||||
// toast.show({
|
||||
// title: res.message || '登录失败',
|
||||
// })
|
||||
// }
|
||||
// }).catch((_err) => {
|
||||
|
||||
// }).finally(() => {
|
||||
// setLoading(false)
|
||||
// })
|
||||
}
|
||||
|
||||
const loginQq = () => {
|
||||
@@ -92,7 +102,7 @@ export default function AuthLogin() {
|
||||
<Text className="text-blue-500">忘记密码?</Text>
|
||||
</View>
|
||||
|
||||
<AButton className="w-full" onPress={loginDefault} disabled={!isValid}>
|
||||
<AButton className="w-full" onPress={loginDefault} disabled={!isValid} loading={loading}>
|
||||
登录
|
||||
</AButton>
|
||||
|
||||
|
||||
@@ -39,11 +39,10 @@ export default function AuthRegister() {
|
||||
password: form.password,
|
||||
}).then((res) => {
|
||||
if (res.isSuccess) {
|
||||
console.log(res)
|
||||
toast.show({
|
||||
title: '注册成功',
|
||||
})
|
||||
// router.replace('/auth/login')
|
||||
router.replace('/auth/login')
|
||||
}
|
||||
else {
|
||||
toast.show({
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
import alovaInstance from '../index'
|
||||
|
||||
const API_PREFIX = '/auth'
|
||||
|
||||
interface RegisterDefaultParams {
|
||||
account: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export function registerDefaultApi(params: RegisterDefaultParams) {
|
||||
return alovaInstance.Post<ResponseData<any>>('/auth/register/default', params)
|
||||
return alovaInstance.Post<ResponseData<any>>(`${API_PREFIX}/register/default`, params)
|
||||
}
|
||||
|
||||
interface LoginDefaultParams {
|
||||
account: string
|
||||
password: string
|
||||
}
|
||||
|
||||
export function loginDefaultApi(params: LoginDefaultParams) {
|
||||
return alovaInstance.Post<ResponseData<any>>(`${API_PREFIX}/login/default`, params)
|
||||
}
|
||||
@@ -30,7 +30,7 @@ function isWhiteListed(url: string) {
|
||||
}
|
||||
|
||||
const alovaInstance = createAlova({
|
||||
baseURL: 'http://192.168.5.6:8085/app',
|
||||
baseURL: 'http://192.168.1.136:8085/app',
|
||||
requestAdapter: axiosRequestAdapter(),
|
||||
timeout: 5000,
|
||||
responded: {
|
||||
|
||||
@@ -28,7 +28,6 @@ const useUserStore = create<UserState>()(
|
||||
),
|
||||
)
|
||||
|
||||
// 在组件外使用
|
||||
const userStore = useUserStore
|
||||
|
||||
export { userStore, useUserStore }
|
||||
Reference in new issue
Block a user