user.js 818 B

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