system.js 1.2 KB
import { take, select, call, takeEvery, put } from 'redux-saga/effects';
import * as types from '../actionTypes';
import { getSystemSelect } from '../../utils/commonUtils';

//切换菜单
export const changeSystemMenu = (values) => {
    return { type: types.SYSTEM_MENU_SELECTED_KEYS, payload: values };
};
/*
* 路由改变菜单回填
*/
export function* selectSysMenus(uaa_perms) {
    const state = yield select();
    const { router } = state;
    const { location = {} } = router;
    const { pathname = '' } = location;
    if (uaa_perms.length > 0) {
        const menuAction = getSystemSelect(pathname, uaa_perms);
        yield put({
            type: types.SYSTEM_MENU_SELECTED_KEYS,
            payload: menuAction
        });
    }
}
/*
路由跳转切点,做页面权限判断
*/
function* handldRouter() {
    while (true) {
        const routerAction = yield take(['@@router/LOCATION_CHANGE']);
        const state = yield select();
        const { payload = {} } = routerAction;
        const { location = {} } = payload;
        const { pathname = '' } = location;
        const { system: { system_menu_perms = [] } } = state;
        yield selectSysMenus(system_menu_perms);
    }
}

export default [handldRouter()];