4.5 KiB
4.5 KiB
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 Programnpm run dev:h5- Run dev server for H5 (browser)npm run dev:app- Run dev server for App platformnpm run dev:custom- Run dev server with custom platform selection
Production Builds
npm run build:mp-weixin- Build for WeChat Mini Programnpm run build:h5- Build for H5npm 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 fromsrc/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
anysparingly, 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 componentssrc/Service/- API service layer and base configsrc/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 viaService.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> ResultDatahas:code,msg,dataproperties
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 functionService.debounce(fn, time)- Debounce functionService.formatDate(time, type)- Format timestampsService.Msg(message, icon?)- Show toastService.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.tsfor how API requests are structured - Look at
src/common/Unit/HttpRequest.tsfor lower-level request handling - Check existing pages in
src/pages/for component structure examples - Use
ResultDataclass from@/common/Domain/ResultDatafor 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)