hookehuyr

docs: 将 CLAUDE.md 翻译成中文

- 将项目开发文档从英文翻译成中文
- 保留所有代码示例、文件路径和技术配置
- 使用清晰易懂的中文表达
Showing 1 changed file with 355 additions and 355 deletions
1 # CLAUDE.md 1 # CLAUDE.md
2 2
3 -This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. 3 +本文件为 Claude Code (claude.ai/code) 在处理此仓库代码时提供指导。
4 - 4 +
5 -## Development Commands 5 +## 开发命令
6 - 6 +
7 -### Core Commands 7 +### 核心命令
8 -- `pnpm dev:weapp` - Start WeChat mini-program development server 8 +- `pnpm dev:weapp` - 启动微信小程序开发服务器
9 -- `pnpm dev:h5` - Start H5 development server 9 +- `pnpm dev:h5` - 启动 H5 开发服务器
10 -- `pnpm build:weapp` - Build for production (WeChat mini-program) 10 +- `pnpm build:weapp` - 构建生产版本(微信小程序)
11 -- `pnpm lint` - Run ESLint 11 +- `pnpm lint` - 运行 ESLint
12 - 12 +
13 -### Other Platform Builds 13 +### 其他平台构建
14 -- `pnpm dev:alipay` - Alipay mini-program development 14 +- `pnpm dev:alipay` - 支付宝小程序开发
15 -- `pnpm dev:swan` - Baidu mini-program development 15 +- `pnpm dev:swan` - 百度小程序开发
16 -- `pnpm dev:tt` - ByteDance mini-program development 16 +- `pnpm dev:tt` - 字节跳动小程序开发
17 - 17 +
18 -## Project Overview 18 +## 项目概述
19 - 19 +
20 -**Manulife WeApp** (臻奇智荟圈) is a wealth management WeChat mini-program built with Taro 4 + Vue 3 + NutUI. 20 +**Manulife WeApp**(臻奇智荟圈)是一个基于 Taro 4 + Vue 3 + NutUI 构建的财富管理微信小程序。
21 - 21 +
22 -### Business Modules 22 +### 业务模块
23 -The app currently includes the following main features: 23 +应用目前包含以下主要功能:
24 -- **Product Showcase** - Hot products display with detail pages 24 +- **产品展示** - 热门产品展示及详情页
25 - - Home page shows hot products with "产品资料" (Product Materials) buttons 25 + - 首页显示热门产品,带"产品资料"按钮
26 - - Product detail page displays comprehensive product information 26 + - 产品详情页展示完整产品信息
27 -- **Material Library** - Training materials and document management 27 +- **资料库** - 培训材料和文档管理
28 - - Knowledge base for training materials and case studies 28 + - 培训材料和案例的知识库
29 - - Material list page with document preview capabilities 29 + - 资料列表页支持文档预览
30 -- **Family Office** (家办) - Family office services 30 +- **家办** - 家族办公室服务
31 -- **Contract Signing** (签单) - Contract signing workflow 31 +- **签单** - 签约流程
32 -- **User Center** - Personal profile, favorites, feedback, help center 32 +- **用户中心** - 个人资料、收藏、反馈、帮助中心
33 - 33 +
34 -## Project Architecture 34 +## 项目架构
35 - 35 +
36 -This is a **Taro 4 + Vue 3 + NutUI** WeChat mini-program with built-in authentication and reusable navigation components. 36 +这是一个基于 **Taro 4 + Vue 3 + NutUI** 的微信小程序,内置身份认证和可复用的导航组件。
37 - 37 +
38 -### Technology Stack 38 +### 技术栈
39 -- **Framework**: Taro 4.1.9 + Vue 3.3.0 + Composition API 39 +- **框架**Taro 4.1.9 + Vue 3.3.0 + Composition API
40 -- **UI Library**: NutUI 4.3.13 (JD.com's UI library for Taro) 40 +- **UI 库**:NutUI 4.3.13(京东推出的 Taro UI 库)
41 -- **State Management**: Pinia 3.0.3 + taro-plugin-pinia 41 +- **状态管理**Pinia 3.0.3 + taro-plugin-pinia
42 -- **HTTP Client**: axios-miniprogram 42 +- **HTTP 客户端**axios-miniprogram
43 -- **Styling**: Less + TailwindCSS 3.x (dual design width system) 43 +- **样式**:Less + TailwindCSS 3.x(双设计宽度系统)
44 -- **Build Tool**: Webpack 5 44 +- **构建工具**Webpack 5
45 -- **Navigation**: Custom TabBar + enhanced navigation hooks 45 +- **导航**:自定义 TabBar + 增强导航 hooks
46 - 46 +
47 -### Dual Design Width System 47 +### 双设计宽度系统
48 -The project uses **two different design widths** configured in `config/index.js:16-23`: 48 +项目在 `config/index.js:16-23` 中配置了**两种不同的设计宽度**
49 -- **NutUI components**: 375px base width 49 +- **NutUI 组件**:375px 基准宽度
50 -- **All other pages**: 750px base width 50 +- **所有其他页面**:750px 基准宽度
51 - 51 +
52 -When working with styles: 52 +处理样式时:
53 -- Check if you're using NutUI components → reference 375px designs 53 +- 使用 NutUI 组件 → 参考 375px 设计稿
54 -- Custom page layouts → reference 750px designs 54 +- 自定义页面布局 → 参考 750px 设计稿
55 - 55 +
56 -### Key Architectural Patterns 56 +### 核心架构模式
57 - 57 +
58 -#### 1. Reusable Navigation Components 58 +#### 1. 可复用的导航组件
59 - 59 +
60 -**TabBar Component** (`src/components/TabBar.vue`): 60 +**TabBar 组件**`src/components/TabBar.vue`):
61 -- Fixed bottom navigation bar 61 +- 固定底部导航栏
62 -- Auto-adapts to safe areas (notch/home indicator) 62 +- 自动适配安全区域(刘海屏/底部指示器)
63 -- Supports icon + text layout 63 +- 支持图标 + 文字布局
64 -- Active state highlighting 64 +- 激活状态高亮
65 -- Used across: Index, Mine, Family Office, Knowledge Base, Signing pages 65 +- 使用于:首页、我的、家办、知识库、签单页面
66 - 66 +
67 -**NavHeader Component** (`src/components/NavHeader.vue`): 67 +**NavHeader 组件**`src/components/NavHeader.vue`):
68 -- Custom navigation header with back button 68 +- 带返回按钮的自定义导航头
69 -- Transparent/background variants 69 +- 透明/背景变体
70 -- Safe area padding for notch devices 70 +- 刘海屏设备的安全区域内边距
71 -- Replaces default Taro navigation bar 71 +- 替代默认的 Taro 导航栏
72 - 72 +
73 -**IconFont Component** (`src/components/IconFont.vue`): 73 +**IconFont 组件**`src/components/IconFont.vue`):
74 -- Icon font wrapper for custom icons 74 +- 自定义图标的图标字体包装器
75 -- Supports size and color customization 75 +- 支持大小和颜色自定义
76 - 76 +
77 -#### 2. Authentication Flow (Required) 77 +#### 2. 身份认证流程(必需)
78 - 78 +
79 -The project has a sophisticated authentication system with automatic session management: 79 +项目具有完善的身份认证系统,支持自动会话管理:
80 - 80 +
81 -**Startup Flow** (`src/app.js:26-214`): 81 +**启动流程**`src/app.js:26-214`):
82 -1. App saves launch path for auth callback 82 +1. 应用保存启动路径用于认证回调
83 -2. Checks network status and handles weak network scenarios 83 +2. 检查网络状态并处理弱网络场景
84 -3. Attempts silent auth if not authenticated 84 +3. 如果未认证,尝试静默认证
85 -4. On auth success, enables offline features 85 +4. 认证成功后,启用离线功能
86 - 86 +
87 -**Core Files**: 87 +**核心文件**
88 -- `src/utils/authRedirect.js` - All auth logic (silent refresh, navigation, state) 88 +- `src/utils/authRedirect.js` - 所有认证逻辑(静默刷新、导航、状态)
89 -- `src/utils/request.js` - HTTP client with 401 auto-refresh interceptor 89 +- `src/utils/request.js` - 带 401 自动刷新拦截器的 HTTP 客户端
90 -- `src/pages/auth/index.vue` - Auth page (must be preserved) 90 +- `src/pages/auth/index.vue` - 认证页(必须保留)
91 -- `src/pages/login/index.vue` - Login page 91 +- `src/pages/login/index.vue` - 登录页
92 - 92 +
93 -**How 401 Auto-Refresh Works** (`src/utils/request.js:241-276`): 93 +**401 自动刷新工作原理**`src/utils/request.js:241-276`):
94 -1. API returns 401 94 +1. API 返回 401
95 -2. Interceptor saves current page path 95 +2. 拦截器保存当前页面路径
96 -3. Calls `refreshSession()` to get new session via WeChat login 96 +3. 调用 `refreshSession()` 通过微信登录获取新会话
97 -4. Retries original request with new session 97 +4. 使用新会话重试原始请求
98 -5. If refresh fails, redirects to auth page 98 +5. 如果刷新失败,跳转到认证页
99 - 99 +
100 -**Important**: The backend MUST provide `/srv/?a=openid_wxapp` endpoint for WeChat login. 100 +**重要**:后端必须提供 `/srv/?a=openid_wxapp` 端点用于微信登录。
101 - 101 +
102 -#### 3. API Layer Architecture 102 +#### 3. API 层架构
103 - 103 +
104 -**API Definition Pattern** (`src/api/index.js`): 104 +**API 定义模式**`src/api/index.js`):
105 ```javascript 105 ```javascript
106 export const yourAPI = (params) => { 106 export const yourAPI = (params) => {
107 return buildApiUrl('your_action', params) 107 return buildApiUrl('your_action', params)
108 } 108 }
109 ``` 109 ```
110 110
111 -**Request Wrapper** (`src/api/fn.js`): 111 +**请求包装器**`src/api/fn.js`):
112 -- All API calls should go through this wrapper 112 +- 所有 API 调用都应通过此包装器
113 -- Handles common error scenarios 113 +- 处理常见错误场景
114 -- Provides consistent interface 114 +- 提供一致的接口
115 115
116 -**URL Building** (`src/utils/tools.js`): 116 +**URL 构建**`src/utils/tools.js`):
117 -- `buildApiUrl(action, params)` - Constructs full API URL 117 +- `buildApiUrl(action, params)` - 构建完整的 API URL
118 -- Automatically merges default parameters from `src/utils/config.js` 118 +- 自动合并来自 `src/utils/config.js` 的默认参数
119 119
120 -#### 4. Enhanced Navigation System 120 +#### 4. 增强导航系统
121 121
122 -**useGo Hook** (`src/hooks/useGo.js`): 122 +**useGo Hook**`src/hooks/useGo.js`):
123 ```javascript 123 ```javascript
124 import { useGo } from '@/hooks/useGo' 124 import { useGo } from '@/hooks/useGo'
125 const go = useGo() 125 const go = useGo()
126 126
127 -go('/page-name') // Auto-completes path 127 +go('/page-name') // 自动补全路径
128 -go('/page', { id: 123 }) // With query params 128 +go('/page', { id: 123 }) // 带查询参数
129 ``` 129 ```
130 130
131 -**Route Storage** (`src/stores/router.js`): 131 +**路由存储**`src/stores/router.js`):
132 -- Maintains stack of visited routes 132 +- 维护已访问路由的栈
133 -- Used for auth callback navigation 133 +- 用于认证回调导航
134 -- Automatically managed by auth flow 134 +- 由认证流程自动管理
135 135
136 -### Page Structure 136 +### 页面结构
137 137
138 -All pages follow this directory structure: 138 +所有页面遵循以下目录结构:
139 ``` 139 ```
140 src/pages/your-page/ 140 src/pages/your-page/
141 -├── index.vue # Page component (must use <script setup>) 141 +├── index.vue # 页面组件(必须使用 <script setup>)
142 -├── index.config.js # Page configuration (navigationBarTitleText, etc.) 142 +├── index.config.js # 页面配置(navigationBarTitleText 等)
143 -└── assets/ # Page-specific assets (optional) 143 +└── assets/ # 页面特定资源(可选)
144 ``` 144 ```
145 145
146 -### Current Pages 146 +### 当前页面
147 - 147 +
148 -**Core Pages**: 148 +**核心页面**
149 -1. `pages/index/index` - Home page (product showcase, search, grid navigation) 149 +1. `pages/index/index` - 首页(产品展示、搜索、网格导航)
150 - - Hot products "产品资料" buttons navigate to `product-detail` page with product ID 150 + - 热门产品的"产品资料"按钮跳转到 `product-detail` 页面,带产品 ID
151 - - Hot materials "查看更多" navigates to `material-list` page 151 + - 热门资料的"查看更多"跳转到 `material-list` 页面
152 - - Grid navigation icons navigate to various business pages 152 + - 网格导航图标跳转到各个业务页面
153 -2. `pages/auth/index` - Authentication page 153 +2. `pages/auth/index` - 认证页
154 -3. `pages/login/index` - Login page 154 +3. `pages/login/index` - 登录页
155 - 155 +
156 -**Business Pages**: 156 +**业务页面**
157 -4. `pages/family-office/index` - Family office services 157 +4. `pages/family-office/index` - 家族办公室服务
158 -5. `pages/knowledge-base/index` - Knowledge base (training materials, cases) 158 +5. `pages/knowledge-base/index` - 知识库(培训材料、案例)
159 -6. `pages/signing/index` - Contract signing 159 +6. `pages/signing/index` - 签约
160 -7. `pages/plan/index` - Business plan management 160 +7. `pages/plan/index` - 业务计划管理
161 -8. `pages/favorites/index` - User favorites 161 +8. `pages/favorites/index` - 用户收藏
162 -9. `pages/feedback/index` - User feedback 162 +9. `pages/feedback/index` - 用户反馈
163 -10. `pages/avatar/index` - Avatar settings 163 +10. `pages/avatar/index` - 头像设置
164 -11. `pages/mine/index` - User profile 164 +11. `pages/mine/index` - 用户资料
165 - 165 +
166 -**Product & Content Pages**: 166 +**产品与内容页面**
167 -12. `pages/product-detail/index` - Product detail page 167 +12. `pages/product-detail/index` - 产品详情页
168 - - Receives `id` parameter via Taro's `useLoad` hook 168 + - 通过 Taro 的 `useLoad` hook 接收 `id` 参数
169 - - Example navigation: `go('/pages/product-detail/index', { id: 1 })` 169 + - 导航示例:`go('/pages/product-detail/index', { id: 1 })`
170 - - Parameters can be used to fetch product details from API 170 + - 参数可用于从 API 获取产品详情
171 -13. `pages/material-list/index` - Material/Document list page 171 +13. `pages/material-list/index` - 资料/文档列表页
172 -14. `pages/help-center/index` - Help center and FAQ page 172 +14. `pages/help-center/index` - 帮助中心和常见问题页
173 -15. `pages/search/index` - Search page for products and materials 173 +15. `pages/search/index` - 产品和资料搜索页
174 - 174 +
175 -**Utility Pages**: 175 +**工具页面**
176 -16. `pages/onboarding/index` - New user onboarding 176 +16. `pages/onboarding/index` - 新用户引导
177 -17. `pages/webview/index` - WebView wrapper for external URLs 177 +17. `pages/webview/index` - 外部 URL 的 WebView 包装器
178 -18. `pages/document-demo/index` - Document preview demo page 178 +18. `pages/document-demo/index` - 文档预览演示页
179 -19. `pages/document-preview/index` - Document preview page 179 +19. `pages/document-preview/index` - 文档预览页
180 - 180 +
181 -### Component Library 181 +### 组件库
182 - 182 +
183 -**Reusable Components**: 183 +**可复用组件**
184 -- `TabBar.vue` - Bottom navigation bar 184 +- `TabBar.vue` - 底部导航栏
185 -- `NavHeader.vue` - Custom navigation header 185 +- `NavHeader.vue` - 自定义导航头
186 -- `IconFont.vue` - Icon font wrapper 186 +- `IconFont.vue` - 图标字体包装器
187 - 187 +
188 -**Feature Components**: 188 +**功能组件**
189 -- `qrCode.vue` - QR code display 189 +- `qrCode.vue` - 二维码显示
190 -- `qrCodeSearch.vue` - QR code scanner 190 +- `qrCodeSearch.vue` - 二维码扫描
191 -- `PosterBuilder/` - Poster generation 191 +- `PosterBuilder/` - 海报生成
192 -- `time-picker-data/` - Time picker data 192 +- `time-picker-data/` - 时间选择器数据
193 - 193 +
194 -### Path Aliases 194 +### 路径别名
195 -All configured in `config/index.js:30-38`: 195 +全部配置在 `config/index.js:30-38`
196 ```javascript 196 ```javascript
197 @/utils src/utils 197 @/utils src/utils
198 @/components src/components 198 @/components src/components
...@@ -204,71 +204,71 @@ All configured in `config/index.js:30-38`: ...@@ -204,71 +204,71 @@ All configured in `config/index.js:30-38`:
204 @/hooks src/hooks 204 @/hooks src/hooks
205 ``` 205 ```
206 206
207 -### Configuration Management 207 +### 配置管理
208 - 208 +
209 -**Environment Config** (`src/utils/config.js`): 209 +**环境配置**`src/utils/config.js`):
210 -**⚠️ MUST BE MODIFIED before use**: 210 +**⚠️ 使用前必须修改**
211 -- `BASE_URL` - Set development/production domain 211 +- `BASE_URL` - 设置开发/生产域名
212 -- `REQUEST_DEFAULT_PARAMS.f` - Set business module identifier 212 +- `REQUEST_DEFAULT_PARAMS.f` - 设置业务模块标识符
213 -- `REQUEST_DEFAULT_PARAMS.client_name` - Set application name 213 +- `REQUEST_DEFAULT_PARAMS.client_name` - 设置应用名称
214 - 214 +
215 -**Build Config** (`config/index.js`): 215 +**构建配置**`config/index.js`):
216 -- Path aliases 216 +- 路径别名
217 -- Design width rules 217 +- 设计宽度规则
218 -- NutUI auto-import 218 +- NutUI 自动导入
219 -- Platform-specific settings 219 +- 平台特定设置
220 - 220 +
221 -**App Config** (`src/app.config.js`): 221 +**应用配置**`src/app.config.js`):
222 -- Page routes registration 222 +- 页面路由注册
223 -- Window configuration 223 +- 窗口配置
224 -- Tab bar configuration (optional) 224 +- 标签栏配置(可选)
225 -- Subpackages (if needed) 225 +- 分包(如需要)
226 - 226 +
227 -## Important Implementation Details 227 +## 重要实现细节
228 - 228 +
229 -### Session Management 229 +### 会话管理
230 -- Session ID stored in `localStorage` with key `sessionid` 230 +- 会话 ID 存储在 `localStorage` 中,键名为 `sessionid`
231 -- Set by `authRedirect.refreshSession()` after successful WeChat login 231 +- 微信登录成功后由 `authRedirect.refreshSession()` 设置
232 -- Automatically injected into request headers by `request.js` interceptor 232 +- `request.js` 拦截器自动注入到请求头中
233 -- Cleared on logout or explicit manual intervention 233 +- 登出或显式手动操作时清除
234 - 234 +
235 -### Promise Single-Pattern 235 +### Promise 单例模式
236 -The auth system uses Promise singletons to prevent concurrent login attempts: 236 +认证系统使用 Promise 单例防止并发登录尝试:
237 -- `auth_promise` in `authRedirect.js` ensures only one refresh at a time 237 +- `authRedirect.js` 中的 `auth_promise` 确保一次只刷新一个
238 -- All concurrent 401s share the same refresh Promise 238 +- 所有并发的 401 共享同一个刷新 Promise
239 -- `.finally()` ensures cleanup regardless of success/failure 239 +- `.finally()` 确保无论成功/失败都执行清理
240 - 240 +
241 -### Request Timeout Handling 241 +### 请求超时处理
242 -- Default timeout: 5 seconds (`src/utils/request.js:79`) 242 +- 默认超时:5 秒(`src/utils/request.js:79`
243 -- Timeout detection via `is_timeout_error()` helper 243 +- 通过 `is_timeout_error()` 辅助函数检测超时
244 -- Network error detection via `is_network_error()` helper 244 +- 通过 `is_network_error()` 辅助函数检测网络错误
245 -- Both trigger weak network fallback flow 245 +- 两者都会触发弱网络降级流程
246 - 246 +
247 -### NutUI Auto-Import 247 +### NutUI 自动导入
248 -NutUI components are auto-imported via unplugin-vue-components (`config/index.js:91-93`). 248 +NutUI 组件通过 unplugin-vue-components 自动导入(`config/index.js:91-93`)。
249 -**No manual imports needed** - just use components directly in templates. 249 +**无需手动导入** - 直接在模板中使用组件即可。
250 - 250 +
251 -### TailwindCSS Integration 251 +### TailwindCSS 集成
252 -- Preflight disabled for mini-program compatibility 252 +- 为小程序兼容性禁用了 Preflight
253 -- `rem2rpx` conversion enabled 253 +- 启用了 `rem2rpx` 转换
254 -- Content paths configured in `tailwind.config.js` 254 +- 内容路径配置在 `tailwind.config.js`
255 -- Use Tailwind for layout, spacing, colors 255 +- 使用 Tailwind 处理布局、间距、颜色
256 -- Use Less for component-specific styles, animations, pseudo-elements 256 +- 使用 Less 处理组件特定样式、动画、伪元素
257 - 257 +
258 -### Styling Guidelines 258 +### 样式指南
259 - 259 +
260 -**When to use TailwindCSS** (80% of cases): 260 +**何时使用 TailwindCSS**(80% 的情况):
261 ```vue 261 ```vue
262 <div class="flex items-center justify-between p-4 bg-white"> 262 <div class="flex items-center justify-between p-4 bg-white">
263 - <h1 class="text-xl font-bold text-gray-900">Title</h1> 263 + <h1 class="text-xl font-bold text-gray-900">标题</h1>
264 </div> 264 </div>
265 ``` 265 ```
266 266
267 -**When to use Less** (20% of cases): 267 +**何时使用 Less**(20% 的情况):
268 -- Component-specific styles 268 +- 组件特定样式
269 -- Deep selectors (`:deep()`) 269 +- 深度选择器(`:deep()`
270 -- Animations and transitions 270 +- 动画和过渡
271 -- Pseudo-elements (`::before`, `::after`) 271 +- 伪元素(`::before``::after`
272 ```less 272 ```less
273 <style lang="less" scoped> 273 <style lang="less" scoped>
274 .custom-card { 274 .custom-card {
...@@ -282,36 +282,36 @@ NutUI components are auto-imported via unplugin-vue-components (`config/index.js ...@@ -282,36 +282,36 @@ NutUI components are auto-imported via unplugin-vue-components (`config/index.js
282 </style> 282 </style>
283 ``` 283 ```
284 284
285 -## Optional Features 285 +## 可选功能
286 286
287 -These features can be removed if not needed: 287 +如果不需要,可以移除以下功能:
288 -- **WeChat Pay**: `src/utils/wechatPay.js`, `src/api/wx/pay.js` 288 +- **微信支付**`src/utils/wechatPay.js``src/api/wx/pay.js`
289 -- **QR Code**: `src/components/qrCode.vue`, `src/components/qrCodeSearch.vue` 289 +- **二维码**`src/components/qrCode.vue``src/components/qrCodeSearch.vue`
290 -- **Poster Builder**: `src/components/PosterBuilder/` 290 +- **海报生成器**`src/components/PosterBuilder/`
291 -- **Time Picker**: `src/components/time-picker-data/` 291 +- **时间选择器**`src/components/time-picker-data/`
292 -- **Offline Cache**: Entire offline booking cache system (if not used) 292 +- **离线缓存**:整个离线预约缓存系统(如果不使用)
293 293
294 -## Development Workflow 294 +## 开发工作流
295 295
296 -### Adding New Pages 296 +### 添加新页面
297 297
298 -1. **Create page directory**: 298 +1. **创建页面目录**
299 ```bash 299 ```bash
300 src/pages/your-page/ 300 src/pages/your-page/
301 ├── index.vue 301 ├── index.vue
302 └── index.config.js 302 └── index.config.js
303 ``` 303 ```
304 304
305 -2. **Configure page** (`index.config.js`): 305 +2. **配置页面**`index.config.js`):
306 ```javascript 306 ```javascript
307 export default { 307 export default {
308 - navigationBarTitleText: 'Your Page Title', 308 + navigationBarTitleText: '您的页面标题',
309 enablePullDownRefresh: true, 309 enablePullDownRefresh: true,
310 backgroundColor: '#f5f5f5' 310 backgroundColor: '#f5f5f5'
311 } 311 }
312 ``` 312 ```
313 313
314 -3. **Register route** in `src/app.config.js`: 314 +3. **`src/app.config.js` 中注册路由**
315 ```javascript 315 ```javascript
316 pages: [ 316 pages: [
317 'pages/your-page/index', 317 'pages/your-page/index',
...@@ -319,7 +319,7 @@ These features can be removed if not needed: ...@@ -319,7 +319,7 @@ These features can be removed if not needed:
319 ] 319 ]
320 ``` 320 ```
321 321
322 -4. **Use composition API** in `index.vue`: 322 +4. **`index.vue` 中使用 composition API**
323 ```vue 323 ```vue
324 <script setup> 324 <script setup>
325 import { ref } from 'vue' 325 import { ref } from 'vue'
...@@ -328,46 +328,46 @@ These features can be removed if not needed: ...@@ -328,46 +328,46 @@ These features can be removed if not needed:
328 const pageId = ref(null) 328 const pageId = ref(null)
329 329
330 useLoad((options) => { 330 useLoad((options) => {
331 - console.log('Page loaded with options:', options) 331 + console.log('页面加载,参数:', options)
332 - // Receive navigation parameters 332 + // 接收导航参数
333 if (options.id) { 333 if (options.id) {
334 pageId.value = options.id 334 pageId.value = options.id
335 - // Fetch data based on ID 335 + // 根据 ID 获取数据
336 } 336 }
337 }) 337 })
338 338
339 useShow(() => { 339 useShow(() => {
340 - console.log('Page shown') 340 + console.log('页面显示')
341 }) 341 })
342 342
343 - // Your component logic 343 + // 您的组件逻辑
344 </script> 344 </script>
345 ``` 345 ```
346 346
347 - **Navigation with Parameters**: 347 + **带参数导航**
348 ```javascript 348 ```javascript
349 - // From another page 349 + // 从另一个页面
350 import { useGo } from '@/hooks/useGo' 350 import { useGo } from '@/hooks/useGo'
351 const go = useGo() 351 const go = useGo()
352 352
353 - // Navigate with query params 353 + // 带查询参数导航
354 go('/pages/product-detail/index', { id: 123, type: 'insurance' }) 354 go('/pages/product-detail/index', { id: 123, type: 'insurance' })
355 ``` 355 ```
356 356
357 -5. **Add navigation** (optional TabBar integration): 357 +5. **添加导航**(可选的 TabBar 集成):
358 - - Import and use `TabBar` component 358 + - 导入并使用 `TabBar` 组件
359 - - Configure active state based on route 359 + - 根据路由配置激活状态
360 360
361 -### Adding API Calls 361 +### 添加 API 调用
362 362
363 -1. **Define API** in `src/api/index.js`: 363 +1. **`src/api/index.js` 中定义 API**
364 ```javascript 364 ```javascript
365 export const getProductListAPI = (params) => { 365 export const getProductListAPI = (params) => {
366 return buildApiUrl('product_list', params) 366 return buildApiUrl('product_list', params)
367 } 367 }
368 ``` 368 ```
369 369
370 -2. **Use in page**: 370 +2. **在页面中使用**
371 ```javascript 371 ```javascript
372 import { getProductListAPI } from '@/api' 372 import { getProductListAPI } from '@/api'
373 import { fn } from '@/api/fn' 373 import { fn } from '@/api/fn'
...@@ -379,33 +379,33 @@ These features can be removed if not needed: ...@@ -379,33 +379,33 @@ These features can be removed if not needed:
379 products.value = res.data 379 products.value = res.data
380 } 380 }
381 } catch (err) { 381 } catch (err) {
382 - console.error('Failed to fetch products:', err) 382 + console.error('获取产品失败:', err)
383 } 383 }
384 } 384 }
385 ``` 385 ```
386 386
387 -### Using Navigation 387 +### 使用导航
388 388
389 -**Recommended**: Use `useGo` hook for enhanced navigation: 389 +**推荐**:使用 `useGo` hook 进行增强导航:
390 ```javascript 390 ```javascript
391 import { useGo } from '@/hooks/useGo' 391 import { useGo } from '@/hooks/useGo'
392 392
393 const go = useGo() 393 const go = useGo()
394 394
395 -// Navigate to page 395 +// 导航到页面
396 go('/pages/detail/index') 396 go('/pages/detail/index')
397 397
398 -// Navigate with params (e.g., product ID) 398 +// 带参数导航(例如产品 ID)
399 go('/pages/product-detail/index', { id: 123 }) 399 go('/pages/product-detail/index', { id: 123 })
400 400
401 -// Navigate with multiple params 401 +// 带多个参数导航
402 go('/pages/material-list/index', { category: 'insurance', page: 1 }) 402 go('/pages/material-list/index', { category: 'insurance', page: 1 })
403 403
404 -// Go back 404 +// 返回
405 go.back() 405 go.back()
406 ``` 406 ```
407 407
408 -**Receiving Parameters in Target Page**: 408 +**在目标页面接收参数**:
409 ```javascript 409 ```javascript
410 import { useLoad } from '@tarojs/taro' 410 import { useLoad } from '@tarojs/taro'
411 import { ref } from 'vue' 411 import { ref } from 'vue'
...@@ -413,16 +413,16 @@ import { ref } from 'vue' ...@@ -413,16 +413,16 @@ import { ref } from 'vue'
413 const productId = ref(null) 413 const productId = ref(null)
414 414
415 useLoad((options) => { 415 useLoad((options) => {
416 - // Access navigation parameters 416 + // 访问导航参数
417 - console.log('Received params:', options) 417 + console.log('接收到的参数:', options)
418 productId.value = options.id 418 productId.value = options.id
419 419
420 - // Fetch data based on parameters 420 + // 根据参数获取数据
421 fetchProductDetail(options.id) 421 fetchProductDetail(options.id)
422 }) 422 })
423 ``` 423 ```
424 424
425 -**Alternative**: Use Taro's built-in navigation: 425 +**替代方案**:使用 Taro 内置导航:
426 ```javascript 426 ```javascript
427 import Taro from '@tarojs/taro' 427 import Taro from '@tarojs/taro'
428 428
...@@ -431,9 +431,9 @@ Taro.navigateTo({ ...@@ -431,9 +431,9 @@ Taro.navigateTo({
431 }) 431 })
432 ``` 432 ```
433 433
434 -### State Management with Pinia 434 +### 使用 Pinia 状态管理
435 435
436 -**Create store** (`src/stores/yourStore.js`): 436 +**创建 store**(`src/stores/yourStore.js`):
437 ```javascript 437 ```javascript
438 import { defineStore } from 'pinia' 438 import { defineStore } from 'pinia'
439 import { ref } from 'vue' 439 import { ref } from 'vue'
...@@ -449,90 +449,90 @@ export const useYourStore = defineStore('yourStore', () => { ...@@ -449,90 +449,90 @@ export const useYourStore = defineStore('yourStore', () => {
449 }) 449 })
450 ``` 450 ```
451 451
452 -**Use in component**: 452 +**在组件中使用**:
453 ```javascript 453 ```javascript
454 import { useYourStore } from '@/stores/yourStore' 454 import { useYourStore } from '@/stores/yourStore'
455 455
456 const store = useYourStore() 456 const store = useYourStore()
457 -store.setState('new value') 457 +store.setState('新值')
458 ``` 458 ```
459 459
460 -## Critical Files Summary 460 +## 关键文件总结
461 - 461 +
462 -### Must Understand Before Modifying 462 +### 修改前必须理解
463 -1. **`src/utils/authRedirect.js`** - Complete auth flow logic 463 +1. **`src/utils/authRedirect.js`** - 完整的认证流程逻辑
464 -2. **`src/utils/request.js`** - HTTP client with interceptors 464 +2. **`src/utils/request.js`** - 带拦截器的 HTTP 客户端
465 -3. **`src/app.js`** - App startup sequence and network handling 465 +3. **`src/app.js`** - 应用启动序列和网络处理
466 -4. **`src/utils/config.js`** - Server configuration (requires modification) 466 +4. **`src/utils/config.js`** - 服务器配置(需要修改)
467 - 467 +
468 -### Key Business Logic 468 +### 核心业务逻辑
469 -1. **`src/api/index.js`** - API definitions 469 +1. **`src/api/index.js`** - API 定义
470 -2. **`src/api/fn.js`** - Request wrapper 470 +2. **`src/api/fn.js`** - 请求包装器
471 -3. **`src/stores/main.js`** - Primary state management 471 +3. **`src/stores/main.js`** - 主要状态管理
472 -4. **`src/stores/router.js`** - Route state for auth callbacks 472 +4. **`src/stores/router.js`** - 认证回调的路由状态
473 - 473 +
474 -### Reusable Components 474 +### 可复用组件
475 -1. **`src/components/TabBar.vue`** - Bottom navigation bar 475 +1. **`src/components/TabBar.vue`** - 底部导航栏
476 -2. **`src/components/NavHeader.vue`** - Custom navigation header 476 +2. **`src/components/NavHeader.vue`** - 自定义导航头
477 -3. **`src/components/IconFont.vue`** - Icon wrapper 477 +3. **`src/components/IconFont.vue`** - 图标包装器
478 - 478 +
479 -### UI/UX Utilities 479 +### UI/UX 工具
480 -1. **`src/utils/uiText.js`** - Centralized copy management 480 +1. **`src/utils/uiText.js`** - 集中式文案管理
481 -2. **`src/utils/network.js`** - Network status utilities 481 +2. **`src/utils/network.js`** - 网络状态工具
482 -3. **`src/hooks/useGo.js`** - Enhanced navigation hook 482 +3. **`src/hooks/useGo.js`** - 增强导航 hook
483 - 483 +
484 -## Debugging Tips 484 +## 调试技巧
485 - 485 +
486 -When debugging issues: 486 +调试问题时:
487 - 487 +
488 -1. **Check environment config**: 488 +1. **检查环境配置**
489 - - Verify `BASE_URL` in `src/utils/config.js` 489 + - 验证 `src/utils/config.js` 中的 `BASE_URL`
490 - - Check business module identifier `f` and `client_name` 490 + - 检查业务模块标识符 `f` `client_name`
491 - 491 +
492 -2. **Verify authentication**: 492 +2. **验证身份认证**
493 - - Check `sessionid` in localStorage 493 + - 检查 localStorage 中的 `sessionid`
494 - - Enable verbose logging in `src/utils/request.js` interceptor 494 + - `src/utils/request.js` 拦截器中启用详细日志
495 - - Test 401 refresh flow 495 + - 测试 401 刷新流程
496 - 496 +
497 -3. **Network issues**: 497 +3. **网络问题**
498 - - Use Taro's built-in network status monitoring 498 + - 使用 Taro 内置的网络状态监控
499 - - Check weak network fallback scenarios 499 + - 检查弱网络降级场景
500 - - Verify offline cache interactions 500 + - 验证离线缓存交互
501 - 501 +
502 -4. **Styling problems**: 502 +4. **样式问题**
503 - - Confirm design width (375px vs 750px) 503 + - 确认设计宽度(375px vs 750px)
504 - - Check if NutUI component or custom component 504 + - 检查是 NutUI 组件还是自定义组件
505 - - Verify TailwindCSS classes are applied 505 + - 验证 TailwindCSS 类是否已应用
506 - 506 +
507 -5. **Navigation issues**: 507 +5. **导航问题**
508 - - Check route is registered in `src/app.config.js` 508 + - 检查路由是否在 `src/app.config.js` 中注册
509 - - Verify page directory structure matches route 509 + - 验证页面目录结构与路由匹配
510 - - Use `useGo` hook for consistent navigation 510 + - 使用 `useGo` hook 进行一致的导航
511 - 511 +
512 -## Best Practices 512 +## 最佳实践
513 - 513 +
514 -### Component Development 514 +### 组件开发
515 -- Use `<script setup>` syntax 515 +- 使用 `<script setup>` 语法
516 -- Composables for reusable logic 516 +- 使用 Composables 处理可复用逻辑
517 -- Props should have type definitions 517 +- Props 应该有类型定义
518 -- Use `emit` for child-to-parent communication 518 +- 使用 `emit` 进行子到父通信
519 -- Prefer TailwindCSS for styling 519 +- 优先使用 TailwindCSS 进行样式设计
520 - 520 +
521 -### API Integration 521 +### API 集成
522 -- Always check `res.code === 1` for success 522 +- 始终检查 `res.code === 1` 判断成功
523 -- Use `try/catch` for error handling 523 +- 使用 `try/catch` 进行错误处理
524 -- Show loading states during requests 524 +- 请求期间显示加载状态
525 -- Handle network errors gracefully 525 +- 优雅地处理网络错误
526 - 526 +
527 -### Performance 527 +### 性能
528 -- Use page lazy loading (subpackages) 528 +- 使用页面懒加载(分包)
529 -- Optimize images with CDN parameters 529 +- 使用 CDN 参数优化图片
530 -- Avoid large data sets without pagination 530 +- 避免无分页的大数据集
531 -- Clean up timers and listeners in `onUnmounted` 531 +- `onUnmounted` 中清理定时器和监听器
532 - 532 +
533 -### Code Style 533 +### 代码风格
534 -- Follow Vue 3 Composition API patterns 534 +- 遵循 Vue 3 Composition API 模式
535 -- Use descriptive variable names 535 +- 使用描述性变量名
536 -- Keep functions focused and small (< 50 lines) 536 +- 保持函数聚焦且简短(< 50 行)
537 -- Add JSDoc comments for complex functions 537 +- 为复杂函数添加 JSDoc 注释
538 -- Run `pnpm lint` before committing 538 +- 提交前运行 `pnpm lint`
......