chore: 脚手架
This commit is contained in:
@@ -16,7 +16,6 @@ const loading = ref(false);
|
||||
* @param values 登录表单数据
|
||||
*/
|
||||
async function handleLogin(values: LoginCodeParams) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(values);
|
||||
}
|
||||
</script>
|
||||
|
@@ -9,7 +9,6 @@ defineOptions({ name: 'ForgetPassword' });
|
||||
const loading = ref(false);
|
||||
|
||||
function handleSubmit(value: string) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('reset email:', value);
|
||||
}
|
||||
</script>
|
||||
|
@@ -1,18 +1,91 @@
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { AuthenticationLogin } from '@vben/common-ui';
|
||||
|
||||
import { omit } from 'lodash-es';
|
||||
|
||||
import { tenantList, type TenantResp } from '#/api';
|
||||
import { captchaImage, type CaptchaResponse } from '#/api/core/captcha';
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
defineOptions({ name: 'Login' });
|
||||
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const captchaInfo = ref<CaptchaResponse>({
|
||||
captchaEnabled: false,
|
||||
img: '',
|
||||
uuid: '',
|
||||
});
|
||||
|
||||
async function loadCaptcha() {
|
||||
const resp = await captchaImage();
|
||||
if (resp.captchaEnabled) {
|
||||
resp.img = `data:image/png;base64,${resp.img}`;
|
||||
}
|
||||
captchaInfo.value = resp;
|
||||
}
|
||||
|
||||
const tenantInfo = ref<TenantResp>({
|
||||
tenantEnabled: false,
|
||||
voList: [],
|
||||
});
|
||||
|
||||
async function loadTenant() {
|
||||
const resp = await tenantList();
|
||||
tenantInfo.value = resp;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadCaptcha();
|
||||
loadTenant();
|
||||
});
|
||||
|
||||
interface LoginForm {
|
||||
code?: string;
|
||||
grantType: string;
|
||||
password: string;
|
||||
tenantId: string;
|
||||
username: string;
|
||||
}
|
||||
|
||||
const loginRef = ref<InstanceType<typeof AuthenticationLogin>>();
|
||||
async function handleAccountLogin(values: LoginForm) {
|
||||
try {
|
||||
const requestParam: any = omit(values, ['code']);
|
||||
// 验证码
|
||||
if (captchaInfo.value.captchaEnabled) {
|
||||
requestParam.code = values.code;
|
||||
requestParam.uuid = captchaInfo.value.uuid;
|
||||
}
|
||||
// 登录
|
||||
await authStore.authLogin(requestParam);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
// 处理验证码错误
|
||||
if (error instanceof Error) {
|
||||
const message = error.message;
|
||||
if (message.includes('captcha') || message.includes('验证码')) {
|
||||
// 刷新验证码
|
||||
loginRef.value?.resetCaptcha();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AuthenticationLogin
|
||||
ref="loginRef"
|
||||
:captcha-base64="captchaInfo.img"
|
||||
:loading="authStore.loginLoading"
|
||||
password-placeholder="123456"
|
||||
username-placeholder="vben"
|
||||
@submit="authStore.authLogin"
|
||||
:tenant-options="tenantInfo.voList"
|
||||
:use-captcha="captchaInfo.captchaEnabled"
|
||||
:use-tenant="tenantInfo.tenantEnabled"
|
||||
password-placeholder="密码"
|
||||
username-placeholder="用户名"
|
||||
@captcha-click="loadCaptcha"
|
||||
@submit="handleAccountLogin"
|
||||
/>
|
||||
</template>
|
||||
|
@@ -11,7 +11,6 @@ defineOptions({ name: 'Register' });
|
||||
const loading = ref(false);
|
||||
|
||||
function handleSubmit(value: LoginAndRegisterParams) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('register submit:', value);
|
||||
}
|
||||
</script>
|
||||
|
Reference in New Issue
Block a user