Merge branch 'feature/task1.0.0_xg' into 'feature/task1.0.0'

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

See merge request yanxuan-frontend/shop-pc!74
merge-requests/75/head
肖广 3 years ago
commit 2c317806a1

@ -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,13 +1,10 @@
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(); next();
return;
}
next();
}); });
}; };

Loading…
Cancel
Save