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