|
| 1 | +# AGENTS.md - unibest Development Guide |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +uniapp + Vue3 + TypeScript + Vite5 + UnoCSS template. Supports H5, WeChat Mini Program, App (Android/iOS/HarmonyOS). |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +``` |
| 10 | +unibest 仓库 (refactor/monorepo 分支) |
| 11 | +└── packages/cli/ # CLI 脚手架工具 |
| 12 | + └── 用户执行 pnpm create unibest 时,从 Git base 分支克隆模板 |
| 13 | +``` |
| 14 | + |
| 15 | +**模板来源:** |
| 16 | +- 用户创建项目时,从 `https://gitee.com/feige996/unibest.git` 的 `base` 分支克隆 |
| 17 | +- CLI 工具本身不包含模板代码 |
| 18 | + |
| 19 | +## Essential Commands |
| 20 | + |
| 21 | +```bash |
| 22 | +# Development |
| 23 | +pnpm dev # H5 dev server |
| 24 | +pnpm dev:h5 # H5 with hot reload |
| 25 | +pnpm dev:mp # WeChat Mini Program |
| 26 | +pnpm dev:app # App development |
| 27 | + |
| 28 | +# Build |
| 29 | +pnpm build # Build current platform |
| 30 | +pnpm build:h5 # H5 output (dist/build/h5) |
| 31 | +pnpm build:mp # WeChat MP (dist/build/mp-weixin) |
| 32 | +pnpm build:app # App output (dist/build/app) |
| 33 | + |
| 34 | +# Lint & Type Check |
| 35 | +pnpm lint # ESLint |
| 36 | +pnpm lint:fix # ESLint auto-fix |
| 37 | +pnpm type-check # TypeScript check |
| 38 | +``` |
| 39 | + |
| 40 | +## Code Style |
| 41 | + |
| 42 | +### TypeScript |
| 43 | +- Use explicit types for params and return values |
| 44 | +- Prefix interfaces with `I`: `IUserInfoRes`, `ILoginForm` |
| 45 | +- Use `import type` for types only |
| 46 | + |
| 47 | +### Vue SFC |
| 48 | +```vue |
| 49 | +<script lang="ts" setup> |
| 50 | +defineOptions({ name: 'PageName' }) |
| 51 | +definePage({ style: { navigationBarTitleText: 'Title' } }) |
| 52 | +</script> |
| 53 | +
|
| 54 | +<template> |
| 55 | + <!-- content --> |
| 56 | +</template> |
| 57 | +
|
| 58 | +<style lang="scss" scoped> |
| 59 | +/* styles */ |
| 60 | +</style> |
| 61 | +``` |
| 62 | +- Order: template → script → style |
| 63 | + |
| 64 | +### Imports |
| 65 | +- Use `@/` alias for src imports: `import { http } from '@/http/http'` |
| 66 | +- Group: external libs → Vue/UniApp → @/ → ../ |
| 67 | + |
| 68 | +### Naming |
| 69 | +| Type | Convention | Example | |
| 70 | +|------|------------|---------| |
| 71 | +| Components | PascalCase | `TabbarItem.vue` | |
| 72 | +| Pages | kebab-case | `login/index.vue` | |
| 73 | +| Stores | useXxxStore | `useUserStore` | |
| 74 | +| API functions | camelCase | `getUserInfo` | |
| 75 | +| Constants | UPPER_SNAKE_CASE | `VITE_SERVER_BASEURL` | |
| 76 | + |
| 77 | +### Error Handling |
| 78 | +```typescript |
| 79 | +try { |
| 80 | + const res = await http.post('/auth/login', data) |
| 81 | + return res |
| 82 | +} |
| 83 | +catch (error) { |
| 84 | + uni.showToast({ title: 'Failed', icon: 'error' }) |
| 85 | + throw error |
| 86 | +} |
| 87 | +``` |
| 88 | + |
| 89 | +### UnoCSS |
| 90 | +- Use utility classes: `flex justify-center items-center px-4 pt-safe` |
| 91 | +- Theme colors: `text-primary`, `bg-primary` |
| 92 | +- Safe areas: `pt-safe`, `pb-safe`, `p-safe` |
| 93 | + |
| 94 | +### API Design |
| 95 | +```typescript |
| 96 | +// Always specify response type |
| 97 | +return http.get<IUserInfoRes>('/user/info') |
| 98 | +return http.post<IAuthLoginRes>('/auth/login', data) |
| 99 | +``` |
| 100 | + |
| 101 | +### Pinia Stores |
| 102 | +```typescript |
| 103 | +export const useUserStore = defineStore('user', () => { |
| 104 | + const userInfo = ref<IUserInfoRes>(initialState) |
| 105 | + const setUserInfo = (val: IUserInfoRes) => { ... } |
| 106 | + return { userInfo, setUserInfo } |
| 107 | +}, { persist: true }) |
| 108 | +``` |
| 109 | + |
| 110 | +## File Structure |
| 111 | +``` |
| 112 | +src/ |
| 113 | +├── api/ # API definitions |
| 114 | +├── components/ # Vue components |
| 115 | +├── hooks/ # Composable hooks |
| 116 | +├── http/ # alova HTTP config |
| 117 | +├── pages/ # Page components |
| 118 | +├── store/ # Pinia stores |
| 119 | +├── types/ # TypeScript types |
| 120 | +└── utils/ # Utility functions |
| 121 | +``` |
| 122 | + |
| 123 | +## ESLint |
| 124 | +- Uses `@uni-helper/eslint-config` |
| 125 | +- `console.log` allowed |
| 126 | +- Run `pnpm lint:fix` before committing |
| 127 | + |
| 128 | +## Important Notes |
| 129 | +- Auto-imports enabled for Vue APIs and uni-app APIs |
| 130 | +- Generated files: `src/service/`, `auto-import.d.ts`, `uni-pages.d.ts` |
| 131 | +- Pages auto-generated from `src/pages/` |
| 132 | +- App config in `manifest.config.ts` |
0 commit comments