|
|
@@ -82,11 +82,13 @@
|
|
|
|
|
|
<script>
|
|
|
import {ServeCaptcha, ServeLogin, ServePubkey, ServeSendVerifyCode} from '@/api/auth'
|
|
|
+import { setUserToken, getUserInfo } from '@/utils/auth'
|
|
|
import { userMixin } from 'assets/js/mixin'
|
|
|
import { isMobile } from '@/utils/validate'
|
|
|
import SmsLock from "@/utils/sms-lock"
|
|
|
import { JSEncrypt } from 'jsencrypt'
|
|
|
import Cookies from 'js-cookie'
|
|
|
+import Vue from "vue";
|
|
|
|
|
|
export default {
|
|
|
mixins: [userMixin],
|
|
|
@@ -155,9 +157,20 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
created() {
|
|
|
- this.getCaptcha()
|
|
|
- this.getPubkey()
|
|
|
- this.smsLockObj = new SmsLock('LOGIN_SMS', 60)
|
|
|
+ const token = Vue.$cookies.get('token')
|
|
|
+ if (token !== null) {
|
|
|
+ this.$router.push('/')
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const user = getUserInfo()
|
|
|
+ if (user === null) {
|
|
|
+ this.getCaptcha()
|
|
|
+ this.getPubkey()
|
|
|
+ this.smsLockObj = new SmsLock('LOGIN_SMS', 60)
|
|
|
+ } else {
|
|
|
+ this.$router.push('/')
|
|
|
+ }
|
|
|
},
|
|
|
destroyed() {
|
|
|
this.smsLockObj.clearInterval()
|
|
|
@@ -213,8 +226,15 @@ export default {
|
|
|
captchaCode: this.form.captchaCode
|
|
|
}).then(res => {
|
|
|
if (res.code === 0) {
|
|
|
- let result = res.data
|
|
|
- const token = result.userToken.accessToken
|
|
|
+ const resData = res.data
|
|
|
+ const userInfo = resData.userInfo
|
|
|
+ const userToken = resData.userToken
|
|
|
+
|
|
|
+ // 保存授权信息到本地缓存
|
|
|
+ setUserToken(userToken)
|
|
|
+ this.$store.commit('UPDATE_USER_INFO', userInfo)
|
|
|
+
|
|
|
+ const token = userToken.accessToken
|
|
|
//取得登录接口的token后,在统一登录中心域名底下设置cookie
|
|
|
Cookies.set('token', token, {
|
|
|
Secure: true,
|
|
|
@@ -226,6 +246,7 @@ export default {
|
|
|
//向父窗口发送登录成功的消息
|
|
|
window.parent.postMessage({ type: 'loginSuccess' }, '*')
|
|
|
}
|
|
|
+ this.$router.push('/')
|
|
|
} else {
|
|
|
this.$notify.info({
|
|
|
title: '提示',
|