fix: 修复session到期没有转到登录页面的问题
This commit is contained in:
parent
b562d02fa1
commit
b38ceba32f
|
@ -48,6 +48,7 @@ public class ShiroUtils {
|
||||||
filterChainDefinitionMap.put("/document/**", "anon");
|
filterChainDefinitionMap.put("/document/**", "anon");
|
||||||
filterChainDefinitionMap.put("/system/theme", "anon");
|
filterChainDefinitionMap.put("/system/theme", "anon");
|
||||||
filterChainDefinitionMap.put("/system/save/baseurl/**", "anon");
|
filterChainDefinitionMap.put("/system/save/baseurl/**", "anon");
|
||||||
|
filterChainDefinitionMap.put("/system/timeout", "anon");
|
||||||
|
|
||||||
filterChainDefinitionMap.put("/v1/catalog/**", "anon");
|
filterChainDefinitionMap.put("/v1/catalog/**", "anon");
|
||||||
filterChainDefinitionMap.put("/v1/agent/**", "anon");
|
filterChainDefinitionMap.put("/v1/agent/**", "anon");
|
||||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.ldap.domain.LdapInfo;
|
||||||
import io.metersphere.log.annotation.MsAuditLog;
|
import io.metersphere.log.annotation.MsAuditLog;
|
||||||
import io.metersphere.notice.domain.MailInfo;
|
import io.metersphere.notice.domain.MailInfo;
|
||||||
import io.metersphere.service.SystemParameterService;
|
import io.metersphere.service.SystemParameterService;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -22,6 +23,8 @@ import java.util.List;
|
||||||
public class SystemParameterController {
|
public class SystemParameterController {
|
||||||
@Resource
|
@Resource
|
||||||
private SystemParameterService SystemParameterService;
|
private SystemParameterService SystemParameterService;
|
||||||
|
@Resource
|
||||||
|
private Environment env;
|
||||||
|
|
||||||
@PostMapping("/edit/email")
|
@PostMapping("/edit/email")
|
||||||
@MsAuditLog(module = "system_parameter_setting", type = OperLogConstants.UPDATE, title = "邮件设置", beforeEvent = "#msClass.getMailLogDetails()", content = "#msClass.getMailLogDetails()", msClass = SystemParameterService.class)
|
@MsAuditLog(module = "system_parameter_setting", type = OperLogConstants.UPDATE, title = "邮件设置", beforeEvent = "#msClass.getMailLogDetails()", content = "#msClass.getMailLogDetails()", msClass = SystemParameterService.class)
|
||||||
|
@ -44,6 +47,11 @@ public class SystemParameterController {
|
||||||
return SystemParameterService.getValue("ui.theme");
|
return SystemParameterService.getValue("ui.theme");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("timeout")
|
||||||
|
public long getTimeout() {
|
||||||
|
return env.getProperty("session.timeout", Long.class, 43200L); // 默认43200s, 12个小时
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/mail/info")
|
@GetMapping("/mail/info")
|
||||||
public MailInfo mailInfo() {
|
public MailInfo mailInfo() {
|
||||||
return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
|
return SystemParameterService.mailInfo(ParamConstants.Classify.MAIL.getValue());
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
<el-col :span="12" class="align-right">
|
<el-col :span="12" class="align-right">
|
||||||
<!-- float right -->
|
<!-- float right -->
|
||||||
<ms-user/>
|
<ms-user ref="headerUser"/>
|
||||||
<ms-language-switch :color="color"/>
|
<ms-language-switch :color="color"/>
|
||||||
<ms-header-org-ws :color="color"/>
|
<ms-header-org-ws :color="color"/>
|
||||||
</el-col>
|
</el-col>
|
||||||
|
@ -39,6 +39,7 @@ const requireComponent = require.context('@/business/components/xpack/', true, /
|
||||||
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") : {};
|
||||||
const theme = requireComponent.keys().length > 0 ? requireComponent("./display/Theme.vue") : {};
|
const theme = requireComponent.keys().length > 0 ? requireComponent("./display/Theme.vue") : {};
|
||||||
|
let timer = null;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'app',
|
name: 'app',
|
||||||
|
@ -49,11 +50,13 @@ export default {
|
||||||
auth: false,
|
auth: false,
|
||||||
header: {},
|
header: {},
|
||||||
logoId: '_blank',
|
logoId: '_blank',
|
||||||
color: ''
|
color: '',
|
||||||
}
|
sessionTimer: null,
|
||||||
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
registerRequestHeaders();
|
registerRequestHeaders();
|
||||||
|
this.initSessionTimer();
|
||||||
if (!hasLicense()) {
|
if (!hasLicense()) {
|
||||||
setDefaultTheme();
|
setDefaultTheme();
|
||||||
this.color = ORIGIN_COLOR;
|
this.color = ORIGIN_COLOR;
|
||||||
|
@ -63,20 +66,20 @@ export default {
|
||||||
this.color = res.data ? res.data : ORIGIN_COLOR;
|
this.color = res.data ? res.data : ORIGIN_COLOR;
|
||||||
setColor(this.color, this.color, this.color, this.color, this.color);
|
setColor(this.color, this.color, this.color, this.color, this.color);
|
||||||
this.$store.commit('setTheme', res.data);
|
this.$store.commit('setTheme', res.data);
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
if (localStorage.getItem("store")) {
|
if (localStorage.getItem("store")) {
|
||||||
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store"))))
|
this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem("store"))));
|
||||||
this.$get("/project/listAll", response => {
|
this.$get("/project/listAll", response => {
|
||||||
let projectIds = response.data;
|
let projectIds = response.data;
|
||||||
if (projectIds && projectIds.length <= 0) {
|
if (projectIds && projectIds.length <= 0) {
|
||||||
this.$store.commit('setProjectId', undefined);
|
this.$store.commit('setProjectId', undefined);
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
window.addEventListener("beforeunload", () => {
|
window.addEventListener("beforeunload", () => {
|
||||||
localStorage.setItem("store", JSON.stringify(this.$store.state))
|
localStorage.setItem("store", JSON.stringify(this.$store.state));
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
beforeCreate() {
|
beforeCreate() {
|
||||||
this.$get("/isLogin").then(response => {
|
this.$get("/isLogin").then(response => {
|
||||||
|
@ -93,12 +96,33 @@ export default {
|
||||||
display.default.showHome(this);
|
display.default.showHome(this);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
window.location.href = "/login"
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
window.location.href = "/login"
|
window.location.href = "/login";
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
methods: {
|
||||||
|
initSessionTimer() {
|
||||||
|
this.$get('/system/timeout')
|
||||||
|
.then(response => {
|
||||||
|
window.addEventListener('click', () => {
|
||||||
|
this.currentTime(response.data.data);
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
});
|
||||||
|
},
|
||||||
|
currentTime(timeout) { // 超时退出
|
||||||
|
if (timer) {
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
timer = null;
|
||||||
|
}
|
||||||
|
timer = window.setTimeout(() => {
|
||||||
|
this.$refs.headerUser.logout();
|
||||||
|
}, 1000 * timeout);
|
||||||
|
},
|
||||||
|
},
|
||||||
components: {
|
components: {
|
||||||
MsLanguageSwitch,
|
MsLanguageSwitch,
|
||||||
MsUser,
|
MsUser,
|
||||||
|
@ -108,7 +132,7 @@ export default {
|
||||||
"LicenseMessage": header.default,
|
"LicenseMessage": header.default,
|
||||||
"Theme": theme.default
|
"Theme": theme.default
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue