index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. import axios from '~plugins/axios'
  2. // 获取品牌详情产品分类信息
  3. function loadBrandCategories ({commit}, params = {}) {
  4. let id = params.id
  5. commit('brandCategories/REQUEST_CATEGORIES', params)
  6. return axios.get(`/api/product/brand/${id}/kinds`)
  7. .then(response => {
  8. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  9. }, err => {
  10. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  11. })
  12. }
  13. // 获取品牌详情型号列表数据
  14. function loadBrandComponent ({commit}, params = {}) {
  15. commit('brandComponent/REQUEST_COMPONENT', params)
  16. return axios.get('/api/product/component/list', { params })
  17. .then(response => {
  18. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  19. }, err => {
  20. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  21. })
  22. }
  23. export const actions = {
  24. // 全局服务初始化
  25. nuxtServerInit (store, { params, route, isServer, req }) {
  26. // 检查设备类型
  27. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  28. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  29. const cookie = isServer ? req.headers['cookie'] : null
  30. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  31. store.commit('option/SET_USER_AGENT', userAgent)
  32. store.commit('option/SET_COOKIES', cookie)
  33. return Promise.all([
  34. // 全局数据
  35. store.dispatch('loadUserInfo')
  36. ])
  37. },
  38. // 获取用户信息
  39. loadUserInfo ({ commit }) {
  40. commit('option/REQUEST_USER_INFO')
  41. return axios.get('/user/authentication')
  42. .then(response => {
  43. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  44. }, err => {
  45. commit('option/REQUEST_USER_INFO_FAILURE', err)
  46. })
  47. },
  48. // 用户退出
  49. logout ({ commit }) {
  50. return axios.get('/logout')
  51. .then(response => {
  52. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  53. })
  54. },
  55. // 获取楼层配置
  56. loadFloors ({ commit }) {
  57. commit('floor/REQUEST_LIST')
  58. return axios.get('/api/floors/home')
  59. .then(response => {
  60. commit('floor/GET_LIST_SUCCESS', response.data)
  61. }, err => {
  62. commit('floor/GET_LIST_FAILURE', err)
  63. })
  64. },
  65. // 获取轮播配置
  66. loadBanners ({ commit }) {
  67. commit('carousel/REQUEST_BANNER')
  68. return axios.get('/api/carousel/home%20page%20banner')
  69. .then(response => {
  70. commit('carousel/GET_BANNER_SUCCESS', response.data)
  71. }, err => {
  72. commit('carousel/GET_BANNER_FAILURE', err)
  73. })
  74. },
  75. // 获取子器件类目
  76. loadProductKinds ({ commit }, params = {}) {
  77. let id = params.id
  78. commit('product/kind/REQUEST_KIND', params)
  79. return axios.get(`/api/product/kind/${id}/children`)
  80. .then(response => {
  81. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  82. }, err => {
  83. commit('product/kind/GET_KIND_FAILURE', {id, err})
  84. })
  85. },
  86. // 获取全部子器件类目
  87. loadAllProductKinds ({ commit }, params = {}) {
  88. let id = params.id
  89. commit('product/kind/REQUEST_KIND', params)
  90. return axios.get(`/api/product/kind/${id}/children_all`)
  91. .then(response => {
  92. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  93. }, err => {
  94. commit('product/kind/GET_KIND_FAILURE', {id, err})
  95. })
  96. },
  97. // 获取首页新闻
  98. loadNewsSnapshot ({ commit }, params = {}) {
  99. commit('news/REQUEST_SNAPSHOT')
  100. return axios.get('/api/news/created', {params})
  101. .then(response => {
  102. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  103. }, err => {
  104. commit('news/GET_SNAPSHOT_FAILURE', err)
  105. })
  106. },
  107. // 获取器件统计信息
  108. loadProductCounts ({ commit }, params = {}) {
  109. commit('product/common/REQUEST_COUNTS')
  110. return axios.get('/api/product/commoncount', {params})
  111. .then(response => {
  112. commit('product/common/GET_COUNTS_SUCCESS', response.data)
  113. }, err => {
  114. commit('product/common/GET_COUNTS_FAILURE', err)
  115. })
  116. },
  117. // 搜索关键字
  118. searchKeywords ({ commit }, params = {}) {
  119. commit('search/REQUEST_KEYWORDS')
  120. return axios.get('/search/similarKeywords', {params})
  121. .then(response => {
  122. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  123. }, err => {
  124. commit('search/GET_KEYWORDS_FAILURE', err)
  125. })
  126. },
  127. resetSearchKeywords ({ commit }) {
  128. commit('search/RESET_KEYWORDS')
  129. },
  130. // 热卖推荐页面
  131. loadProductHot ({commit}, params = {}) {
  132. commit('original/REQUEST_HOT')
  133. return axios.get('/api/commodity/latest', {params})
  134. .then(response => {
  135. commit('original/GET_HOT_SUCCESS', response.data)
  136. }, err => {
  137. commit('original/GET_HOT_FAILURE', err)
  138. })
  139. },
  140. // 器件详情页面
  141. // 获得器件详情信息
  142. loadComponentDetail ({commit}, params = {}) {
  143. let id = params.id
  144. commit('componentDetail/REQUEST_DETAIL', params)
  145. return axios.get(`/api/product/component/${id}`)
  146. .then(response => {
  147. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  148. if (response.data) {
  149. commit('componentMenu/REQUEST_MENU', params)
  150. return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
  151. .then(response => {
  152. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  153. }, err => {
  154. commit('componentMenu/GET_MENU_FAILURE', err)
  155. })
  156. }
  157. }, err => {
  158. commit('componentDetail/GET_DETAIL_FAILURE', err)
  159. })
  160. },
  161. // 获取器件详情页面包屑导航
  162. loadComponentMenu ({commit}, params = {}) {
  163. let pid = params.id
  164. commit('componentMenu/REQUEST_MENU', params)
  165. return axios.get(`/api/product/kind/structing/${pid}`)
  166. .then(response => {
  167. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  168. }, err => {
  169. commit('componentMenu/GET_MENU_FAILURE', err)
  170. })
  171. },
  172. // 器件详情页选择商家
  173. loadComponentStore ({commit}, params = {}) {
  174. let id = params.uuid
  175. commit('componentStore/REQUEST_STORE', params)
  176. return axios.get(`/api/store-service/stores/uuid/${id}`)
  177. .then(response => {
  178. commit('componentStore/GET_STORE_SUCCESS', response.data)
  179. }, err => {
  180. commit('componentStore/GET_STORE_FAILURE', err)
  181. })
  182. },
  183. // 器件详情页商家列表
  184. loadComponentInformation ({commit}, uuid = '', pageParams = { page: 1, count: 10 }) {
  185. let params = {}
  186. let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
  187. // let sorting = {minPriceRMB: 'ASC'}
  188. params.filter = filter
  189. // params.sorting = sorting
  190. params.page = pageParams.page
  191. params.count = pageParams.count
  192. commit('componentInformation/REQUEST_INFORMATION')
  193. return axios.get('/api/commodity/goods/page', { params })
  194. .then(response => {
  195. commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
  196. }, err => {
  197. commit('componentInformation/GET_INFORMATION_FAILURE', err)
  198. })
  199. },
  200. // 品牌详情页面
  201. // 获得品牌详情信息
  202. loadBrandDetail ({commit, dispatch}, params = {}) {
  203. let id = params.id
  204. commit('brandDetail/REQUEST_DETAIL', params)
  205. return axios.get(`/api/product/brand/${id}`)
  206. .then(response => {
  207. let brand = response.data || {}
  208. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  209. return Promise.all([
  210. loadBrandCategories({ commit }, {id: brand.id}),
  211. loadBrandComponent({ commit }, {count: 10, filter: { brandid: brand.id }, page: 1})
  212. ])
  213. }, err => {
  214. commit('brandDetail/GET_DETAIL_FAILURE', err)
  215. })
  216. },
  217. // 获取品牌详情产品分类信息
  218. loadBrandCategories ({commit}, params = {}) {
  219. let id = params.id
  220. commit('brandCategories/REQUEST_CATEGORIES', params)
  221. return axios.get(`/api/product/brand/${id}/kinds`)
  222. .then(response => {
  223. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  224. }, err => {
  225. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  226. })
  227. },
  228. // 获取品牌详情型号列表数据
  229. loadBrandComponent ({commit}, params = {}) {
  230. commit('brandComponent/REQUEST_COMPONENT', params)
  231. return axios.get('/api/product/component/list', { params })
  232. .then(response => {
  233. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  234. }, err => {
  235. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  236. })
  237. },
  238. // 获取品牌详情分页信息
  239. loadBrandPages ({commit}, params = {}) {
  240. commit('brandPages/REQUEST_PAGES', params)
  241. return axios.get('/api/product/PAGES/list', { params })
  242. .then(response => {
  243. commit('brandPages/GET__SUCCESS', response.data)
  244. }, err => {
  245. commit('brandPages/GET_COMPONENT_FAILURE', err)
  246. })
  247. },
  248. // 获取帮助中心信息
  249. loadHelpSnapsho ({ commit }, params = {}) {
  250. commit('help/REQUEST_SNAPSHO')
  251. return axios.get('/api/help-service/helps', {params})
  252. .then(response => {
  253. commit('help/GET_SNAPSHO_SUCCESS', response.data)
  254. }, err => {
  255. commit('help/GET_SNAPSHO_FAILURE', err)
  256. })
  257. },
  258. // 获取帮助中心二级菜单
  259. loadHelpList ({ commit }, params = {}) {
  260. commit('help/REQUEST_HELPLIST')
  261. return axios.get('/api/help-service/issues', {params})
  262. .then(response => {
  263. commit('help/GET_HELPLIST_SUCCESS', response.data)
  264. }, err => {
  265. commit('help/GET_HELPLIST_FAILURE', err)
  266. })
  267. },
  268. // 获取帮助中心名称
  269. loadHelpTitle ({ commit }, params = {}) {
  270. let id = params.id
  271. commit('help/REQUEST_TITLE')
  272. return axios.get(`/api/help-service/${id}`, {params})
  273. .then(response => {
  274. commit('help/GET_TITLE_SUCCESS', response.data)
  275. }, err => {
  276. commit('help/GET_TITLE_FAILURE', err)
  277. })
  278. },
  279. // 获取详情
  280. loadHelpDetail ({ commit }, params = {}) {
  281. let id = params.id
  282. commit('help/REQUEST_DETAIL')
  283. return axios.get(`/api/help-service/issues/${id}`, {params})
  284. .then(response => {
  285. commit('help/GET_DETAIL_SUCCESS', response.data)
  286. let id = response.data.navId
  287. commit('help/REQUEST_TITLE')
  288. return axios.get(`/api/help-service/${id}`)
  289. .then(response => {
  290. commit('help/GET_TITLE_SUCCESS', response.data)
  291. }, err => {
  292. commit('help/GET_TITLE_FAILURE', err)
  293. })
  294. }, err => {
  295. commit('help/GET_DETAIL_FAILURE', err)
  296. })
  297. }
  298. }