<template>
|
<div class="login-container">
|
<div class="header">
|
<img :src="iconUrl(basicInfo.icon)" style="height:60px;">
|
<div class="tool">
|
<el-button type="primary" class="btn-current" @click="goLoginPage">{{ $t('forget_pwd.login_header_btn') }}</el-button>
|
<el-button plain @click="goRegPage">{{ $t('forget_pwd.reg') }}</el-button>
|
</div>
|
</div>
|
|
<el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
|
<div class="title-container">
|
<h3 class="title">{{ $t('forget_pwd.title') }}</h3>
|
</div>
|
|
<el-form-item v-if="checkModel=='phone'||checkModel=='email'" prop="username">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input v-model="loginForm.username" :placeholder="$t('forget_pwd.username')" name="username" type="text" auto-complete="new-password" @input="changeCheckType()" />
|
</el-form-item>
|
<!--手机验证表单-->
|
<el-row v-if="checkModel=='phone'" :gutter="10">
|
<el-col :span="16">
|
<el-form-item prop="verificationcode">
|
<span class="svg-container">
|
<i class="el-icon-yrt-dianhua3"></i>
|
</span>
|
<el-input v-model.number="loginForm.verificationcode" :placeholder="$t('forget_pwd.verificationcode')" name="verificationcode" auto-complete="off" @keyup.enter.native="handleLogin" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="8">
|
<el-button plain style="padding:18px 35px;" @click="getPhoneCode">获取验证码</el-button>
|
<el-button v-show="!show" plain style="padding:18px 35px;">{{ count }}s后重发</el-button>
|
</el-col>
|
|
</el-row>
|
|
<el-form-item v-if="checkModel=='phone'||checkModel=='backemail'" prop="password">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input :type="passwordType" v-model="loginForm.password" :placeholder="$t('forget_pwd.password')" name="password" auto-complete="new-password" @keyup.enter.native="handleLogin" />
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon icon-class="eye" />
|
</span>
|
</el-form-item>
|
|
<el-form-item v-if="checkModel=='phone'||checkModel=='backemail'" prop="password_repeat">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input :type="passwordType" v-model="loginForm.password_repeat" :placeholder="$t('forget_pwd.password_repeat')" name="password_repeat" auto-complete="new-password" @keyup.enter.native="handleLogin" />
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon icon-class="eye" />
|
</span>
|
</el-form-item>
|
<!---->
|
<!--邮箱验证表单-->
|
<el-form-item v-if="checkModel=='email'" prop="Emaliverificationcode">
|
<span class="svg-container">
|
<svg-icon icon-class="verification-code" />
|
</span>
|
<el-input v-model.number="loginForm.Emaliverificationcode" :placeholder="$t('login.verificationcode')" name="Emaliverificationcode" auto-complete="off" @keyup.enter.native="handleLogin" />
|
<span class="show-pwd" @click="getVerificationCodeImg">
|
<img ref="codeimg" :src="codeImgData" style="width: 80px;height: 30px;margin-top: 3px;">
|
</span>
|
</el-form-item>
|
<!---->
|
|
<el-button :loading="loading" type="primary" class="btn-login" @click="handleLogin">{{ $t('forget_pwd.logIn_btn') }}</el-button>
|
</el-form>
|
</div>
|
</template>
|
|
<script>
|
import Vue from "vue";
|
import { isvalidUsername } from "@/utils/validate";
|
import LangSelect from "@/components/LangSelect";
|
import SocialSign from "./socialsignin";
|
import common from "@/utils/common";
|
Vue.prototype.common = common;
|
import { mapGetters } from "vuex";
|
|
export default {
|
name: "Login",
|
components: { LangSelect, SocialSign },
|
data() {
|
// 验证规则
|
const validateUsername = (rule, value, callback) => {
|
if (this.checkModel === "phone") {
|
var re = /^1[345789]\d{9}$/;
|
if (re.test(value)) {
|
callback();
|
} else {
|
callback(new Error("手机号格式不正确!"));
|
}
|
} else if (this.checkModel === "email") {
|
re = /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/;
|
if (re.test(value)) {
|
callback();
|
} else {
|
callback(new Error("邮箱格式不正确!"));
|
}
|
}
|
if (isvalidUsername(value)) {
|
callback(new Error("用户名不合法"));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (rule, value, callback) => {
|
if (value.length < 3) {
|
callback(new Error("密码必须大于3位"));
|
} else {
|
callback();
|
}
|
};
|
const validateRepeatPassword = (rule, value, callback) => {
|
if (value.length < 3) {
|
callback(new Error("密码必须大于3位"));
|
} else if (value !== this.loginForm.password) {
|
callback(new Error("两次密码输入不一致"));
|
} else {
|
callback();
|
}
|
};
|
|
return {
|
loginForm: {
|
username: "",
|
password: "",
|
password_repeat: "",
|
verificationcode: "",
|
Emaliverificationcode: ""
|
},
|
loginRules: {
|
username: [{ required: true, trigger: "blur", validator: validateUsername }],
|
password: [{ required: true, trigger: "blur", validator: validatePassword }],
|
password_repeat: [{ required: true, trigger: "blur", validator: validateRepeatPassword }],
|
verificationcode: [
|
{ required: true, trigger: "blur", message: "验证码必填" },
|
{ type: "number", trigger: "blur", message: "验证码不是数字" }
|
],
|
Emaliverificationcode: [
|
{ required: true, trigger: "blur", message: "验证码必填" },
|
{ type: "number", trigger: "blur", message: "验证码不是数字" }
|
]
|
},
|
passwordType: "password",
|
loading: false,
|
showDialog: false,
|
redirect: undefined,
|
codeImgData: null, // 图片数据
|
checkModel: "phone",
|
count: "",
|
show: true,
|
timer: null
|
};
|
},
|
computed: {
|
...mapGetters(["sidebar", "name", "avatar", "device", "basicInfo"])
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
this.redirect = route.query && route.query.redirect;
|
},
|
immediate: true
|
}
|
},
|
mounted() {
|
this.findCheckModel();
|
this.getVerificationCodeImg();
|
},
|
methods: {
|
iconUrl(images) {
|
if (images) {
|
if (images.indexOf("[") >= 0) {
|
const imgs = JSON.parse(images);
|
return imgs[0].src;
|
} else {
|
return images;
|
}
|
}
|
return "";
|
},
|
showPwd() {
|
if (this.passwordType === "password") {
|
this.passwordType = "";
|
} else {
|
this.passwordType = "password";
|
}
|
},
|
// 找回密码
|
handleLogin() {
|
if (this.checkModel === "phone") {
|
var username = this.loginForm.username;
|
var re = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
|
if (!re.test(username)) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "手机格式不正确!"
|
});
|
return;
|
}
|
// 验证码
|
var verificationcode = this.loginForm.verificationcode;
|
if (!verificationcode) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "验证码必填!"
|
});
|
return;
|
}
|
// 密码
|
var password = this.loginForm.password;
|
if (password.length < 3) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "密码必须大于3位!"
|
});
|
return;
|
}
|
|
// 重复密码
|
var password_repeat = this.loginForm.password_repeat;
|
if (password_repeat.length < 3) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "密码必须大于3位!"
|
});
|
return;
|
} else if (password_repeat !== password) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "两次密码不一致!"
|
});
|
return;
|
}
|
|
this.loading = true;
|
var url = "/api/User/PhoneUpdatePwd";
|
var guid = this.common.getUserGuid();
|
var params = {
|
Mobile: username,
|
ValidateCode: verificationcode,
|
UserPwd: password,
|
RepeatPassWord: password,
|
guid: guid
|
};
|
var callback = res => {
|
this.loading = false;
|
|
if (res.result) {
|
this.$notify({
|
title: "成功",
|
message: "密码修改成功,请重新登陆。",
|
type: "success"
|
});
|
window.location.href = "#/login";
|
} else {
|
this.$notify.error({
|
title: "错误提示",
|
message: res.Msg
|
});
|
this.getVerificationCodeImg();
|
}
|
};
|
this.common.ajax(url, params, callback);
|
}
|
},
|
// 登录跳转
|
goLoginPage() {
|
window.location.href = "#/login";
|
},
|
// 注册跳转
|
goRegPage() {
|
window.location.href = "#/reg";
|
},
|
// 切换找回密码模式
|
changeCheckType() {
|
if (this.loginForm.username.indexOf("@") !== -1) {
|
if (this.checkModel !== "email") {
|
this.$message("切换为邮箱验证模式");
|
}
|
this.checkModel = "email";
|
} else {
|
if (this.checkModel !== "phone") {
|
this.$message("切换为手机号验证模式");
|
}
|
this.checkModel = "phone";
|
}
|
},
|
// 获得验证码图片
|
getVerificationCodeImg() {
|
var the = this;
|
var guid = this.common.getUserGuid();
|
var url = "/api/Auth/GetValidateCode";
|
var data = { guid: guid };
|
var callback = function(res, textStatus) {
|
if (res.result) {
|
the.codeImgData = "data:image/png;base64," + res.data;
|
} else {
|
this.$notify.error({
|
title: "错误提示",
|
message: res.Msg
|
});
|
}
|
};
|
|
this.common.ajax(url, data, callback);
|
},
|
// 定义页面类型
|
findCheckModel() {
|
var url = window.location.href;
|
url = url.split("?")[1];
|
if (url) {
|
var strs = url.split("&");
|
if (strs.length === 2) {
|
var emaliAddress = strs[0].split("=")[1];
|
var emaliCheckCode = strs[1].split("=")[1];
|
if (emaliAddress && emaliCheckCode) {
|
this.checkModel = "backemail";
|
this.emaliAddress = emaliAddress;
|
this.emaliCheckCode = emaliCheckCode;
|
}
|
}
|
}
|
},
|
// 获取手机验证码
|
getPhoneCode() {
|
// this.loading = true;
|
var that = this;
|
// var guid = this.common.getUserGuid();
|
var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
|
if (!reg.test(that.loginForm.username)) {
|
this.$notify.error({
|
title: "错误提示",
|
message: "请输入正确的手机号格式!"
|
});
|
return;
|
}
|
|
var url = "/api/User/SendForGetValidateCode";
|
var params = {
|
Mobile: that.loginForm.username
|
};
|
|
var callback = res => {
|
// this.loading = false;
|
if (res.result) {
|
this.$notify({
|
title: "成功",
|
message: "验证码已发送至手机!",
|
type: "success"
|
});
|
|
const TIME_COUNT = 60;
|
if (!this.timer) {
|
this.count = TIME_COUNT;
|
this.show = false;
|
this.timer = setInterval(() => {
|
if (this.count > 0 && this.count <= TIME_COUNT) {
|
this.count--;
|
} else {
|
this.show = true;
|
clearInterval(this.timer);
|
this.timer = null;
|
}
|
}, 1000);
|
}
|
} else {
|
this.$notify.error({
|
title: "错误提示",
|
message: res.Msg
|
});
|
}
|
};
|
this.common.ajax(url, params, callback, true);
|
}
|
}
|
};
|
</script>
|
|
<style rel="stylesheet/scss" lang="scss" scoped>
|
$bg: #fbfbfb;
|
$dark_gray: #889aa4;
|
$light_gray: #666;
|
$cursor: #666;
|
|
.header {
|
background-color: white;
|
position: relative;
|
display: table-cell;
|
display: -webkit-box;
|
-webkit-box-pack: center;
|
-webkit-box-orient: vertical;
|
height: 80px;
|
width: 100%;
|
padding: 10px 30px;
|
.tool {
|
top: 20px;
|
right: 30px;
|
position: absolute;
|
}
|
border-bottom: 1px solid #f3f3f3;
|
}
|
|
/* reset element-ui css */
|
.login-container {
|
/deep/ .el-input {
|
display: inline-block;
|
height: 47px;
|
width: 85%;
|
input {
|
background: transparent;
|
border: 0px;
|
-webkit-appearance: none;
|
border-radius: 0px;
|
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;
|
}
|
}
|
}
|
/deep/ .el-form-item {
|
background: rgba(216, 216, 216, 0.05);
|
border: 1px solid #ddd;
|
border-radius: 4px;
|
|
color: #454545;
|
.el-form-item__content {
|
background-color: $bg;
|
border-radius: 4px;
|
}
|
}
|
}
|
|
.login-container {
|
height: 100%;
|
width: 100%;
|
.login-form {
|
position: absolute;
|
left: 0;
|
right: 0;
|
width: 520px;
|
max-width: 100%;
|
padding: 35px 35px 15px 35px;
|
margin: 120px auto;
|
border: 1px solid #eee;
|
border-radius: 4px;
|
.btn-login {
|
width: 100%;
|
margin-bottom: 30px;
|
height: 46px;
|
}
|
.forget-pwd {
|
padding: 0 10px;
|
text-align: right;
|
a {
|
font-family: PingFangSC-Light;
|
font-size: 14px;
|
color: #0099ff;
|
letter-spacing: 0;
|
&:hover {
|
color: #71c6ff;
|
}
|
}
|
}
|
}
|
.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: #666;
|
margin: 0px auto 40px auto;
|
text-align: center;
|
font-weight: bold;
|
}
|
.set-language {
|
color: #666;
|
position: absolute;
|
top: 5px;
|
right: 0px;
|
}
|
}
|
.show-pwd {
|
position: absolute;
|
right: 10px;
|
top: 7px;
|
font-size: 16px;
|
color: $dark_gray;
|
cursor: pointer;
|
user-select: none;
|
}
|
.thirdparty-button {
|
position: absolute;
|
right: 35px;
|
bottom: 28px;
|
}
|
}
|
</style>
|
|
<style rel="stylesheet/scss" lang="scss">
|
html,
|
body {
|
background-color: #fff;
|
}
|
.vux-divider {
|
white-space: nowrap;
|
width: 100%;
|
text-align: center;
|
padding: 10px 0;
|
color: #666;
|
overflow: hidden;
|
position: relative;
|
.text {
|
display: inline-block;
|
padding: 0 10px;
|
position: relative;
|
z-index: 100;
|
background-color: #fff;
|
}
|
&::before {
|
content: " ";
|
width: 50%;
|
border-top: 1px solid #e4e7ed;
|
height: 1px;
|
display: inline-block;
|
position: absolute;
|
top: 19px;
|
right: 0;
|
}
|
&::after {
|
content: " ";
|
width: 50%;
|
border-top: 1px solid #e4e7ed;
|
height: 1px;
|
display: inline-block;
|
position: absolute;
|
top: 19px;
|
left: 0;
|
}
|
}
|
</style>
|