2020-10-10 17:33:29 +08:00
|
|
|
<template>
|
|
|
|
<div class="login" id="login">
|
2021-04-15 17:48:52 +08:00
|
|
|
<div class="limiter">
|
|
|
|
<div class="container-login100">
|
|
|
|
<div class="wrap-login100">
|
|
|
|
<span class="login100-form-title p-b-26">WVP视频平台</span>
|
|
|
|
<span class="login100-form-title p-b-48">
|
|
|
|
<i class="fa fa-video-camera"></i>
|
|
|
|
</span>
|
2020-10-10 17:33:29 +08:00
|
|
|
|
2021-04-15 17:48:52 +08:00
|
|
|
<div class="wrap-input100 validate-input" data-validate = "Valid email is: a@b.c">
|
|
|
|
<input :class="'input100 ' + (username==''?'':'has-val')" type="text" v-model="username" name="username">
|
|
|
|
<span class="focus-input100" data-placeholder="用户名"></span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="wrap-input100 validate-input" data-validate="Enter password">
|
|
|
|
<span class="btn-show-pass">
|
|
|
|
<i :class="'fa ' + (!showPassword?'fa-eye':'fa-eye-slash')" @click="showPassword = !showPassword"></i>
|
|
|
|
</span>
|
|
|
|
<input :class="'input100 ' + (password==''?'':'has-val')" :type="(!showPassword?'password':'text')" v-model="password" name="password">
|
|
|
|
<span class="focus-input100" data-placeholder="密码"></span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="container-login100-form-btn">
|
2021-08-31 09:44:19 +08:00
|
|
|
<div class="wrap-login100-form-btn" :class="{'login-loading': isLoging}" v-loading="isLoging" element-loading-background="rgb(0 0 0 / 0%);" element-loading-custom-class="login-loading-class">
|
2021-04-15 17:48:52 +08:00
|
|
|
<div class="login100-form-bgbtn"></div>
|
|
|
|
<button class="login100-form-btn" @click="login">登录</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-10-10 17:33:29 +08:00
|
|
|
</div>
|
2021-04-15 17:48:52 +08:00
|
|
|
</div>
|
2020-10-10 17:33:29 +08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-01-13 18:10:26 +08:00
|
|
|
import crypto from 'crypto'
|
2020-10-10 17:33:29 +08:00
|
|
|
export default {
|
|
|
|
name: 'Login',
|
|
|
|
data(){
|
|
|
|
return {
|
|
|
|
isLoging: false,
|
2021-04-15 17:48:52 +08:00
|
|
|
showPassword: false,
|
2021-08-31 09:44:19 +08:00
|
|
|
loginLoading: false,
|
2020-10-10 17:33:29 +08:00
|
|
|
username: '',
|
|
|
|
password: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created(){
|
2021-01-28 14:26:48 +08:00
|
|
|
var that = this;
|
|
|
|
document.onkeydown = function(e) {
|
|
|
|
var key = window.event.keyCode;
|
|
|
|
if (key == 13) {
|
|
|
|
that.login();
|
|
|
|
}
|
2020-10-10 17:33:29 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods:{
|
|
|
|
|
|
|
|
//登录逻辑
|
|
|
|
login(){
|
|
|
|
if(this.username!='' && this.password!=''){
|
|
|
|
this.toLogin();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
//登录请求
|
|
|
|
toLogin(){
|
|
|
|
|
|
|
|
//一般要跟后端了解密码的加密规则
|
|
|
|
//这里例子用的哈希算法来自./js/sha1.min.js
|
|
|
|
|
|
|
|
//需要想后端发送的登录参数
|
|
|
|
let loginParam = {
|
|
|
|
username: this.username,
|
2021-01-13 18:10:26 +08:00
|
|
|
password: crypto.createHash('md5').update(this.password, "utf8").digest('hex')
|
2020-10-10 17:33:29 +08:00
|
|
|
}
|
|
|
|
var that = this;
|
|
|
|
//设置在登录状态
|
|
|
|
this.isLoging = true;
|
|
|
|
|
2021-04-12 16:04:04 +08:00
|
|
|
this.$axios({
|
2021-04-13 10:13:36 +08:00
|
|
|
method: 'get',
|
2021-06-22 11:57:46 +08:00
|
|
|
url:"/api/user/login",
|
2021-04-13 10:13:36 +08:00
|
|
|
params: loginParam
|
2021-04-12 16:04:04 +08:00
|
|
|
}).then(function (res) {
|
2020-10-10 17:33:29 +08:00
|
|
|
console.log(JSON.stringify(res));
|
2021-08-08 09:10:58 +08:00
|
|
|
if (res.data.code == 0 && res.data.msg == "success") {
|
2020-10-10 17:33:29 +08:00
|
|
|
that.$cookies.set("session", {"username": that.username}) ;
|
|
|
|
//登录成功后
|
2021-01-28 14:26:48 +08:00
|
|
|
that.cancelEnterkeyDefaultAction();
|
2020-10-10 17:33:29 +08:00
|
|
|
that.$router.push('/');
|
2021-01-13 17:49:19 +08:00
|
|
|
}else{
|
|
|
|
that.isLoging = false;
|
|
|
|
that.$message({
|
|
|
|
showClose: true,
|
|
|
|
message: '登录失败,用户名或密码错误',
|
|
|
|
type: 'error'
|
|
|
|
});
|
2020-10-10 17:33:29 +08:00
|
|
|
}
|
2021-04-12 16:04:04 +08:00
|
|
|
}).catch(function (error) {
|
2021-04-14 16:33:10 +08:00
|
|
|
that.$message.error(error.response.data.msg);
|
2020-10-26 11:40:46 +08:00
|
|
|
that.isLoging = false;
|
2020-10-10 17:33:29 +08:00
|
|
|
});
|
|
|
|
},
|
2021-01-28 14:26:48 +08:00
|
|
|
setCookie: function (cname, cvalue, exdays) {
|
|
|
|
var d = new Date();
|
|
|
|
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
|
|
|
|
var expires = "expires=" + d.toUTCString();
|
|
|
|
console.info(cname + "=" + cvalue + "; " + expires);
|
|
|
|
document.cookie = cname + "=" + cvalue + "; " + expires;
|
|
|
|
console.info(document.cookie);
|
|
|
|
},
|
|
|
|
cancelEnterkeyDefaultAction: function() {
|
|
|
|
document.onkeydown = function(e) {
|
|
|
|
var key = window.event.keyCode;
|
|
|
|
if (key == 13) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-10 17:33:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|