|
@@ -4,6 +4,7 @@ import QueryString from 'qs';
|
|
|
import { useUserStore } from '/@/store/modules/user';
|
|
|
import { RouteLocationNormalized } from 'vue-router';
|
|
|
import { useMessage } from '../web/useMessage';
|
|
|
+import { AUTO_LOGIN_URL_QUERY } from '/@/router/constant';
|
|
|
|
|
|
/** 自动登录功能的Hook,该Hook是为了部署在同一局域网内的多套系统之间能够无缝切换 */
|
|
|
export function useAutoLogin() {
|
|
@@ -11,7 +12,7 @@ export function useAutoLogin() {
|
|
|
function open(url: string, redirect?: string, target?: string) {
|
|
|
const userStore = useUserStore();
|
|
|
const qs = QueryString.stringify({
|
|
|
- autoLogin: true,
|
|
|
+ [AUTO_LOGIN_URL_QUERY.key]: AUTO_LOGIN_URL_QUERY.val,
|
|
|
username: userStore.getUserInfo.username,
|
|
|
workNo: userStore.getUserInfo.workNo,
|
|
|
redirect,
|
|
@@ -19,12 +20,13 @@ export function useAutoLogin() {
|
|
|
window.open(`${url}?${qs}`, target);
|
|
|
}
|
|
|
|
|
|
- /** 用在路由守卫里,执行自动登录的逻辑,如果存在符合自动登录标准的query则执行自动登录 */
|
|
|
- async function doAutoLogin(route: RouteLocationNormalized) {
|
|
|
+ /** 用在路由守卫里,执行自动登录的逻辑,如果存在符合自动登录标准的query则执行自动登录,返回是否需要重定向 */
|
|
|
+ async function doAutoLogin(route: RouteLocationNormalized): Promise<boolean> {
|
|
|
const userStore = useUserStore();
|
|
|
- if (!route.query) return;
|
|
|
- const { autoLogin, username, workNo } = route.query;
|
|
|
- if (!autoLogin || !username || !workNo) return;
|
|
|
+ if (!route.query) return false;
|
|
|
+ if (route.query[AUTO_LOGIN_URL_QUERY.key] !== AUTO_LOGIN_URL_QUERY.val) return false;
|
|
|
+ const { username, workNo } = route.query;
|
|
|
+ if (!username || !workNo) return false;
|
|
|
const params = {
|
|
|
username: username as string,
|
|
|
workNo: workNo as string,
|
|
@@ -32,10 +34,11 @@ export function useAutoLogin() {
|
|
|
};
|
|
|
try {
|
|
|
await userStore.autoLogin(params);
|
|
|
+ return true;
|
|
|
} catch (e: any) {
|
|
|
const message = useMessage().createMessage;
|
|
|
message.error(e.message);
|
|
|
- return;
|
|
|
+ return false;
|
|
|
}
|
|
|
}
|
|
|
|