index.js 15 KB

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