555 lines
18 KiB
Java
555 lines
18 KiB
Java
<template>
|
|
<div class="main">
|
|
<a-form v-if="!mobile" :form="form" class="user-layout-login" ref="formLogin" id="formLogin">
|
|
<div class="user-box">
|
|
<span class="title">用户登录</span>
|
|
<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-icon slot="prefix" type="user" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="3"></a-col>
|
|
</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="password"
|
|
autocomplete="false"
|
|
placeholder="请输入密码"
|
|
>
|
|
<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 style="margin-bottom: 0%;">
|
|
<a-col :span="3"></a-col>
|
|
<a-col :span="12">
|
|
<a-form-item>
|
|
<a-input
|
|
v-decorator="['inputCode',validatorRules.inputCode]"
|
|
size="large"
|
|
type="text"
|
|
@change="inputCodeChange"
|
|
autocomplete="off"
|
|
placeholder="请输入验证码">
|
|
<a-icon slot="prefix" type="safety" :style="{ color: '#B3B7C2',fontSize:'20px'}"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="6" style="text-align: right">
|
|
<img v-if="requestCodeSuccess" style="margin-top: 2px;" :src="randCodeImage"
|
|
@click="handleChangeCheckCode"/>
|
|
<img v-else style="margin-top: 2px;" src="../../assets/checkcode.png" @click="handleChangeCheckCode"/>
|
|
</a-col>
|
|
<a-col :span="3"></a-col>
|
|
</a-row>
|
|
<a-row style="margin-bottom: 2%;">
|
|
<a-col :span="3"></a-col>
|
|
<a-col :span="13">
|
|
<a-form-item>
|
|
<a-checkbox v-decorator="['rememberMe', {initialValue: true, valuePropName: 'checked'}]">自动登录</a-checkbox>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="6">
|
|
<a-form-item>
|
|
<a-button type="primary" @click="ssoLogin">SSO登录</a-button>
|
|
</a-form-item>
|
|
</a-col>
|
|
<!-- <a-col :span="5" style="text-align: right;color: #1891FF;">-->
|
|
<!-- <a-form-item>-->
|
|
<!-- <router-link :to="{ name: 'alteration'}" class="forge-password" style="float: right;">-->
|
|
<!-- 忘记密码-->
|
|
<!-- </router-link>-->
|
|
<!-- </a-form-item>-->
|
|
<!-- </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>
|
|
</a-form>
|
|
<a-form v-if="mobile" :form="form" class="user-layout-login user-layout-login-mobile" ref="formLogin"
|
|
id="formLogin">
|
|
<div class="user-box user-box-mobile">
|
|
<a-row>
|
|
<a-col :span="24">
|
|
<a-form-item>
|
|
<a-input
|
|
size="large"
|
|
v-decorator="['username',{initialValue:'', rules: validatorRules.username.rules,validateTrigger: 'blur'}]"
|
|
type="text"
|
|
placeholder="请输入帐号">
|
|
<a-icon slot="prefix" type="user" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="24">
|
|
<a-form-item>
|
|
<a-input
|
|
v-decorator="['password',{initialValue:'', rules: validatorRules.password.rules,validateTrigger: 'blur'}]"
|
|
size="large"
|
|
type="password"
|
|
autocomplete="false"
|
|
placeholder="请输入密码"
|
|
>
|
|
<a-icon slot="prefix" type="lock" :style="{ color: '#B3B7C2',fontSize:'20px' }"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="14">
|
|
<a-form-item>
|
|
<a-input
|
|
v-decorator="['inputCode',validatorRules.inputCode]"
|
|
size="large"
|
|
type="text"
|
|
@change="inputCodeChange"
|
|
placeholder="请输入验证码">
|
|
<a-icon slot="prefix" type="safety" :style="{ color: '#B3B7C2',fontSize:'20px'}"/>
|
|
</a-input>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="10" style="text-align: right">
|
|
<img v-if="requestCodeSuccess" style="margin-top: 2px;" :src="randCodeImage"
|
|
@click="handleChangeCheckCode"/>
|
|
<img v-else style="margin-top: 2px;" src="../../assets/checkcode.png" @click="handleChangeCheckCode"/>
|
|
</a-col>
|
|
</a-row>
|
|
<a-row>
|
|
<a-col :span="12">
|
|
<a-form-item>
|
|
<a-checkbox v-decorator="['rememberMe', {initialValue: true, valuePropName: 'checked'}]">自动登录</a-checkbox>
|
|
</a-form-item>
|
|
</a-col>
|
|
<a-col :span="12" style="text-align: right">
|
|
<a-form-item>
|
|
<a-button type="primary" @click="ssoLogin">sso登录</a-button>
|
|
</a-form-item>
|
|
</a-col>
|
|
|
|
|
|
<!-- <a-col :span="9" style="text-align: right;color: #1891FF;">-->
|
|
<!-- <a-form-item>-->
|
|
<!-- <router-link :to="{ name: 'alteration'}" class="forge-password" style="float: right;">-->
|
|
<!-- 忘记密码-->
|
|
<!-- </router-link>-->
|
|
<!-- </a-form-item>-->
|
|
<!-- </a-col>-->
|
|
</a-row>
|
|
<a-row class="login-btn">
|
|
<a-col :span="24">
|
|
<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>
|
|
</div>
|
|
</a-form>
|
|
</div>
|
|
</template>
|
|
<script>
|
|
import { mapActions } from 'vuex'
|
|
import { timeFix, welcome } from '@/utils/util'
|
|
import Vue from 'vue'
|
|
import { putAction, postAction, getAction } from '@/api/manage'
|
|
import { getRSAPublicKey } from '@/api/login.js'
|
|
import { login, logout, phoneLogin, thirdLogin } from '@/api/login'
|
|
import { ACCESS_TOKEN, USER_NAME, USER_INFO, UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'
|
|
|
|
const Base64 = require('js-base64').Base64
|
|
import { JSEncrypt } from 'jsencrypt'
|
|
|
|
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: '',
|
|
code: ''
|
|
}
|
|
},
|
|
created() {
|
|
this.currdatetime = new Date().getTime()
|
|
Vue.ls.remove(ACCESS_TOKEN)
|
|
|
|
this.handleChangeCheckCode()
|
|
let query = []
|
|
if (this.$route.query.redirect) {
|
|
query = this.$route.query.redirect.includes('code=') ? this.$route.query.redirect.split('code=') : []
|
|
this.code = query[1]
|
|
}
|
|
if (this.code) {
|
|
this.ssoLoginSuccess()
|
|
}
|
|
this.getRouterData()
|
|
// redirect=%2F%3Fcode%3DST-213-iZP4qQMa2xC3Thfn4Irg-signin.nio.com
|
|
},
|
|
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() {
|
|
let that = this
|
|
let 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对象
|
|
let 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()
|
|
let that = this
|
|
this.form.validateFields(['mobile'], { force: true }, (err, values) => {
|
|
if (!values.mobile) {
|
|
that.cmsFailed('请输入手机号')
|
|
} else if (!err) {
|
|
this.state.smsSendBtn = true
|
|
let 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)
|
|
let 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.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
|
|
})
|
|
this.getPublicKey()
|
|
},
|
|
//获取RSA公钥
|
|
getPublicKey() {
|
|
// 获取公钥
|
|
getRSAPublicKey().then(res => {
|
|
this.rsaPublicKey = res.result
|
|
})
|
|
},
|
|
loginSuccess() {
|
|
let langCn = localStorage.language
|
|
// 默认中文
|
|
if (!langCn) {
|
|
localStorage.setItem('language', 'zh-cn')
|
|
}
|
|
let fullPath = ''
|
|
let isPhone = localStorage.getItem('isPhone')
|
|
if (isPhone == 'yes'){
|
|
fullPath = '/phoneSearch'
|
|
}else{
|
|
fullPath = '/dashboard/analysis'
|
|
}
|
|
this.$router.push({ path: fullPath }).catch((res) => {
|
|
})
|
|
this.$notification.success({
|
|
message: '欢迎',
|
|
description: `${timeFix()},欢迎回来`
|
|
})
|
|
|
|
},
|
|
cmsFailed(err) {
|
|
this.$notification['error']({
|
|
message: '登录失败',
|
|
description: err,
|
|
duration: 4
|
|
})
|
|
},
|
|
requestFailed(err) {
|
|
this.form.resetFields()
|
|
this.$notification['error']({
|
|
message: '登录失败',
|
|
// description:'账号或密码错误',
|
|
description: err.message == '验证码错误' ? err.message : '账号或密码错误',
|
|
duration: 4
|
|
})
|
|
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('您的手机号码格式不正确!')
|
|
}
|
|
},
|
|
validateInputCode(rule, value, callback) {
|
|
if (!value || this.verifiedCode == this.inputCodeContent) {
|
|
callback()
|
|
} else {
|
|
callback('您输入的验证码不正确!')
|
|
}
|
|
},
|
|
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
|
|
})
|
|
}
|
|
})
|
|
},
|
|
//sso登录跳转
|
|
ssoLogin() {
|
|
window.open('https://signin-test.nio.com/oauth2/authorize?client_id=100679&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdashboard%2Fanalysis&response_type=code', '_blank')
|
|
},
|
|
//sso登录
|
|
ssoLoginSuccess() {
|
|
let that = this
|
|
let loginParams = {}
|
|
loginParams.checkKey = that.currdatetime
|
|
loginParams.rsaPublicKey = that.rsaPublicKey
|
|
// 新建JSEncrypt对象
|
|
let encrypt = new JSEncrypt()
|
|
encrypt.setPublicKey(loginParams.rsaPublicKey)
|
|
getAction(`opensso/callback`, { code: this.code }).then(res => {
|
|
if (res.success) {
|
|
Vue.ls.set(ACCESS_TOKEN, res.result.token, 7 * 24 * 60 * 60 * 1000)
|
|
Vue.ls.set(USER_NAME, res.result.userInfo.username, 7 * 24 * 60 * 60 * 1000)
|
|
Vue.ls.set(USER_INFO, res.result.userInfo, 7 * 24 * 60 * 60 * 1000)
|
|
Vue.ls.set(UI_CACHE_DB_DICT_DATA, res.result.sysAllDictItems, 7 * 24 * 60 * 60 * 1000)
|
|
this.$store.commit('SET_TOKEN', res.result.token)
|
|
this.$store.commit('SET_INFO', res.result.userInfo)
|
|
this.$store.commit('SET_NAME', {
|
|
username: res.result.userInfo.username,
|
|
realname: res.result.userInfo.realname,
|
|
welcome: welcome()
|
|
})
|
|
this.$store.commit('SET_AVATAR', res.result.userInfo.avatar)
|
|
this.loginSuccess()
|
|
} else if (res.message == '【单点登录】获取access_token失败') {
|
|
this.ssoLogin()
|
|
} else {
|
|
this.$message.error(res.message)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
}
|
|
|
|
// 判断当前设备
|
|
function isMobile() {
|
|
var userAgentInfo = navigator.userAgent
|
|
|
|
var mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod']
|
|
|
|
var mobile_flag = false
|
|
|
|
//根据userAgent判断是否是手机
|
|
for (var v = 0; v < mobileAgents.length; v++) {
|
|
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
|
|
mobile_flag = true
|
|
break
|
|
}
|
|
}
|
|
var screen_width = window.screen.width
|
|
var screen_height = window.screen.height
|
|
|
|
//根据屏幕分辨率判断是否是手机
|
|
if (screen_width < 500 && screen_height < 800) {
|
|
mobile_flag = true
|
|
}
|
|
return mobile_flag
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.ant-input-affix-wrapper /deep/ .ant-input:not(:first-child) {
|
|
padding-left: 40px;
|
|
}
|
|
|
|
.ant-row {
|
|
margin-bottom: 4%;
|
|
}
|
|
|
|
.main {
|
|
height: 100%;
|
|
|
|
.user-layout-login {
|
|
z-index: 99;
|
|
width: 24%;
|
|
height: 56%;
|
|
padding: 3% 0 3% 0;
|
|
min-width: 332px;
|
|
min-height: 460px;
|
|
background: #fff;
|
|
border-radius: 20px;
|
|
position: absolute;
|
|
right: 8%;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
|
|
.user-box {
|
|
width: 100%;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
flex-direction: column;
|
|
|
|
.title {
|
|
display: block;
|
|
color: #1891FF;
|
|
font-size: 28px;
|
|
font-weight: 500;
|
|
margin: 0 0 5% 0;
|
|
text-align: center;
|
|
}
|
|
|
|
.login-btn {
|
|
margin-bottom: 0;
|
|
font-size: 10px;
|
|
}
|
|
}
|
|
}
|
|
|
|
.user-layout-login-mobile {
|
|
right: 0;
|
|
width: 100%;
|
|
min-width: 0 !important;
|
|
height: 46% !important;
|
|
background: transparent;
|
|
min-height: 0;
|
|
padding: 0 0.4rem 0 0.4rem;
|
|
position: absolute;
|
|
top: 3.6rem;
|
|
margin-top: 6rem;
|
|
transform: translateY(-50%);
|
|
|
|
.ant-row {
|
|
margin-bottom: 0;
|
|
}
|
|
}
|
|
}
|
|
</style>
|