global.js 1.02 KB
import { queryNotices } from '@/services/user';
const GlobalModel = {
  namespace: 'global',
  state: {
    collapsed: false,
    loading: false,
    urlFileExport: '',
    dataModal: {
      modalType: '',
      modalShow: false,
      modalData: {},
    },
    preImgDataModal: {
      modalType: '',
      modalShow: false,
      modalData: {},
    },
  },
  effects: {},
  reducers: {
    changeLayoutCollapsed(
      state = {
        notices: [],
        collapsed: true,
      },
      { payload },
    ) {
      return { ...state, collapsed: payload };
    },
  },
  subscriptions: {
    setup({ history, dispatch }) {
      // Subscribe history(url) change, trigger `load` action if pathname is `/`
      history.listen(({ pathname, search }) => {
        // 路由发生变化的时候切换菜单
        const whiteList = ['/user/login'];

        if (!whiteList.includes(pathname)) {
          // 获取用户信息
          dispatch({ type: 'user/fetchCurrent' });
        }
      });
    },
  },
};
export default GlobalModel;