router.beforeEach((to, from, next) => {
if (!skipAuth(to.path)) {
let currentDatetime = new Date().getTime();
let lastLoginSuccessDateTime = localStorage.getItem(“createTokenTime”) ? Number(localStorage.getItem(“createTokenTime”)) : 0
let loginSessionPeriod = 1000 * 60 * 60 * 24 * 7;
if (!(localStorage.getItem(“_token”) && (currentDatetime – lastLoginSuccessDateTime < loginSessionPeriod))) {
//未登录
location.href = “/login”;
}
}
next();
})
function skipAuth(to: String) {
const skipAuthUri = [‘/login’];
for (let uri of skipAuthUri) {
if (to == uri) {
return true;
}
}
return false;
}
本文来自 余 倩倩 投稿,不代表 PmTemple 立场,如若转载,请注明出处:
。如有涉及侵权行为,请发送相关证明材料至邮箱admin@pmtemple.com