From 9f6406424e786a7da995ce445ba05b5690948fec Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Sat, 30 Jun 2018 11:36:06 +0800 Subject: [PATCH] auto commit on save Former-commit-id: e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly e201f6227d9a219f4649f5da143f6bca9450533b [formerly 942fc2c1ecb4acadc3ea3263fa98dcb0cc8a8384 [formerly 5a76e04062564d23570aa415dd3aefc68d23e5f6]]]]] Former-commit-id: bd8706af49ef4017e036b4a0db1d291fdebf3b61 Former-commit-id: 6068f9065eb9d80b4e46fc8508ae3e6a0bade5eb Former-commit-id: d7aa5aff751370ac1ce7c8681b70d2f4f6fd679b [formerly 77c021aaf98c021623f641310c007451b8489d81] Former-commit-id: 306eb675bbd8331b4adc95e0db5197c262174ad8 Former-commit-id: 11d9451e600878ce1448b555915a3c73aae37adf Former-commit-id: acaf75124bec8cea6b21ad581d60a660ce0d1cf6 Former-commit-id: 7fedcb8810b5ae39617f62e002bad67d72388460 Former-commit-id: 81cc5e9d1f2c2fe1d15f596994e1b93cd13bf25c --- src/router/index.js | 52 +++++++++++++++++++ src/router/index.js.REMOVED.git-id | 1 - ...MOVED.git-id => routers.js.REMOVED.git-id} | 0 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 src/router/index.js delete mode 100644 src/router/index.js.REMOVED.git-id rename src/router/{router.js.REMOVED.git-id => routers.js.REMOVED.git-id} (100%) diff --git a/src/router/index.js b/src/router/index.js new file mode 100755 index 00000000..f4ecf27c --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,52 @@ +import Vue from 'vue' +import VueRouter from 'vue-router' +import Cookies from 'js-cookie' + +import routers from './routers' + +import util from '@/libs/util.js' + +Vue.use(VueRouter) + +let router = new VueRouter({ routers }) + +/** + * 路由拦截 + * 权限验证 + */ +router.beforeEach((to, from, next) => { + // 验证当前路由所有的匹配中是否需要有登陆验证的 + if (to.matched.some(r => r.meta.requiresAuth)) { + // 这里暂时将cookie里是否存有token作为验证是否登陆的条件 + // 请根据自身业务需要修改 + if (Cookies.get('token')) { + next() + } else { + // 没有登陆的时候跳转到登陆界面 + next({ + name: 'login' + }) + } + } else { + // 不需要身份校验 直接通过 + next() + } +}) + +// TODO: 路由跳转后自动滚动到顶部 +router.afterEach(to => { + // 需要的信息 + const app = router.app + const { name, params, query } = to + // dev + console.group('router.afterEach') + console.log('app: ', app) + console.log('name: ', name) + console.log('params: ', params) + console.log('query: ', query) + console.groupEnd() + // 多页控制 打开新的页面 + util.openNewPage(app, name, params, query) +}) + +export default router diff --git a/src/router/index.js.REMOVED.git-id b/src/router/index.js.REMOVED.git-id deleted file mode 100644 index a8a6682b..00000000 --- a/src/router/index.js.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -0088ad6cc03c64af08ec7f8e7e691d0fec144c65 \ No newline at end of file diff --git a/src/router/router.js.REMOVED.git-id b/src/router/routers.js.REMOVED.git-id similarity index 100% rename from src/router/router.js.REMOVED.git-id rename to src/router/routers.js.REMOVED.git-id