index.js 10.0 KB

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