311 lines
9.0 KiB
Python
311 lines
9.0 KiB
Python
<template>
|
||
<div class="login">
|
||
<div class="login-form" style="display: flex;justify-content: space-between">
|
||
<div style="width: 250px;border-right: 1px dashed #409EFF;">
|
||
<img src="./../../assets/face.png" style="margin-top: 65px;" @click="takePhoto()">
|
||
</div>
|
||
<div style="width: 360px;">
|
||
<h3 class="title">航玻生产管理系统</h3>
|
||
<el-tabs v-model="activeName" :stretch="true">
|
||
<el-tab-pane label="账号密码登录">
|
||
<el-form
|
||
ref="loginForm"
|
||
:model="loginForm"
|
||
:rules="loginRules"
|
||
>
|
||
<el-form-item prop="username">
|
||
<el-input
|
||
ref="username"
|
||
v-model="loginForm.username"
|
||
placeholder="账号"
|
||
name="username"
|
||
type="text"
|
||
tabindex="1"
|
||
auto-complete="on"
|
||
><svg-icon
|
||
slot="prefix"
|
||
icon-class="user"
|
||
class="el-input__icon input-icon"
|
||
/></el-input>
|
||
</el-form-item>
|
||
|
||
<el-form-item prop="password">
|
||
<el-input
|
||
:key="passwordType"
|
||
ref="password"
|
||
v-model="loginForm.password"
|
||
:type="passwordType"
|
||
placeholder="密码"
|
||
name="password"
|
||
tabindex="2"
|
||
auto-complete="on"
|
||
id="passwordInput"
|
||
@keyup.enter.native="handleLogin"
|
||
><svg-icon
|
||
slot="prefix"
|
||
icon-class="password"
|
||
class="el-input__icon input-icon"
|
||
/></el-input>
|
||
<span class="show-pwd" @click="showPwd">
|
||
<svg-icon
|
||
:icon-class="passwordType === 'password' ? 'eye' : 'eye-open'"
|
||
/>
|
||
</span>
|
||
</el-form-item>
|
||
<el-button
|
||
:loading="loading"
|
||
type="primary"
|
||
style="width: 100%; margin-bottom: 30px"
|
||
@click.native.prevent="handleLogin"
|
||
>登录</el-button
|
||
>
|
||
</el-form>
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</div>
|
||
</div>
|
||
<el-dialog :visible.sync="limitedPhoto" @close="closeCamera">
|
||
<div style="font-size: 28px;color: #333333;text-align: center;font-weight: bold;margin-bottom: 15px;">打卡</div>
|
||
<div class="testTracking">
|
||
<faceLogin ref="faceTracking" name="faceLogin" @func="getMsgFormSon"></faceLogin>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import faceLogin from '@/components/faceLogin/tracking.vue'
|
||
export default {
|
||
name: "Login",
|
||
components:{
|
||
faceLogin
|
||
},
|
||
data() {
|
||
// const validateUsername = (rule, value, callback) => {
|
||
// if (!validUsername(value)) {
|
||
// callback(new Error('请输入正确账号!'))
|
||
// } else {
|
||
// callback()
|
||
// }
|
||
// }
|
||
const validatePassword = (rule, value, callback) => {
|
||
if (value.length < 4) {
|
||
callback(new Error("密码长度小于4位!"));
|
||
} else {
|
||
callback();
|
||
}
|
||
};
|
||
return {
|
||
timer: null,
|
||
buttonmsg: "发送验证码",
|
||
count: 60,
|
||
loginForm: {
|
||
username: "",
|
||
password: "",
|
||
},
|
||
loginRules: {
|
||
username: [{ required: true, trigger: "blur", message: "请输入账户" }],
|
||
password: [
|
||
{
|
||
required: true,
|
||
trigger: "blur",
|
||
validator: validatePassword,
|
||
message: "请输入密码",
|
||
},
|
||
],
|
||
},
|
||
|
||
|
||
activeName: "",
|
||
loading: false,
|
||
passwordType: "password",
|
||
redirect: undefined,
|
||
limitedPhoto: false,
|
||
};
|
||
},
|
||
created() {
|
||
this.getUP();
|
||
},
|
||
watch: {
|
||
$route: {
|
||
handler: function (route) {
|
||
this.redirect = route.query && route.query.redirect;
|
||
},
|
||
immediate: true,
|
||
},
|
||
},
|
||
methods: {
|
||
showPwd() {
|
||
if (this.passwordType === "password") {
|
||
this.passwordType = "";
|
||
} else {
|
||
this.passwordType = "password";
|
||
}
|
||
this.$nextTick(() => {
|
||
this.$refs.password.focus();
|
||
});
|
||
},
|
||
|
||
handleLogin() {
|
||
this.$refs.loginForm.validate((valid) => {
|
||
if (valid) {
|
||
this.loading = true;
|
||
this.$store
|
||
.dispatch("user/login", this.loginForm)
|
||
.then(() => {
|
||
this.$store.dispatch("user/getCount", {})
|
||
this.$router.push({ path: this.redirect || "/" });
|
||
this.loading = false;
|
||
localStorage.setItem("rem_username", this.loginForm.username);
|
||
localStorage.setItem("rem_password", this.loginForm.password);
|
||
})
|
||
.catch(() => {
|
||
this.loading = false;
|
||
});
|
||
|
||
} else {
|
||
console.log("error submit!!");
|
||
return false;
|
||
}
|
||
});
|
||
},
|
||
|
||
//读取cookie
|
||
getUP() {
|
||
|
||
this.loginForm.username = localStorage.getItem("rem_username");
|
||
this.loginForm.password = localStorage.getItem("rem_password");
|
||
},
|
||
//人脸登录
|
||
takePhoto(){
|
||
this.limitedPhoto = true;
|
||
this.openTheCamera();
|
||
},
|
||
/*打开相机*/
|
||
openTheCamera () {
|
||
this.$nextTick(function () {
|
||
let _this = this;
|
||
this.thisVideo = document.getElementById('videoCamera');
|
||
// 旧版本浏览器可能根本不支持mediaDevices,我们首先设置一个空对象
|
||
if (navigator.mediaDevices === undefined) {
|
||
navigator.mediaDevices = {}
|
||
}
|
||
// 一些浏览器实现了部分mediaDevices,我们不能只分配一个对象
|
||
// 使用getUserMedia,因为它会覆盖现有的属性。
|
||
// 这里,如果缺少getUserMedia属性,就添加它。
|
||
if (navigator.mediaDevices.getUserMedia === undefined) {
|
||
navigator.mediaDevices.getUserMedia = function (constraints) {
|
||
// 首先获取现存的getUserMedia(如果存在)
|
||
let getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.getUserMedia;
|
||
// 有些浏览器不支持,会返回错误信息
|
||
// 保持接口一致
|
||
if (!getUserMedia) {
|
||
return Promise.reject(new Error('getUserMedia is not implemented in this browser'))
|
||
}
|
||
// 否则,使用Promise将调用包装到旧的navigator.getUserMedia
|
||
return new Promise(function (resolve, reject) {
|
||
getUserMedia.call(navigator, constraints, resolve, reject)
|
||
})
|
||
}
|
||
}
|
||
|
||
let constraints = { audio: false, video: { width: this.videoWidth, height: this.videoHeight, transform: 'scaleX(-1)' } };
|
||
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
|
||
// 旧的浏览器可能没有srcObject
|
||
if ('srcObject' in _this.thisVideo) {
|
||
_this.thisVideo.srcObject = stream
|
||
} else {
|
||
// 避免在新的浏览器中使用它,因为它正在被弃用。
|
||
_this.thisVideo.src = window.URL.createObjectURL(stream)
|
||
}
|
||
_this.thisVideo.onloadedmetadata = function (e) {
|
||
_this.thisVideo.play();
|
||
}
|
||
}).catch(err => {
|
||
console.log(err)
|
||
})
|
||
});
|
||
},
|
||
/*关闭相机*/
|
||
closeCamera () {
|
||
debugger;
|
||
this.$refs.faceTracking.closeCamera();
|
||
// this.thisVideo.srcObject.getTracks()[0].stop();
|
||
},
|
||
getMsgFormSon(data){
|
||
// this.limitedPhoto = data;
|
||
},
|
||
},
|
||
};
|
||
</script>
|
||
|
||
<style lang="scss">
|
||
.login {
|
||
display: flex;
|
||
justify-content: center;
|
||
align-items: center;
|
||
height: 100%;
|
||
background-image: url("../../assets/beijing.jpg");
|
||
background-size: cover;
|
||
}
|
||
.title {
|
||
margin: 30px auto 30px auto;
|
||
text-align: center;
|
||
color: #0174d7;
|
||
}
|
||
.logo {
|
||
width: 350px;
|
||
height: 140px;
|
||
}
|
||
|
||
.login-form {
|
||
border-radius: 6px;
|
||
background: #ffffff;
|
||
width: 700px;
|
||
padding: 25px;
|
||
.el-input {
|
||
height: 45px;
|
||
input {
|
||
height: 45px;
|
||
}
|
||
}
|
||
.input-icon {
|
||
height: 39px;
|
||
width: 14px;
|
||
margin-left: 2px;
|
||
}
|
||
}
|
||
#passwordInput{
|
||
padding-right: 35px;
|
||
}
|
||
.show-pwd {
|
||
height: 39px;
|
||
margin-right: 2px;
|
||
}
|
||
.login-tip {
|
||
font-size: 13px;
|
||
text-align: center;
|
||
color: #bfbfbf;
|
||
}
|
||
.login-code {
|
||
width: 33%;
|
||
height: 38px;
|
||
float: right;
|
||
img {
|
||
cursor: pointer;
|
||
vertical-align: middle;
|
||
}
|
||
}
|
||
.show-pwd {
|
||
position: absolute;
|
||
right: 10px;
|
||
top: 7px;
|
||
font-size: 16px;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
}
|
||
.login-code-img {
|
||
height: 38px;
|
||
}
|
||
</style>
|