Commit d61f00c6 by 胡锦波

1. init 登录回调

parent bef5c33f
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Waiting...</title>
</head>
<body>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Waiting...</title>
</head>
<body>
<div></div>
</body>
<script>
const v = window.location.href;
window.location.href = v.replace('callback.html', 'oidc-redirect')
</script>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Silent Renew Token for SpeEDI Cargo</title>
</head>
<body>
<div></div>
</body>
<script>
const v = window.location.href;
window.location.href = v.replace('callback.html', 'oidc-silent-redirect')
</script>
</html>
\ No newline at end of file
......@@ -59,14 +59,29 @@ const api = {
const oidc = {
client_id: clientId,
redirect_uri: `${host}/oidc-redirect`,
redirect_uri: `${host}/callback.html`,
response_type: "id_token token",
scope:
"workapps.client api.workapps.user api.workapps.org api.workapps.open openid",
silent_redirect_uri: `${host}/oidc-silent-redirect`,
silent_redirect_uri: `${host}/silentrenew.html`,
post_logout_redirect_uri: host
} as UserManagerSettings;
// const oidc = {
// authority: "http://106.120.107.150:5000",
// client_id: "teamix-team-manager-web-pc",
// client_secret: "123456",
// redirect_uri: "http://106.120.107.150:7772/callback.html",
// response_type: "id_token token",
// scope: "workapps.client api.workapps.user api.workapps.org api.workapps.open openid",
// post_logout_redirect_uri: "http://106.120.107.150:7772",
// silent_redirect_uri: "http://106.120.107.150:7772/silentrenew.html",
// automaticSilentRenew: true,
// accessTokenExpiringNotificationTime: 60,
// filterProtocolClaims: true,
// loadUserInfo: true
// };
function getValue(map: Map<Environment, string>) {
return map.get(envir) || map.get(Environment.Dev);
}
......
......@@ -129,12 +129,13 @@ function login() {
}
async function tryLogin(): Promise<void> {
const instance = setupOidcManager();
return UserController.getUser().then(r => {
if (!UserController.checkAutoNav()) {
if (!r) {
login();
instance.signinRedirect({ state: { returnUrl: UserController.getReturnUrl() || window.location.href } });
} else if (TokenManager.isExpired(r)) {
login();
instance.signinRedirect({ state: { returnUrl: UserController.getReturnUrl() || window.location.href } });
}
}
});
......
......@@ -11,6 +11,14 @@ const compatibleUrl = [
oldPath: "/SelectOrg",
direction: Direction.Home
},
// {
// oldPath: "/callback.html",
// direction: Direction.Redirect
// },
// {
// oldPath: "/silentrenew.html",
// direction: Direction.SilentRedirect
// },
{
oldPath: "/workadmin/addressbook/home",
direction: Direction.AddressBook
......
interface InnerHandler {
key: string;
action: (to?: string | null, from?: string | null) => void;
}
/***
* 动态注册一个响应路由切换时的事件推送器,当路由变化时会触发注册的回调
*/
export class RouterEventer {
private static readonly actions: InnerHandler[] = [];
public static registerOnRouterChanged(vue: Vue, action: () => void) {
const key = this.addAction(action);
vue.$once('hook:beforeDestroy', () => {
_.remove(this.actions, i => i.key === key);
});
return this;
}
private static addAction(action: () => void) {
const key = new Date().valueOf() + '_' + Math.ceil(Math.random() * 1000);
this.actions.push({ key, action });
return key;
}
public static raiseOnRouterChanged(target?: string | null, from?: string | null) {
for (const item of this.actions) {
item.action(target, from);
}
return this;
}
}
import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import { Dictionary } from "vue-router/types/router";
import { UserController } from '@/api/token';
import { Direction } from './direction';
import { RouterEventer } from './event-bus';
import { MetaHeader } from './meta-header';
import { setCompatibleUrl } from './compatible-url';
import { Envir } from '@/api/env';
import { loginRouters } from "@/router/sub-router/login";
Vue.use(VueRouter);
......@@ -124,6 +127,10 @@ const navigation = (vue: Vue, direction: Direction, query?: Dictionary<string>,
vue.$router.push(p);
};
const whiteList = [
Direction.Redirect, Direction.SilentRedirect
];
Vue.prototype.go = async function(direction: Direction, params?: Dictionary<string>, query?: Dictionary<string>) {
const vue = this as Vue;
navigation(vue, direction, query, params);
......@@ -150,5 +157,13 @@ Vue.prototype.getCurrentDirection = function() {
return Direction.Home;
};
router.afterEach((to, from) => {
RouterEventer.raiseOnRouterChanged(to.name, from.name);
document.title = (Envir.isStaging() ? '【组织管理后台测试】' : '') + (to.meta?.title || "首页");
if (to.meta && to.meta.direction && !_.includes(whiteList, to.meta.direction)) {
UserController.tryLogin();
}
});
export default router;
export { Direction };
......@@ -11,7 +11,7 @@ module.exports = {
devServer: {
host: '0.0.0.0',
port: 8086,
port: 8080,
https: false,
hotOnly: false,
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment