home.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import PersistedState from '../PersistedState'
  2. import { homeIndexAdList, homeIndexProductList } from '../../api/homeindex'
  3. import { getArticleList } from '../../api/homeArticle'
  4. // initial state
  5. const state = {
  6. banners:PersistedState.getStorage('home','banners'), // 首页Banner
  7. navs:PersistedState.getStorage('home','navs'), // 首页导航
  8. floorAds:PersistedState.getStorage('home','floorAds'), // 横屏广告图
  9. promotionAds:PersistedState.getStorage('home','promotionAds'), // 促销广告图 3 张
  10. articles:PersistedState.getStorage('home','articles'), // 商城公告分类下的文章 首页显示
  11. hotProducts:PersistedState.getStorage('home','hotProducts'), // 首页热门产品
  12. recentlyProducts:PersistedState.getStorage('home','recentlyProducts'),
  13. goodProducts:PersistedState.getStorage('home','goodProducts'),
  14. xianshiProducts:PersistedState.getStorage('home','xianshiProducts'),
  15. special:PersistedState.getStorage('home','special',{}),
  16. closePopupAdv:false,
  17. closeStorePopupAdv:false,
  18. }
  19. // mutations
  20. const mutations = {
  21. saveHomeSpecial(state, data){
  22. if(data.editablePage){
  23. state.special[data.pagePath+data.itemId+data.storeId]=data
  24. }else{
  25. state.special[data.pagePath+data.itemId+data.storeId]=false
  26. }
  27. PersistedState.setStorage('home',state)
  28. },
  29. saveClosePopupAdv (state, data) {
  30. state.closePopupAdv = data.closePopupAdv
  31. },
  32. saveCloseStorePopupAdv (state, data) {
  33. state.closeStorePopupAdv = data.closeStorePopupAdv
  34. },
  35. saveHomeAds (state, data) {
  36. state.banners = data.result.banners
  37. state.navs = data.result.navs
  38. state.floorAds = data.result.floor_ads
  39. state.promotionAds = data.result.promotion_ads
  40. PersistedState.setStorage('home',state)
  41. },
  42. saveHomeArticles (state, data) {
  43. state.articles = data.result.article_list
  44. PersistedState.setStorage('home',state)
  45. },
  46. saveHomeProducts (state, data) {
  47. state.hotProducts = data.result.hot_products
  48. state.recentlyProducts = data.result.recently_products
  49. state.goodProducts = data.result.good_products
  50. state.xianshiProducts = data.result.xianshi_products
  51. PersistedState.setStorage('home',state)
  52. }
  53. }
  54. // actions
  55. const actions = {
  56. // 获取首页轮播图
  57. fetchHomeAd ({ commit, state }, params) {
  58. return new Promise((resolve, reject) => {
  59. homeIndexAdList().then(
  60. (response) => {
  61. commit('saveHomeAds', response)
  62. resolve(response)
  63. }, (error) => {
  64. reject(error)
  65. })
  66. })
  67. },
  68. // 获取首页商城公告分类下文章
  69. fetchHomeArticle ({ commit, state }, params) {
  70. return new Promise((resolve, reject) => {
  71. // 文章分类ID为1 下的文章列表
  72. getArticleList('', 1).then(
  73. (response) => {
  74. commit('saveHomeArticles', response)
  75. resolve(response)
  76. }, (error) => {
  77. reject(error)
  78. })
  79. })
  80. },
  81. // 获取首页产品
  82. fetchHomeProduct ({ commit, state }, params) {
  83. return new Promise((resolve, reject) => {
  84. homeIndexProductList(params.name).then(
  85. (response) => {
  86. commit('saveHomeProducts', response)
  87. resolve(response)
  88. }, (error) => {
  89. reject(error)
  90. })
  91. })
  92. }
  93. }
  94. export default {
  95. state,
  96. mutations,
  97. actions
  98. }