index.js 13 KB

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