访问 http://localhost:4200/weight
时自动跳转到登录页面。
经过深入分析,发现以下问题:
问题:在 index.html
中通过CDN引入了ECharts,同时npm也安装了echarts包,导致模块加载冲突。
修复:
index.html
中的CDN引入在 app.config.ts
中正确配置ngx-echarts使用npm安装的echarts
// app.config.ts
importProvidersFrom(
NgxEchartsModule.forRoot({
echarts: () => import('echarts')
})
)
问题:NgxEchartsModule没有正确注册到应用配置中。
修复:在 app.config.ts
中添加了正确的provider配置。
如果页面仍然跳转到登录页,可能是因为:
Angular开发服务器需要重启才能加载新的配置更改。
解决方案:
# 停止当前服务器 (Ctrl+C)
# 重新启动
cd campus_health_app/frontend/campus-health-app
npm start
旧的JavaScript可能仍在缓存中。
解决方案:
或者:
如果weight模块加载失败,Angular会触发通配符路由重定向到login。
调试方法:
http://localhost:4200/weight
预期的控制台输出:
✅ WeightComponent initialized
📊 Starting data subscriptions
📝 Received weight records: 0
如果组件有编译错误,会导致模块无法加载。
检查方法:
cd campus_health_app/frontend/campus-health-app
npm run build
查看是否有ERROR输出。
# 在运行npm start的终端按 Ctrl+C 停止
# 然后重新启动
cd campus_health_app/frontend/campus-health-app
npm start
访问测试页面:
file:///D:/workspace/Agi/zrd-nb666/campus_health_app/frontend/campus-health-app/test-routes.html
点击"体重管理"链接,观察:
成功进入weight页面后:
http://localhost:4200/weight
不跳转在浏览器控制台输入:
// 查看当前路由状态
console.log(window.location);
// 查看localStorage中的数据
console.log(localStorage.getItem('weight_data'));
在控制台输入:
// 假设你在其他页面,尝试编程式导航
window.location.href = '/weight';
在Network面板中筛选:
成功修复后,访问 http://localhost:4200/weight
应该看到:
顶部导航栏:
统计卡片(3个):
主图表区域:
筛选栏:
其他图表:
底部:
原因:数据服务初始化失败 解决:确保WeightDataService正确注入
原因:ECharts模块加载失败 解决:
原因:路由配置错误 解决:检查weight.routes.ts导出是否正确
原因:CSS未加载或样式文件过大 解决:
如果问题仍然存在,请提供以下信息:
已修改的文件:
src/index.html
- 移除ECharts CDNsrc/app/app.config.ts
- 添加NgxEchartsModule配置src/app/modules/weight/weight.component.ts
- 添加调试日志src/app/modules/weight/weight.component.html
- 完整模板src/app/modules/weight/weight.component.scss
- 响应式样式src/app/modules/weight/models/weight.models.ts
- 数据模型src/app/services/weight-data.service.ts
- 数据服务2025-10-20