import store from '../src/store';
import vue from 'vue';
export default function (state) {
  // alert(122);
  console.log(state,'statestatestatestatestate======');
  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?.authorities) {
    store.commit('user/setAuthorities', state.user.authorities);
  }
  if (state.user?.authorityDept) {
    store.dispatch('user/getCurrentUserAuthorityDept');
  }
  if (state.paramsSetData) {
    store.dispatch('paramsSetData/setParamsDataInfo');
  }
}

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