|
|
@ -8,6 +8,7 @@
|
|
|
|
import { TOKEN_KEY } from "@/constants";
|
|
|
|
import { TOKEN_KEY } from "@/constants";
|
|
|
|
import { ApiGetCurrentUser, ApiPostLogout } from "@/plugins/api/account";
|
|
|
|
import { ApiGetCurrentUser, ApiPostLogout } from "@/plugins/api/account";
|
|
|
|
import { ApiGetCartList } from "@/plugins/api/cart";
|
|
|
|
import { ApiGetCartList } from "@/plugins/api/cart";
|
|
|
|
|
|
|
|
import { ApiGetCategoryOneList } from "@/plugins/api/goods";
|
|
|
|
const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000;
|
|
|
|
const ONE_DAY = 86400000; // 一天的毫秒数 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
|
|
|
|
const state = () => ({
|
|
|
|
const state = () => ({
|
|
|
@ -16,6 +17,7 @@ const state = () => ({
|
|
|
|
loginVisible: false, // 是否展示登录弹窗
|
|
|
|
loginVisible: false, // 是否展示登录弹窗
|
|
|
|
seckillTabVisible: false, // 公共头是否展示秒杀tab
|
|
|
|
seckillTabVisible: false, // 公共头是否展示秒杀tab
|
|
|
|
cartProducts: [], // 购物车列表
|
|
|
|
cartProducts: [], // 购物车列表
|
|
|
|
|
|
|
|
categroyData: [], // 公共页头分类数据
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const mutations = {
|
|
|
|
const mutations = {
|
|
|
|
setUserInfo(state, info) {
|
|
|
|
setUserInfo(state, info) {
|
|
|
@ -42,14 +44,23 @@ const mutations = {
|
|
|
|
setCartProducts(state, val) {
|
|
|
|
setCartProducts(state, val) {
|
|
|
|
state.cartProducts = val;
|
|
|
|
state.cartProducts = val;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
setCategroyData(state, val) {
|
|
|
|
|
|
|
|
state.categroyData = val;
|
|
|
|
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const actions = {
|
|
|
|
const actions = {
|
|
|
|
nuxtServerInit({ state, commit, dispatch }) {
|
|
|
|
async nuxtServerInit({ state, commit, dispatch }) {
|
|
|
|
|
|
|
|
// 设置token数据
|
|
|
|
const token = this.$cookies.get(TOKEN_KEY);
|
|
|
|
const token = this.$cookies.get(TOKEN_KEY);
|
|
|
|
if (!state.token && token) {
|
|
|
|
if (!state.token && token) {
|
|
|
|
commit("setToken", token);
|
|
|
|
commit("setToken", token);
|
|
|
|
dispatch("getUserInfo");
|
|
|
|
dispatch("getUserInfo");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 获取分类数据
|
|
|
|
|
|
|
|
const { result } = await ApiGetCategoryOneList();
|
|
|
|
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
commit("setCategroyData", result);
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
async getUserInfo({ commit }) {
|
|
|
|
async getUserInfo({ commit }) {
|
|
|
|
const { result } = await ApiGetCurrentUser();
|
|
|
|
const { result } = await ApiGetCurrentUser();
|
|
|
|