# 权限

## 设计思路

权限管理主要基于用户的角色实现，主要分为2部分，菜单权限和资源权限。菜单权限主要用于前端菜单的显示，资源权限主要用于页面按钮等DOM元素的显示和隐藏，主要流程如下：

* 后台维护用户表、角色表、菜单表、资源表 - 给角色分配菜单和资源的权限
* 给用户分配角色，`一对多`
* 用户登录成功，通过用户角色获取到用户拥有权限的菜单列表和资源列表，存入服务端缓存
* 前端主页面会请求服务器，从缓存中获取到用户的菜单和资源
* 前端通过获取的有权限的菜单生成菜单树
* 前端页面需要控制权限的DOM元素，增加一个指令，如v-auth="'addUser'"，会在后端返回的资源列表中查找addUder，如果没有，就隐藏这个DOM

## 要点

* 权限数据会在用户登录的时查询出来，并缓存到服务器。
* 后端需要有请求拦截器来验证每个请求是否越权
* 权限管理的实现，需要和后端有比较多的约定，请查阅 [服务端-权限](https://ccqiuqiu.gitbook.io/iface/service/quan-xian)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ccqiuqiu.gitbook.io/iface/ru-men/quan-xian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
