Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global model effects *query duplicated execution #11

Open
cw1427 opened this issue Aug 7, 2019 · 3 comments
Open

Global model effects *query duplicated execution #11

cw1427 opened this issue Aug 7, 2019 · 3 comments

Comments

@cw1427
Copy link

cw1427 commented Aug 7, 2019

models/app.js model里的effects *query 应该会被 多次调用。感觉应该像antd-admin原来那样做了sign来判断, 把第一次处理过的结果都放到store中可好?

let menus = yield call(menuService.query); let menuHash = {}, openKeys = []; menus.forEach(item => { menuHash[item.id] = item }); if (menus.length > 0) { openKeys = [sMenu_${menus[0].id}`];
}
let menuTree = arrayToTree(menus, 'id', 'parentId');

    let permissions = permission.getPermissions();
    if (!permissions) {
      permissions = yield call(permissionsService.query);
      permission.setPermissions(permissions)
    }`

另外,我对 react不太熟悉,umijs中用了好多约定路由,能否从umijs层面对router 进行处理,从而过滤出menu 数据,而不需要后台代码返回。另外,权限控制是否也能在umijs进行router 切换时进行拦截。比如给router 的push 方法加个flow控制。

@cw1427
Copy link
Author

cw1427 commented Aug 7, 2019

大致过了下代码,其实也没有很好的解决前端权限控制。至少没有看到在router切换时有进行权限判断。react-router真不太孰,不知道有没有vue-router的那个before after 拦截方法进行处理?

@liuxx-u
Copy link
Owner

liuxx-u commented Aug 8, 2019

是的,目前代码在router切换的时候没有做权限判断,以前是在layout的render中获取当前页面对应的menu,通过permission.check(menu.permissionName)校验的权限,校验通过渲染{children},否则渲染405页面。这个方式有缺陷,后面就删除掉了。

react-router是有onEnter与onLeave的钩子函数可以进行处理的。

@cw1427
Copy link
Author

cw1427 commented Aug 8, 2019

Hi @liuxx001 :
antD-pro里的router menu设计正是我上面说的方式,只是antD-pro太庞大了,我不太想用,你对react 比较熟悉,有没考虑参考antd-pro里的设计,做到antd-admin里,或者你这个fork里,大家可以共享。
https://pro.ant.design/docs/router-and-nav-cn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants