import PersistedState from '../PersistedState' import { homeIndexAdList, homeIndexProductList } from '../../api/homeindex' import { getArticleList } from '../../api/homeArticle' // initial state const state = { banners:PersistedState.getStorage('home','banners'), // 首页Banner navs:PersistedState.getStorage('home','navs'), // 首页导航 floorAds:PersistedState.getStorage('home','floorAds'), // 横屏广告图 promotionAds:PersistedState.getStorage('home','promotionAds'), // 促销广告图 3 张 articles:PersistedState.getStorage('home','articles'), // 商城公告分类下的文章 首页显示 hotProducts:PersistedState.getStorage('home','hotProducts'), // 首页热门产品 recentlyProducts:PersistedState.getStorage('home','recentlyProducts'), goodProducts:PersistedState.getStorage('home','goodProducts'), xianshiProducts:PersistedState.getStorage('home','xianshiProducts'), special:PersistedState.getStorage('home','special',{}), closePopupAdv:false, closeStorePopupAdv:false, } // mutations const mutations = { saveHomeSpecial(state, data){ if(data.editablePage){ state.special[data.pagePath+data.itemId+data.storeId]=data }else{ state.special[data.pagePath+data.itemId+data.storeId]=false } PersistedState.setStorage('home',state) }, saveClosePopupAdv (state, data) { state.closePopupAdv = data.closePopupAdv }, saveCloseStorePopupAdv (state, data) { state.closeStorePopupAdv = data.closeStorePopupAdv }, saveHomeAds (state, data) { state.banners = data.result.banners state.navs = data.result.navs state.floorAds = data.result.floor_ads state.promotionAds = data.result.promotion_ads PersistedState.setStorage('home',state) }, saveHomeArticles (state, data) { state.articles = data.result.article_list PersistedState.setStorage('home',state) }, saveHomeProducts (state, data) { state.hotProducts = data.result.hot_products state.recentlyProducts = data.result.recently_products state.goodProducts = data.result.good_products state.xianshiProducts = data.result.xianshi_products PersistedState.setStorage('home',state) } } // actions const actions = { // 获取首页轮播图 fetchHomeAd ({ commit, state }, params) { return new Promise((resolve, reject) => { homeIndexAdList().then( (response) => { commit('saveHomeAds', response) resolve(response) }, (error) => { reject(error) }) }) }, // 获取首页商城公告分类下文章 fetchHomeArticle ({ commit, state }, params) { return new Promise((resolve, reject) => { // 文章分类ID为1 下的文章列表 getArticleList('', 1).then( (response) => { commit('saveHomeArticles', response) resolve(response) }, (error) => { reject(error) }) }) }, // 获取首页产品 fetchHomeProduct ({ commit, state }, params) { return new Promise((resolve, reject) => { homeIndexProductList(params.name).then( (response) => { commit('saveHomeProducts', response) resolve(response) }, (error) => { reject(error) }) }) } } export default { state, mutations, actions }