import store from '../src/store';
import vue from 'vue';
export default function (state) {
  if (!state) {
    return;
  }
  // 主题
  if (state.theme) {
    for (const key in state.theme) {
      store.commit('theme/SET', { key, value: state.theme[key] });
    }

    store.dispatch('theme/setColor', state.theme.color);
    store.dispatch('theme/setWeakMode', state.theme.weakMode);
    store.dispatch('theme/setStyleResponsive', state.theme.styleResponsive);
  }
  //   用户信息
  if (state.user?.info) {
    store.commit('user/setUserInfo', state.user.info);
  }
  if (state.user?.authorityDept) {
    store.dispatch('user/getCurrentUserAuthorityDept');
  }
}

export const createMutationObserve = ({ modules = [] }) => {
  return (mutation, state) => {
    if (
      modules?.length &&
      modules.find((i) => mutation.type.startWidth(i + '/'))
    ) {
      vue.$portalStore.commit(mutation.type, mutation.payload);
    }
  };
};
