login.js 1015 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. export const login_types = {
  2. mutations: {
  3. userLogin: 'userLogin',
  4. userLogout: 'userLogout',
  5. SET_IS_LOGIN: 'SET_IS_LOGIN',
  6. SET_CAPTCHA: 'SET_CAPTCHA'
  7. },
  8. actions: {
  9. tryLogin: 'tryLogin',
  10. },
  11. }
  12. export const state = function (){
  13. return {
  14. userInfo: {
  15. id: '',
  16. name: '',
  17. },
  18. isLogin: false,
  19. captcha: '1'
  20. }
  21. }
  22. export const mutations = {
  23. [login_types.mutations.userLogin](state, userInfo) {
  24. state.userInfo = userInfo;
  25. state.isLogin = true;
  26. },
  27. [login_types.mutations.userLogout](state) {
  28. state.userInfo = {};
  29. state.isLogin = false;
  30. },
  31. [login_types.mutations.SET_IS_LOGIN](state, isLogin) {
  32. state.isLogin = isLogin;
  33. },
  34. [login_types.mutations.SET_CAPTCHA](state, captcha) {
  35. state.captcha = captcha;
  36. }
  37. }
  38. export const actions = {
  39. }
  40. export const getters = {
  41. userInfo: state => state.userInfo,
  42. isLogin: state => state.isLogin,
  43. captcha: state => state.captcha
  44. }
  45. export default {
  46. state,
  47. mutations,
  48. actions,
  49. getters
  50. }