app.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import * as api from '@/api/index'
  2. import {ElMessageBox} from "element-plus";
  3. const state = {
  4. apiProxy: {
  5. EzServer6Api: 'EzServer6-api', // 地图底图代理
  6. },
  7. userInfo: null
  8. }
  9. const getters = {
  10. isLogin(state) {
  11. return localStorage.getItem('sc_token')
  12. }
  13. }
  14. const mutations = {
  15. SET_USER_INFO(state, data) {
  16. state.userInfo = data
  17. }
  18. }
  19. const actions = {
  20. LOAD_USER_INFO({ commit }, refresh = false) {
  21. return new Promise((resolve, reject) => {
  22. if (refresh || !state.userInfo) {
  23. api.default.getUserInfo().then(res => {
  24. commit('SET_USER_INFO', res.userInfo)
  25. resolve(res.userInfo)
  26. }).catch(() => {
  27. })
  28. } else {
  29. resolve()
  30. }
  31. })
  32. },
  33. EXIT_LOGIN({ commit }) {
  34. ElMessageBox.confirm('确定进行[退出]操作?', '提示', {
  35. confirmButtonText: '确定',
  36. cancelButtonText: '取消',
  37. type: 'warning'
  38. }).then(() => {
  39. api.default.logout()
  40. localStorage.removeItem('sc_token')
  41. location.reload()
  42. }).catch(() => {
  43. })
  44. },
  45. }
  46. export default {
  47. namespaced: true,
  48. state,
  49. getters,
  50. mutations,
  51. actions
  52. }