You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.1 KiB
34 lines
1.1 KiB
<script setup lang="ts">
|
|
definePageMeta({ layout: false });
|
|
|
|
const auth = useAuth();
|
|
const router = useRouter();
|
|
const route = useRoute();
|
|
const authForm = ref<InstanceType<typeof AuthForm> | null>(null);
|
|
const loading = ref(false);
|
|
|
|
async function handleSubmit(data: { username: string; password: string; captchaToken: string; captchaCode: string }) {
|
|
loading.value = true;
|
|
try {
|
|
const result = await auth.login(data.username, data.password, data.captchaToken, data.captchaCode);
|
|
if (result.success) {
|
|
const redirect = (route.query.redirect as string) || "/";
|
|
router.push(redirect);
|
|
} else {
|
|
authForm.value?.setError(result.message || "登录失败");
|
|
authForm.value?.refreshCaptcha();
|
|
}
|
|
} catch {
|
|
authForm.value?.setError("网络错误,请重试");
|
|
authForm.value?.refreshCaptcha();
|
|
} finally {
|
|
loading.value = false;
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-col items-center justify-center min-h-screen px-5" style="background: #f5f5f7;">
|
|
<AuthForm ref="authForm" mode="login" @submit="handleSubmit" />
|
|
</div>
|
|
</template>
|
|
|