index.js 17 KB

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