index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import axios from '~plugins/axios'
  2. import cityService from '~plugins/city-service'
  3. export const actions = {
  4. // 全局服务初始化
  5. nuxtServerInit (store, { params, route, isDev, isServer, req }) {
  6. // 检查设备类型
  7. const userAgent = isServer ? req.headers['user-agent'] : navigator.userAgent
  8. const isMobile = /(iPhone|iPod|Opera Mini|Android.*Mobile|NetFront|PSP|BlackBerry|Windows Phone)/ig.test(userAgent)
  9. const cookie = isServer ? req.headers['cookie'] : null
  10. store.commit('option/SET_MOBILE_LAYOUT', isMobile)
  11. store.commit('option/SET_USER_AGENT', userAgent)
  12. store.commit('option/SET_COOKIES', cookie)
  13. // 设置跳转的URL
  14. if (!isDev) {
  15. store.commit('option/UPDATE_URL', 'http://192.168.253.66:8081/')
  16. }
  17. return Promise.all([
  18. // 全局数据
  19. // store.dispatch('loadCarouselInfo', { client_type: 'cc', cityId: '5' }),
  20. store.dispatch('loadIsLogin')
  21. ])
  22. },
  23. // 判断是否登录
  24. loadIsLogin ({ commit }) {
  25. commit('option/REQUEST_IS_LOGIN')
  26. return axios.get('/sso/login/isLogin')
  27. .then(response => {
  28. console.log(JSON.stringify(response.data))
  29. commit('option/REQUEST_IS_LOGIN_SUCCESS', response.data.data)
  30. }, err => {
  31. commit('option/REQUEST_IS_LOGIN_FAILURE', err)
  32. })
  33. },
  34. // 用户退出
  35. logout ({ commit }) {
  36. return axios.get('/sso/login/logout')
  37. .then(response => {
  38. commit('option/REQUEST_LOGOUT_SUCCESS', response.data)
  39. })
  40. },
  41. // 获取表单配置
  42. loadFormData ({ commit }, params = {}) {
  43. commit('formConfig/REQUEST_FORMDATA')
  44. return cityService.get('/api/serve/config.action', {params})
  45. .then(response => {
  46. commit('formConfig/GET_FORMDATA_SUCCESS', response.data)
  47. }, err => {
  48. commit('formConfig/GET_FORMDATA_FAILURE', err)
  49. })
  50. }
  51. }