签入版本
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# 12.7 前端编码规范
|
||||
|
||||
:::tip 概述
|
||||
前端编码规范涵盖 Vue 组件、TypeScript、API 模块、样式和代码风格等方面。
|
||||
前端编码规范涵盖 Vue 组件、TypeScript、API 模块、样式和代码风格等方面。前端工程位于 `ui/` 目录(Vue3 + TypeScript + ElementPlus + Pinia)。
|
||||
:::
|
||||
|
||||
## Vue 组件规范
|
||||
@@ -60,13 +60,13 @@ interface User {
|
||||
status: number;
|
||||
}
|
||||
|
||||
// 枚举定义
|
||||
// 枚举定义(统一放 ui/src/enums/ 下,如 pageEnum.ts、httpEnum.ts)
|
||||
enum UserStatus {
|
||||
ENABLE = 1,
|
||||
DISABLE = 2,
|
||||
}
|
||||
|
||||
// API 响应类型
|
||||
// API 响应类型(分页结构见 12.1/12.2)
|
||||
interface PageResult<T> {
|
||||
records: T[];
|
||||
total: number;
|
||||
@@ -110,21 +110,26 @@ export function userDelete(id: number) {
|
||||
}
|
||||
```
|
||||
|
||||
:::info 路径前缀
|
||||
API 函数中 `url` 不带 `/api` 前缀——由 `ui/.env.production` 的 `VITE_GLOB_API_URL_PREFIX=/api` 在请求层统一拼接。
|
||||
:::
|
||||
|
||||
## 命名规范
|
||||
|
||||
| 类型 | 规范 | 示例 |
|
||||
|------|------|------|
|
||||
| 组件文件 | PascalCase | `BasicTable.vue` |
|
||||
| API 文件 | camelCase | `user.ts` |
|
||||
| API 文件 | camelCase,按模块分目录(`ui/src/api/{模块}/`) | `system/user.ts` |
|
||||
| API 函数 | camelCase | `getUserPage` |
|
||||
| Store 文件 | camelCase | `user.ts` |
|
||||
| Store 文件 | camelCase(`ui/src/store/modules/`) | `user.ts` |
|
||||
| 枚举文件 | camelCase + Enum 后缀(`ui/src/enums/`) | `pageEnum.ts` |
|
||||
| 常量 | UPPER_SNAKE_CASE | `ACCESS_TOKEN` |
|
||||
| CSS 类 | kebab-case | `page-container` |
|
||||
|
||||
## 代码风格
|
||||
|
||||
```bash
|
||||
# ESLint 检查
|
||||
# ESLint 检查(脚本自带 --fix)
|
||||
pnpm lint:eslint
|
||||
|
||||
# Prettier 格式化
|
||||
@@ -132,6 +137,9 @@ pnpm lint:prettier
|
||||
|
||||
# Stylelint 检查
|
||||
pnpm lint:stylelint
|
||||
|
||||
# TypeScript 类型检查
|
||||
pnpm type:check
|
||||
```
|
||||
|
||||
:::warning 禁止事项
|
||||
@@ -139,4 +147,4 @@ pnpm lint:stylelint
|
||||
- 不要使用 `console.log`(生产环境)
|
||||
- 不要在模板中写复杂逻辑(提取为 computed 或方法)
|
||||
- 不要在 `setup` 外使用 Composition API
|
||||
:::
|
||||
:::
|
||||
|
||||
Reference in New Issue
Block a user