202 lines
4.4 KiB
Markdown
202 lines
4.4 KiB
Markdown
|
|
# 🔥 紧急修复 - 成长记录接口参数传递错误
|
|||
|
|
|
|||
|
|
## ❌ 问题描述
|
|||
|
|
|
|||
|
|
前端调用成长记录接口时,参数传递方式错误,导致后端无法接收到 `studentId` 参数。
|
|||
|
|
|
|||
|
|
**错误信息:**
|
|||
|
|
```
|
|||
|
|
Required request parameter 'studentId' for method parameter type Long is not present
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**错误的URL:**
|
|||
|
|
```
|
|||
|
|
http://localhost:8080/api/growth-record/parent/list?params=%5Bobject%20Object%5D
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🔍 根本原因
|
|||
|
|
|
|||
|
|
前端代码中使用了错误的参数传递方式:
|
|||
|
|
|
|||
|
|
**错误写法:**
|
|||
|
|
```javascript
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', {
|
|||
|
|
params: {
|
|||
|
|
studentId: this.getStudentId(),
|
|||
|
|
recordType: 'daily',
|
|||
|
|
page: this.page,
|
|||
|
|
size: this.pageSize
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
这会导致整个 `params` 对象被当作字符串传递。
|
|||
|
|
|
|||
|
|
**正确写法:**
|
|||
|
|
```javascript
|
|||
|
|
const params = {
|
|||
|
|
studentId: this.getStudentId(),
|
|||
|
|
recordType: 'daily',
|
|||
|
|
page: this.page,
|
|||
|
|
size: this.pageSize
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', params)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## ✅ 修复内容
|
|||
|
|
|
|||
|
|
### 1. 修复服务反馈列表页面
|
|||
|
|
|
|||
|
|
**文件:** `peidu/uniapp/src/user-package/pages/feedback/list.vue`
|
|||
|
|
|
|||
|
|
**修改前:**
|
|||
|
|
```javascript
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', {
|
|||
|
|
params: {
|
|||
|
|
studentId: this.getStudentId(),
|
|||
|
|
recordType: 'daily',
|
|||
|
|
page: this.page,
|
|||
|
|
size: this.pageSize
|
|||
|
|
}
|
|||
|
|
})
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**修改后:**
|
|||
|
|
```javascript
|
|||
|
|
const params = {
|
|||
|
|
studentId: this.getStudentId(),
|
|||
|
|
recordType: 'daily',
|
|||
|
|
page: this.page,
|
|||
|
|
size: this.pageSize
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('请求参数:', params)
|
|||
|
|
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', params)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 修复成长记录列表页面
|
|||
|
|
|
|||
|
|
**文件:** `peidu/uniapp/src/user-package/pages/growth/list.vue`
|
|||
|
|
|
|||
|
|
**修改前:**
|
|||
|
|
```javascript
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', { params })
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**修改后:**
|
|||
|
|
```javascript
|
|||
|
|
console.log('请求参数:', params)
|
|||
|
|
|
|||
|
|
const res = await request.get('/api/growth-record/parent/list', params)
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 📝 request.get 方法说明
|
|||
|
|
|
|||
|
|
根据 `peidu/uniapp/src/utils/request.js` 的实现:
|
|||
|
|
|
|||
|
|
```javascript
|
|||
|
|
request.get = function(url, params) {
|
|||
|
|
return request({
|
|||
|
|
url: url,
|
|||
|
|
method: 'GET',
|
|||
|
|
params: params // ✅ 第二个参数直接就是 params
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**正确用法:**
|
|||
|
|
```javascript
|
|||
|
|
// ✅ 正确:直接传递参数对象
|
|||
|
|
request.get('/api/xxx', { key1: value1, key2: value2 })
|
|||
|
|
|
|||
|
|
// ❌ 错误:不要包装在 params 中
|
|||
|
|
request.get('/api/xxx', { params: { key1: value1, key2: value2 } })
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## 🚀 立即测试
|
|||
|
|
|
|||
|
|
### 1. 重新编译前端
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
cd peidu/uniapp
|
|||
|
|
npm run build:mp-weixin
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 2. 刷新小程序
|
|||
|
|
|
|||
|
|
在微信开发者工具中点击"编译"按钮
|
|||
|
|
|
|||
|
|
### 3. 测试服务反馈列表
|
|||
|
|
|
|||
|
|
1. 打开小程序
|
|||
|
|
2. 进入家长端
|
|||
|
|
3. 点击"服务反馈"菜单
|
|||
|
|
4. 验证:
|
|||
|
|
- ✅ 列表正常加载
|
|||
|
|
- ✅ 显示每日反馈数据
|
|||
|
|
- ✅ 控制台无错误
|
|||
|
|
|
|||
|
|
### 4. 测试成长记录列表
|
|||
|
|
|
|||
|
|
1. 点击"成长记录"菜单
|
|||
|
|
2. 验证:
|
|||
|
|
- ✅ 列表正常加载
|
|||
|
|
- ✅ 可以切换标签
|
|||
|
|
- ✅ 控制台无错误
|
|||
|
|
|
|||
|
|
## 🔍 验证方法
|
|||
|
|
|
|||
|
|
### 查看控制台日志
|
|||
|
|
|
|||
|
|
**正确的日志:**
|
|||
|
|
```
|
|||
|
|
开始加载反馈列表,parentId: 1
|
|||
|
|
请求参数: {studentId: 1, recordType: "daily", page: 1, size: 10}
|
|||
|
|
[Request] GET URL: http://localhost:8080/api/growth-record/parent/list?studentId=1&recordType=daily&page=1&size=10
|
|||
|
|
[Request] GET Params: {studentId: 1, recordType: "daily", page: 1, size: 10}
|
|||
|
|
接口返回: {code: 200, message: "success", data: {...}}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**错误的日志:**
|
|||
|
|
```
|
|||
|
|
[Request] GET URL: http://localhost:8080/api/growth-record/parent/list?params=%5Bobject%20Object%5D
|
|||
|
|
接口返回: {code: 500, message: "系统异常,请稍后重试", data: null}
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 查看后端日志
|
|||
|
|
|
|||
|
|
**正确的日志:**
|
|||
|
|
```
|
|||
|
|
=== 家长端获取成长记录列表 ===
|
|||
|
|
studentId: 1, recordType: daily, startDate: null, endDate: null
|
|||
|
|
查询成功,总记录数: 10
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**错误的日志:**
|
|||
|
|
```
|
|||
|
|
Required request parameter 'studentId' for method parameter type Long is not present
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
## ✅ 修复完成
|
|||
|
|
|
|||
|
|
- [x] 修复服务反馈列表页面参数传递
|
|||
|
|
- [x] 修复成长记录列表页面参数传递
|
|||
|
|
- [x] 添加调试日志
|
|||
|
|
- [x] 编写修复文档
|
|||
|
|
|
|||
|
|
## 📞 如有问题
|
|||
|
|
|
|||
|
|
如果修复后仍有问题,请检查:
|
|||
|
|
1. 前端是否重新编译
|
|||
|
|
2. 小程序是否刷新
|
|||
|
|
3. 控制台日志是否正确
|
|||
|
|
4. 后端服务是否正常运行
|
|||
|
|
|
|||
|
|
---
|
|||
|
|
|
|||
|
|
**修复日期:** 2026-01-23
|
|||
|
|
**修复人员:** Kiro AI Assistant
|
|||
|
|
**状态:** ✅ 已修复,待测试
|