index.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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, isDev, isServer, req }) {
  26. // 检查设备类型
  27. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  28. const isMobile = /(iPhone|iPad|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. // 设置跳转的URL
  34. if (!isDev) {
  35. store.commit('option/UPDATE_URL', 'http://www.usoftmall.com')
  36. }
  37. return Promise.all([
  38. // 全局数据
  39. store.dispatch('loadUserInfo'),
  40. store.dispatch('loadProductCounts', { _status: 'actived' }),
  41. store.dispatch('loadHotSearchDevice'),
  42. store.dispatch('loadHotSearchBrand'),
  43. store.dispatch('loadNewFloors')
  44. ])
  45. },
  46. // 获取用户信息
  47. loadUserInfo ({ commit }) {
  48. commit('option/REQUEST_USER_INFO')
  49. return axios.get('/user/authentication')
  50. .then(response => {
  51. commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
  52. }, err => {
  53. commit('option/REQUEST_USER_INFO_FAILURE', err)
  54. })
  55. },
  56. // 用户退出
  57. logout ({ commit }) {
  58. return axios.get('/logout')
  59. .then(response => {
  60. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  61. })
  62. },
  63. // 获取楼层配置
  64. loadFloors ({ commit }) {
  65. commit('floor/REQUEST_LIST')
  66. return axios.get('/api/floors/home')
  67. .then(response => {
  68. commit('floor/GET_LIST_SUCCESS', response.data)
  69. }, err => {
  70. commit('floor/GET_LIST_FAILURE', err)
  71. })
  72. },
  73. // 批量获取产品信息
  74. loadBatchCommodities ({ commit }, params = {}) {
  75. commit('floor/REQUEST_EXPANDLIST')
  76. return axios.get('/api/commodity/detail', params)
  77. .then(response => {
  78. commit('floor/GET_EXPANDLIST_SUCCESS', response.data)
  79. }, err => {
  80. commit('floor/GET_EXPANDLIST_FAILURE', err)
  81. })
  82. },
  83. // 获取轮播配置
  84. loadBanners ({ commit }, params = {}) {
  85. commit('carousel/REQUEST_BANNER')
  86. return axios.get('/api/carousel/' + params.type + '%20' + (params.type === 'home' ? 'page' : 'zone') + '%20banner')
  87. .then(response => {
  88. commit('carousel/GET_BANNER_SUCCESS', response.data)
  89. }, err => {
  90. commit('carousel/GET_BANNER_FAILURE', err)
  91. })
  92. },
  93. // 获取新楼层配置
  94. loadNewFloors ({ commit }) {
  95. commit('floor/REQUEST_NEWLIST')
  96. return axios.get('/api/floors/home-v3')
  97. .then(response => {
  98. commit('floor/GET_NEWLIST_SUCCESS', response.data)
  99. }, err => {
  100. commit('floor/GET_NEWLIST_FAILURE', err)
  101. })
  102. },
  103. // 获取子器件类目
  104. loadProductKinds ({ commit }, params = {}) {
  105. let id = params.id
  106. commit('product/kind/REQUEST_KIND', params)
  107. return axios.get(`/api/product/kind/${id}/children`)
  108. .then(response => {
  109. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  110. }, err => {
  111. commit('product/kind/GET_KIND_FAILURE', {id, err})
  112. })
  113. },
  114. // 获取全部子器件类目
  115. loadAllProductKinds ({ commit }, params = {}) {
  116. let id = params.id
  117. commit('product/kind/REQUEST_KIND', params)
  118. return axios.get(`/api/product/kind/${id}/children_all`)
  119. .then(response => {
  120. commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
  121. }, err => {
  122. commit('product/kind/GET_KIND_FAILURE', {id, err})
  123. })
  124. },
  125. // 获取首页新闻
  126. loadNewsSnapshot ({ commit }, params = {}) {
  127. commit('news/REQUEST_SNAPSHOT')
  128. return axios.get('/api/news/created', {params})
  129. .then(response => {
  130. commit('news/GET_SNAPSHOT_SUCCESS', response.data)
  131. }, err => {
  132. commit('news/GET_SNAPSHOT_FAILURE', err)
  133. })
  134. },
  135. // 获取器件统计信息
  136. loadProductCounts ({ commit }, params = {}) {
  137. commit('product/common/REQUEST_COUNTS')
  138. return axios.get('/api/product/commoncount', {params})
  139. .then(response => {
  140. commit('product/common/GET_COUNTS_SUCCESS', response.data)
  141. }, err => {
  142. commit('product/common/GET_COUNTS_FAILURE', err)
  143. })
  144. },
  145. // 搜索关键字
  146. searchKeywords ({ commit }, params = {}) {
  147. commit('search/REQUEST_KEYWORDS')
  148. return axios.get('/search/similarKeywords', {params})
  149. .then(response => {
  150. commit('search/GET_KEYWORDS_SUCCESS', response.data)
  151. }, err => {
  152. commit('search/GET_KEYWORDS_FAILURE', err)
  153. })
  154. },
  155. resetSearchKeywords ({ commit }) {
  156. commit('search/RESET_KEYWORDS')
  157. },
  158. // 热卖推荐页面
  159. loadProductHot ({commit}, params = {}) {
  160. commit('original/REQUEST_HOT')
  161. return axios.get('/api/commodity/latest', {params})
  162. .then(response => {
  163. commit('original/GET_HOT_SUCCESS', response.data)
  164. }, err => {
  165. commit('original/GET_HOT_FAILURE', err)
  166. })
  167. },
  168. // 器件详情页面
  169. // 获得器件详情信息
  170. loadComponentDetail ({commit}, params = {}) {
  171. let id = params.id
  172. commit('componentDetail/REQUEST_DETAIL', params)
  173. return axios.get(`/api/product/component/${id}`)
  174. .then(response => {
  175. commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
  176. if (response.data) {
  177. commit('componentMenu/REQUEST_MENU', params)
  178. return axios.get(`/api/product/kind/structing/${response.data.kindid}`)
  179. .then(response => {
  180. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  181. }, err => {
  182. commit('componentMenu/GET_MENU_FAILURE', err)
  183. })
  184. }
  185. }, err => {
  186. commit('componentDetail/GET_DETAIL_FAILURE', err)
  187. })
  188. },
  189. // 获取器件详情页面包屑导航
  190. loadComponentMenu ({commit}, params = {}) {
  191. let pid = params.id
  192. commit('componentMenu/REQUEST_MENU', params)
  193. return axios.get(`/api/product/kind/structing/${pid}`)
  194. .then(response => {
  195. commit('componentMenu/GET_MENU_SUCCESS', response.data)
  196. }, err => {
  197. commit('componentMenu/GET_MENU_FAILURE', err)
  198. })
  199. },
  200. // 器件详情页选择商家
  201. loadComponentStore ({commit}, params = {}) {
  202. let id = params.uuid
  203. commit('componentStore/REQUEST_STORE', params)
  204. return axios.get(`/api/store-service/stores/uuid/${id}`)
  205. .then(response => {
  206. commit('componentStore/GET_STORE_SUCCESS', response.data)
  207. }, err => {
  208. commit('componentStore/GET_STORE_FAILURE', err)
  209. })
  210. },
  211. // 器件详情页商家列表
  212. loadComponentInformation ({commit}, params = {}) {
  213. // let params = {}
  214. // let filter = {uuid: uuid.uuid, ignoreUMall: false, ignoreStore: false}
  215. // // let sorting = {minPriceRMB: 'ASC'}
  216. // params.filter = filter
  217. // // params.sorting = sorting
  218. // params.page = pageParams.page
  219. // params.count = pageParams.count
  220. commit('componentInformation/REQUEST_INFORMATION')
  221. return axios.get('/api/commodity/goods/page', { params })
  222. .then(response => {
  223. commit('componentInformation/GET_INFORMATION_SUCCESS', response.data)
  224. }, err => {
  225. commit('componentInformation/GET_INFORMATION_FAILURE', err)
  226. })
  227. },
  228. // 获取库存寄售店铺storeid
  229. getUmallStoreId ({commit}) {
  230. commit('componentUmallStoreId/REQUEST_STOREID')
  231. return axios.get('/api/store-service/stores/UmallStore')
  232. .then(response => {
  233. commit('componentUmallStoreId/GET_STOREID_SUCCESS', response.data)
  234. }, err => {
  235. commit('componentUmallStoreId/GET_STOREID_FAILURE', err)
  236. })
  237. },
  238. // 品牌详情页面
  239. // 获得品牌详情信息
  240. loadBrandDetail ({commit, dispatch}, params = {}) {
  241. let id = params.id
  242. commit('brandDetail/REQUEST_DETAIL', params)
  243. return axios.get(`/api/product/brand/${id}`)
  244. .then(response => {
  245. let brand = response.data || {}
  246. commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
  247. return Promise.all([
  248. loadBrandCategories({ commit }, {id: brand.id}),
  249. loadBrandComponent({ commit }, {count: 10, filter: { brandid: brand.id }, page: 1})
  250. ])
  251. }, err => {
  252. commit('brandDetail/GET_DETAIL_FAILURE', err)
  253. })
  254. },
  255. // 获取品牌详情产品分类信息
  256. loadBrandCategories ({commit}, params = {}) {
  257. let id = params.id
  258. commit('brandCategories/REQUEST_CATEGORIES', params)
  259. return axios.get(`/api/product/brand/${id}/kinds`)
  260. .then(response => {
  261. commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
  262. }, err => {
  263. commit('brandCategories/GET_CATEGORIES_FAILURE', err)
  264. })
  265. },
  266. // 获取品牌详情型号列表数据
  267. loadBrandComponent ({commit}, params = {}) {
  268. commit('brandComponent/REQUEST_COMPONENT', params)
  269. return axios.get('/api/product/component/list', { params })
  270. .then(response => {
  271. commit('brandComponent/GET_COMPONENT_SUCCESS', response.data)
  272. }, err => {
  273. commit('brandComponent/GET_COMPONENT_FAILURE', err)
  274. })
  275. },
  276. // 获取品牌详情分页信息
  277. loadBrandPages ({commit}, params = {}) {
  278. commit('brandPages/REQUEST_PAGES', params)
  279. return axios.get('/api/product/PAGES/list', { params })
  280. .then(response => {
  281. commit('brandPages/GET__SUCCESS', response.data)
  282. }, err => {
  283. commit('brandPages/GET_COMPONENT_FAILURE', err)
  284. })
  285. },
  286. // 留言板
  287. // 提交了留言板信息
  288. uploadMessageBoardInformation ({commit}, params) {
  289. commit('messageBoard/REQUEST_INFORMATION')
  290. return axios.post('/api/operation/messageBoard', params)
  291. .then(response => {
  292. commit('messageBoard/GET_INFORMATION_SUCCESS', response.data)
  293. }, err => {
  294. commit('messageBoard/GET_INFORMATION_FAILURE', err)
  295. })
  296. },
  297. // 验证用户是否登录
  298. userIsLogin ({commit}) {
  299. commit('messageBoardIsLogin/REQUEST_LOGIN')
  300. return axios.get('/user/authentication')
  301. .then(response => {
  302. commit('messageBoardIsLogin/GET_LOGIN_SUCCESS', response.data)
  303. }, err => {
  304. commit('messageBoardIsLogin/GET_LOGIN_FAILURE', err)
  305. })
  306. },
  307. // 获取留言记录信息
  308. getMessageBoardInformation ({commit}, params) {
  309. let sorting = {createDate: 'DESC'}
  310. params.sorting = sorting
  311. commit('messageBoardInformation/REQUEST_INFORMATION', params)
  312. return axios.get('/operation/messageBoard/pageInfo/user', { params })
  313. .then(response => {
  314. commit('messageBoardInformation/GET_INFORMATION_SUCCESS', response.data)
  315. }, err => {
  316. commit('messageBoardInformation/GET_INFORMATION_FAILURE', err)
  317. })
  318. },
  319. // 获取帮助中心信息
  320. loadHelpSnapsho ({ commit }, params = {}) {
  321. commit('help/REQUEST_SNAPSHO')
  322. return axios.get('/api/help-service/helps', {params})
  323. .then(response => {
  324. commit('help/GET_SNAPSHO_SUCCESS', response.data)
  325. }, err => {
  326. commit('help/GET_SNAPSHO_FAILURE', err)
  327. })
  328. },
  329. // 获取帮助中心二级菜单
  330. loadHelpList ({ commit }, params = {}) {
  331. commit('help/REQUEST_HELPLIST')
  332. return axios.get('/api/help-service/issues', {params})
  333. .then(response => {
  334. commit('help/GET_HELPLIST_SUCCESS', response.data)
  335. }, err => {
  336. commit('help/GET_HELPLIST_FAILURE', err)
  337. })
  338. },
  339. // 获取帮助中心名称
  340. loadHelpTitle ({ commit }, params = {}) {
  341. let id = params.id
  342. commit('help/REQUEST_TITLE')
  343. return axios.get(`/api/help-service/${id}`, {params})
  344. .then(response => {
  345. commit('help/GET_TITLE_SUCCESS', response.data)
  346. }, err => {
  347. commit('help/GET_TITLE_FAILURE', err)
  348. })
  349. },
  350. // 获取详情
  351. loadHelpDetail ({ commit }, params = {}) {
  352. let id = params.id
  353. commit('help/REQUEST_DETAIL')
  354. return axios.get(`/api/help-service/issues/${id}`, {params})
  355. .then(response => {
  356. commit('help/GET_DETAIL_SUCCESS', response.data)
  357. let id = response.data.navId
  358. commit('help/REQUEST_TITLE')
  359. return axios.get(`/api/help-service/${id}`)
  360. .then(response => {
  361. commit('help/GET_TITLE_SUCCESS', response.data)
  362. }, err => {
  363. commit('help/GET_TITLE_FAILURE', err)
  364. })
  365. }, err => {
  366. commit('help/GET_DETAIL_FAILURE', err)
  367. })
  368. },
  369. // 获取最多搜索量的 器件
  370. loadHotSearchDevice ({commit}) {
  371. commit('hotSearchDevice/REQUEST_HOT')
  372. return axios.get('/api/product/component/mostSearchComponent')
  373. .then(response => {
  374. commit('hotSearchDevice/GET_HOT_SUCCESS', response.data)
  375. }, err => {
  376. commit('hotSearchDevice/GET_HOT_FAILURE', err)
  377. })
  378. },
  379. // 获取最多搜索量的 品牌
  380. loadHotSearchBrand ({commit}) {
  381. commit('hotSearchBrand/REQUEST_HOT')
  382. return axios.get('/api/product/brand/mostSearchBrands')
  383. .then(response => {
  384. commit('hotSearchBrand/GET_HOT_SUCCESS', response.data)
  385. }, err => {
  386. commit('hotSearchBrand/GET_HOT_FAILURE', err)
  387. })
  388. }
  389. }