From 4ba40cf54797bdd82e9547222aaa2f4678a6682c Mon Sep 17 00:00:00 2001 From: lnn19986213 <1667908750@qq.com> Date: Wed, 8 May 2024 11:08:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 51 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/src/router/index.js b/src/router/index.js index fc6f13a..3474202 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -14,32 +14,32 @@ const router = createRouter({ component: () => import('../view/home.vue'), children: [ { - name:'首页', + name: '首页', path: '/home/index', component: () => import('../view/sy.vue'), }, { - name:'养老', + name: '养老', path: '/home/yl', component: () => import('../view/yl.vue'), }, { - name:'卫生', + name: '卫生', path: '/home/hygiene', component: () => import('../view/hygiene.vue'), }, { - name:'教育', + name: '教育', path: '/home/education', component: () => import('../view/education.vue'), }, { - name:'就业补助', + name: '就业补助', path: '/home/work', component: () => import('../view/work.vue'), }, { - name:'智能分析', + name: '智能分析', path: '/home/analyze', component: () => import('../view/analyze.vue'), }, @@ -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 \ No newline at end of file