✨ feat: 添加新单点登录功能;新增singleSign接口及相关路由和视图
This commit is contained in:
parent
1b5cca52ca
commit
21cbb63052
|
@ -19,6 +19,18 @@ export function login(username, password, code, uuid) {
|
|||
})
|
||||
}
|
||||
|
||||
export function singleSign(username, password) {
|
||||
return request({
|
||||
url: '/singleSign',
|
||||
headers: {
|
||||
isToken: false,
|
||||
repeatSubmit: false
|
||||
},
|
||||
method: 'post',
|
||||
data: { username, password }
|
||||
})
|
||||
}
|
||||
|
||||
// 注册方法
|
||||
export function register(data) {
|
||||
return request({
|
||||
|
|
|
@ -8,7 +8,7 @@ import { isRelogin } from '@/utils/request'
|
|||
|
||||
NProgress.configure({ showSpinner: false })
|
||||
|
||||
const whiteList = ['/login', '/register', '/LoginSso', '/LoginRedirect']
|
||||
const whiteList = ['/login', '/register', '/LoginSso', '/LoginRedirect', '/SingleSign']
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
NProgress.start()
|
||||
|
|
|
@ -51,6 +51,11 @@ export const constantRoutes = [
|
|||
component: () => import('@/views/login-sso'),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/SingleSign',
|
||||
component: () => import('@/views/single-sign'),
|
||||
hidden: true
|
||||
},
|
||||
{
|
||||
path: '/LoginRedirect',
|
||||
component: () => import('@/views/login-redirect'),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { login, logout, getInfo, getAccountName } from '@/api/login'
|
||||
import { login, logout, getInfo, getAccountName, singleSign } from '@/api/login'
|
||||
import { getToken, setToken, removeToken } from '@/utils/auth'
|
||||
import {encrypt, decrypt} from '@/utils/secret'
|
||||
const user = {
|
||||
|
@ -51,6 +51,21 @@ const user = {
|
|||
})
|
||||
},
|
||||
|
||||
SingleSign({ commit }, userInfo) {
|
||||
const username = userInfo.username.trim();
|
||||
const password = userInfo.password;
|
||||
let encodePs = encrypt(password)//加密
|
||||
return new Promise((resolve, reject) => {
|
||||
singleSign(username, encodePs).then(res => {
|
||||
setToken(res.token)
|
||||
commit('SET_TOKEN', res.token)
|
||||
resolve()
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
// 获取用户信息
|
||||
GetInfo({ commit, state }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "SingleSign",
|
||||
data() {
|
||||
return {
|
||||
redirect: undefined
|
||||
};
|
||||
},
|
||||
created() {
|
||||
this.singleSign();
|
||||
},
|
||||
methods: {
|
||||
singleSign() {
|
||||
const { userName, password = "123456" } = this.$route.query;
|
||||
this.$store.dispatch("SingleSign", { userName, password }).then(() => {
|
||||
this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
|
||||
}).catch((error) => {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
Loading…
Reference in New Issue