store.js 961 B

1234567891011121314151617181920212223242526272829303132333435
  1. import store from '../src/store';
  2. /**
  3. * 同步门户下发的主题与用户信息(与 EOM qiankun_config/store.js 一致)
  4. */
  5. export default function initParentStore(state) {
  6. if (!state) {
  7. return;
  8. }
  9. // 主题(门户可能传 store 或 store.state)
  10. const theme = state.theme || state.state?.theme;
  11. if (theme) {
  12. for (const key in theme) {
  13. store.commit('theme/SET', { key, value: theme[key] });
  14. }
  15. if (theme.color != null) {
  16. store.dispatch('theme/setColor', theme.color);
  17. }
  18. if (theme.weakMode != null) {
  19. store.dispatch('theme/setWeakMode', theme.weakMode);
  20. }
  21. if (theme.styleResponsive != null) {
  22. store.dispatch('theme/setStyleResponsive', theme.styleResponsive);
  23. }
  24. }
  25. const user = state.user || state.state?.user;
  26. if (user?.info) {
  27. store.commit('user/setUserInfo', user.info);
  28. }
  29. if (user?.authorities) {
  30. store.commit('user/setAuthorities', user.authorities);
  31. }
  32. }