| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- import axios from '~plugins/axios'
- export const actions = {
- // 全局服务初始化
- nuxtServerInit (store, { params, route, isServer, req }) {
- // 检查设备类型
- const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
- const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
- store.commit('option/SET_MOBILE_LAYOUT', isMobile)
- store.commit('option/SET_USER_AGENT', userAgent)
- return Promise.all([
- // 全局数据
- // store.dispatch('loadUserInfo')
- ])
- },
- // 获取用户信息
- loadUserInfo ({ commit }) {
- commit('option/REQUEST_USER_INFO')
- return axios.get('/user/authentication')
- .then(response => {
- commit('option/REQUEST_USER_INFO_SUCCESS', response.data)
- }, err => {
- commit('option/REQUEST_USER_INFO_FAILURE', err)
- })
- },
- // 用户退出
- logout ({ commit }) {
- return axios.get('/logout')
- .then(response => {
- commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
- })
- },
- // 获取楼层配置
- loadFloors ({ commit }) {
- commit('floor/REQUEST_LIST')
- return axios.get('/api/floors/home')
- .then(response => {
- commit('floor/GET_LIST_SUCCESS', response.data)
- }, err => {
- commit('floor/GET_LIST_FAILURE', err)
- })
- },
- // 获取轮播配置
- loadBanners ({ commit }) {
- commit('carousel/REQUEST_BANNER')
- return axios.get('/api/carousel/home%20page%20banner')
- .then(response => {
- commit('carousel/GET_BANNER_SUCCESS', response.data)
- }, err => {
- commit('carousel/GET_BANNER_FAILURE', err)
- })
- },
- // 获取子器件类目
- loadProductKinds ({ commit }, params = {}) {
- let id = params.id
- commit('product/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children`)
- .then(response => {
- commit('product/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/GET_KIND_FAILURE', {id, err})
- })
- },
- // 获取全部子器件类目
- loadAllProductKinds ({ commit }, params = {}) {
- let id = params.id
- commit('product/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children_all`)
- .then(response => {
- commit('product/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/GET_KIND_FAILURE', {id, err})
- })
- },
- // 获取首页新闻
- loadNewsSnapshot ({ commit }, params = {}) {
- commit('news/REQUEST_SNAPSHOT')
- return axios.get('/api/news/created', {params})
- .then(response => {
- commit('news/GET_SNAPSHOT_SUCCESS', response.data)
- }, err => {
- commit('news/GET_SNAPSHOT_FAILURE', err)
- })
- },
- // 获取器件统计信息
- loadProductCounts ({ commit }, params = {}) {
- commit('product/REQUEST_COUNTS')
- return axios.get('/api/product/commoncount', {params})
- .then(response => {
- commit('product/GET_COUNTS_SUCCESS', response.data)
- }, err => {
- commit('product/GET_COUNTS_FAILURE', err)
- })
- },
- // 搜索关键字
- searchKeywords ({ commit }, params = {}) {
- commit('search/REQUEST_KEYWORDS')
- return axios.get('/search/similarKeywords', {params})
- .then(response => {
- commit('search/GET_KEYWORDS_SUCCESS', response.data)
- }, err => {
- commit('search/GET_KEYWORDS_FAILURE', err)
- })
- },
- resetSearchKeywords ({ commit }) {
- commit('search/RESET_KEYWORDS')
- },
- // 热卖推荐页面
- loadProductHot ({commit}, params = {}) {
- commit('original/REQUEST_HOT')
- return axios.get('/api/commodity/latest', {params})
- .then(response => {
- commit('original/GET_HOT_SUCCESS', response.data)
- }, err => {
- commit('original/GET_HOT_FAILURE', err)
- })
- },
- // 器件详情页面
- // 获得器件详情信息
- loadComponentDetail ({commit}, params = {}) {
- let id = params.id
- console.log(id)
- commit('componentDetail/REQUEST_DETAIL', params)
- return axios.get(`/api/product/component/${id}`)
- .then(response => {
- console.log('response', response.data)
- commit('componentDetail/GET_DETAIL_SUCCESS', response.data)
- }, err => {
- commit('componentDetail/GET_DETAIL_FAILURE', err)
- })
- },
- // 获取器件详情页面包屑导航
- loadComponentMenu ({commit}, params = {}) {
- let pid = params.id
- console.log(pid)
- commit('componentMenu/REQUEST_MENU', params)
- return axios.get(`/api/product/kind/structing/${pid}`)
- .then(response => {
- console.log('response', response.data)
- commit('componentMenu/GET_MENU_SUCCESS', response.data)
- }, err => {
- commit('componentMenu/GET_MENU_FAILURE', err)
- })
- },
- // 器件详情页选择商家
- loadComponentStore ({commit}, params = {}) {
- let sid = params.id
- commit('componentStore/REQUEST_STORE', params)
- return axios.get(`/api/store-service/stores/uuid/${sid}`)
- .then(response => {
- console.log('response', response.data)
- commit('componentStore/GET_STORE_SUCCESS', response.data)
- }, err => {
- commit('componentStore/GET_STORE_FAILURE', err)
- })
- },
- // 品牌详情页面
- // 获得品牌详情信息
- loadBrandDetail ({commit}, params = {}) {
- let id = params.id
- console.log(id)
- commit('brandDetail/REQUEST_DETAIL', params)
- return axios.get(`/api/product/brand/${id}`)
- .then(response => {
- console.log('response', response.data)
- commit('brandDetail/GET_DETAIL_SUCCESS', response.data)
- }, err => {
- commit('brandDetail/GET_DETAIL_FAILURE', err)
- })
- },
- // 获取品牌详情产品分类信息
- loadBrandCategories ({commit}, params = {}) {
- let id = params.id
- commit('brandCategories/REQUEST_CATEGORIES', params)
- return axios.get(`/api/product/brand/${id}/kinds`)
- .then(response => {
- console.log('response', response.data)
- commit('brandCategories/GET_CATEGORIES_SUCCESS', response.data)
- }, err => {
- commit('brandCategories/GET_CATEGORIES_FAILURE', err)
- })
- }
- }
|