<template>
|
<div class="login-container">
|
<div class="header">
|
<img :src="basicInfo.icon">
|
<div class="tool">
|
<el-button plain @click="goLoginPage">{{ $t('login.logIn') }}</el-button>
|
<el-button type="primary" class="btn-current" @click="goRegPage">{{ $t('login.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('reg.title') }}</h3>
|
</div>
|
|
<el-form-item prop="username">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input v-model="loginForm.username" :placeholder="$t('login.username')" name="username" type="text" auto-complete="on" />
|
</el-form-item>
|
|
<el-form-item prop="email">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input v-model="loginForm.email" :placeholder="$t('login.email')" name="email" type="text" auto-complete="on" />
|
</el-form-item>
|
|
<el-form-item prop="password">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input :type="passwordType" v-model="loginForm.password" :placeholder="$t('reg.password')" name="password" auto-complete="on" @keyup.enter.native="handleLogin" />
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon icon-class="eye" />
|
</span>
|
</el-form-item>
|
|
<el-form-item>
|
<span class="svg-container">
|
<svg-icon icon-class="verification-code" />
|
</span>
|
<el-popover v-model="visible" placement="bottom" width="320" trigger="manual">
|
<el-input slot="reference" v-model="selectUsertype" :placeholder="$t('reg.usertype')" name="verification" auto-complete="on" @keyup.enter.native="handleLogin" @blur="changeVisible(false)" @focus="changeVisible(true)" @input="searchType()" />
|
<div class="adddiv" @click="addNewType(selectUsertype)"> add {{ selectUsertype }}</div>
|
<ul>
|
<li v-for="item in usertypeOptions" :key="item.value" :label="item.label" :value="item.value" @click="selectOldType(item.label)">{{ item.label }}</li>
|
</ul>
|
</el-popover>
|
</el-form-item>
|
<el-button :loading="loading" type="primary" class="btn-login" @click.native.prevent="handleLogin">{{ $t('login.reg') }}</el-button>
|
<div class="view-license">
|
<el-checkbox v-model="checked">
|
<span class="text">
|
查看并同意我们的<a href="#/reg-service">服务条款</a>和<a href="#/reg-service">隐私权</a>
|
</span>
|
</el-checkbox>
|
</div>
|
</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 (isvalidUsername(value)) {
|
callback(new Error("输入用户名不合法"));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (rule, value, callback) => {
|
if (value.length < 3) {
|
callback(new Error("密码必须大于3位"));
|
} else {
|
callback();
|
}
|
};
|
|
return {
|
loginForm: {
|
username: "",
|
email: "",
|
password: ""
|
},
|
loginRules: {
|
username: [
|
{ required: true, trigger: "blur", validator: validateUsername }
|
],
|
email: [
|
{ required: true, trigger: "blur", message: "email必填" },
|
{ type: "email", trigger: "blur", message: "email格式不正确" }
|
],
|
password: [
|
{ required: true, trigger: "blur", validator: validatePassword }
|
]
|
},
|
passwordType: "password",
|
loading: false,
|
showDialog: false,
|
redirect: undefined,
|
codeImgData: null, // 图片数据
|
checked: false,
|
usertypeOptions: [],
|
selectUsertype: null,
|
UsertypeList: null,
|
addValue: 0, // 添加下拉框
|
visible: false
|
};
|
},
|
computed: {
|
...mapGetters(["sidebar", "name", "avatar", "device", "basicInfo"])
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
this.redirect = route.query && route.query.redirect;
|
},
|
immediate: true
|
}
|
},
|
mounted() {
|
this.getUsertypeOptions();
|
},
|
methods: {
|
showPwd() {
|
if (this.passwordType === "password") {
|
this.passwordType = "";
|
} else {
|
this.passwordType = "password";
|
}
|
},
|
// 注册验证
|
handleLogin() {
|
var the = this;
|
this.$refs.loginForm.validate(valid => {
|
if (!valid) {
|
this.$notify.error({
|
title: "验证消息",
|
message: "校验信息不正确,请正确填写!"
|
});
|
return false;
|
}
|
if (!this.selectUsertype) {
|
this.$notify.error({
|
title: "验证消息",
|
message: "请选择填写用户类型!"
|
});
|
return false;
|
}
|
if (!this.checked) {
|
this.$notify.error({
|
title: "验证消息",
|
message: "请同意服务条款和隐私权!"
|
});
|
return false;
|
}
|
|
this.loading = true;
|
var guid = this.common.getUserGuid();
|
var url = "/api/User/Reg";
|
var selectUsertype = this.selectUsertype;
|
var Usertype_Id = -1;
|
var Usertype = selectUsertype;
|
|
var params = {
|
UserName: the.loginForm.username,
|
UserPwd: the.loginForm.password,
|
Email: the.loginForm.email,
|
UsertypeName: Usertype,
|
Usertype_Id: Usertype_Id,
|
guid: guid
|
};
|
|
var callback = res => {
|
this.loading = false;
|
if (res.Msg) {
|
this.$message(res.Msg);
|
}
|
if (res.result) {
|
window.location.href = "#/login";
|
} else {
|
this.loading = false;
|
}
|
// the.getVerificationCodeImg();
|
};
|
this.common.ajax(url, params, callback);
|
});
|
},
|
// 获取用户类型列表
|
getUsertypeOptions() {
|
this.loading = true;
|
var the = this;
|
var guid = this.common.getUserGuid();
|
var url = "/api/User/GetUserType";
|
var params = {
|
UserName: the.loginForm.username,
|
guid: guid
|
};
|
|
var callback = res => {
|
// console.info(JSON.stringify(res));
|
this.loading = false;
|
if (res.result) {
|
var UsertypeList = res.data;
|
this.UsertypeList = UsertypeList;
|
var optionTree = [];
|
for (var index in UsertypeList) {
|
var UsertypeInfo = UsertypeList[index];
|
var optionNode = {
|
value: UsertypeInfo.Usertype_Id,
|
label: UsertypeInfo.UsertypeName
|
};
|
optionTree.push(optionNode);
|
}
|
this.usertypeOptions = optionTree;
|
} else {
|
this.$message(res.Msg);
|
this.loading = false;
|
}
|
// the.getVerificationCodeImg();
|
};
|
this.common.ajax(url, params, callback);
|
},
|
// 查找类型
|
searchType() {
|
var selectUsertype = this.selectUsertype;
|
var UsertypeList = this.UsertypeList;
|
var TrueUsertypeList = [];
|
for (var index in UsertypeList) {
|
var UsertypeInfo = UsertypeList[index];
|
if (UsertypeInfo.UsertypeName.indexOf(selectUsertype) !== -1) {
|
var optionNode = {
|
value: UsertypeInfo.Usertype_Id,
|
label: UsertypeInfo.UsertypeName
|
};
|
TrueUsertypeList.push(optionNode);
|
}
|
}
|
this.usertypeOptions = TrueUsertypeList;
|
},
|
// 选中类型
|
selectOldType(val) {
|
this.selectUsertype = val;
|
this.$message("选择成功!");
|
},
|
// 添加类型
|
addNewType(val) {
|
// this.selectUsertype=val;
|
|
this.loading = true;
|
var guid = this.common.getUserGuid();
|
var url = "/api/User/AddUserType";
|
var params = {
|
UsertypeName: val,
|
guid: guid
|
};
|
|
var callback = res => {
|
this.$message(res.Msg);
|
this.loading = false;
|
if (res.result) {
|
this.selectUsertype = val;
|
}
|
};
|
this.common.ajax(url, params, callback);
|
},
|
// 登录跳转
|
goLoginPage() {
|
window.location.href = "#/login";
|
},
|
// 注册跳转
|
goRegPage() {
|
window.location.href = "#/reg";
|
},
|
changeVisible(val) {
|
this.visible = val;
|
}
|
}
|
};
|
</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>
|