login.js 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {
  2. reqLogin
  3. } from "@/request/api.js";
  4. import cloneDeep from 'lodash/cloneDeep'
  5. import pick from 'lodash/pick'
  6. const stateReset = {
  7. loginInfo: {}, //当前登录用户信息
  8. };
  9. const state = cloneDeep(stateReset);
  10. const getters = {};
  11. const mutations = {
  12. // 重置数据
  13. resetVxLogin(state,args={}) {
  14. Object.assign(state, cloneDeep(stateReset),pick(args,Object.keys(cloneDeep(stateReset))));
  15. },
  16. // 登录
  17. vxLogin(state, args) {
  18. state.loginInfo = args || {};
  19. },
  20. // 修改当前登录用户信息
  21. changeLoginInfo(state, args) {
  22. state.loginInfo.user = args || {};
  23. },
  24. };
  25. const actions = {
  26. // 登录
  27. async vxLogin({
  28. commit
  29. }, args) {
  30. let result = await reqLogin(args);
  31. if (result.status == 200) {
  32. commit("vxLogin", result.user);
  33. }
  34. return result;
  35. },
  36. };
  37. export default {
  38. namespaced: true,
  39. state,
  40. getters,
  41. mutations,
  42. actions,
  43. };