# 代码规范
## Python 后端规范
- 遵循 PEP 8 规范
- 使用 Black 进行代码格式化
- 使用 isort 进行导入排序
- 使用类型注解(Type Hints)
- 异步函数使用 async/await
- 错误处理使用自定义异常类
**示例**:
```python
from typing import List, Optional
from fastapi import HTTPException
async def get_devices(
skip: int = 0,
limit: int = 100
) -> List[Device]:
"""获取设备列表"""
try:
devices = await device_service.get_all(skip, limit)
return devices
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
```
## Vue 前端规范
- 使用 Composition API(setup script)
- 组件使用 PascalCase 命名
- 使用 TypeScript 类型检查
- 遵循 Vue 官方风格指南
- 使用 ESLint + Prettier 格式化
**示例**:
```vue
```
## Git 提交规范
使用 Conventional Commits 格式:
```
():
类型:
- feat: 新功能
- fix: 修复bug
- docs: 文档更新
- style: 代码格式
- refactor: 重构
- test: 测试
- chore: 构建/工具
示例:
feat(device): 添加设备导入功能
fix(auth): 修复登录token过期问题
```