From e97096ffbc2de867a766bb646b38150723fe3a2b Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Tue, 17 May 2022 10:58:28 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=8E=BB=E6=8E=89=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=89=8D=E7=BD=AE=E9=92=A9=E5=AD=90=E5=86=85=E6=9C=AA?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=B7=B3=E8=BD=AC=E9=A1=B5=E9=9D=A2=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/router.js | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/plugins/router.js b/plugins/router.js index 805547e..5bde2fa 100644 --- a/plugins/router.js +++ b/plugins/router.js @@ -1,21 +1,13 @@ export default ({ app }) => { app.router.beforeEach((to, from, next) => { - // const { token, userInfo } = app.store.state; - // if (token) { - // if (Object.keys(userInfo).length === 0) { - // app.store.dispatch("getUserInfo"); - // } - // next(); - // return; - // } - - // // 未登录打开需要登录的页面,跳首页 - // const needLoginPage = [/\/account/, /\/cart/]; - // const result = needLoginPage.some((item) => item.test(to.path)); - // if (result) { - // next("/"); - // return; - // } + const { token, userInfo } = app.store.state; + if (token) { + if (Object.keys(userInfo).length === 0) { + app.store.dispatch("getUserInfo"); + } + next(); + return; + } next(); }); }; From ff4a7679175a55b0567aec6a592d07c54ea40ecb Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Tue, 17 May 2022 11:34:51 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=E6=9C=AA=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=B7=B3=E9=A6=96=E9=A1=B5=E6=94=BE=E5=85=A5=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E4=BB=B6=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- layouts/module/header/index.vue | 10 ++++++++++ middleware/redirect.js | 10 ++++++++++ nuxt.config.js | 3 ++- pages/index/index.vue | 2 -- plugins/router.js | 9 +++------ 5 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 middleware/redirect.js diff --git a/layouts/module/header/index.vue b/layouts/module/header/index.vue index 8fddce2..faded79 100644 --- a/layouts/module/header/index.vue +++ b/layouts/module/header/index.vue @@ -116,6 +116,7 @@