登录添加加载状态

This commit is contained in:
al 2024-12-04 16:55:45 +08:00
parent 08520b0b4f
commit 923bd04f34
2 changed files with 13 additions and 1 deletions
screeens/Login
PasswordLogin
PhoneNumLogin

View File

@ -23,6 +23,7 @@ export default function PasswordLogin() {
const [regionCode, setRegionCode] = useState("86");
const [mobilePhone, setMobilePhone] = useState("");
const [password, setPassword] = useState("");
const [isLoading, setIsLoading] = useState(false);
//
useEffect(() => {
@ -88,6 +89,7 @@ export default function PasswordLogin() {
password: encryptedPassword,
...base,
});
setIsLoading(true);
try {
const response = await fetch(
`${apiUrl}/api/login/login_by_pswd?signature=${signature}`,
@ -111,6 +113,7 @@ export default function PasswordLogin() {
text1: data.msg,
topOffset: 60,
});
setIsLoading(false);
return;
}
//
@ -122,9 +125,11 @@ export default function PasswordLogin() {
account: data.data.account,
login_time: new Date().getTime(),
});
setIsLoading(false);
//
signIn(data, mobilePhone, regionCode);
} catch (error) {
setIsLoading(false);
console.error(error);
}
};
@ -216,6 +221,7 @@ export default function PasswordLogin() {
color="#FF669E"
radius="999"
size="md"
loading={isLoading}
onPress={handleSubmit}
titleStyle={tailwind("text-base font-medium")}
containerStyle={tailwind("mt-2")}

View File

@ -20,7 +20,7 @@ export default function PhoneNumLogin() {
//
const [isCounting, setIsCounting] = useState(false);
const [seconds, setSeconds] = useState(60);
const [isLoading, setIsLoading] = useState(false);
//
const [regionCode, setRegionCode] = useState("86");
const [mobilePhone, setMobilePhone] = useState("");
@ -140,6 +140,7 @@ export default function PhoneNumLogin() {
inviter: inviterCode,
...base,
});
setIsLoading(true);
try {
const response = await fetch(
`${apiUrl}/api/login/login_by_veri_code?signature=${signature}`,
@ -159,6 +160,7 @@ export default function PhoneNumLogin() {
);
const data = await response.json();
if (data.ret === -1) {
setIsLoading(false);
Toast.show({
type: "error",
text1: data.msg,
@ -176,6 +178,7 @@ export default function PhoneNumLogin() {
});
//
if (data.data.is_enabled) {
setIsLoading(false);
signIn(data, mobilePhone, regionCode);
return;
}
@ -184,6 +187,7 @@ export default function PhoneNumLogin() {
await save("account", data.data.account);
await save("mobile_phone", mobile_phone);
await save("region_code", regionCode);
setIsLoading(false);
navigation.navigate("SetPassword", {
data: data,
mobile_phone: mobile_phone,
@ -191,6 +195,7 @@ export default function PhoneNumLogin() {
mobilePhone: mobilePhone,
});
} catch (error) {
setIsLoading(false);
console.error(error);
}
};
@ -287,6 +292,7 @@ export default function PhoneNumLogin() {
color="#FF669E"
radius="999"
size="md"
loading={isLoading}
onPress={handleSubmit}
titleStyle={tailwind("text-base font-medium")}
containerStyle={tailwind("mt-2")}