text: import { routerRedux } from 'dva/router';
  import { accountLogin } from '../services/api';
  import { accountLogout } from '../services/api';
  import { setAuthority } from '../utils/authority';
  import { reloadAuthorized } from '../utils/Authorized';
  import {ENUMS} from '../utils/enums'
  import {optSucessNotify,optFailedNotify} from '../utils/notify'
  
  export default {
    namespace: 'login',
  
    state: {
      status: undefined,
    },
  
    effects: {
      *login({ payload }, { call, put }) {
        const response = yield call(accountLogin, payload);
        yield put({
          type: 'changeLoginStatus',
          payload: response,
        });
  
        // Login successfully
        if (response.code === ENUMS.ErrCode.Success) {
          reloadAuthorized();
          yield put(routerRedux.push('/'));
        }else{
          optFailedNotify("登录失败");
        }
      },
      *logout(_, { put, select ,call}) {
        try {
          // get location pathname
          const urlParams = new URL(window.location.href);
          const pathname = yield select(state => state.routing.location.pathname);
          // add the parameters in the url
          urlParams.searchParams.set('redirect', pathname);
          window.history.replaceState(null, 'login', urlParams.href);
  
          yield call(accountLogout)
  
        } finally {
          yield put({
            type: 'changeLoginStatus',
            payload: {
              status: false,
              currentAuthority: 'guest',
            },
          });
          reloadAuthorized();
          yield put(routerRedux.push('/user/login'));
        }
      },
    },
  
    reducers: {
      changeLoginStatus(state, { payload }) {
        setAuthority(payload.currentAuthority);
        return {
          ...state,
          status: payload.status,
          type: payload.type,
        };
      },
    },
  };
  