<template>
|
<div class="login-container">
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" autocomplete="on"
|
label-position="left">
|
|
<div class="title-container">
|
<h3 class="title">鸿蒙智能电子锁管理平台</h3>
|
</div>
|
|
<el-form-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 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%;margin-bottom:40px;"
|
@click.prevent="handleLogin">登录</el-button>
|
</el-form>
|
<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 lang="ts">
|
import { defineComponent } from 'vue';
|
import { ElMessage, type FormItemRule } from 'element-plus';
|
import type { IForm } from '@/types/element-plus';
|
import store from '@/store';
|
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';
|
|
const { $loading, $confirm, $message } = useElement();
|
const { ukey, face } = config;
|
|
interface QueryType {
|
// 自定义key 任意字符串
|
[propname: string]: string
|
}
|
|
export default defineComponent({
|
name: 'Login',
|
data() {
|
const validateUsername: FormItemRule['validator'] = (_rule, value, callback) => {
|
if (!value.trim()) {
|
callback(new Error('请输入用户名'));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword: FormItemRule['validator'] = (_rule, value, callback) => {
|
if (value.length < 1) {
|
callback(new Error('请输入密码,至少1位'));
|
} else {
|
callback();
|
}
|
};
|
return {
|
uKey: ukey,
|
faceCfg: face,
|
uKeyVisible: false,
|
faceVisible: false,
|
loginForm: {
|
username: '',
|
password: ''
|
},
|
loginRules: {
|
username: [{ required: true, trigger: 'blur', validator: validateUsername }],
|
password: [{ required: true, trigger: 'blur', validator: validatePassword }]
|
},
|
passwordType: 'password',
|
capsTooltip: false,
|
loading: false,
|
showDialog: false,
|
redirect: undefined,
|
otherQuery: {}
|
};
|
},
|
components: {
|
UkeyBind,
|
FaceLogin,
|
},
|
computed: {
|
|
uKeyState() {
|
let state = -1;
|
let uKey = store.ukey();
|
let cls = "state-error";
|
// 设置uKey的状态
|
if (uKey.connect) {
|
if (uKey.isIn) {
|
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;
|
},
|
...mapState(store.ukey, ['isIn', 'connect', 'id'])
|
},
|
watch: {
|
$route: {
|
handler: function (route) {
|
const query = route.query;
|
if (query) {
|
this.redirect = query.redirect;
|
this.otherQuery = this.getOtherQuery(query);
|
}
|
},
|
immediate: true
|
}
|
},
|
created() {
|
// window.addEventListener('storage', this.afterQRScan)
|
},
|
mounted() {
|
if (this.loginForm.username === '') {
|
(this.$refs.username as HTMLElement).focus();
|
} else if (this.loginForm.password === '') {
|
(this.$refs.password as HTMLElement).focus();
|
}
|
this.themeChange('blue-theme');
|
},
|
unmounted() {
|
// window.removeEventListener('storage', this.afterQRScan)
|
},
|
methods: {
|
themeChange(val) {
|
store.settings().changeSetting({
|
key: 'theme',
|
value: val
|
});
|
},
|
checkCapslock(e) {
|
const { key } = e;
|
this.capsTooltip = key && key.length === 1 && (key >= 'A' && key <= 'Z');
|
},
|
showPwd() {
|
if (this.passwordType === 'password') {
|
this.passwordType = '';
|
} else {
|
this.passwordType = 'password';
|
}
|
this.$nextTick(() => {
|
(this.$refs.password as HTMLElement).focus();
|
});
|
},
|
handleLogin() {
|
if (ukey) {
|
this.uKeyLoginFn();
|
} else {
|
this.normalLogin();
|
}
|
},
|
uKeyLoginFn() {
|
//
|
if (!this.connect) {
|
$message.error("请先安装uKey客户端服务");
|
return;
|
}
|
if (!this.isIn) {
|
$message.warning("请先插入uKey");
|
return;
|
}
|
|
// 校验用户
|
if (this.loginForm.username && this.loginForm.password) {
|
// 开启等待框
|
this.loading = true;
|
uKeyLogin(
|
this.loginForm.username,
|
this.loginForm.password,
|
this.id
|
)
|
.then((res) => {
|
// 对结果进行处理
|
console.log('res', res, '=============');
|
let { code, data, data2, msg } = res;
|
this.loading = false;
|
if (code && data) {
|
setUname(data2.uname);
|
setToken('admin');
|
setUrole(data2.urole);
|
ElMessage({
|
message: msg,
|
type: 'success'
|
});
|
this.$router.push({ path: this.redirect || '/', query: this.otherQuery });
|
} else {
|
ElMessage({
|
message: msg,
|
type: 'error'
|
});
|
}
|
|
})
|
.catch((error) => {
|
// 关闭等待
|
this.loading = false;
|
console.log(error);
|
$message.error("网络异常");
|
});
|
} else {
|
$message.error("用户名或密码不能为空");
|
}
|
},
|
normalLogin() {
|
(this.$refs.loginForm as IForm).validate(valid => {
|
return new Promise((resolve, reject) => {
|
if (valid) {
|
this.loading = true;
|
store.user().login(this.loginForm)
|
.then((res) => {
|
this.loading = false;
|
let { code, data, msg } = res;
|
if (code && data) {
|
ElMessage({
|
message: msg,
|
type: 'success'
|
});
|
this.$router.push({ path: this.redirect || '/', query: this.otherQuery });
|
} else {
|
ElMessage({
|
message: msg,
|
type: 'error'
|
});
|
}
|
}).catch((error) => {
|
this.loading = false;
|
// 请求失败,处理错误
|
if (error.message === 'Network Error') {
|
// 如果是网络错误,显示中文消息
|
ElMessage({
|
message: '网络错误,请检查您的网络连接或服务器状态。',
|
type: 'error'
|
});
|
} else {
|
// 其他类型的错误,可以根据需要处理
|
ElMessage({
|
message: error,
|
type: 'warning'
|
});
|
}
|
}).finally(() => {
|
resolve();
|
});
|
} else {
|
console.log('error submit!!');
|
reject();
|
}
|
});
|
});
|
},
|
getOtherQuery(query: QueryType) {
|
return Object.keys(query).reduce((acc: QueryType, cur) => {
|
if (cur !== 'redirect') {
|
acc[cur] = query[cur];
|
}
|
return acc;
|
}, {});
|
}
|
// afterQRScan() {
|
// if (e.key === 'x-admin-oauth-code') {
|
// const code = getQueryObject(e.newValue)
|
// const codeMap = {
|
// wechat: 'code',
|
// tencent: 'code'
|
// }
|
// const type = codeMap[this.auth_type]
|
// const codeName = code[type]
|
// if (codeName) {
|
// store.user().LoginByThirdparty(codeName).then(() => {
|
// this.$router.push({ path: this.redirect || '/' })
|
// })
|
// } else {
|
// alert('第三方登录失败')
|
// }
|
// }
|
// }
|
}
|
});
|
</script>
|
|
<style lang="scss">
|
/* 修复input 背景不协调 和光标变色 */
|
/* Detail see https://github.com/PanJiaChen/vue-element-admin/pull/927 */
|
|
$bg: #283443;
|
$light_gray: #fff;
|
$cursor: #fff;
|
|
@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: $light_gray;
|
height: 47px;
|
caret-color: $cursor;
|
|
&:-webkit-autofill {
|
box-shadow: 0 0 0px 1000px $bg inset !important;
|
-webkit-text-fill-color: $cursor !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("./images/login_bg.jpg");
|
background-size: 100% 100%;
|
background-repeat: no-repeat;
|
overflow: hidden;
|
|
.login-form {
|
position: relative;
|
width: 520px;
|
max-width: 100%;
|
padding: 36px 35px 36px;
|
margin: 260px auto 0;
|
overflow: hidden;
|
background-color: #1d4167;
|
}
|
|
.tips {
|
font-size: 14px;
|
color: #fff;
|
margin-bottom: 10px;
|
|
span {
|
&:first-of-type {
|
margin-right: 16px;
|
}
|
}
|
}
|
|
.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: 26px;
|
color: $light_gray;
|
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>
|