605 lines
18 KiB
Vue
605 lines
18 KiB
Vue
<template>
|
|
<div class="main" :class="{ 'main-mobile': mobile }">
|
|
<a-form v-if="!mobile" :form="form" class="user-layout-login" ref="formLogin" id="formLogin">
|
|
<div class="user-box">
|
|
<div class="login-header">账号登录</div>
|
|
<div class="login-body">
|
|
<a-row>
|
|
<a-col :span="3"></a-col>
|
|
<label class="lable-font">账号</label>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="3"></a-col>
|
|
<a-col :span="18">
|
|
<a-form-item>
|
|
<a-input
|
|
size="large"
|
|
v-decorator="['username',{initialValue:'', rules: validatorRules.username.rules,validateTrigger: 'blur'}]"
|
|
type="text"
|
|
placeholder="请输入账号">
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="3"></a-col>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="3"></a-col>
|
|
<label class="lable-font">密码</label>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="3"></a-col>
|
|
<a-col :span="18">
|
|
<a-form-item>
|
|
<a-input
|
|
v-decorator="['password',{initialValue:'', rules: validatorRules.password.rules,validateTrigger: 'blur'}]"
|
|
size="large"
|
|
:type="passwordType"
|
|
autocomplete="false"
|
|
placeholder="请输入密码"
|
|
>
|
|
<a-icon title="显示密码" @click="passwordType='text'" slot="suffix" v-if="passwordType==='password'" type="eye" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
<a-icon title="隐藏密码" @click="passwordType='password'" slot="suffix" v-else type="eye-invisible" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
<!-- <a-icon slot="prefix" type="lock" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>-->
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="3"></a-col>
|
|
</a-row>
|
|
<a-row class="login-btn">
|
|
<a-col :span="3"></a-col>
|
|
<a-col :span="18">
|
|
<a-form-item>
|
|
<a-button
|
|
block
|
|
size="large"
|
|
type="primary"
|
|
htmlType="submit"
|
|
:loading="loginBtn"
|
|
@click.stop.prevent="handleSubmit"
|
|
:disabled="loginBtn">
|
|
{{ loginBtn ? "登录中" : "登录" }}
|
|
</a-button>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="3"></a-col>
|
|
</a-row>
|
|
</div>
|
|
</div>
|
|
</a-form>
|
|
<a-form v-else :form="form" class="user-layout-login-mobile">
|
|
<div class="system-title">
|
|
<img :src="require('@assets/images/system-title.png')" alt="昆鸿设备管理系统">
|
|
</div>
|
|
<a-row class="login-form">
|
|
<a-col :span="24">
|
|
<a-form-item>
|
|
<a-input
|
|
size="large"
|
|
v-decorator="['username',{initialValue:'', rules: validatorRules.username.rules,validateTrigger: 'blur'}]"
|
|
type="text"
|
|
placeholder="请输入账号">
|
|
<img slot="prefix" class="prefix-icon" :src="require('@assets/images/icon/account.png')" alt="账号"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="24">
|
|
<a-form-item>
|
|
<a-input
|
|
v-decorator="['password',{initialValue:'', rules: validatorRules.password.rules,validateTrigger: 'blur'}]"
|
|
size="large"
|
|
:type="passwordType"
|
|
autocomplete="false"
|
|
placeholder="请输入密码"
|
|
>
|
|
<img slot="prefix" class="prefix-icon" :src="require('@assets/images/icon/password.png')" alt="密码"/>
|
|
<a-icon title="显示密码" @click="passwordType='text'" slot="suffix" v-if="passwordType==='password'" type="eye" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
<a-icon title="隐藏密码" @click="passwordType='password'" slot="suffix" v-else type="eye-invisible" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
<!-- <a-icon slot="prefix" type="lock" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>-->
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="24" class="login-btn">
|
|
<a-form-item>
|
|
<a-button
|
|
block
|
|
size="large"
|
|
type="primary"
|
|
htmlType="submit"
|
|
:loading="loginBtn"
|
|
@click.stop.prevent="handleSubmit"
|
|
:disabled="loginBtn">
|
|
{{ loginBtn ? "登录中" : "登录" }}
|
|
</a-button>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
</a-form>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
import { mapActions } from 'vuex'
|
|
import { timeFix } from '@/utils/util'
|
|
import Vue from 'vue'
|
|
import { ACCESS_TOKEN/* , ENCRYPTED_STRING, USER_INFO */ } from '@/store/mutation-types'
|
|
import { postAction, getAction } from '@/api/manage'
|
|
|
|
import { getRSAPublicKey } from '@/utils/encryption.js'
|
|
import { JSEncrypt } from 'jsencrypt'
|
|
// const Base64 = require('js-base64').Base64
|
|
|
|
export default {
|
|
components: {},
|
|
data () {
|
|
return {
|
|
loginBtn: false,
|
|
mobile: isMobile(),
|
|
// login type: 0 email, 1 username, 2 telephone
|
|
loginType: 0,
|
|
stepCaptchaVisible: false,
|
|
form: this.$form.createForm(this),
|
|
state: {
|
|
time: 60,
|
|
smsSendBtn: false
|
|
},
|
|
validatorRules: {
|
|
username: { rules: [{ required: true, message: '请输入用户名!' }, { validator: this.handleUsernameOrEmail }] },
|
|
password: { rules: [{ required: true, message: '请输入密码!', validator: 'click' }] },
|
|
mobile: { rules: [{ validator: this.validateMobile }] },
|
|
captcha: { rule: [{ required: true, message: '请输入验证码!' }] },
|
|
inputCode: { rules: [{ required: true, message: '请输入验证码!' }] }
|
|
},
|
|
velorifiedCode: '',
|
|
inputCodeContent: '',
|
|
inputCodeNull: true,
|
|
currentUsername: '',
|
|
currdatetime: '',
|
|
randCodeImage: '',
|
|
requestCodeSuccess: false,
|
|
rsaPublicKey: '',
|
|
passwordType: 'password' // passwordType : password , text
|
|
}
|
|
},
|
|
created () {
|
|
this.currdatetime = new Date().getTime()
|
|
Vue.ls.remove(ACCESS_TOKEN)
|
|
this.getRouterData()
|
|
this.handleChangeCheckCode()
|
|
this.getPublicKey() // 获取秘钥
|
|
},
|
|
methods: {
|
|
...mapActions(['Login', 'Logout', 'PhoneLogin']),
|
|
handleUsernameOrEmail (rule, value, callback) {
|
|
const regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/
|
|
if (regex.test(value)) {
|
|
this.loginType = 0
|
|
} else {
|
|
this.loginType = 1
|
|
}
|
|
callback()
|
|
},
|
|
handleSubmit () {
|
|
const that = this
|
|
const loginParams = {}
|
|
that.loginBtn = true
|
|
that.form.validateFields(['username', 'password', 'inputCode', 'rememberMe'], { force: true }, (err, values) => {
|
|
if (!err) {
|
|
loginParams.remember_me = values.rememberMe
|
|
loginParams.captcha = that.inputCodeContent
|
|
loginParams.checkKey = that.currdatetime
|
|
loginParams.rsaPublicKey = that.rsaPublicKey
|
|
// 新建JSEncrypt对象
|
|
const encrypt = new JSEncrypt()
|
|
encrypt.setPublicKey(loginParams.rsaPublicKey)
|
|
// 公钥加密
|
|
loginParams.username = encrypt.encrypt(values.username)
|
|
loginParams.password = encrypt.encrypt(values.password)
|
|
// 登录
|
|
that.Login(loginParams).then((/* res */) => {
|
|
this.loginSuccess()
|
|
}).catch((err) => {
|
|
if (err.code === 500) {
|
|
// 刷新验证码
|
|
this.handleChangeCheckCode()
|
|
}
|
|
that.requestFailed(err)
|
|
})
|
|
} else {
|
|
that.loginBtn = false
|
|
}
|
|
})
|
|
},
|
|
getCaptcha (e) {
|
|
e.preventDefault()
|
|
const that = this
|
|
this.form.validateFields(['mobile'], { force: true }, (err, values) => {
|
|
if (!values.mobile) {
|
|
that.cmsFailed('请输入手机号')
|
|
} else if (!err) {
|
|
this.state.smsSendBtn = true
|
|
const interval = window.setInterval(() => {
|
|
if (that.state.time-- <= 0) {
|
|
that.state.time = 60
|
|
that.state.smsSendBtn = false
|
|
window.clearInterval(interval)
|
|
}
|
|
}, 1000)
|
|
|
|
const hide = this.$message.loading('验证码发送中..', 0)
|
|
const smsParams = {}
|
|
smsParams.mobile = values.mobile
|
|
smsParams.smsmode = '0'
|
|
postAction('/sys/sms', smsParams)
|
|
.then(res => {
|
|
if (!res.success) {
|
|
setTimeout(hide, 0)
|
|
this.cmsFailed(res.message)
|
|
}
|
|
setTimeout(hide, 500)
|
|
})
|
|
.catch(err => {
|
|
setTimeout(hide, 1)
|
|
clearInterval(interval)
|
|
that.state.time = 60
|
|
that.state.smsSendBtn = false
|
|
this.requestFailed(err)
|
|
})
|
|
}
|
|
}
|
|
)
|
|
},
|
|
handleChangeCheckCode () {
|
|
this.form.setFieldsValue({ inputCode: '' })
|
|
this.currdatetime = new Date().getTime()
|
|
getAction(`/sys/randomImage/${this.currdatetime}`).then(res => {
|
|
if (res.success) {
|
|
this.randCodeImage = res.result
|
|
this.requestCodeSuccess = true
|
|
} else {
|
|
this.$message.error(res.message)
|
|
this.requestCodeSuccess = false
|
|
}
|
|
}).catch(() => {
|
|
this.requestCodeSuccess = false
|
|
})
|
|
},
|
|
// 获取RSA公钥
|
|
getPublicKey () {
|
|
// 获取公钥
|
|
getRSAPublicKey().then(res => {
|
|
this.rsaPublicKey = res.result
|
|
})
|
|
},
|
|
loginSuccess () {
|
|
// pc端跳转根路径,移动端跳转移动端路径
|
|
if (this.mobile) {
|
|
this.$router.push({ path: '/mobile' }).catch((/* res */) => {})
|
|
} else {
|
|
this.$router.push({ path: '/' }).catch((/* res */) => {})
|
|
}
|
|
this.$notification.success({
|
|
message: '欢迎',
|
|
description: `${timeFix()},欢迎回来`
|
|
})
|
|
},
|
|
cmsFailed (err) {
|
|
this.$notification.error({
|
|
message: '验证码发送失败',
|
|
description: err,
|
|
duration: 4
|
|
})
|
|
},
|
|
requestFailed (err) {
|
|
this.$notification.error({
|
|
message: '登录失败',
|
|
description: ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试',
|
|
duration: 4
|
|
})
|
|
|
|
// 如果是RSA过期,延迟1.5秒刷新页面
|
|
if (err.code && err.code === 600) {
|
|
setTimeout(function () {
|
|
location.reload()
|
|
}, 1500)
|
|
}
|
|
|
|
this.loginBtn = false
|
|
},
|
|
validateMobile (rule, value, callback) {
|
|
if (!value || new RegExp(/^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/).test(value)) {
|
|
callback()
|
|
} else {
|
|
callback(new Error('您的手机号码格式不正确!'))
|
|
}
|
|
},
|
|
validateInputCode (rule, value, callback) {
|
|
if (!value || this.verifiedCode === this.inputCodeContent) {
|
|
callback()
|
|
} else {
|
|
callback(new Error('您输入的验证码不正确!'))
|
|
}
|
|
},
|
|
generateCode (value) {
|
|
this.verifiedCode = value.toLowerCase()
|
|
},
|
|
inputCodeChange (e) {
|
|
this.inputCodeContent = e.target.value
|
|
},
|
|
getRouterData () {
|
|
this.$nextTick(() => {
|
|
if (this.$route.params.username) {
|
|
this.form.setFieldsValue({
|
|
username: this.$route.params.username
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
// 判断当前设备
|
|
function isMobile () {
|
|
const userAgentInfo = navigator.userAgent
|
|
|
|
const mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
|
|
|
|
let mobileFlag = false
|
|
|
|
// 根据userAgent判断是否是手机
|
|
for (let v = 0; v < mobileAgents.length; v++) {
|
|
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
|
|
mobileFlag = true
|
|
break
|
|
}
|
|
}
|
|
const screenWidth = window.screen.width
|
|
const screenHeight = window.screen.height
|
|
|
|
// 根据屏幕分辨率判断是否是手机
|
|
if (screenWidth < 500 && screenHeight < 800) {
|
|
mobileFlag = true
|
|
}
|
|
return mobileFlag
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
@import "~@/assets/less/modifyLessVars.less";
|
|
.ant-input-affix-wrapper/deep/ .ant-input:not(:first-child){
|
|
padding-left: 40px;
|
|
}
|
|
.ant-row{
|
|
margin-bottom: 4%;
|
|
}
|
|
// pc端背景
|
|
.main:not(.main-mobile) {
|
|
background: #001125 url("~@/assets/mobile-login-bg.png") no-repeat;
|
|
background-position: left top;
|
|
}
|
|
.main{
|
|
height: 100%;
|
|
background-color: #001125;
|
|
overflow: hidden;
|
|
|
|
.user-layout-login {
|
|
position: absolute;
|
|
right: 8vw;
|
|
top: 20vh;
|
|
width: 600px;
|
|
border: 1px solid rgba(0, 148, 255, 0.24);
|
|
border-bottom: 1px @primary-color solid;
|
|
// 左下右下高亮边框
|
|
&::before, &::after {
|
|
position: absolute;
|
|
content: '';
|
|
display: block;
|
|
width: 3%;
|
|
min-width: 16px;
|
|
height: 1px;
|
|
bottom: -1px;
|
|
background-color: #2EE4FD;
|
|
}
|
|
|
|
&::before {
|
|
left: 0;
|
|
}
|
|
|
|
&::after {
|
|
right: 0;
|
|
}
|
|
|
|
.login-header {
|
|
background-image: url("~@/assets/images/componentImg/header-bg-side.png"),
|
|
url("~@/assets/images/componentImg/header-bg-center.png"),
|
|
url("~@/assets/images/componentImg/header-bg-side.png");
|
|
background-repeat: no-repeat;
|
|
background-position: left, center, right;
|
|
background-size: 1px 100%, calc(100% - 2px) 100%, 1px 100%;
|
|
border: none;
|
|
line-height: 80px;
|
|
font-size: 28px;
|
|
text-align: center;
|
|
min-height: 100px;
|
|
height: 100px;
|
|
padding: 0 16px;
|
|
}
|
|
|
|
.login-body {
|
|
padding: 20px 0;
|
|
|
|
.ant-form label {
|
|
font-size: 16px;
|
|
}
|
|
}
|
|
}
|
|
@media screen and (min-width: 1370px) {
|
|
.user-layout-login {
|
|
.user-box{
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
display: flex;
|
|
overflow-y: auto;
|
|
//justify-content: space-between;
|
|
flex-direction: column;
|
|
.lable-font{
|
|
font-weight: 500;
|
|
//color:#000;
|
|
}
|
|
.title{
|
|
position:relative;
|
|
display: block;
|
|
//color: #000;
|
|
font-size: 28px;
|
|
font-weight: 500;
|
|
margin: 0 0 3% 0;
|
|
text-align: center;
|
|
//&::after{
|
|
// content:'';
|
|
// position:absolute;
|
|
// bottom: -2px;
|
|
// left:calc( 50% - 25px);
|
|
// width: 50px;
|
|
// height: 3px;
|
|
// background-color: #0F6FC4;
|
|
//}
|
|
}
|
|
.login-btn{
|
|
margin-top: 20px;
|
|
font-size: 10px;
|
|
}
|
|
.ant-row{
|
|
margin-bottom: 10px;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
@media screen and (max-width: 1366px) {
|
|
.user-layout-login {
|
|
width: 500px;
|
|
|
|
.login-header {
|
|
line-height: 50px;
|
|
font-size: 18px;
|
|
text-align: center;
|
|
min-height: 60px;
|
|
height: 60px;
|
|
padding: 0 16px;
|
|
}
|
|
|
|
.login-body {
|
|
|
|
.ant-form label {
|
|
font-size: 13px;
|
|
}
|
|
}
|
|
.user-box{
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
display: flex;
|
|
//justify-content: space-between;
|
|
flex-direction: column;
|
|
.lable-font{
|
|
font-weight: 700;
|
|
//color:#000;
|
|
}
|
|
.title{
|
|
position:relative;
|
|
display: block;
|
|
//color: #000;
|
|
font-size: 20px;
|
|
font-weight: 500;
|
|
margin: 0 0 5% 0;
|
|
text-align: center;
|
|
&::after{
|
|
content:'';
|
|
position:absolute;
|
|
bottom: -2px;
|
|
left:calc( 50% - 15px);
|
|
width: 35px;
|
|
height: 3px;
|
|
background-color: #0F6FC4;
|
|
}
|
|
}
|
|
.login-btn{
|
|
margin-top: 2px;
|
|
font-size: 10px;
|
|
}
|
|
.ant-row{
|
|
margin-bottom: 10px;
|
|
}
|
|
}
|
|
}
|
|
.input_height {
|
|
/deep/ .ant-input{
|
|
|
|
height: 30px !important;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
.user-layout-login-mobile {
|
|
position: relative;
|
|
height: 100vh;
|
|
|
|
&::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
display: block;
|
|
width: 100%;
|
|
height: 4.8rem;
|
|
background: url("~@/assets/mobile-login-bg.png") no-repeat;
|
|
background-position-y: -0.88rem;
|
|
background-size: cover;
|
|
}
|
|
|
|
.system-title {
|
|
user-select: none;
|
|
position: absolute;
|
|
left: 50%;
|
|
top: 4rem;
|
|
width: 3.84rem;
|
|
transform: translateX(-50%);
|
|
|
|
img {
|
|
width: 100%;
|
|
}
|
|
}
|
|
|
|
// 移动端登录表单样式
|
|
.login-form {
|
|
padding: 5.62rem 0.48rem 0;
|
|
|
|
/deep/.ant-input-affix-wrapper .ant-input-prefix {
|
|
left: 0;
|
|
.prefix-icon {
|
|
width: .48rem;
|
|
}
|
|
}
|
|
/deep/.ant-input {
|
|
border: none;
|
|
border-radius: 0;
|
|
background: none !important;
|
|
border-bottom: 0.02rem solid rgba(0,148,255,0.4);
|
|
box-shadow: none;
|
|
height: .96rem;
|
|
padding-left: .72rem;
|
|
font-family: PingFang SC, PingFang SC, sans-serif;
|
|
font-weight: 400;
|
|
font-size: 0.32rem;
|
|
line-height: 0.48rem;
|
|
}
|
|
.login-btn {
|
|
.ant-btn {
|
|
background: url("~@assets/images/login-btn.png") no-repeat;
|
|
background-size: 100% 100%;
|
|
height: 0.96rem;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
</style>
|