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

后台用户角色问题 #5

Closed
afacode opened this issue Jul 18, 2019 · 7 comments
Closed

后台用户角色问题 #5

afacode opened this issue Jul 18, 2019 · 7 comments

Comments

@afacode
Copy link

afacode commented Jul 18, 2019

我现在在学后台权限这块功能。
现在后台是一个用户只能对一个角色吗,如果多个角色怎么做高效,还有每次验证权限都得请求数据库,可以一次请求存下来吗,如果能,怎么存,可以下次更新代码的时候添加一下吗,感谢

@maoxiaoquan
Copy link
Owner

你可以看前台的用户是一个用户多角色的

@maoxiaoquan
Copy link
Owner

不过我判断权限的时候取巧了一下,其实我自己也是学习的,每次请求的原因是,有的时候实时更新了权限,能实时刷新,可以存,每次登陆的时候根据直接获取用户角色权限可以和登录态存一起,但是如果更新角色权限了就没法实时刷新权限,所以我就没有存

@maoxiaoquan
Copy link
Owner

角色的权限Id是通过逗号分隔的,多角色,直接遍历一下,去除相同的,连接到一个字符串,indexOf判断有没有就可以,我为了省事,就没有去重,没多大的关系

@maoxiaoquan
Copy link
Owner

这个系统,
前台是一个用户多角色,判断权限是,取多角色权限遍历后,权限ID逗号分隔连接在一起,通过indexOf判断,(这个应该能理解我的意思吧,这是我自己想的方法,我不知道别人是咋弄的)
后台就是一个管理员单角色

@maoxiaoquan
Copy link
Owner

第二种方法还可以通过:
用户A有两个角色 -----> B和C 的角色ID为 1 和 2
然后需要判断权限的为登录权限 /login 权限ID为 3
直接去查询表,角色 ID为 1或者 2,权限ID为3,有没有这一条数据在,
有就说明有权限,没有就是没有权限,

@maoxiaoquan
Copy link
Owner

方法有很多,每个人想的都不一样

@afacode
Copy link
Author

afacode commented Jul 19, 2019

感谢

@afacode afacode closed this as completed Jul 19, 2019
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