login.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { EMClient } from '@/EaseIM';
  2. import { emUserInfos } from '@/EaseIM/emApis';
  3. const { fetchUserInfoWithLoginId } = emUserInfos();
  4. const loginStore = {
  5. state: {
  6. loginStatus: false,
  7. loginUserBaseInfos: {
  8. loginUserId: '',
  9. phoneNumber: '',
  10. },
  11. loginUserProfiles: {},
  12. },
  13. mutations: {
  14. RESET_LOGIN_STORE: (state) => {
  15. state.loginStatus = false;
  16. state.loginUserBaseInfos = {
  17. loginUserId: '',
  18. phoneNumber: '',
  19. };
  20. state.loginUserProfiles = {};
  21. },
  22. SET_LOGIN_STATUS: (state, status) => {
  23. state.loginStatus = status;
  24. },
  25. SET_LOGIN_USER_BASE_INFOS: (state, baseInfos) => {
  26. state.loginUserBaseInfos = Object.assign({}, baseInfos);
  27. },
  28. SET_LOGIN_USER_PROFILES: (state, profiles) => {
  29. state.loginUserProfiles = Object.assign({}, profiles);
  30. },
  31. },
  32. actions: {
  33. async fetchLoginUserProfile({ commit }) {
  34. try {
  35. const profiles = await fetchUserInfoWithLoginId();
  36. commit('SET_LOGIN_USER_PROFILES', profiles[EMClient.user]);
  37. } catch (error) {
  38. console.log('>>>>登录用户个人信息获取失败', error);
  39. }
  40. },
  41. },
  42. getters: {
  43. loginUserProfiles(state) {
  44. return state.loginUserProfiles;
  45. },
  46. },
  47. };
  48. export default loginStore;