feat: 未登录跳首页放入中间件判断

merge-requests/74/head
xiaoguang 3 years ago
parent 9956949fac
commit ff4a767917

@ -116,6 +116,7 @@
<script> <script>
import { mapState } from "vuex"; import { mapState } from "vuex";
import { CATEGROY_LEVEL } from "@/constants"; import { CATEGROY_LEVEL } from "@/constants";
import { ApiGetHomeSeckill } from "@/plugins/api/seckill";
import HeaderInfoBar from "./HeaderInfoBar.vue"; import HeaderInfoBar from "./HeaderInfoBar.vue";
import HeaderCategory from "./HeaderCategory.vue"; import HeaderCategory from "./HeaderCategory.vue";
import HeaderCart from "./HeaderCart.vue"; import HeaderCart from "./HeaderCart.vue";
@ -173,7 +174,16 @@ export default {
} }
}, },
}, },
created() {
this.getSeckillData();
},
methods: { methods: {
async getSeckillData() {
const { result } = await ApiGetHomeSeckill();
if (result && result.activityTimeVO) {
this.$store.commit("setSeckillTabVisible", true);
}
},
onLoginClick() { onLoginClick() {
this.$isLoginValidate(); this.$isLoginValidate();
}, },

@ -0,0 +1,10 @@
export default function ({ app, route, redirect }) {
if (!app.store.state.token) {
// 未登录直接打开需要登录的页面,跳转首页
const needLoginPage = [/\/account/, /\/cart/];
const result = needLoginPage.some((item) => item.test(route.path));
if (result) {
redirect("/");
}
}
}

@ -29,7 +29,8 @@ export default {
path: '/', path: '/',
component: resolve(__dirname, 'pages/index/index.vue') component: resolve(__dirname, 'pages/index/index.vue')
}) })
} },
middleware: ['redirect']
}, },
// Global CSS: https://go.nuxtjs.dev/config-css // Global CSS: https://go.nuxtjs.dev/config-css

@ -74,8 +74,6 @@ export default {
seckillData = seckillDataResult; seckillData = seckillDataResult;
} }
if (seckillData.activityTimeVO) { if (seckillData.activityTimeVO) {
store.commit("setSeckillTabVisible", true);
// //
const { result } = await ApiGetSeckillGoods({ const { result } = await ApiGetSeckillGoods({
pageIndex: 1, pageIndex: 1,

@ -1,12 +1,9 @@
export default ({ app }) => { export default ({ app }) => {
app.router.beforeEach((to, from, next) => { app.router.beforeEach((to, from, next) => {
// 获取用户信息
const { token, userInfo } = app.store.state; const { token, userInfo } = app.store.state;
if (token) { if (token && Object.keys(userInfo).length === 0) {
if (Object.keys(userInfo).length === 0) { app.store.dispatch("getUserInfo");
app.store.dispatch("getUserInfo");
}
next();
return;
} }
next(); next();
}); });

Loading…
Cancel
Save