123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- import { Component, OnInit } from '@angular/core';
- import { Router } from '@angular/router'; // 导入 Router 服务
- import { CloudFPlan } from 'src/lib/cloudspplan'; // 引入 CloudFPlan 类
- @Component({
- selector: 'app-page-plan',
- templateUrl: './page-plan.component.html',
- styleUrls: ['./page-plan.component.scss'],
- standalone: true, // 如果你使用的是独立组件模式
- })
- export class PagePlanComponent implements OnInit {
- plan: string = ''; // 用于存储 Plan 字段的内容
- cloudFPlan: any;
- constructor(private router: Router) { } // 注入 Router
- ngOnInit() {
- this.loadPlanData(); // 页面初始化时加载计划数据
- }
- // 获取当前登录用户的 FPlan 数据
- async loadPlanData() {
- try {
- const cloudFPlan = new CloudFPlan(); // 创建 CloudFPlan 实例
- const fPlan = await cloudFPlan.getCurrentUserFPlan(); // 获取当前用户的 FPlan 数据
- console.log('User Data:', fPlan);
-
- if (fPlan) {
- // 获取 Plan 字段的内容
- this.plan = fPlan.data['data']['Plan'] || ''; // 如果 Plan 字段为空,赋值为 ''。
- console.log('plan1', this.plan);
- }
- console.log('plan2', this.plan);
- } catch (error) {
- console.error('加载计划数据失败', error);
- this.plan = '加载计划数据失败,请稍后再试。'; // 加载失败时的提示信息
- }
- }
- // 退出按钮点击时的处理方法
- exitPlan() {
- console.log('退出运动计划');
- // 执行退出逻辑,例如跳转到首页
- this.router.navigate(['/home']); // 假设跳转到首页路径为 /home
- }
- }
|