# 前端约定 ## 优先参考的代码来源 - 当前目标目录下最近似页面、API、types。 - 标准单表:`src/views/demo/demo/index.vue`、`src/api/demo/demo/index.ts`、`src/api/demo/demo/types.ts`。 - 树表:`src/views/demo/tree/index.vue`、`src/views/workflow/category/index.vue`。 - 复杂系统页:`src/views/system/user/index.vue`、`src/views/system/role/index.vue`、`src/views/system/post/index.vue`、`src/views/system/config/index.vue`。 - workflow 页:`src/views/workflow/*`、`src/api/workflow/*`。 - 监控页:`src/views/monitor/*`、`src/api/monitor/*`。 - 公共 hooks:`src/hooks/async/useLoading.ts`、`src/hooks/dialog/*`、`src/hooks/form/*`、`src/hooks/table/*`、`src/hooks/tree/*`。 - 项目内 generator 模板: `gen/api.ts.vm` `gen/types.ts.vm` `gen/index.vue.vm` `gen/index-tree.vue.vm` ## 基础栈与格式 - 技术栈是 Vue 3 + TypeScript + Element Plus + Vite + Pinia。 - 包管理按仓库现状使用 pnpm。 - `.editorconfig` 要求 UTF-8、LF、2 空格缩进。 - 当前仓库没有 `.prettierrc`;格式化使用 `pnpm run fmt`,lint 使用 `pnpm lint`。 - 不要在一个页面里混入与仓库不一致的格式和写法。 ## API 文件规则 - 标准 API 文件放在 `src/api///index.ts`,同目录维护 `types.ts`。 - import 顺序优先跟随附近文件,标准生成页常见形式: `import type { XxxForm, XxxQuery, XxxVO } from '@/api///types';` `import type { PageResult } from '@/api/types';` `import type { AxiosPromise } from '@/utils/api-types';` `import request from '@/utils/request';` - 不要从 `axios` 引入 `AxiosPromise`。 - 列表分页接口通常返回 `AxiosPromise>`。 - 树表列表接口通常返回 `AxiosPromise`。 - 详情接口返回 `AxiosPromise`;复杂详情返回单独的 `InfoVO`。 - 标准函数命名: `listXxx` -> `GET ///list` `getXxx` -> `GET ///{id}` `addXxx` -> `POST //` `updateXxx` -> `PUT //` `delXxx` -> `DELETE ///{id or ids}` `changeXxxStatus` -> `PUT ///changeStatus` - query string 用 `params`,请求体用 `data`。 - 加密、防重复提交等 headers 直接写在请求配置里,例如用户重置密码中的 `isEncrypt`、`repeatSubmit`。 - 当前仓库有些 API 使用 `export const`,有些使用 `export function`;新增标准 CRUD 优先跟随 `gen/api.ts.vm` 和相邻模块。 - 只有相邻模块已有 `export default { ... }` 聚合时才新增默认导出。 ## 类型文件规则 - 标准类型定义 `VO`、`Form`、`Query`,必要时补 `InfoVO`、`TreeVO`、`ResetPwdForm` 等扩展类型。 - `Form` 通常继承 `BaseEntity`。 - 非树表 `Query` 通常继承 `PageQuery`。 - 树表 `Query` 通常不继承 `PageQuery`。 - ID 字段通常使用 `string | number`,批量删除参数使用 `string | number | Array`。 - Java 数值类型映射为 `number`,Boolean 映射为 `boolean`,日期/文本默认 `string`。 - 日期范围查询保留 `params?: any`,不要因为它看起来宽松就删掉。 - 列表对象、表单对象、查询对象职责分开;字段不一致时不要强行复用一个接口。 - 能明确写出类型时不要用 `any`;组件库、字典或历史接口确实无法收窄时再保留。 ## Vue 页面结构规则 - 页面优先使用 `