4.8 KiB
4.8 KiB
本月收益显示为0排查步骤
日期: 2026-01-31
问题: 服务商首页的"本月收益"显示¥0,但代码已经修改
排查步骤
步骤1: 确认文件路径
实际使用的文件:
peidu/uniapp/pages/index/components/ServiceProviderHome.vue
不是:
peidu/uniapp/src/pages/index/components/ServiceProviderHome.vue
步骤2: 确认代码修改
检查 loadMonthEarnings() 方法:
async loadMonthEarnings() {
try {
console.log('开始加载本月收益...')
const res = await request({
url: '/api/provider/earnings/stats',
method: 'GET',
params: { type: 'month' } // ✅ 使用 month 参数
})
console.log('本月收益响应:', res)
if (res.code === 200 && res.data) {
this.monthEarnings = {
total: Number(res.data.earnings) || 0, // ✅ 使用 earnings 字段
settled: 0,
pending: 0,
withdrawable: 0
}
console.log('✓ 本月收益已更新:', this.monthEarnings)
}
} catch (error) {
console.error('加载本月收益失败:', error)
this.monthEarnings = { total: 0, settled: 0, pending: 0, withdrawable: 0 }
}
}
步骤3: 清除缓存并重新编译
方法1: 微信开发者工具
-
清除缓存
- 点击顶部菜单 "工具" → "清除缓存"
- 勾选 "清除数据缓存"
- 勾选 "清除文件缓存"
- 勾选 "清除网络缓存"
- 点击 "确定"
-
重新编译
- 点击顶部的 "编译" 按钮
- 等待编译完成(查看控制台输出)
-
强制刷新
- 编译完成后,点击 "编译" 按钮旁边的下拉箭头
- 选择 "清除缓存并重新编译"
方法2: 删除编译产物
-
关闭微信开发者工具
-
删除编译缓存目录
# 删除 node_modules/.cache 目录
cd peidu/uniapp
rmdir /s /q node_modules\.cache
# 删除 unpackage 目录
rmdir /s /q unpackage
- 重新打开项目并编译
步骤4: 检查控制台日志
打开微信开发者工具的控制台(Console标签),查找以下日志:
开始加载本月收益...
本月收益响应: {code: 200, data: {earnings: 222, ...}}
✓ 本月收益已更新: {total: 222, settled: 0, pending: 0, withdrawable: 0}
如果看到这些日志:
- ✅ 代码正常执行
- ✅ API返回了数据
- ✅ monthEarnings 已更新
如果没有看到日志:
- ❌ 可能还在使用旧的编译文件
- ❌ 需要强制清除缓存
步骤5: 检查API响应
在控制台的 Network 标签中,查找以下请求:
Request URL: /api/provider/earnings/stats?type=month
Response: {
"code": 200,
"data": {
"earnings": 222,
"courseCount": 1,
"studentCount": 1,
"duration": 1
}
}
如果API返回正确:
- ✅ 后端工作正常
- 问题在前端缓存
如果API返回错误:
- ❌ 需要检查后端服务
- ❌ 需要重启后端
步骤6: 检查数据绑定
在控制台输入以下命令,查看数据:
// 查看 monthEarnings 数据
console.log(this.monthEarnings)
预期输出:
{
total: 222,
settled: 0,
pending: 0,
withdrawable: 0
}
常见问题
Q1: 清除缓存后还是显示¥0
解决方案:
- 完全关闭微信开发者工具
- 删除项目的
unpackage目录 - 重新打开项目
- 重新编译
Q2: 控制台没有看到日志
可能原因:
- 日志级别设置太高
- 代码没有保存
- 编译失败
解决方案:
- 检查控制台的日志级别设置
- 确认文件已保存(Ctrl+S)
- 查看编译错误信息
Q3: API返回数据但页面不更新
可能原因:
- 数据绑定问题
- Vue响应式失效
解决方案:
- 使用
this.$set()更新数据 - 使用
this.$forceUpdate()强制更新
终极解决方案
如果以上步骤都不行,执行以下操作:
1. 完全清理项目
cd peidu/uniapp
# 删除所有缓存
rmdir /s /q node_modules\.cache
rmdir /s /q unpackage
rmdir /s /q .hbuilderx
# 重新安装依赖(如果需要)
# npm install
2. 重启开发工具
- 完全关闭微信开发者工具
- 重新打开
- 重新导入项目
- 重新编译
3. 检查文件是否真的修改了
打开文件 peidu/uniapp/pages/index/components/ServiceProviderHome.vue,搜索 loadMonthEarnings,确认代码是:
params: { type: 'month' } // ✅ 必须是 month
和
total: Number(res.data.earnings) || 0 // ✅ 必须是 earnings
验证成功的标志
- 控制台日志:
开始加载本月收益...
本月收益响应: {code: 200, data: {earnings: 222, ...}}
✓ 本月收益已更新: {total: 222, ...}
- 页面显示:
本月收益: ¥222
- 与收益统计一致:
- 服务商首页: 本月收益 ¥222
- 收益查看 → 收益统计 → 本月: 总收益 ¥222