import axios from '~plugins/axios' import cityService from '~plugins/city-service' export const actions = { // 全局服务初始化 nuxtServerInit (store, { params, route, isDev, 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) const cookie = isServer ? req.headers['cookie'] : null store.commit('option/SET_MOBILE_LAYOUT', isMobile) store.commit('option/SET_USER_AGENT', userAgent) store.commit('option/SET_COOKIES', cookie) // 设置跳转的URL if (!isDev) { store.commit('option/UPDATE_URL', 'http://192.168.253.66:8081/') } return Promise.all([ // 全局数据 // store.dispatch('loadCarouselInfo', { client_type: 'cc', cityId: '5' }), store.dispatch('loadIsLogin') ]) }, // 判断是否登录 loadIsLogin ({ commit }) { commit('option/REQUEST_IS_LOGIN') return axios.get('/sso/login/isLogin') .then(response => { // console.log(JSON.stringify(response.data.content)) commit('option/REQUEST_IS_LOGIN_SUCCESS', response.data.data) }, err => { commit('option/REQUEST_IS_LOGIN_FAILURE', err) }) }, // 用户退出 logout ({ commit }) { return axios.get('/sso/login/logout') .then(response => { commit('option/REQUEST_LOGOUT_SUCCESS', response.data) }) }, // 获取表单配置 loadFormData ({ commit }, params = {}) { commit('formConfig/REQUEST_FORMDATA') return cityService.get('/api/serve/config.action', {params}) .then(response => { commit('formConfig/GET_FORMDATA_SUCCESS', response.data) }, err => { commit('formConfig/GET_FORMDATA_FAILURE', err) }) } }