Forráskód Böngészése

feat: 修改了数据请求的先后顺序

YuJing 1 hónapja
szülő
commit
518de384cd

+ 9 - 9
features/feature/src/main/ets/model/Index.ets

@@ -71,15 +71,15 @@ export class BabyInfo {
   }
   }
 
 
   // 覆盖赋值
   // 覆盖赋值
-  static override(info: BabyInfo ,newInfo: BabyInfo){
-    info.avatarUrl = newInfo.avatarUrl;
-    info.backgroundUrl = newInfo.backgroundUrl;
-    info.birthday = newInfo.birthday;
-    info.gender = newInfo.gender;
-    info.id = newInfo.id;
-    info.name = newInfo.name;
-    info.days = newInfo.days;
-    info.userId = newInfo.userId;
+  static override(info: BabyInfo ,newInfo?: BabyInfo){
+    info.avatarUrl = newInfo?.avatarUrl;
+    info.backgroundUrl = newInfo?.backgroundUrl;
+    info.birthday = newInfo?.birthday;
+    info.gender = newInfo?.gender;
+    info.id = newInfo?.id;
+    info.name = newInfo?.name;
+    info.days = newInfo?.days;
+    info.userId = newInfo?.userId;
   }
   }
 }
 }
 
 

+ 24 - 8
features/feature/src/main/ets/viewModel/MainViewModel.ets

@@ -38,14 +38,10 @@ export class MainViewModel{
 
 
     if(this.userInfo.checkLogin()){
     if(this.userInfo.checkLogin()){
       // 宝宝信息没有的话也没必要加载后续数据了
       // 宝宝信息没有的话也没必要加载后续数据了
-      this.getBabyList().then(async () => {
-        await this.getWeeklyPlan()
-        await this.getDishList()
-        await this.getWeeklyPurchaseList()
-        this.eventFunc.forEach(f => f())
-      })
+      await this.getBabyList()
+      await this.getDishList()
     } else {
     } else {
-      this.babyList = []
+      this.clearDataSource(true)
     }
     }
   }
   }
 
 
@@ -64,9 +60,15 @@ export class MainViewModel{
   }
   }
 
 
   // 修改选中的宝宝信息
   // 修改选中的宝宝信息
-  updateBabyInfo(index: number) {
+  async updateBabyInfo(index: number) {
+    this.clearDataSource()
+
     BabyInfo.override(this.babyInfo, this.babyList[index])
     BabyInfo.override(this.babyInfo, this.babyList[index])
     this.selectedBabyIndex = index
     this.selectedBabyIndex = index
+
+    await this.getWeeklyPlan()
+    await this.getWeeklyPurchaseList()
+    this.eventFunc.forEach(f => f())
   }
   }
 
 
   // 添加事件
   // 添加事件
@@ -81,6 +83,18 @@ export class MainViewModel{
     return this.dishList[index]
     return this.dishList[index]
   }
   }
 
 
+  // 清空数据源
+  clearDataSource(isLoginOut: boolean = false) {
+    this.allPlan = {}
+    this.planList = {}
+    this.purchaseList = []
+
+    if(isLoginOut){
+      BabyInfo.override(this.babyInfo)
+      this.babyList = []
+    }
+  }
+
   // 获取本周食谱计划
   // 获取本周食谱计划
   async getWeeklyPlan(startDate?: string){
   async getWeeklyPlan(startDate?: string){
       try {
       try {
@@ -96,6 +110,8 @@ export class MainViewModel{
   async updateWeeklyPlan(): Promise<boolean>{
   async updateWeeklyPlan(): Promise<boolean>{
     try {
     try {
       await BabyFoodApi.updateWeeklyPlan(this.planList!)
       await BabyFoodApi.updateWeeklyPlan(this.planList!)
+      // 修改食谱清单后需刷新采购清单
+      this.getWeeklyPurchaseList()
       return true
       return true
     } catch (e) {
     } catch (e) {
       return false
       return false