Files
2026-10-20 21:19:44 +08:00

53 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# I. 前端 Enums 速查
:::tip 概述
src/enums/ 枚举常量速查。前后端枚举对照原则:后端 consts 是真值(biz_err/log_type 等),前端 enums 是消费侧镜像——后端改值须同步前端(破坏性变更流程)。
:::
## 枚举文件清单
| 文件 | 常量 | 用途 |
|------|------|------|
| httpEnum.ts | RequestEnum | GET/POST/PUT/DELETE 方法 |
| | ResultEnum | SUCCESS=0 / ERROR=1 / TIMEOUT 等(信封 code 对照) |
| | ContentTypeEnum | application/json、multipart 等 |
| pageEnum.ts | PageEnum | 页面路径常量(BASE_LOGIN 等) |
| cacheEnum.ts | CacheEnum | 缓存键 |
| permissionsEnum.ts | 通配权限等 | `*:*:*` 超管通配 |
| roleEnum.ts | 角色常量 | ROLE_SUPER_ADMIN 对照 |
| avatarEnum.ts | 头像枚举 | 内置头像集 |
| breakpointEnum.ts | 断点 | 响应式断点 |
存储键另见 `store/mutation-types.ts`(ACCESS_TOKEN/FIRST_ROUTE)。
## 前后端关键对照
| 前端 | 后端真值 |
|------|---------|
| ResultEnum.SUCCESS=0 | response.Ok(code 0) |
| ResultEnum.ERROR=1 | response.Fail 降级(code 1) |
| 401 处理 | consts.CodeUnauthorized(唯一保留原码) |
| permissionsEnum 通配 `*:*:*` | index.GetUser 超管返回 |
| roleEnum ROLE_SUPER_ADMIN | consts 超管角色编码 |
| log_type 映射 | consts/log_type.go(41 值,前端按值显示中文) |
## log_type 前端映射(常用段)
```text
1=新增 2=修改 3=删除 4=查询 5=导入 6=导出
13=启用 14=禁用 15=上传 16=下载 19=代码生成 22=登录 23=登出 24=重置
99=其他
(完整 41 值见后端 consts/log_type.go——数值勿改)
```
## 使用规约
```text
import { ResultEnum } from '@/enums/httpEnum';
if (code === ResultEnum.SUCCESS) {...}
✓ 跨页复用的常量进 enums/
✓ 后端枚举映射表集中管理(勿散落)
✗ 魔法数字/魔法字符串散落页面
```