<template>
|
<div class="login-container">
|
<div class="login-header">
|
<img src="../assets/login/login-text.png" alt="" />
|
</div>
|
<div class="login-box">
|
<!-- 左侧图片 -->
|
<div class="left-img">
|
<img src="../assets/login/bg.png" alt="" />
|
</div>
|
<!-- 右侧登录 -->
|
<div class="login-formbox">
|
<el-form
|
v-if="show"
|
ref="loginRef"
|
:model="loginForm"
|
:rules="loginRules"
|
class="login-form"
|
>
|
<div class="title">欢迎登录...</div>
|
<div style="color: #666666; font-size: 0.8rem; margin: 0.5rem 0">
|
WELCOME TO LOGIN
|
</div>
|
|
<el-form-item prop="userName">
|
<el-input
|
v-model="loginForm.userName"
|
style="height: 3.13rem"
|
ref="userNameRef"
|
type="text"
|
size="large"
|
autocomplete="off"
|
placeholder="请输入您的登录账号"
|
/>
|
</el-form-item>
|
<el-form-item prop="password">
|
<el-input
|
show-password
|
v-model="loginForm.password"
|
style="height: 3.13rem"
|
type="password"
|
size="large"
|
auto-complete="off"
|
placeholder="请输入密码"
|
>
|
</el-input>
|
</el-form-item>
|
<!-- <el-form-item prop="tenantId">
|
<el-input
|
v-model="loginForm.tenantId"
|
style="height: 3.13rem"
|
ref="tenantId"
|
type="text"
|
size="large"
|
auto-complete="off"
|
placeholder="请输入公司唯一码"
|
/>
|
</el-form-item> -->
|
<el-form-item prop="verificationCode">
|
<div style="display: flex">
|
<el-input
|
v-model="loginForm.verificationCode"
|
size="large"
|
@keyup.enter="handleLogin"
|
style="height: 3.13rem; width: 17.19rem; margin-right: 0.63rem"
|
auto-complete="off"
|
placeholder="验证码"
|
>
|
</el-input>
|
<div class="login-code" style="">
|
<img
|
:src="codeUrl"
|
@click="getCode"
|
style="width: 7.19rem; height: 3.13rem"
|
class="login-code-img"
|
/>
|
</div>
|
</div>
|
</el-form-item>
|
<el-form-item>
|
<el-button
|
:loading="loading"
|
color="#1F63FF"
|
size="large"
|
style="width: 100%; height: 3.13rem"
|
@click.prevent="handleLogin"
|
>
|
<span v-if="!loading">登 录</span>
|
<span v-else>登 录 中...</span>
|
</el-button>
|
<div
|
style="
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
width: 100%;
|
margin-top: 1.25rem;
|
"
|
>
|
<span
|
style="
|
color: #4386ff;
|
border-bottom: 1px solid #4386ff;
|
font-weight: bold;
|
cursor: pointer;
|
font-size: 1rem;
|
"
|
@click="show = false"
|
>人脸识别登录</span
|
>
|
</div>
|
</el-form-item>
|
</el-form>
|
<div class="face-login" v-else>
|
<span style="font-size: 0.88rem; font-weight: bold; color: #333333"
|
>请将脸部正对蓝色显示框内,并保持光线充足</span
|
>
|
<div
|
style="
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
border: 1px solid #4386ff;
|
border-radius: 50%;
|
width: 18.75rem;
|
height: 18.75rem;
|
margin: 2.06rem 0;
|
background-color: #f1fcff;
|
"
|
>
|
<img src="@/assets/login/face.png" alt="" />
|
</div>
|
<el-button type="primary" size="small" style="width: 100%"
|
>开始识别</el-button
|
>
|
<div
|
style="
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
width: 100%;
|
margin-top: 1.25rem;
|
"
|
>
|
<span
|
style="
|
color: #4386ff;
|
border-bottom: 1px solid #4386ff;
|
font-weight: bold;
|
cursor: pointer;
|
font-size: 1rem;
|
"
|
@click="show = true"
|
>账号登录</span
|
>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { getCodeImg, login } from "@/api/login";
|
import { useRouter, useRoute } from "vue-router";
|
import { getCurrentInstance, ref, nextTick, onMounted } from "vue";
|
import { ElMessage } from "element-plus";
|
import store from "@/store";
|
|
const router = useRouter();
|
const route = useRoute();
|
|
const { proxy } = getCurrentInstance();
|
|
const show = ref(true); // 是否显示登录框
|
|
const codeUrl = ref(""); // 验证码
|
const loading = ref(false); // 登录加载状态
|
|
const loginForm = ref({
|
userName: "",
|
password: "",
|
verificationCode: "",
|
UUID: undefined,
|
tenantId: "0",
|
});
|
// tenantId: route.query.tenantId ? route.query.tenantId : "",
|
const loginRules = {
|
userName: [
|
{ required: true, trigger: "blur", message: "请输入您的登录账号" },
|
],
|
password: [{ required: true, trigger: "blur", message: "请输入您的密码" }],
|
verificationCode: [
|
{ required: true, trigger: "blur", message: "请输入验证码" },
|
],
|
// tenantId: [{ required: true, trigger: "blur", message: "请输入公司唯一码" }],
|
};
|
|
function handleLogin() {
|
proxy.$refs.loginRef.validate((valid) => {
|
if (valid) {
|
loading.value = true;
|
login(loginForm.value)
|
.then((res) => {
|
if (res.status) {
|
store.commit("setUserInfo", { ...res.data });
|
router.push({ path: "/" });
|
}
|
})
|
.catch((err) => {
|
loginForm.value.verificationCode = "";
|
getCode();
|
loading.value = false;
|
return proxy.$message.error(res.message);
|
});
|
setTimeout(() => {
|
loading.value = false;
|
}, 1000);
|
}
|
});
|
}
|
|
//获取验证码方法
|
function getCode() {
|
getCodeImg().then((res) => {
|
if (res.Code == 500) {
|
getCode();
|
return;
|
}
|
codeUrl.value = "data:image/gif;base64," + res.img;
|
loginForm.value.UUID = res.uuid;
|
});
|
}
|
//绑定输入框焦点对象
|
const userNameRef = ref();
|
nextTick(() => {
|
userNameRef.value.focus();
|
});
|
|
//获取验证码
|
getCode();
|
</script>
|
|
<style lang="less" scoped>
|
// * {
|
// box-sizing: border-box;
|
// padding: 0;
|
// margin: 0;
|
// }
|
.login-container {
|
width: 100%;
|
min-height: 100vh;
|
display: flex;
|
flex-direction: column;
|
.login-header {
|
display: flex;
|
align-items: center;
|
height: 4.38rem;
|
background-color: #006eff;
|
padding-left: 2.06rem;
|
box-sizing: border-box;
|
img {
|
width: 16rem;
|
height: 3.38rem;
|
}
|
}
|
.login-box {
|
width: 100%;
|
height: calc(100vh - 4.57rem);
|
display: flex;
|
background-color: #f6f7fc;
|
.left-img {
|
width: 100%;
|
height: 100%;
|
img {
|
width: 100%;
|
height: 100%;
|
}
|
}
|
.login-formbox {
|
width: 100%;
|
height: 100%;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
.title {
|
color: rgb(16, 16, 16);
|
font-size: 2rem;
|
font-weight: 600;
|
position: relative;
|
}
|
.title::after {
|
position: absolute;
|
bottom: 0;
|
content: "";
|
display: block;
|
width: 9rem;
|
height: 1rem;
|
background: linear-gradient(to right, #006eff, #ffffff);
|
opacity: 0.5;
|
}
|
}
|
.face-login {
|
display: flex;
|
flex-direction: column;
|
}
|
}
|
}
|
</style>
|