user.js 757 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { VerifyLogin } from '@/api/api'
  2. import Cookies from 'js-cookie'
  3. const getDefaultState = () => {
  4. return {
  5. JSESSSIONID: Cookies.get('JSESSIONID') || '',
  6. }
  7. }
  8. const state = getDefaultState()
  9. const mutations = {
  10. RESET_JSESSIONID: (state, JSESSSIONID) => {
  11. Cookies.set('JSESSIONID', JSESSSIONID);
  12. state.JSESSSIONID = JSESSSIONID
  13. }
  14. }
  15. const actions = {
  16. // user login
  17. setJsessionId({ commit }) {
  18. return new Promise((resolve, reject) => {
  19. VerifyLogin().then(response => {
  20. const { data } = response
  21. commit('RESET_JSESSIONID', data.JSESSSIONID)
  22. resolve()
  23. }).catch(error => {
  24. reject(error)
  25. })
  26. })
  27. },
  28. }
  29. export default {
  30. namespaced: true,
  31. state,
  32. mutations,
  33. actions
  34. }