javascript - js状态很多不同操作用啥设计模式或优化?
给我你的怀抱
给我你的怀抱 2017-05-16 13:05:10
0
2
578

就是有十个等级,不同等级开放不同功能;要用js来写.我用if或switch的或写起来感觉很乱不好管理!!!
还有后台直接吧用户的等级输出在html中让我用js去取,这样是不是很不安全啊??该怎么个弄法?难道每次都发个请求去验证用户等级?

给我你的怀抱
给我你的怀抱

reply all(2)
世界只因有你

There are many ways to do it. Let the background send you Json. If you want to upgrade in time based on points, just load the array of [level, points] asynchronously when the page is initialized, and then calculate it based on the cached array to reach a certain level. The points are upgraded and related resources are displayed. If you want to display different pages according to different levels, you can directly transfer the json of the corresponding level to the background. For example, {username:xxx,lv:3,....} can display different functions according to the value of lv, or simply Let him send you the content to be displayed as well.

小葫芦

How to store the user level and store it in HTML? After the user is authenticated, the server can store the user level in session or nosql, and the client can store it directly in the cookie. Every time a request is made, there is no need to verify the user level unless the request involves user level and permission functions.
The client obtains the user level information in the cookie. Since you are designing into the level and permission categories, it is recommended to write all the permission functions into a prototype first, and then declare a method class and object. This method will judge the user by Level and permission, that is, if the user meets this permission, copy the function prototype and instantiate it (similar to inheritance), so that you don’t have to make judgments with if statements

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!