<template>
|
<div class="login-container">
|
<div class="header">
|
<img :src="common.showFirstImage(basicInfo.logo)" class="logo">
|
<div class="tool">
|
<!-- <el-button type="primary" class="btn-current" @click="goLoginPage">{{ $t('login.logIn') }}</el-button>
|
<el-button plain @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">欢迎登录{{ basicInfo.sysName }}</h3>
|
<!-- <lang-select class="set-language" /> -->
|
</div>
|
|
<el-form-item v-if="showUserProduct" prop="userProductCode">
|
<span class="svg-container">
|
<svg-icon icon-class="user" />
|
</span>
|
<el-input v-model="loginForm.userProductCode" :placeholder="$t('login.userProductCode')" name="userProductCode" type="text" auto-complete="on" @keyup.enter.native="handleLogin" />
|
</el-form-item>
|
|
<el-form-item prop="username">
|
<span class="svg-container">
|
<i class="el-icon-yrt-dianhua3"></i>
|
</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="password">
|
<span class="svg-container">
|
<svg-icon icon-class="password" />
|
</span>
|
<el-input :type="passwordType" v-model="loginForm.password" :placeholder="$t('login.password')" name="password" auto-complete="on" autocomplete="new-password" @keyup.enter.native="handleLogin" />
|
<span class="show-pwd" @click="showPwd">
|
<svg-icon :icon-class="passwordType=='password'?'eye':'eye-open'" />
|
</span>
|
</el-form-item>
|
|
<el-form-item v-if="checkcode" prop="verificationcode">
|
<span class="svg-container">
|
<svg-icon icon-class="verification-code" />
|
</span>
|
<el-input v-model.number="loginForm.verificationcode" :placeholder="$t('login.verificationcode')" name="verificationcode" 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.native.prevent="handleLogin">{{ $t('login.logIn') }}</el-button>
|
<!-- <div class="forget-pwd">
|
<a href="#/forget-pwd">忘记密码?</a>
|
</div> -->
|
<!-- <div v-if="userList.length" class="login-user-list">
|
<div class="vux-divider">
|
<span class="text">已经登录过的账号账套</span>
|
</div>
|
<el-tag v-for="(item, index) in userList" :key="index" style="cursor:pointer;" closable @close="closeUserInfo" @click.native="autoLogin(item)">
|
{{ item.userName + "(" + item.userProductCode + ")" }}
|
</el-tag>
|
</div> -->
|
</el-form>
|
|
<el-dialog :title="$t('login.thirdparty')" :visible.sync="showDialog" append-to-body>
|
{{ $t('login.thirdpartyTips') }}
|
<br>
|
<br>
|
<br>
|
<social-sign />
|
</el-dialog>
|
|
</div>
|
</template>
|
|
<script>
|
import { isvalidUsername } from "@/utils/validate";
|
import LangSelect from "@/components/LangSelect";
|
import SocialSign from "./socialsignin";
|
import Cookies from "js-cookie";
|
import { log } from "util";
|
|
export default {
|
name: "Login",
|
components: { LangSelect, SocialSign },
|
data() {
|
// 验证规则
|
const validateUsername = (rule, value, callback) => {
|
if (isvalidUsername(value)) {
|
callback(new Error("Please enter the correct user name"));
|
} else {
|
callback();
|
}
|
};
|
const validatePassword = (rule, value, callback) => {
|
if (value.length < 3) {
|
callback(new Error("The password can not be less than 3 digits"));
|
} else {
|
callback();
|
}
|
};
|
|
return {
|
loginForm: {
|
userProductCode: "",
|
username: "",
|
password: "",
|
verificationcode: ""
|
},
|
loginRules: {
|
// userProductCode: [
|
// { required: true, trigger: "blur", message: "产品编号必填" }
|
// ],
|
username: [{ required: true, trigger: "blur", validator: validateUsername }],
|
password: [{ required: true, trigger: "blur", validator: validatePassword }],
|
verificationcode: [{ required: true, trigger: "blur", message: "验证码必填" }, { type: "number", trigger: "blur", message: "验证码不是数字" }]
|
},
|
passwordType: "password",
|
loading: false,
|
showDialog: false,
|
redirect: undefined,
|
codeImgData: null, // 图片数据
|
// 显示验证码
|
checkcode: false,
|
// 登录过的用列表
|
userList: [],
|
// 显示账套
|
showUserProduct: false,
|
// 系统信息
|
basicInfo: {}
|
};
|
},
|
watch: {
|
$route: {
|
handler: function(route) {
|
this.redirect = route.query && route.query.redirect;
|
},
|
immediate: true
|
}
|
},
|
created() {
|
this.userList = Cookies.getJSON("userList") || [];
|
this.getBasicInfo();
|
},
|
mounted() {
|
this.getVerificationCodeImg();
|
},
|
destroyed() {},
|
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;
|
}
|
|
this.loading = true;
|
var guid = this.common.getUserGuid();
|
var verificationcode = the.loginForm.verificationcode;
|
if (!this.checkcode) {
|
verificationcode = "pass";
|
}
|
if (this.checkcode && verificationcode === "pass") {
|
this.$notify.error({
|
title: "验证消息",
|
message: "验证码不正确,请正确填写!"
|
});
|
return false;
|
}
|
|
var params = {
|
openNodeApi: true,
|
userProductCode: the.loginForm.userProductCode,
|
userName: the.loginForm.username,
|
userPwd: the.loginForm.password,
|
validateCode: verificationcode,
|
guid: guid,
|
sourceMachine:'WMS'
|
};
|
this.autoLogin(params);
|
});
|
},
|
autoLogin(params) {
|
var url = "/api/auth/login";
|
var callback = res => {
|
if (res.result) {
|
this.$message.success(res.msg);
|
Cookies.remove("needcheckCode");
|
debugger;
|
this.$store
|
.dispatch("LoginByUsername", {
|
userInfo: res.data,
|
menuList: res.dynamic
|
})
|
.then(() => {
|
this.loading = false;
|
this.$router.push({ path: this.redirect || "/" });
|
})
|
.catch(() => {
|
this.loading = false;
|
});
|
debugger;
|
var userProductCode = res.data.userProductCode;
|
log(userProductCode);
|
// 记录已经登录过的账套
|
var isExist = this.userList.find(item => item.userProductCode === userProductCode);
|
if (!isExist) {
|
params.userProductCode = userProductCode;
|
params.validateCode = "pass";
|
this.userList.push(params);
|
}
|
Cookies.set("userList", this.userList);
|
|
} else {
|
this.$message.error(res.msg);
|
var needcheckCode = Cookies.get("needcheckCode");
|
if (needcheckCode !== null && needcheckCode !== "") {
|
needcheckCode = parseInt(needcheckCode) + 1;
|
Cookies.set("needcheckCode", needcheckCode);
|
if (needcheckCode >= 3) {
|
this.checkcode = true;
|
} else {
|
this.checkcode = false;
|
}
|
} else {
|
this.checkcode = false;
|
Cookies.set("needcheckCode", 1);
|
}
|
// 显示账套输入框
|
if (res.statusCode === 501) {
|
this.showUserProduct = true;
|
}
|
this.loading = false;
|
|
}
|
|
if(res.data&&res.data.userTrueName){
|
localStorage.setItem('creator', res.data.userTrueName)
|
}
|
|
this.getVerificationCodeImg();
|
};
|
this.common.ajax(url, params, callback, this.$refs.loginForm);
|
},
|
// 获得验证码图片
|
getVerificationCodeImg() {
|
var needcheckCode = Cookies.get("needcheckCode");
|
if (needcheckCode >= 3) {
|
this.checkcode = true;
|
var the = this;
|
var guid = this.common.getUserGuid();
|
var url = "/api/Auth/GetValidateCode";
|
var data = {
|
openNodeApi: true,
|
guid: guid
|
};
|
var callback = function(res, textStatus) {
|
if (res.result) {
|
the.codeImgData = "data:image/png;base64," + res.data;
|
} else {
|
the.$message.error(res.msg);
|
}
|
};
|
this.common.ajax(url, data, callback, true);
|
} else {
|
this.checkcode = false;
|
}
|
},
|
// 登录跳转
|
goLoginPage() {
|
window.location.href = "#/login";
|
},
|
// 注册跳转
|
goRegPage() {
|
window.location.href = "http://plat-site-test.iwms.xin/#/reg";
|
},
|
// 删除登录历史记录
|
closeUserInfo(params) {
|
var findIndex = this.userList.findIndex(item => item.userProductCode === params.userProductCode);
|
this.userList.splice(findIndex, 1);
|
Cookies.set("userList", this.userList);
|
},
|
// 获得系统信息
|
getBasicInfo() {
|
const url = "/api/sys/basicInfo/getSysInfo";
|
this.common.ajax(
|
url,
|
{
|
href: location.href
|
},
|
res => {
|
this.basicInfo = res.data;
|
this.$store.dispatch("setBasicInfo", this.basicInfo);
|
document.title = this.basicInfo.sysName;
|
let $favicon = document.querySelector('link[rel="icon"]');
|
const link = this.basicInfo.icon;
|
if ($favicon !== null) {
|
$favicon.href = link;
|
} else {
|
$favicon = document.createElement("link");
|
$favicon.rel = "icon";
|
$favicon.href = link;
|
document.head.appendChild($favicon);
|
}
|
}
|
);
|
}
|
}
|
};
|
</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;
|
border-bottom: 1px solid #f3f3f3;
|
.tool {
|
top: 20px;
|
right: 30px;
|
position: absolute;
|
}
|
.logo {
|
height: 60px;
|
}
|
}
|
|
/* 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>
|