| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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/kind/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children`)
- .then(response => {
- commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/kind/GET_KIND_FAILURE', {id, err})
- })
- },
- // 获取全部子器件类目
- loadAllProductKinds ({ commit }, params = {}) {
- let id = params.id
- commit('product/kind/REQUEST_KIND', params)
- return axios.get(`/api/product/kind/${id}/children_all`)
- .then(response => {
- commit('product/kind/GET_KIND_SUCCESS', { id, result: response.data })
- }, err => {
- commit('product/kind/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/common/REQUEST_COUNTS')
- return axios.get('/api/product/commoncount', {params})
- .then(response => {
- commit('product/common/GET_COUNTS_SUCCESS', response.data)
- }, err => {
- commit('product/common/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')
- }
- }
|