<template>
|
<div class="login-container">
|
<div class="site-title">
|
<svg-icon icon-class="lock1"></svg-icon>鸿蒙智能电子锁管理平台
|
</div>
|
<div class="img-hm"></div>
|
<div class="login-wrap">
|
<el-form
|
ref="loginFormRef"
|
:model="loginForm"
|
:rules="loginRules"
|
class="login-form"
|
autocomplete="on"
|
label-position="left"
|
>
|
<div class="title-container">
|
<h3 class="title">用户登录</h3>
|
</div>
|
<el-form-item class="input-item" prop="username">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input
|
ref="username"
|
v-model="loginForm.username"
|
placeholder="Username"
|
name="username"
|
type="text"
|
tabindex="1"
|
autocomplete="on"
|
/>
|
</el-form-item>
|
<el-tooltip
|
v-model="capsTooltip"
|
:content="passwordType === 'password' ?'显示密码':'隐藏密码'"
|
placement="right"
|
manual
|
>
|
<el-form-item class="input-item" prop="password">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input
|
:key="passwordType"
|
ref="password"
|
v-model="loginForm.password"
|
:type="passwordType"
|
placeholder="Password"
|
name="password"
|
tabindex="2"
|
autocomplete="on"
|
@keyup="checkCapslock"
|
@blur="capsTooltip = false"
|
@keyup.enter="handleLogin"
|
/>
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon
|
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
/>
|
</span>
|
</el-form-item>
|
</el-tooltip>
|
<el-button
|
:loading="loading"
|
type="primary"
|
style="width:100%; height:50px; margin-bottom:40px;"
|
@click.prevent="handleLogin"
|
>登录</el-button
|
>
|
</el-form>
|
</div>
|
<div class="tools-container">
|
<div
|
class="tools-item"
|
:class="uKeyState"
|
v-if="uKey"
|
@click="uKeyVisible = true"
|
>
|
<span class="ukey"></span>
|
</div>
|
<div class="tools-item" v-if="faceCfg" @click="faceVisible = true">
|
<span class="face"></span>
|
</div>
|
</div>
|
<!-- uKey的验证 -->
|
<el-dialog
|
title="uKey绑定"
|
width="750px"
|
v-model="uKeyVisible"
|
:close-on-click-modal="false"
|
top="0"
|
class="dialog-center"
|
:modal-append-to-body="false"
|
>
|
<ukey-bind v-if="uKeyVisible" v-model:visible="uKeyVisible"></ukey-bind>
|
</el-dialog>
|
|
<!-- 人脸登陆 -->
|
<el-dialog
|
title="人脸登陆"
|
width="480px"
|
v-model="faceVisible"
|
:close-on-click-modal="false"
|
top="0"
|
class="dialog-center"
|
:modal-append-to-body="false"
|
>
|
<face-login v-if="faceVisible"></face-login>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup name="Login">
|
import { ref, computed, reactive, watch, onMounted, nextTick } from 'vue';
|
import { ElMessage } from 'element-plus';
|
|
import { mapState } from 'pinia';
|
import config from '@/utils/config.js';
|
import UkeyBind from './components/UKeyBind/index.vue';
|
import useElement from '@/hooks/useElement.js';
|
import { uKeyLogin } from '@/api/user';
|
import FaceLogin from './components/face/FaceLogin.vue';
|
import { getToken, removeToken, setToken, getUname, setUname, removeUname, getUrole, setUrole, removeUrole } from '@/utils/auth';
|
import { useUserStore } from '@/store/user';
|
import { useSettingsStore } from '@/store/settings';
|
import { useUKeyStore } from '@/store/ukey';
|
import { storeToRefs } from 'pinia';
|
import { useRoute, useRouter } from 'vue-router';
|
|
const route = useRoute();
|
const router = useRouter();
|
|
const userStore = useUserStore();
|
const settingsStore = useSettingsStore();
|
const ukeyStore = useUKeyStore();
|
|
const { isIn, connect, id } = storeToRefs(ukeyStore);
|
const { login } = userStore;
|
const { changeSetting } = settingsStore;
|
|
const { $loading, $confirm, $message } = useElement();
|
const { ukey: _ukey, face } = config;
|
|
const uKeyState = computed(() => {
|
let state = -1;
|
let cls = "state-error";
|
// 设置uKey的状态
|
if (connect.value) {
|
if (isIn.value) {
|
state = 1;
|
} else {
|
state = 0;
|
}
|
} else {
|
state = -1;
|
}
|
// 根据状态确定uKey图表的颜色
|
switch (state) {
|
case 0:
|
cls = "state-default";
|
break;
|
case 1:
|
cls = "";
|
break;
|
default:
|
cls = "state-error";
|
break;
|
}
|
return cls;
|
});
|
|
const validateUsername = (_rule, value, callback) => {
|
if (!value.trim()) {
|
callback(new Error('请输入用户名'));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (_rule, value, callback) => {
|
if (value.length < 1) {
|
callback(new Error('请输入密码,至少1位'));
|
} else {
|
callback();
|
}
|
};
|
|
const uKey = ref(_ukey);
|
const faceCfg = ref(face);
|
|
const uKeyVisible = ref(false);
|
const faceVisible = ref(false);
|
const loginFormRef = ref();
|
const username = ref();
|
const password = ref();
|
const loginForm = reactive({
|
username: '',
|
password: ''
|
});
|
const loginRules = reactive({
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
});
|
|
const passwordType = ref('password');
|
const capsTooltip = ref(false);
|
const loading = ref(false);
|
const showDialog = ref(false);
|
const redirect = ref(undefined);
|
const otherQuery = ref({});
|
|
watch(
|
() => route.path,
|
() => {
|
let query = route.query;
|
if (query) {
|
redirect.value = query.redirect;
|
otherQuery.value = getOtherQuery(query);
|
}
|
},
|
{
|
immediate: true
|
}
|
);
|
|
onMounted(() => {
|
if (loginForm.username === '') {
|
username.value.focus();
|
} else if (loginForm.password === '') {
|
password.value.focus();
|
}
|
themeChange('blue-theme');
|
});
|
|
function themeChange(val) {
|
changeSetting({
|
key: 'theme',
|
value: val
|
});
|
}
|
|
function checkCapslock(e) {
|
const { key } = e;
|
capsTooltip.value = key && key.length === 1 && (key >= 'A' && key <= 'Z');
|
}
|
|
function showPwd() {
|
if (passwordType.value === 'password') {
|
passwordType.value = '';
|
} else {
|
passwordType.value = 'password';
|
}
|
nextTick(() => {
|
password.value.focus();
|
})
|
}
|
|
function handleLogin() {
|
if (uKey.value) {
|
uKeyLoginFn();
|
} else {
|
normalLogin();
|
}
|
}
|
|
function uKeyLoginFn() {
|
if (!connect.value) {
|
$message.error("请先安装uKey客户端服务");
|
return;
|
}
|
if (!isIn.value) {
|
$message.warning("请先插入uKey");
|
return;
|
}
|
// 校验用户
|
if (loginForm.username && loginForm.password) {
|
// 开启等待框
|
loading.value = true;
|
uKeyLogin(
|
loginForm.username,
|
loginForm.password,
|
id.value
|
)
|
.then((res) => {
|
let { code, data, data2, msg } = res;
|
loading.value = false;
|
if (code && data) {
|
setUname(data2.uname);
|
setToken('admin');
|
setUrole(data2.urole);
|
ElMessage({
|
message: msg,
|
type: 'success'
|
});
|
router.push({ path: redirect.value || '/', query: otherQuery.value });
|
} else {
|
ElMessage({
|
message: msg,
|
type: 'error'
|
});
|
}
|
}).catch((error) => {
|
loading.value = false;
|
console.log(error);
|
$message.error("网络异常");
|
})
|
} else {
|
$message.error("用户名或密码不能为空");
|
}
|
}
|
|
function normalLogin() {
|
loginFormRef.value.validate(valid => {
|
return new Promise((resolve, reject) => {
|
if (valid) {
|
loading.value = true;
|
login(loginForm)
|
.then((res) => {
|
loading.value = false;
|
let { code, data, msg } = res;
|
if (code && data) {
|
ElMessage({
|
message: msg,
|
type: 'success'
|
});
|
router.push({ path: redirect.value || '/', query: otherQuery.value });
|
} else {
|
ElMessage({
|
message: msg,
|
type: 'error'
|
});
|
}
|
}).catch((error) => {
|
loading.value = false;
|
console.log('error', error, '=============');
|
|
if (error?.message === 'Network Error') {
|
// 如果是网络错误,显示中文消息
|
ElMessage({
|
message: '网络错误,请检查您的网络连接或服务器状态。',
|
type: 'error'
|
});
|
} else {
|
ElMessage({
|
message: error,
|
type: 'warning'
|
});
|
}
|
}).finally(() => {
|
loading.value = false;
|
resolve();
|
});
|
} else {
|
reject();
|
}
|
})
|
});
|
}
|
|
function getOtherQuery(query) {
|
return Object.keys(query).reduce((acc, cur) => {
|
if (cur !== 'redirect') {
|
acc[cur] = query[cur];
|
}
|
return acc;
|
}, {});
|
}
|
</script>
|
|
<style lang="scss">
|
/* 修复input 背景不协调 和光标变色 */
|
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
|
$bg: #283443;
|
$light_gray: #fff;
|
$cursor: #999;
|
$input_bg: rgba(0, 0, 0, 0.1);
|
$input_color: #000;
|
|
@supports (-webkit-mask: none) and (not (cater-color: $cursor)) {
|
.login-container .el-input input {
|
color: $cursor;
|
}
|
}
|
|
/* reset element-plus css */
|
.login-container {
|
.el-input {
|
height: 47px;
|
width: 85%;
|
|
.el-input__wrapper,
|
input {
|
background: transparent;
|
border: 0px;
|
-webkit-appearance: none;
|
border-radius: 0px;
|
box-shadow: none;
|
}
|
|
input {
|
padding: 12px 5px 12px 15px;
|
color: $input_color;
|
height: 47px;
|
caret-color: $cursor;
|
|
&:-webkit-autofill {
|
box-shadow: 0 0 0px 1000px $input_bg inset !important;
|
-webkit-text-fill-color: $input_color !important;
|
}
|
}
|
}
|
|
.el-form-item {
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
background: rgba(0, 0, 0, 0.1);
|
border-radius: 5px;
|
color: #454545;
|
}
|
}
|
</style>
|
|
<style lang="scss" scoped>
|
$bg: #2d3a4b;
|
$dark_gray: #889aa4;
|
$light_gray: #eee;
|
|
.login-container {
|
min-height: 100%;
|
width: 100%;
|
background-image: url("@/assets/images/login-bg.jpg");
|
background-size: 100% 100%;
|
background-repeat: no-repeat;
|
overflow: hidden;
|
|
.login-wrap {
|
// display: none;
|
position: relative;
|
width: 520px;
|
max-width: 100%;
|
// margin: 260px 10% 0 auto;
|
margin: 260px auto 0;
|
transform: translate(clamp(0px, calc(36vw - 50%), 50vw), 0);
|
padding: 8px;
|
overflow: hidden;
|
// background-color: #1d4167;
|
background: rgba(255, 255, 255, 0.2);
|
border: 2px solid #0d3c68;
|
|
.login-form {
|
background: #fff;
|
padding: 36px 70px 36px;
|
border: 2px solid #064ec3;
|
}
|
.input-item {
|
margin-bottom: 28px;
|
}
|
}
|
|
.site-title {
|
font-size: 30px;
|
font-weight: 700;
|
color: #07fcff;
|
position: absolute;
|
left: 0;
|
top: 12%;
|
transform: translate(clamp(0px, calc(18vw - 50%), 50vw), -50%);
|
}
|
|
.tips {
|
font-size: 14px;
|
color: #fff;
|
margin-bottom: 10px;
|
|
span {
|
&:first-of-type {
|
margin-right: 16px;
|
}
|
}
|
}
|
|
.img-hm {
|
position: absolute;
|
width: clamp(500px, 50vw, 800px);
|
height: clamp(300px, 80vh, 80vh);
|
background: url(@/assets/images/img-hm.png) center center / contain no-repeat;
|
left: 0;
|
top: 20%;
|
transform: translate(clamp(0px, calc(24vw - 50%), 50vw), 0);
|
}
|
|
.svg-container {
|
padding: 6px 5px 6px 15px;
|
color: $dark_gray;
|
vertical-align: middle;
|
width: 30px;
|
display: inline-block;
|
}
|
|
.title-container {
|
position: relative;
|
|
.title {
|
font-size: 18px;
|
color: #0296f3;
|
margin: 0px auto 40px auto;
|
// text-align: center;
|
font-weight: bold;
|
}
|
}
|
|
.show-pwd {
|
position: absolute;
|
right: 10px;
|
top: 7px;
|
font-size: 16px;
|
color: $dark_gray;
|
cursor: pointer;
|
user-select: none;
|
}
|
|
.thirdparty-button {
|
position: absolute;
|
right: 0;
|
bottom: 6px;
|
}
|
|
.tools-container {
|
position: absolute;
|
bottom: 0;
|
right: 0;
|
background-color: #ffffff;
|
}
|
|
.tools-container .tools-item {
|
padding: 8px;
|
width: 40px;
|
height: 40px;
|
cursor: pointer;
|
|
.face {
|
display: inline-block;
|
width: 100%;
|
height: 100%;
|
background: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M161.6 153.1h128.7V73.3H99.7c-8.3 0-15.1 6.7-15.1 15.1V286h76.9V153.1z m692.7 132.8h76.9V88.3c0-8.3-6.7-15.1-15.1-15.1H725.9V153h128.3v132.9zM605 449.2s140.1 88.3 161.6 22.2c0-148.1-115.8-268-258.5-268s-258.5 119.9-258.5 268C386.9 521.9 605 449.2 605 449.2z m161.6 134.1h-43.2s1 59.4-53.8 78C668.4 693.9 615 829 508.7 829c-106.2 0-160.9-135.1-162.2-167.7-55-18.9-52.5-78-52.5-78h-44.5s-1.6 78 64.6 100.6c1.6 38.2 66.2 189.9 193.9 189.9s192.6-151.4 193.9-189.9c66.3-22.5 64.7-100.6 64.7-100.6zM161.9 738.1H84.6v197.6c0 8.3 6.7 15.1 15.1 15.1h190.2V871h-128V738.1z m692.4 132.8H725.9v79.8h190.2c8.3 0 15.1-6.7 15.1-15.1V738.1h-76.9v132.8zM945 520H79c-8.2 0-15 6.7-15 15v2.2c0 8.2 6.7 15 15 15h866c8.2 0 15-6.7 15-15V535c0-8.3-6.7-15-15-15z' fill='%23333333'%3e%3c/path%3e%3c/svg%3e") center center / contain no-repeat;
|
}
|
|
.ukey {
|
display: inline-block;
|
width: 100%;
|
height: 100%;
|
background: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%230000ff'%3e%3c/path%3e%3c/svg%3e") center center / contain no-repeat;
|
}
|
|
&.state-default .ukey {
|
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%23808080'%3e%3c/path%3e%3c/svg%3e")
|
}
|
|
&.state-error .ukey {
|
background-image: url("data:image/svg+xml,%3csvg viewBox='0 0 1024 1024' version='1.1' xmlns='http://www.w3.org/2000/svg' %3e%3cpath d='M456.26 247.11a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m160 0a8 8 0 0 1 8 7.75v48.25a8 8 0 0 1-7.75 8h-48.25a8 8 0 0 1-8-7.75v-48.25a8 8 0 0 1 7.76-8h48.24z m72-64h-352v248h352z m79.9 357.5h-53.7a8 8 0 0 0-6.6 3.5l-81 118.2a157.35 157.35 0 0 0-8.2 15.6h-0.9v-129.2a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v274.4a8 8 0 0 0 8 8h45.9a8 8 0 0 0 8-8V689h0.9a90.25 90.25 0 0 0 7.7 15.2L712 827.71a8.19 8.19 0 0 0 6.6 3.4h58.3a7.84 7.84 0 0 0 4.7-1.6 8 8 0 0 0 1.7-11.2l-103-139.1 94.3-125.8a8.37 8.37 0 0 0 1.6-4.8 8 8 0 0 0-8.04-8z m-459.3 0.1h-46.1a8 8 0 0 0-8 8v160.8q0 126.6 116.6 126.6 120.9 0 120.8-129.9v-157.5a8 8 0 0 0-8-8h-45.9a8 8 0 0 0-8 8v164q0 69.9-56.2 69.9-57.15 0-57.2-72.6v-161.3a8 8 0 0 0-8-8z m419.4-429.6a32 32 0 0 1 32 31.47v288.53c65.54 0 118.93 51.06 120 114.09v357.91a8 8 0 0 1-7.75 8H152.26a8 8 0 0 1-8-7.75V547.11c0-63.26 52.73-115 118-116h2v-288a32 32 0 0 1 31.47-32h432.53z' fill='%23ff0000'%3e%3c/path%3e%3c/svg%3e");
|
}
|
}
|
|
.tools-container .tools-item:hover {
|
background-color: #e4e4e4;
|
}
|
|
.tools-container .iconfont {
|
font-size: 22px;
|
color: #0080ff;
|
}
|
|
.tools-container .state-default .iconfont {
|
color: #808080;
|
}
|
|
.tools-container .state-error .iconfont {
|
color: #ff0000;
|
}
|
|
:deep(.dialog-center) {
|
box-sizing: content-box;
|
}
|
|
|
@media only screen and (max-width: 470px) {
|
.thirdparty-button {
|
display: none;
|
}
|
}
|
}
|
</style>
|