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

怎么做权限管理呢 #314

Closed
jarvislin94 opened this issue May 26, 2017 · 5 comments
Closed

怎么做权限管理呢 #314

jarvislin94 opened this issue May 26, 2017 · 5 comments

Comments

@jarvislin94
Copy link

No description provided.

@jarvislin94
Copy link
Author

请问下怎么实现权限管理?有什么好的解决方案吗谢谢😆

@jackple
Copy link
Contributor

jackple commented Jun 2, 2017

  • 我现在是分4种用户权限类型level(0超级管理员,1管理员,2权限组账户,3普通账户)
  • 有user和userGroup表,其中包含authorizedMenu字段
  • 如果level为0/1,拥有全部权限(其中0超级管理员不能新增,并且只给开发者使用),如果level为2,对应的权限在userGroup表的authorizedMenu字段,如果level为3,对应的权限在user表的authorizedMenu字段

只是大概说一下,谢谢

@DiroKate
Copy link

DiroKate commented Jun 8, 2017

@jackple 有没有源码可以参考一下?

@jackple
Copy link
Contributor

jackple commented Jun 9, 2017

@DiroKate 我是都在服务端控制的
贴主要的给你
async function getUserMenu(uid) { const resdata = Object.assign({}, BASERESDATA), startTime = new Date().getTime(), userInfo = await new DBCtrl(User).findOne({ _id: uid }); if (!userInfo) { Object.assign(resdata, { menu: [], message: '没有要查询的账户', }); return resdata; } const {level, userGroupID, authorizedMenu} = userInfo; let result; //超级管理员和管理员拥有全部菜单权限 if (level === 0 || level === 1) { result = await new DBCtrl(Menu).find({}, null, { sort: { orderBy: 1 } }); } //查找用户组权限 else if (userGroupID) { const userGroupuInfo = await new DBCtrl(UserGroup).findOne({ _id: userGroupID }), userGroupuAthorizedMenu = userGroupuInfo.authorizedMenu; result = await new DBCtrl(Menu).find({ "id": { "$in": userGroupuAthorizedMenu } }, null, { sort: { orderBy: 1 } }); } //查找用户权限 else if (authorizedMenu && authorizedMenu.length > 0) { result = await new DBCtrl(Menu).find({ "id": { "$in": authorizedMenu } }, null, { sort: { orderBy: 1 } }); } else { Object.assign(resdata, { menu: [], message: '用户无菜单权限', }); return resdata; } if (result && result.length) { Object.assign(resdata, { menu: result, }); return resdata; } Object.assign(resdata, { menu: [], message: '获取菜单失败', }); return resdata; }
代码写得烂,见笑了
前端直接用antd的Tree组件来调整权限

@zuiidea
Copy link
Owner

zuiidea commented Jul 5, 2017

#384

@zuiidea zuiidea closed this as completed Jul 5, 2017
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

4 participants