forked from erp-dev/erp
feat: added frontend_pages models(basic_info) and api(v2), support employees query pages that they can visit by themself token
This commit is contained in:
167
docs/api_v2_employee_visible_pages.md
Normal file
167
docs/api_v2_employee_visible_pages.md
Normal file
@@ -0,0 +1,167 @@
|
||||
# 获取当前用户可见页面 API
|
||||
|
||||
## 概述
|
||||
|
||||
获取当前登录用户关联的员工岗位所拥有的可见前端页面列表。
|
||||
|
||||
- **端点**: `GET /api/v2/me/visible-pages/`
|
||||
- **认证**: 需要登录
|
||||
- **权限**: 任意已认证用户
|
||||
|
||||
## 业务逻辑
|
||||
|
||||
1. 从 `request.user` 获取当前登录用户
|
||||
2. 通过 `user.employee` 获取关联的员工
|
||||
3. 员工通过 `position` 字段关联到岗位(`EmployeeType`)
|
||||
4. 岗位通过 `visible_pages` 多对多字段关联到前端页面(`FrontendPage`)
|
||||
5. **权限继承**: 如果授予主菜单(`page_type=main`),自动包含其所有子菜单
|
||||
|
||||
## 请求
|
||||
|
||||
无需参数,自动从登录用户获取。
|
||||
|
||||
### 请求示例
|
||||
|
||||
```bash
|
||||
curl -X GET "http://localhost:8000/api/v2/me/visible-pages/" \
|
||||
-H "Authorization: Token <your-token>"
|
||||
```
|
||||
|
||||
## 响应
|
||||
|
||||
### 成功响应 (200 OK)
|
||||
|
||||
```json
|
||||
{
|
||||
"employee_id": 1,
|
||||
"employee_name": "张三",
|
||||
"position_id": 2,
|
||||
"position_title": "生产主管",
|
||||
"visible_pages": [
|
||||
{
|
||||
"key": "production",
|
||||
"label": "生产管理",
|
||||
"page_type": "main",
|
||||
"parent_key": null,
|
||||
"sort_order": 100
|
||||
},
|
||||
{
|
||||
"key": "production-kanban",
|
||||
"label": "生产看板",
|
||||
"page_type": "sub",
|
||||
"parent_key": "production",
|
||||
"sort_order": 101
|
||||
},
|
||||
{
|
||||
"key": "printing-order-list",
|
||||
"label": "生产订单",
|
||||
"page_type": "sub",
|
||||
"parent_key": "production",
|
||||
"sort_order": 102
|
||||
}
|
||||
],
|
||||
"visible_keys": [
|
||||
"printing-order-list",
|
||||
"production",
|
||||
"production-kanban"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
### 响应字段说明
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| `employee_id` | int \| null | 员工ID(无关联员工时为 null) |
|
||||
| `employee_name` | string \| null | 员工姓名 |
|
||||
| `position_id` | int \| null | 岗位ID(无岗位时为 null) |
|
||||
| `position_title` | string \| null | 岗位名称 |
|
||||
| `visible_pages` | array | 可见页面详情列表(按 sort_order 排序) |
|
||||
| `visible_keys` | array | 可见页面 key 列表(已排序,便于前端快速查找) |
|
||||
|
||||
### visible_pages 对象结构
|
||||
|
||||
| 字段 | 类型 | 说明 |
|
||||
|------|------|------|
|
||||
| `key` | string | 页面唯一标识(前端路由 key) |
|
||||
| `label` | string | 页面显示名称 |
|
||||
| `page_type` | string | 页面类型:`main`(主菜单)或 `sub`(子菜单) |
|
||||
| `parent_key` | string \| null | 父级菜单 key(主菜单为 null) |
|
||||
| `sort_order` | int | 排序值 |
|
||||
|
||||
### 用户未关联员工
|
||||
|
||||
```json
|
||||
{
|
||||
"employee_id": null,
|
||||
"employee_name": null,
|
||||
"position_id": null,
|
||||
"position_title": null,
|
||||
"visible_pages": [],
|
||||
"visible_keys": []
|
||||
}
|
||||
```
|
||||
|
||||
### 员工无岗位
|
||||
|
||||
```json
|
||||
{
|
||||
"employee_id": 5,
|
||||
"employee_name": "无岗位员工",
|
||||
"position_id": null,
|
||||
"position_title": null,
|
||||
"visible_pages": [],
|
||||
"visible_keys": []
|
||||
}
|
||||
```
|
||||
|
||||
### 错误响应
|
||||
|
||||
#### 未认证 (401 Unauthorized)
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "Authentication credentials were not provided."
|
||||
}
|
||||
```
|
||||
|
||||
## 前端使用示例
|
||||
|
||||
```javascript
|
||||
// 获取当前用户可见页面
|
||||
async function getMyVisiblePages() {
|
||||
const response = await fetch('/api/v2/me/visible-pages/', {
|
||||
headers: { 'Authorization': `Token ${token}` }
|
||||
});
|
||||
const data = await response.json();
|
||||
|
||||
// 使用 visible_keys 快速判断菜单是否可见
|
||||
const canSeeProduction = data.visible_keys.includes('production');
|
||||
|
||||
// 或使用 visible_pages 渲染菜单
|
||||
const menuItems = data.visible_pages.filter(p => p.page_type === 'main');
|
||||
|
||||
return data;
|
||||
}
|
||||
```
|
||||
|
||||
## 相关命令
|
||||
|
||||
### 同步前端页面数据
|
||||
|
||||
```bash
|
||||
# 从 docs/menu_keys.json 同步页面到数据库
|
||||
python manage.py sync_frontend_pages
|
||||
|
||||
# 预览模式(不实际写入)
|
||||
python manage.py sync_frontend_pages --dry-run
|
||||
|
||||
# 清空后重新同步
|
||||
python manage.py sync_frontend_pages --clear
|
||||
```
|
||||
|
||||
## 相关模型
|
||||
|
||||
- `basic_info.FrontendPage` - 前端页面
|
||||
- `basic_info.EmployeeType` - 员工岗位(含 `visible_pages` 字段)
|
||||
- `basic_info.Employee` - 员工(含 `position` 和 `sys_user` 字段)
|
||||
186
docs/menu_keys.json
Normal file
186
docs/menu_keys.json
Normal file
@@ -0,0 +1,186 @@
|
||||
{
|
||||
"menus": [
|
||||
{
|
||||
"key": "plate-opening",
|
||||
"label": "开版管理",
|
||||
"children": [
|
||||
{ "key": "plate-order-kanban", "label": "开版看板" },
|
||||
{ "key": "plate-order", "label": "开版订单" },
|
||||
{ "key": "plate-order-staging", "label": "开版暂存" },
|
||||
{ "key": "process-node-view", "label": "流程查看" },
|
||||
{ "key": "plate-order-statistics", "label": "开版数据" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "production",
|
||||
"label": "生产管理",
|
||||
"children": [
|
||||
{ "key": "production-kanban", "label": "生产看板" },
|
||||
{ "key": "printing-order-list", "label": "生产订单" },
|
||||
{ "key": "printing-job-list", "label": "生产订单明细" },
|
||||
{ "key": "production-statistics", "label": "生产数据" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "business",
|
||||
"label": "业务管理",
|
||||
"children": [
|
||||
{ "key": "production-order", "label": "生产订单" },
|
||||
{ "key": "process-management", "label": "流程编排" },
|
||||
{ "key": "state-management", "label": "工序状态管理" },
|
||||
{ "key": "parameter-management", "label": "工艺参数管理" },
|
||||
{ "key": "business-object", "label": "业务对象管理" },
|
||||
{ "key": "workflow-testing", "label": "工作流测试" },
|
||||
{ "key": "kanban-demo", "label": "看板组件" },
|
||||
{ "key": "vehicle-record-list", "label": "车次记录" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "procurement",
|
||||
"label": "采购管理",
|
||||
"children": [
|
||||
{ "key": "purchase-order", "label": "采购订单" },
|
||||
{ "key": "purchase-return-order", "label": "采购退货单" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "sales",
|
||||
"label": "销售管理",
|
||||
"children": [
|
||||
{ "key": "sales-order-list", "label": "销售单" },
|
||||
{ "key": "sales-return-order", "label": "销售退货单" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "inventory",
|
||||
"label": "库存管理",
|
||||
"children": [
|
||||
{ "key": "inbound-list", "label": "入库单列表" },
|
||||
{ "key": "outbound-list", "label": "出库单列表" },
|
||||
{ "key": "stock-transfer", "label": "库存调拨" },
|
||||
{ "key": "stock-summary", "label": "库存合计" },
|
||||
{ "key": "stock-realtime", "label": "库存实时清单" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "finance",
|
||||
"label": "财务管理",
|
||||
"children": [
|
||||
{ "key": "payment-order", "label": "付款单" },
|
||||
{ "key": "receipt-order", "label": "收款单" },
|
||||
{ "key": "customer-statement", "label": "客户对账单" },
|
||||
{ "key": "supplier-statement", "label": "供应商对账单" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "report",
|
||||
"label": "报表中心",
|
||||
"children": [
|
||||
{ "key": "report-center", "label": "报表中心" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "basic-data",
|
||||
"label": "基础资料",
|
||||
"children": [
|
||||
{ "key": "customer-management", "label": "客户资料" },
|
||||
{ "key": "supplier-management", "label": "供应商资料" },
|
||||
{ "key": "warehouse-list", "label": "仓库资料" },
|
||||
{ "key": "product-category-list", "label": "产品类别" },
|
||||
{ "key": "product-list", "label": "产品资料" },
|
||||
{ "key": "employee-management", "label": "员工资料" },
|
||||
{ "key": "user-create", "label": "新建用户" },
|
||||
{ "key": "employee-type-management", "label": "职位类型" },
|
||||
{ "key": "device-list", "label": "设备资料" },
|
||||
{ "key": "bank-account-list", "label": "银行账户" },
|
||||
{ "key": "quick-input-list", "label": "字典管理" },
|
||||
{ "key": "vehicle-type-list", "label": "车辆类型" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"all_keys": {
|
||||
"main_menus": [
|
||||
"plate-opening",
|
||||
"production",
|
||||
"business",
|
||||
"procurement",
|
||||
"sales",
|
||||
"inventory",
|
||||
"finance",
|
||||
"report",
|
||||
"basic-data"
|
||||
],
|
||||
"sub_menus": [
|
||||
"plate-order-kanban",
|
||||
"plate-order",
|
||||
"plate-order-staging",
|
||||
"process-node-view",
|
||||
"plate-order-statistics",
|
||||
"production-kanban",
|
||||
"printing-order-list",
|
||||
"printing-job-list",
|
||||
"production-statistics",
|
||||
"production-order",
|
||||
"process-management",
|
||||
"state-management",
|
||||
"parameter-management",
|
||||
"business-object",
|
||||
"workflow-testing",
|
||||
"kanban-demo",
|
||||
"vehicle-record-list",
|
||||
"purchase-order",
|
||||
"purchase-return-order",
|
||||
"sales-order-list",
|
||||
"sales-return-order",
|
||||
"inbound-list",
|
||||
"outbound-list",
|
||||
"stock-transfer",
|
||||
"stock-summary",
|
||||
"stock-realtime",
|
||||
"payment-order",
|
||||
"receipt-order",
|
||||
"customer-statement",
|
||||
"supplier-statement",
|
||||
"report-center",
|
||||
"customer-management",
|
||||
"supplier-management",
|
||||
"warehouse-list",
|
||||
"product-category-list",
|
||||
"product-list",
|
||||
"employee-management",
|
||||
"user-create",
|
||||
"employee-type-management",
|
||||
"device-list",
|
||||
"bank-account-list",
|
||||
"quick-input-list",
|
||||
"vehicle-type-list"
|
||||
]
|
||||
},
|
||||
"examples": {
|
||||
"admin": {
|
||||
"description": "管理员 - 全部权限",
|
||||
"allowed_menus": ["*"]
|
||||
},
|
||||
"production_manager": {
|
||||
"description": "生产主管 - 开版+生产+基础资料",
|
||||
"allowed_menus": ["plate-opening", "production", "basic-data"]
|
||||
},
|
||||
"salesman": {
|
||||
"description": "销售员 - 销售+部分基础资料",
|
||||
"allowed_menus": ["sales", "customer-management", "product-list"]
|
||||
},
|
||||
"warehouse_keeper": {
|
||||
"description": "仓管员 - 库存+部分基础资料",
|
||||
"allowed_menus": ["inventory", "warehouse-list", "product-list"]
|
||||
},
|
||||
"finance_staff": {
|
||||
"description": "财务人员 - 财务+报表+对账相关",
|
||||
"allowed_menus": ["finance", "report", "customer-management", "supplier-management"]
|
||||
},
|
||||
"normal_staff": {
|
||||
"description": "普通员工 - 只看看板",
|
||||
"allowed_menus": ["production-kanban", "plate-order-kanban"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user