first commit
This commit is contained in:
107
AGENTS.md
Normal file
107
AGENTS.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# AGENTS.md - Guide for Coding Agents
|
||||
|
||||
## Project Overview
|
||||
This is a **uni-app** project (Vue 3 + TypeScript + Vite) for building multi-platform applications (primarily WeChat Mini Program, also supports H5, App, etc.). It uses uview-plus UI component library and is set up with TypeScript.
|
||||
|
||||
## Build & Development Commands
|
||||
|
||||
### Development Servers
|
||||
- `npm run dev:mp-weixin` - Run dev server for WeChat Mini Program
|
||||
- `npm run dev:h5` - Run dev server for H5 (browser)
|
||||
- `npm run dev:app` - Run dev server for App platform
|
||||
- `npm run dev:custom` - Run dev server with custom platform selection
|
||||
|
||||
### Production Builds
|
||||
- `npm run build:mp-weixin` - Build for WeChat Mini Program
|
||||
- `npm run build:h5` - Build for H5
|
||||
- `npm run build:app` - Build for App platform
|
||||
|
||||
### Type Checking
|
||||
- `npm run type-check` - Run TypeScript type checking (vue-tsc --noEmit)
|
||||
|
||||
## Code Style Guidelines
|
||||
|
||||
### Imports
|
||||
- Use path alias `@/*` for imports from `src/` directory
|
||||
- Example: `import { Service } from '@/Service/Service'`
|
||||
- Group imports by: external libraries → internal modules
|
||||
- No specific linter/formatter configured, but follow existing style
|
||||
|
||||
### TypeScript
|
||||
- Use TypeScript for all new code
|
||||
- Define types/interfaces for data models
|
||||
- Use `any` sparingly, prefer proper type definitions
|
||||
- Project uses `"extends": "@vue/tsconfig/tsconfig.json"`
|
||||
|
||||
### Naming Conventions
|
||||
- **Files**: PascalCase for TypeScript classes (e.g., `Service.ts`, `HttpRequest.ts`), kebab-case for Vue components in pages (e.g., `my.vue`, `address.vue`)
|
||||
- **Classes**: PascalCase (e.g., `Service`, `HttpRequest`)
|
||||
- **Methods/Functions**: camelCase (e.g., `GetUserToken()`, `formatDate()`)
|
||||
- **Variables**: camelCase
|
||||
- **Constants**: UPPER_SNAKE_CASE (when applicable)
|
||||
|
||||
### Directory Structure
|
||||
- `src/pages/` - Page components (main pages and subPackages)
|
||||
- `src/components/` - Reusable Vue components
|
||||
- `src/Service/` - API service layer and base config
|
||||
- `src/common/` - Common utilities (Unit, Domain)
|
||||
- `src/common/Unit/` - Helper classes (HttpRequest, StorageAssist, etc.)
|
||||
- `src/common/Domain/` - Domain models (ResultData, etc.)
|
||||
- `src/static/` - Static assets (images, icons, etc.)
|
||||
|
||||
### Error Handling
|
||||
- Use `Service.Request()` for API calls which handles:
|
||||
- Token authentication (adds Bearer token)
|
||||
- 401 (token expired) → clears token, redirects to login
|
||||
- Other error codes (40101, 1004, 40188, 1008)
|
||||
- Use `uni.showToast()` for user feedback via `Service.Msg()`
|
||||
- Use `Service.Alert()` for modal dialogs
|
||||
|
||||
### API Requests
|
||||
- Always use `Service.Request(url, method, data)` for API calls
|
||||
- HTTP methods: 'GET', 'POST', 'PUT'
|
||||
- Request returns `Promise<ResultData>`
|
||||
- `ResultData` has: `code`, `msg`, `data` properties
|
||||
|
||||
### UI Components
|
||||
- Use **uview-plus** (imported as `u-*` components via easycom)
|
||||
- Easycom auto-import configured: `^u-(.*)` → `uview-plus/components/u-$1/u-$1.vue`
|
||||
- Color UI is also available (imported in App.vue)
|
||||
|
||||
### Vue Components
|
||||
- Use `<script setup lang="ts">` for Vue 3 composition API
|
||||
- Use uni-app lifecycle hooks: `onLaunch`, `onShow`, `onHide`, etc.
|
||||
- SCSS is supported for styles
|
||||
|
||||
### Storage
|
||||
- Use `Service.SetStorageCache(key, data)` to set storage
|
||||
- Use `Service.GetStorageCache(key)` to get storage
|
||||
- Use `Service.DelStorageCache(key)` to delete storage
|
||||
- Token is stored with key 'token', user state with 'StateDomain'
|
||||
|
||||
### Navigation
|
||||
- `Service.GoPage(path)` - Navigate to new page (uni.navigateTo)
|
||||
- `Service.GoPageDelse(path)` - Redirect (replace current page, uni.redirectTo)
|
||||
- `Service.GoPageTab(path)` - Switch to tab bar page (uni.switchTab)
|
||||
- `Service.GoPageBack()` - Go back (uni.navigateBack)
|
||||
|
||||
### Key Utilities
|
||||
- `Service.throttle(fn, time)` - Throttle function
|
||||
- `Service.debounce(fn, time)` - Debounce function
|
||||
- `Service.formatDate(time, type)` - Format timestamps
|
||||
- `Service.Msg(message, icon?)` - Show toast
|
||||
- `Service.LoadIng(text)` / `Service.LoadClose()` - Show/hide loading
|
||||
|
||||
## Testing
|
||||
No test framework configured in this project yet.
|
||||
|
||||
## Existing Patterns to Follow
|
||||
- Look at `src/Service/Service.ts` for how API requests are structured
|
||||
- Look at `src/common/Unit/HttpRequest.ts` for lower-level request handling
|
||||
- Check existing pages in `src/pages/` for component structure examples
|
||||
- Use `ResultData` class from `@/common/Domain/ResultData` for API responses
|
||||
|
||||
## Important Notes
|
||||
- This is a multi-platform project - write code compatible with uni-app standards
|
||||
- Be cautious with platform-specific APIs - use uni-app conditional compilation (`#ifdef MP-WEIXIN`, etc.) if needed
|
||||
- Global colors defined in App.vue: --nav-mian (#FF6A00), --nav-vice (#FF7F00), --nav-diluted (#F2C0A3)
|
||||
Reference in New Issue
Block a user