Refactor mini program environment configuration and remove deprecated debug features
- Simplified the environment configuration in app.js by removing the debug environment options and related functions. - Set a default API base URL for production while allowing commented options for local and testing environments. - Cleaned up settings.js by removing the debug environment label and switching functionality, streamlining the user interface. - Updated documentation to reflect the removal of debug features and added a summary of synchronization requirements in the planning document.
This commit is contained in:
74
.cursor/docs/目录无法加载-排查分析.md
Normal file
74
.cursor/docs/目录无法加载-排查分析.md
Normal file
@@ -0,0 +1,74 @@
|
||||
# 正式版小程序「目录无法加载数据」排查分析
|
||||
|
||||
## 一、数据流梳理
|
||||
|
||||
| 页面/时机 | 接口 | 用途 |
|
||||
|----------|------|------|
|
||||
| App onLaunch | `GET /api/miniprogram/book/all-chapters` | 预加载全书章节到 globalData.bookData |
|
||||
| 目录页 onLoad | `GET /api/miniprogram/book/parts` | **主接口**:懒加载篇章列表(不含章节详情) |
|
||||
| 目录页展开篇章 | `GET /api/miniprogram/book/chapters-by-part?partId=xxx` | 按篇章拉取章节列表 |
|
||||
|
||||
**目录页展示依赖的是 `book/parts`**,不依赖 `all-chapters`。`all-chapters` 失败只会影响首页等处的预加载,目录页应能独立加载。
|
||||
|
||||
---
|
||||
|
||||
## 二、后端接口验证结果
|
||||
|
||||
运行 `SOUL_TEST_ENV=soulapi python scripts/test/check-catalog-api.py` 实测:
|
||||
|
||||
- **book/parts**:✅ 正常,返回 6 个篇章、90 个章节、5 个固定模块
|
||||
- **all-chapters**:偶发 SSL 连接中断(大响应体时)
|
||||
- **health**:偶发 SSL 握手超时
|
||||
|
||||
**结论**:正式环境 soulapi 的 `book/parts` 接口可用且数据正常,后端不是主要瓶颈。
|
||||
|
||||
---
|
||||
|
||||
## 三、可能原因与排查步骤
|
||||
|
||||
### 1. baseUrl 指向错误
|
||||
|
||||
- **现象**:正式版请求到 souldev 或 localhost
|
||||
- **处理**:`app.js` 中 baseUrl 改为注释切换方式,正式环境使用 `https://soulapi.quwanzhi.com`
|
||||
|
||||
### 2. 服务器域名未配置(优先排查)
|
||||
|
||||
- **现象**:正式版请求失败,开发工具勾选「不校验合法域名」时正常
|
||||
- **处理**:微信公众平台 → 开发 → 开发管理 → 开发设置 → 服务器域名 → **request 合法域名**
|
||||
- **必须包含**:`https://soulapi.quwanzhi.com`
|
||||
- **注意**:正式版、体验版都会校验,缺配置会导致请求被拦截
|
||||
|
||||
### 3. 正式环境数据库为空
|
||||
|
||||
- **现象**:接口返回 `parts: []`、`totalSections: 0`
|
||||
- **排查**:执行诊断脚本,若 parts 为空则检查正式库 `chapters` 表
|
||||
- **处理**:确认正式库已导入 `soul_miniprogram.sql` 及必要迁移脚本
|
||||
|
||||
### 4. SSL/网络不稳定
|
||||
|
||||
- **现象**:偶发连接中断、超时
|
||||
- **排查**:多次调用诊断脚本,观察是否间歇失败
|
||||
- **处理**:检查正式服务器 SSL 配置、反向代理、超时设置
|
||||
|
||||
### 5. 前端错误处理导致无提示
|
||||
|
||||
- **现象**:请求失败但用户只看到空白
|
||||
- **代码**:`chapters.js` 的 `loadParts` 在 catch 中 `setData({ bookData: [], totalSections: 0 })`,不弹窗
|
||||
- **建议**:可在 catch 中增加 `wx.showToast({ title: '加载失败,请重试', icon: 'none' })` 便于用户感知
|
||||
|
||||
---
|
||||
|
||||
## 四、建议操作顺序
|
||||
|
||||
1. **确认 request 合法域名**:在微信公众平台添加 `https://soulapi.quwanzhi.com`
|
||||
2. **本地验证接口**:`SOUL_TEST_ENV=soulapi python scripts/test/check-catalog-api.py`
|
||||
3. **正式版真机测试**:清除小程序缓存后重新打开,观察目录页是否加载
|
||||
4. **若仍失败**:在 `chapters.js` 的 `loadParts` 中加 `console.log` 或 `wx.showModal` 输出错误信息,便于定位
|
||||
|
||||
---
|
||||
|
||||
## 五、相关文件
|
||||
|
||||
- 小程序:`miniprogram/app.js`(baseUrl)、`miniprogram/pages/chapters/chapters.js`(loadParts)
|
||||
- 后端:`soul-api/internal/handler/book.go`(BookParts、BookChaptersByPart)
|
||||
- 诊断脚本:`scripts/test/check-catalog-api.py`
|
||||
Reference in New Issue
Block a user