index.js 15 KB

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