feat: 添加新单点登录功能;新增singleSign接口及相关路由和视图

This commit is contained in:
LokerL 2024-11-25 15:11:39 +08:00
parent 1b5cca52ca
commit 21cbb63052
5 changed files with 61 additions and 2 deletions

View File

@ -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) { export function register(data) {
return request({ return request({

View File

@ -8,7 +8,7 @@ import { isRelogin } from '@/utils/request'
NProgress.configure({ showSpinner: false }) NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/register', '/LoginSso', '/LoginRedirect'] const whiteList = ['/login', '/register', '/LoginSso', '/LoginRedirect', '/SingleSign']
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() NProgress.start()

View File

@ -51,6 +51,11 @@ export const constantRoutes = [
component: () => import('@/views/login-sso'), component: () => import('@/views/login-sso'),
hidden: true hidden: true
}, },
{
path: '/SingleSign',
component: () => import('@/views/single-sign'),
hidden: true
},
{ {
path: '/LoginRedirect', path: '/LoginRedirect',
component: () => import('@/views/login-redirect'), component: () => import('@/views/login-redirect'),

View File

@ -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 { getToken, setToken, removeToken } from '@/utils/auth'
import {encrypt, decrypt} from '@/utils/secret' import {encrypt, decrypt} from '@/utils/secret'
const user = { 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 }) { GetInfo({ commit, state }) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@ -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>