index.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. import axios from '~plugins/axios'
  2. export const actions = {
  3. // 全局服务初始化
  4. nuxtServerInit (store, { params, route, isServer, req }) {
  5. // 检查设备类型
  6. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  7. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  8. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  9. store.commit('option/SET_USER_AGENT', userAgent)
  10. return Promise.all([
  11. // 全局数据
  12. // store.dispatch('loadUserInfo')
  13. ])
  14. },
  15. // 获取用户信息
  16. loadUserInfo ({ commit }) {
  17. commit('option/REQUEST_USER_INFO')
  18. return axios.get('/user/authentication')
  19. .then(response => {
  20. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  21. }, err => {
  22. commit('option/REQUEST_USER_INFO_FAILURE', err)
  23. })
  24. },
  25. // 用户退出
  26. logout ({ commit }) {
  27. return axios.get('/logout')
  28. .then(response => {
  29. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  30. })
  31. },
  32. // 获取楼层配置
  33. loadFloors ({ commit }) {
  34. commit('floor/REQUEST_LIST')
  35. return axios.get('/api/floors/home')
  36. .then(response => {
  37. commit('floor/GET_LIST_SUCCESS', response.data)
  38. }, err => {
  39. commit('floor/GET_LIST_FAILURE', err)
  40. })
  41. },
  42. // 获取轮播配置
  43. loadBanners ({ commit }) {
  44. commit('carousel/REQUEST_BANNER')
  45. return axios.get('/api/carousel/home%20page%20banner')
  46. .then(response => {
  47. commit('carousel/GET_BANNER_SUCCESS', response.data)
  48. }, err => {
  49. commit('carousel/GET_BANNER_FAILURE', err)
  50. })
  51. },
  52. // 获取子器件类目
  53. loadProductKinds ({ commit }, params = {}) {
  54. let id = params.id
  55. commit('product/REQUEST_KIND', params)
  56. return axios.get(`/api/product/kind/${id}/children`)
  57. .then(response => {
  58. commit('product/GET_KIND_SUCCESS', { id, result: response.data })
  59. }, err => {
  60. commit('product/GET_KIND_FAILURE', {id, err})
  61. })
  62. },
  63. // 获取全部子器件类目
  64. loadAllProductKinds ({ commit }, params = {}) {
  65. let id = params.id
  66. commit('product/REQUEST_KIND', params)
  67. return axios.get(`/api/product/kind/${id}/children_all`)
  68. .then(response => {
  69. commit('product/GET_KIND_SUCCESS', { id, result: response.data })
  70. }, err => {
  71. commit('product/GET_KIND_FAILURE', {id, err})
  72. })
  73. },
  74. // 获取首页新闻
  75. loadNewsSnapshot ({ commit }, params = {}) {
  76. commit('news/REQUEST_SNAPSHOT')
  77. return axios.get('/api/news/created', {params})
  78. .then(response => {
  79. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  80. }, err => {
  81. commit('news/GET_SNAPSHOT_FAILURE', err)
  82. })
  83. },
  84. // 获取器件统计信息
  85. loadProductCounts ({ commit }, params = {}) {
  86. commit('product/REQUEST_COUNTS')
  87. return axios.get('/api/product/commoncount', {params})
  88. .then(response => {
  89. commit('product/GET_COUNTS_SUCCESS', response.data)
  90. }, err => {
  91. commit('product/GET_COUNTS_FAILURE', err)
  92. })
  93. },
  94. // 搜索关键字
  95. searchKeywords ({ commit }, params = {}) {
  96. commit('search/REQUEST_KEYWORDS')
  97. return axios.get('/search/similarKeywords', {params})
  98. .then(response => {
  99. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  100. }, err => {
  101. commit('search/GET_KEYWORDS_FAILURE', err)
  102. })
  103. },
  104. resetSearchKeywords ({ commit }) {
  105. commit('search/RESET_KEYWORDS')
  106. },
  107. // 热卖推荐页面
  108. loadProductHot ({commit}, params = {}) {
  109. commit('original/REQUEST_HOT')
  110. return axios.get('/api/commodity/latest', {params})
  111. .then(response => {
  112. commit('original/GET_HOT_SUCCESS', response.data)
  113. }, err => {
  114. commit('original/GET_HOT_FAILURE', err)
  115. })
  116. },
  117. // 器件详情页面
  118. // 获得器件详情信息
  119. loadComponentDetail ({commit}, params = {}) {
  120. let id = params.id
  121. console.log(id)
  122. commit('componentDetail/REQUEST_DETAIL', params)
  123. return axios.get(`/api/product/component/${id}`)
  124. .then(response => {
  125. console.log('response', response.data)
  126. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  127. }, err => {
  128. commit('componentDetail/GET_DETAIL_FAILURE', err)
  129. })
  130. },
  131. // 获取器件详情页面包屑导航
  132. loadComponentMenu ({commit}, params = {}) {
  133. let pid = params.id
  134. console.log(pid)
  135. commit('componentMenu/REQUEST_MENU', params)
  136. return axios.get(`/api/product/kind/structing/${pid}`)
  137. .then(response => {
  138. console.log('response', response.data)
  139. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  140. }, err => {
  141. commit('componentMenu/GET_MENU_FAILURE', err)
  142. })
  143. },
  144. // 器件详情页选择商家
  145. loadComponentStore ({commit}, params = {}) {
  146. let sid = params.id
  147. commit('componentStore/REQUEST_STORE', params)
  148. return axios.get(`/api/store-service/stores/uuid/${sid}`)
  149. .then(response => {
  150. console.log('response', response.data)
  151. commit('componentStore/GET_STORE_SUCCESS', response.data)
  152. }, err => {
  153. commit('componentStore/GET_STORE_FAILURE', err)
  154. })
  155. },
  156. // 品牌详情页面
  157. // 获得品牌详情信息
  158. loadBrandDetail ({commit}, params = {}) {
  159. let id = params.id
  160. console.log(id)
  161. commit('brandDetail/REQUEST_DETAIL', params)
  162. return axios.get(`/api/product/brand/${id}`)
  163. .then(response => {
  164. console.log('response', response.data)
  165. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  166. }, err => {
  167. commit('brandDetail/GET_DETAIL_FAILURE', err)
  168. })
  169. },
  170. // 获取品牌详情产品分类信息
  171. loadBrandCategories ({commit}, params = {}) {
  172. let id = params.id
  173. commit('brandCategories/REQUEST_CATEGORIES', params)
  174. return axios.get(`/api/product/brand/${id}/kinds`)
  175. .then(response => {
  176. console.log('response', response.data)
  177. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  178. }, err => {
  179. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  180. })
  181. }
  182. }