✨ feat: 添加单点登录功能-前端
This commit is contained in:
parent
b47cd4011f
commit
2642714bb4
|
@ -57,4 +57,12 @@ export function getCodeImg() {
|
|||
method: 'get',
|
||||
timeout: 20000
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function getAccountName(data) {
|
||||
return request({
|
||||
url: '/getAccountName',
|
||||
method: 'get',
|
||||
params: data
|
||||
})
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import { isRelogin } from '@/utils/request'
|
|||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
const whiteList = ['/login', '/register']
|
||||
const whiteList = ['/login', '/register', '/LoginSso']
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start()
|
||||
|
|
|
@ -46,6 +46,11 @@ export const constantRoutes = [
|
|||
component: () => import('@/views/login'),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/LoginSso',
|
||||
component: () => import('@/views/login-sso'),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/register',
|
||||
component: () => import('@/views/register'),
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { login, logout, getInfo } from '@/api/login'
|
||||
import { login, logout, getInfo, getAccountName } from '@/api/login'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
import {encrypt, decrypt} from '@/utils/secret'
|
||||
import {encrypt, decrypt} from '@/utils/secret'
|
||||
const user = {
|
||||
state: {
|
||||
token: getToken(),
|
||||
|
@ -95,6 +95,22 @@ const user = {
|
|||
removeToken()
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
|
||||
LoginSso({ commit }, code) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getAccountName({"code": code}).then((res) => {
|
||||
if (res.code == 200) {
|
||||
setToken(res.token)
|
||||
commit('SET_TOKEN', res.token)
|
||||
resolve()
|
||||
} else {
|
||||
reject(res)
|
||||
}
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "LoginSso",
|
||||
data() {
|
||||
return {
|
||||
loginRules: {},
|
||||
//验证码开关
|
||||
captchaOnOff: true,
|
||||
//注册开关
|
||||
register: false,
|
||||
//重定向
|
||||
redirect: undefined
|
||||
};
|
||||
},
|
||||
created() {
|
||||
//页面初始化时调单点登录方法
|
||||
this.loginSso();
|
||||
},
|
||||
methods: {
|
||||
loginSso() {
|
||||
//获取地址栏中的code
|
||||
const code = this.$route.query.code;
|
||||
console.log("code="+code)
|
||||
//调用登录的接口
|
||||
if(code==''||code==undefined||code==null){
|
||||
//请求中不带code,拦截为正常登录
|
||||
} else {
|
||||
this.$store.dispatch("LoginSso", code).then(() => {
|
||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
||||
}).catch((error) => {
|
||||
console.error(error);
|
||||
this.$message.error("单点登录失败");
|
||||
this.$router.push({ path: "/login" }).catch(()=>{});
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue