Files
certd/packages/ui/certd-client/src/views/framework/login/index.vue
T

279 lines
8.3 KiB
Vue
Raw Normal View History

2023-01-29 13:44:19 +08:00
<template>
2024-09-22 02:06:34 +08:00
<div class="main login-page">
2025-04-17 22:34:21 +08:00
<a-form v-if="!twoFactor.loginId" ref="formRef" class="user-layout-login" name="custom-validation" :model="formState" v-bind="layout" @finish="handleFinish" @finish-failed="handleFinishFailed">
2023-01-29 13:44:19 +08:00
<!-- <div class="login-title">登录</div>-->
2024-11-28 17:36:45 +08:00
<a-tabs v-model:active-key="formState.loginType" :tab-bar-style="{ textAlign: 'center', borderBottom: 'unset' }">
<a-tab-pane key="password" tab="密码登录" :disabled="sysPublicSettings.passwordLoginEnabled !== true">
<template v-if="formState.loginType === 'password'">
<!-- <div class="login-title">登录</div>-->
<a-form-item required has-feedback name="username" :rules="rules.username">
<a-input v-model:value="formState.username" placeholder="请输入用户名/邮箱/手机号" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="password" :rules="rules.password">
<a-input-password v-model:value="formState.password" placeholder="请输入密码" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input-password>
</a-form-item>
</template>
2023-01-29 13:44:19 +08:00
</a-tab-pane>
2024-11-28 17:36:45 +08:00
<a-tab-pane key="sms" tab="短信验证码登录" :disabled="sysPublicSettings.smsLoginEnabled !== true">
<template v-if="formState.loginType === 'sms'">
<a-form-item has-feedback name="mobile" :rules="rules.mobile">
<a-input v-model:value="formState.mobile" placeholder="请输入手机号" autocomplete="off">
<template #prefix>
<fs-icon icon="ion:phone-portrait-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item has-feedback name="imgCode">
<image-code v-model:value="formState.imgCode" v-model:random-str="formState.randomStr"></image-code>
2024-11-28 17:36:45 +08:00
</a-form-item>
2023-01-29 13:44:19 +08:00
2024-11-28 17:36:45 +08:00
<a-form-item name="smsCode" :rules="rules.smsCode">
2025-04-17 01:15:55 +08:00
<sms-code v-model:value="formState.smsCode" :img-code="formState.imgCode" :mobile="formState.mobile" :phone-code="formState.phoneCode" :random-str="formState.randomStr" />
2024-11-28 17:36:45 +08:00
</a-form-item>
</template>
2023-01-29 13:44:19 +08:00
</a-tab-pane>
</a-tabs>
<a-form-item>
<a-button type="primary" size="large" html-type="submit" :loading="loading" class="login-button">登录</a-button>
2025-05-26 22:50:58 +08:00
<div v-if="!settingStore.isComm" class="mt-2"><a href="https://certd.docmirror.cn/guide/use/forgotpasswd/" target="_blank">忘记管理员密码</a></div>
2023-01-29 13:44:19 +08:00
</a-form-item>
<a-form-item class="user-login-other">
2024-12-01 03:02:59 +08:00
<router-link v-if="hasRegisterTypeEnabled()" class="register" :to="{ name: 'register' }"> 注册 </router-link>
2023-01-29 13:44:19 +08:00
</a-form-item>
</a-form>
2025-04-17 22:34:21 +08:00
<a-form v-else ref="twoFactorFormRef" class="user-layout-login" :model="twoFactor" v-bind="layout">
<div class="mb-10 flex flex-center">请打开您的Authenticator APP获取动态验证码</div>
<a-form-item name="verifyCode">
<a-input ref="verifyCodeInputRef" v-model:value="twoFactor.verifyCode" placeholder="请输入动态验证码" allow-clear @keydown.enter="handleTwoFactorSubmit">
2025-04-17 22:34:21 +08:00
<template #prefix>
<fs-icon icon="ion:lock-closed-outline"></fs-icon>
</template>
</a-input>
</a-form-item>
<a-form-item>
<loading-button type="primary" size="large" html-type="button" class="login-button" :click="handleTwoFactorSubmit">OTP验证登录</loading-button>
</a-form-item>
<a-form-item class="user-login-other">
<a class="register" @click="twoFactor.loginId = null"> 返回 </a>
</a-form-item>
</a-form>
2023-01-29 13:44:19 +08:00
</div>
</template>
<script lang="ts">
import { defineComponent, nextTick, reactive, ref, toRaw } from "vue";
2025-04-12 23:59:03 +08:00
import { useUserStore } from "/src/store/user";
import { useSettingStore } from "/@/store/settings";
import { utils } from "@fast-crud/fast-crud";
import ImageCode from "/@/views/framework/login/image-code.vue";
import SmsCode from "/@/views/framework/login/sms-code.vue";
2023-01-29 13:44:19 +08:00
export default defineComponent({
2023-06-28 15:18:36 +08:00
name: "LoginPage",
components: { SmsCode, ImageCode },
2023-01-29 13:44:19 +08:00
setup() {
const verifyCodeInputRef = ref();
2023-01-29 13:44:19 +08:00
const loading = ref(false);
const userStore = useUserStore();
const settingStore = useSettingStore();
2023-01-29 13:44:19 +08:00
const formRef = ref();
const formState = reactive({
2023-06-28 15:18:36 +08:00
username: "",
2024-11-28 17:36:45 +08:00
phoneCode: "86",
2023-01-29 13:44:19 +08:00
mobile: "",
2023-06-28 15:18:36 +08:00
password: "",
2023-01-29 13:44:19 +08:00
loginType: "password", //password
imgCode: "",
2024-11-28 17:36:45 +08:00
smsCode: "",
2025-04-17 01:15:55 +08:00
randomStr: "",
2023-01-29 13:44:19 +08:00
});
const rules = {
mobile: [
{
required: true,
2025-04-17 01:15:55 +08:00
message: "请输入手机号",
},
2023-01-29 13:44:19 +08:00
],
username: [
{
required: true,
2025-04-17 01:15:55 +08:00
message: "请输入用户名",
},
2023-01-29 13:44:19 +08:00
],
password: [
{
required: true,
2025-04-17 01:15:55 +08:00
message: "请输入登录密码",
},
2023-01-29 13:44:19 +08:00
],
smsCode: [
{
required: true,
2025-04-17 01:15:55 +08:00
message: "请输入短信验证码",
},
],
2023-01-29 13:44:19 +08:00
};
const layout = {
labelCol: {
2025-04-17 01:15:55 +08:00
span: 0,
2023-01-29 13:44:19 +08:00
},
wrapperCol: {
2025-04-17 01:15:55 +08:00
span: 24,
},
2023-01-29 13:44:19 +08:00
};
2025-04-17 22:34:21 +08:00
const twoFactor = reactive({
loginId: "",
verifyCode: "",
});
const handleTwoFactorSubmit = async () => {
await userStore.loginByTwoFactor(twoFactor);
};
const handleFinish = async (values: any) => {
2023-01-29 13:44:19 +08:00
loading.value = true;
try {
2024-11-28 17:36:45 +08:00
const loginType = formState.loginType;
await userStore.login(loginType, toRaw(formState));
2025-04-17 22:34:21 +08:00
} catch (e: any) {
//@ts-ignore
if (e.code === 10020) {
//双重认证
2025-04-17 22:34:21 +08:00
//@ts-ignore
twoFactor.loginId = e.data;
await nextTick();
verifyCodeInputRef.value.focus();
2025-04-17 22:34:21 +08:00
} else {
throw e;
}
2023-01-29 13:44:19 +08:00
} finally {
loading.value = false;
}
};
const handleFinishFailed = (errors: any) => {
utils.logger.log(errors);
2023-01-29 13:44:19 +08:00
};
const resetForm = () => {
formRef.value.resetFields();
};
const isLoginError = ref();
const sysPublicSettings = settingStore.getSysPublic;
2024-12-01 03:02:59 +08:00
function hasRegisterTypeEnabled() {
return sysPublicSettings.registerEnabled && (sysPublicSettings.usernameRegisterEnabled || sysPublicSettings.emailRegisterEnabled);
}
2025-05-26 22:50:58 +08:00
2023-01-29 13:44:19 +08:00
return {
loading,
formState,
formRef,
rules,
layout,
handleFinishFailed,
handleFinish,
resetForm,
isLoginError,
2024-12-01 03:02:59 +08:00
sysPublicSettings,
2025-04-17 01:15:55 +08:00
hasRegisterTypeEnabled,
2025-04-17 22:34:21 +08:00
twoFactor,
handleTwoFactorSubmit,
verifyCodeInputRef,
2025-05-26 22:50:58 +08:00
settingStore,
2023-01-29 13:44:19 +08:00
};
2025-04-17 01:15:55 +08:00
},
2023-01-29 13:44:19 +08:00
});
</script>
<style lang="less">
@import "../../../style/theme/index.less";
2024-09-22 02:06:34 +08:00
.login-page.main {
2024-09-23 14:04:33 +08:00
//margin: 20px !important;
margin-bottom: 100px;
2024-09-22 02:06:34 +08:00
.user-layout-login {
2024-11-28 17:36:45 +08:00
//label {
// font-size: 14px;
//}
2023-01-29 13:44:19 +08:00
2024-09-22 02:06:34 +08:00
.login-title {
color: @primary-color;
font-size: 18px;
text-align: center;
margin: 20px;
}
.getCaptcha {
display: block;
width: 100%;
}
2023-01-29 13:44:19 +08:00
2024-11-28 17:36:45 +08:00
.image-code {
height: 34px;
}
.input-right {
width: 160px;
margin-left: 10px;
}
2024-09-22 02:06:34 +08:00
.forge-password {
font-size: 14px;
}
2023-01-29 13:44:19 +08:00
2024-09-22 02:06:34 +08:00
button.login-button {
padding: 0 15px;
font-size: 16px;
width: 100%;
}
2023-01-29 13:44:19 +08:00
2024-09-22 02:06:34 +08:00
.user-login-other {
text-align: left;
margin-top: 30px;
margin-bottom: 30px;
2024-11-28 17:36:45 +08:00
//line-height: 22px;
2023-01-29 13:44:19 +08:00
2024-09-22 02:06:34 +08:00
.item-icon {
font-size: 24px;
color: rgba(0, 0, 0, 0.2);
margin-left: 16px;
vertical-align: middle;
cursor: pointer;
transition: color 0.3s;
2023-01-29 13:44:19 +08:00
2024-09-22 02:06:34 +08:00
&:hover {
color: @primary-color;
}
2023-01-29 13:44:19 +08:00
}
2024-09-22 02:06:34 +08:00
.register {
float: right;
}
}
2024-11-28 17:36:45 +08:00
.fs-icon {
2024-09-22 02:06:34 +08:00
color: rgba(0, 0, 0, 0.45);
2024-11-28 17:36:45 +08:00
margin-right: 4px;
}
.ant-input-affix-wrapper {
line-height: 1.8 !important;
font-size: 14px !important;
> * {
line-height: 1.8 !important;
font-size: 14px !important;
}
2023-01-29 13:44:19 +08:00
}
}
}
</style>