|
@@ -2,19 +2,21 @@
|
|
|
|
|
|
import QueryString from 'qs';
|
|
|
import { useUserStore } from '/@/store/modules/user';
|
|
|
-import { useRoute } from 'vue-router';
|
|
|
+import { useRoute, useRouter } from 'vue-router';
|
|
|
|
|
|
/** 单点登录功能的Hook,该Hook是为了部署在同一局域网内的多套系统之间能够无缝切换 */
|
|
|
export function useSSO() {
|
|
|
+ const router = useRouter();
|
|
|
const userStore = useUserStore();
|
|
|
const route = useRoute();
|
|
|
|
|
|
/** 启用单点登录功能来跳转新的页面 */
|
|
|
- function open(url: string, target?: string) {
|
|
|
+ function open(url: string, redirect?: string, target?: string) {
|
|
|
const qs = QueryString.stringify({
|
|
|
username: userStore.userInfo?.username,
|
|
|
// 毫无意义的伪装,但我就是要装一下
|
|
|
id: userStore.getPassword,
|
|
|
+ redirect,
|
|
|
});
|
|
|
window.open(`${url}?${qs}`, target);
|
|
|
}
|
|
@@ -22,7 +24,7 @@ export function useSSO() {
|
|
|
/** 用在跳转到的页面上,执行单点登录的逻辑 */
|
|
|
function doSSO() {
|
|
|
if (!route.query) return;
|
|
|
- const { username, id } = route.query;
|
|
|
+ const { username, id, redirect } = route.query;
|
|
|
if (!username || !id) return;
|
|
|
const realPassword = userStore.decryptPassword(id as string);
|
|
|
const params = {
|
|
@@ -30,7 +32,11 @@ export function useSSO() {
|
|
|
password: realPassword,
|
|
|
checkKey: new Date().getTime(),
|
|
|
};
|
|
|
- userStore.login(params);
|
|
|
+ userStore.login(params).then(() => {
|
|
|
+ if (redirect) {
|
|
|
+ router.push(redirect as string);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
return {
|