This commit is contained in:
lnn19986213 2024-05-08 11:08:00 +08:00
parent b51e366577
commit 4ba40cf547
1 changed files with 45 additions and 6 deletions

View File

@ -48,4 +48,43 @@ const router = createRouter({
]
})
function getCookie(cname) {
var name = cname + '='
var ca = document.cookie.split(';')
for (var i = 0; i < ca.length; i++) {
var c = ca[i].trim()
if (c.indexOf(name) == 0)
return c.substring(name.length, c.length)
}
return ''
}
router.beforeEach((to, form, next) => {
var token = getCookie('lytoken')
if (token == '') {
window.location.href =
'http://220.191.238.50:996/api/login?returnURL=' +
window.location.href
} else {
$.ajax({
url: '/api/zzdn_event/auditToken?token=' + token,
type: 'GET',
async: true,
success: function (res) {
if (res.code == '500') {
window.location.href =
'http://220.191.238.50:996/api/login?returnURL=' +
window.location.href
}
},
})
}
$.ajaxSetup({
beforeSend: function (xhr) {
token && xhr.setRequestHeader('x-token', token)
return true
},
})
})
export default router