fix: 修复OIDC登陆的问题

This commit is contained in:
Captain.B 2021-09-13 16:02:38 +08:00 committed by 刘瑞斌
parent 3e3014c7ff
commit 25c2e08209
1 changed files with 19 additions and 9 deletions

View File

@ -38,6 +38,7 @@ import {registerRequestHeaders} from "@/common/js/ajax";
import {ORIGIN_COLOR} from "@/common/js/constants"; import {ORIGIN_COLOR} from "@/common/js/constants";
import MsTaskCenter from "@/business/components/task/TaskCenter"; import MsTaskCenter from "@/business/components/task/TaskCenter";
import MsNotification from "@/business/components/notice/Notification"; import MsNotification from "@/business/components/notice/Notification";
const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/); const requireComponent = require.context('@/business/components/xpack/', true, /\.vue$/);
const header = requireComponent.keys().length > 0 ? requireComponent("./license/LicenseMessage.vue") : {}; const header = requireComponent.keys().length > 0 ? requireComponent("./license/LicenseMessage.vue") : {};
const display = requireComponent.keys().length > 0 ? requireComponent("./display/Display.vue") : {}; const display = requireComponent.keys().length > 0 ? requireComponent("./display/Display.vue") : {};
@ -60,7 +61,6 @@ export default {
}; };
}, },
created() { created() {
registerRequestHeaders();
this.initSessionTimer(); this.initSessionTimer();
if (!hasLicense()) { if (!hasLicense()) {
setDefaultTheme(); setDefaultTheme();
@ -73,14 +73,12 @@ export default {
this.$store.commit('setTheme', res.data); this.$store.commit('setTheme', res.data);
}); });
} }
if (localStorage.getItem("store")) { // OIDC redirect
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store")))); if (window.location.href.endsWith('/#/') || window.location.href.endsWith('/#')) {
this.$get("/project/listAll", response => { window.location.replace("/#/setting/personsetting");
let projectIds = response.data; setTimeout(() => {
if (projectIds && projectIds.length <= 0) { window.location.reload();
this.$store.commit('setProjectId', undefined); }, 500);
}
});
} }
window.addEventListener("beforeunload", () => { window.addEventListener("beforeunload", () => {
localStorage.setItem("store", JSON.stringify(this.$store.state)); localStorage.setItem("store", JSON.stringify(this.$store.state));
@ -91,6 +89,7 @@ export default {
if (response.data.success) { if (response.data.success) {
this.$setLang(response.data.data.language); this.$setLang(response.data.data.language);
saveLocalStorage(response.data); saveLocalStorage(response.data);
registerRequestHeaders();
this.auth = true; this.auth = true;
// //
if (header.default !== undefined) { if (header.default !== undefined) {
@ -100,6 +99,17 @@ export default {
if (display.default !== undefined) { if (display.default !== undefined) {
display.default.showHome(this); display.default.showHome(this);
} }
//
if (localStorage.getItem("store")) {
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store"))));
this.$get("/project/listAll", response => {
let projectIds = response.data;
if (projectIds && projectIds.length <= 0) {
this.$store.commit('setProjectId', undefined);
}
});
}
} else { } else {
window.location.href = "/login"; window.location.href = "/login";
} }