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

297 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">
<a-form
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">
<div class="flex">
<a-input v-model:value="formState.imgCode" placeholder="请输入图片验证码" autocomplete="off">
2023-01-29 13:44:19 +08:00
<template #prefix>
2024-11-28 17:36:45 +08:00
<fs-icon icon="ion:image-outline"></fs-icon>
2023-01-29 13:44:19 +08:00
</template>
</a-input>
2024-11-28 17:36:45 +08:00
<div class="input-right">
<img class="image-code" :src="imageCodeUrl" @click="resetImageCode" />
</div>
</div>
</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">
<div class="flex">
<a-input v-model:value="formState.smsCode" placeholder="短信验证码">
2023-01-29 13:44:19 +08:00
<template #prefix>
2024-11-28 17:36:45 +08:00
<fs-icon icon="ion:mail-outline"></fs-icon>
2023-01-29 13:44:19 +08:00
</template>
</a-input>
2024-11-28 17:36:45 +08:00
<div class="input-right">
<a-button class="getCaptcha" type="primary" tabindex="-1" :disabled="smsSendBtnDisabled" @click="sendSmsCode">
{{ smsTime <= 0 ? "发送" : smsTime + " s" }}
</a-button>
</div>
</div>
</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>
</a-form-item>
<a-form-item class="user-login-other">
<router-link v-if="sysPublicSettings.registerEnabled" class="register" :to="{ name: 'register' }"> 注册 </router-link>
2023-01-29 13:44:19 +08:00
</a-form-item>
</a-form>
</div>
</template>
<script lang="ts">
2023-01-29 13:44:19 +08:00
import { defineComponent, reactive, ref, toRaw, computed } from "vue";
import { useUserStore } from "/src/store/modules/user";
import { useSettingStore } from "/@/store/modules/settings";
import { utils } from "@fast-crud/fast-crud";
2024-11-28 17:36:45 +08:00
import * as api from "/src/api/modules/api.basic";
import { nanoid } from "nanoid";
import { notification } from "ant-design-vue";
2023-01-29 13:44:19 +08:00
export default defineComponent({
2023-06-28 15:18:36 +08:00
name: "LoginPage",
2023-01-29 13:44:19 +08:00
setup() {
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: "",
randomStr: ""
2023-01-29 13:44:19 +08:00
});
const rules = {
mobile: [
{
required: true,
2024-11-28 17:36:45 +08:00
message: "请输入手机号"
2023-01-29 13:44:19 +08:00
}
],
username: [
{
required: true,
message: "请输入用户名"
}
],
password: [
{
required: true,
message: "请输入登录密码"
}
],
smsCode: [
{
required: true,
message: "请输入短信验证码"
}
]
};
const layout = {
labelCol: {
span: 0
},
wrapperCol: {
span: 24
}
};
const handleFinish = async (values: any) => {
utils.logger.log(values, formState);
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));
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 imageCodeUrl = ref();
function resetImageCode() {
2024-11-28 17:36:45 +08:00
formState.randomStr = nanoid(10);
let url = "/api/basic/code/captcha";
imageCodeUrl.value = url + "?randomStr=" + formState.randomStr;
2023-01-29 13:44:19 +08:00
}
resetImageCode();
const smsTime = ref(0);
const smsSendBtnDisabled = computed(() => {
if (smsTime.value === 0) {
return false;
}
return !!formState.smsCode;
});
2024-11-28 17:36:45 +08:00
async function sendSmsCode() {
if (!formState.mobile) {
notification.error({ message: "请输入手机号" });
return;
}
if (!formState.imgCode) {
notification.error({ message: "请输入图片验证码" });
return;
}
await api.sendSmsCode({
phoneCode: formState.phoneCode,
mobile: formState.mobile,
imgCode: formState.imgCode,
randomStr: formState.randomStr
});
smsTime.value = 60;
setInterval(() => {
smsTime.value--;
}, 1000);
2023-01-29 13:44:19 +08:00
}
const sysPublicSettings = settingStore.getSysPublic;
2023-01-29 13:44:19 +08:00
return {
loading,
formState,
formRef,
rules,
layout,
handleFinishFailed,
handleFinish,
resetForm,
isLoginError,
imageCodeUrl,
resetImageCode,
smsTime,
smsSendBtnDisabled,
sendSmsCode,
sysPublicSettings
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>