|
|
@@ -1,58 +1,37 @@
|
|
|
-export const state = () => ({
|
|
|
- kinds: {
|
|
|
- fetching: false,
|
|
|
- data: []
|
|
|
- },
|
|
|
- counts: {
|
|
|
- fetching: false,
|
|
|
- data: []
|
|
|
- }
|
|
|
-})
|
|
|
+import axios from '~/plugins/axios'
|
|
|
|
|
|
-export const mutations = {
|
|
|
- REQUEST_KIND (state, action) {
|
|
|
- if (!action.id) {
|
|
|
- state.kinds.fetching = true
|
|
|
- } else {
|
|
|
- const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
|
|
|
- if (kind) {
|
|
|
- kind.fetching = true
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- GET_KIND_FAILURE (state, action) {
|
|
|
- if (!action.id) {
|
|
|
- state.kinds.fetching = false
|
|
|
- } else {
|
|
|
- const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
|
|
|
- if (kind) {
|
|
|
- kind.fetching = false
|
|
|
- }
|
|
|
- }
|
|
|
+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')
|
|
|
+ ])
|
|
|
},
|
|
|
- GET_KIND_SUCCESS (state, action) {
|
|
|
- if (!action.id) {
|
|
|
- state.kinds.fetching = false
|
|
|
- action.result.forEach(kind => {
|
|
|
- kind.fetching = false
|
|
|
+ // 品牌列表推荐品牌配置
|
|
|
+ loadRecommends ({ commit }) {
|
|
|
+ commit('brand/REQUEST_RECOMMENDS')
|
|
|
+ return axios.get(`/api/product/brand/hot/5`)
|
|
|
+ .then(response => {
|
|
|
+ commit('brand/GET_RECOMMENDS_SUCCESS', response.data)
|
|
|
+ }, err => {
|
|
|
+ commit('brand/GET_RECOMMENDS_FAILURE', err)
|
|
|
})
|
|
|
- state.kinds.data = action.result
|
|
|
- } else {
|
|
|
- const kind = state.kinds.data.find(kind => Object.is(kind.id, action.id))
|
|
|
- if (kind) {
|
|
|
- kind.fetching = false
|
|
|
- kind.children = action.result
|
|
|
- }
|
|
|
- }
|
|
|
},
|
|
|
- REQUEST_COUNTS (state) {
|
|
|
- state.counts.fetching = true
|
|
|
- },
|
|
|
- GET_COUNTS_FAILURE (state) {
|
|
|
- state.counts.fetching = false
|
|
|
- },
|
|
|
- GET_COUNTS_SUCCESS (state, result) {
|
|
|
- state.counts.fetching = false
|
|
|
- state.counts.data = result
|
|
|
+ // 品牌列表配置
|
|
|
+ loadBrands ({ commit }, params = {}) {
|
|
|
+ let keyword = params.keyword
|
|
|
+ commit('brand/REQUEST_BRANDS', params)
|
|
|
+ return axios.get(`/api/product/brand/initial/${keyword}`)
|
|
|
+ .then(response => {
|
|
|
+ commit('brand/GET_BRANDS_SUCCESS', response.data)
|
|
|
+ }, err => {
|
|
|
+ commit('brand/GET_BRANDS_FAILURE', err)
|
|
|
+ })
|
|
|
}
|
|
|
}
|