Ver Fonte

feat: 优化部分UI显示, 新增年龄段筛选

YuJing há 1 mês atrás
pai
commit
8021c14aa2

+ 2 - 2
commons/basic/src/main/ets/apis/YTRequest.ets

@@ -13,9 +13,9 @@ import { userInfo } from '../models/UserInfo';
 import { yTRouter } from '../utils/YTRouter';
 
 
-// export const baseURL: string = 'https://hm.ytpm.net/prod-activity'
+// export const baseURL: string = 'https://hm.ytpm.net/prod-babyfood'
 
-export const baseURL: string = 'http://192.168.1.160:48104'
+export const baseURL: string = 'https://hm.ytpm.net/prod-babyfood'
 
 export const instance = axios.create({
   baseURL,

+ 2 - 2
features/feature/src/main/ets/components/YTDiaLogBuild.ets

@@ -562,7 +562,7 @@ struct AddPlanComp{
           .fontWeight(500)
           .textAlign(TextAlign.Center)
           .fontColor(this.week == index ? Color.White : Color.Black)
-          .backgroundColor(this.week == index ? '#FF5F84' : '#F6F6F6')
+          .backgroundColor(this.week == index ? '#95C50A' : '#F6F6F6')
           .borderRadius(10)
           .padding({ left: 16, right: 16, top: 5, bottom: 5 })
           .onClick(() => { this.week = index })
@@ -579,7 +579,7 @@ struct AddPlanComp{
           .fontWeight(500)
           .textAlign(TextAlign.Center)
           .fontColor(this.meal == index ? Color.White : Color.Black)
-          .backgroundColor(this.meal == index ? '#FF5F84' : '#F6F6F6')
+          .backgroundColor(this.meal == index ? '#95C50A' : '#F6F6F6')
           .borderRadius(10)
           .padding({ left: 16, right: 16, top: 5, bottom: 5 })
           .onClick(() => { this.meal = index })

+ 3 - 4
features/feature/src/main/ets/pages/RecipeSearchPage.ets

@@ -1,7 +1,5 @@
-import { yTRouter } from 'basic'
-import { LengthMetrics } from '@kit.ArkUI'
+import { curves, LengthMetrics } from '@kit.ArkUI'
 import { RecipeSearchViewModel } from '../viewModel/RecipeSearchViewModel'
-import { Cuisine, Recipe } from '../model/Index'
 import { RecipeComp } from '../components/RecipeComp'
 
 
@@ -22,7 +20,7 @@ struct RecipeSearchPage{
             .width(20)
             .aspectRatio(1)
             .onClick(() => {
-              yTRouter.pop()
+              this.vm._onBackPress()
             })
 
           // 搜索框
@@ -114,6 +112,7 @@ struct RecipeSearchPage{
       .padding({ top: this.vm.safeTop, left: 24, right: 24 })
     }
     .hideTitleBar(true)
+    .onBackPressed(() => { return this.vm._onBackPress() })
   }
 
   // 搜索记录关键字

+ 2 - 1
features/feature/src/main/ets/utils/RouterUtils.ets

@@ -30,7 +30,8 @@ class RouterUtils{
    * @param back
    */
   router2RecipeSearchPage(back?: Callback<PopInfo>){
-    yTRouter.pushPathByName('RecipeSearchPage', null, back, true)
+
+    yTRouter.pushPathByName('RecipeSearchPage', null, back, false)
   }
 }
 

+ 2 - 2
features/feature/src/main/ets/view/MainView.ets

@@ -249,7 +249,7 @@ export struct MainView {
     Menu() {
       ForEach(this.vm.babyList, (item: BabyInfo, index: number) => {
         MenuItem({ content: item.name ?? '无' })
-          .onClick(() => { this.vm.updateBabyInfo(index) })
+          .onClick(() => { this.vm.updateBabyInfo(index, true) })
       }, (item: BabyInfo) => item?.id + '')
 
       MenuItem({ content: '添加宝宝' })
@@ -404,7 +404,7 @@ struct RecipeWidget{
             }
             .justifyContent(FlexAlign.End)
             .width(110)
-            .bindMenu(this._MenuWidget, { hapticFeedbackMode: HapticFeedbackMode.ENABLED })
+            .bindMenu(this.vm.dishList ? this._MenuWidget :  null, { hapticFeedbackMode: HapticFeedbackMode.ENABLED })
             .onClick(() => { this.openMenu(item.text!) })
           }
           .width('100%')

+ 18 - 2
features/feature/src/main/ets/view/SecondView.ets

@@ -26,7 +26,7 @@ export struct SecondView {
           }
 
           Row({space: 5}){
-            Text('全部年龄')
+            Text(this.vm.ageRange[this.vm.monthRange])
               .fontSize(12)
               .fontWeight(500)
               .fontColor('#95C50A')
@@ -39,6 +39,7 @@ export struct SecondView {
           .borderRadius(8)
           .backgroundColor('#EFF4E1')
           .padding({ left: 14, right: 14, top: 8, bottom: 8 })
+          .bindMenu(this.ageFilterWidget, { hapticFeedbackMode: HapticFeedbackMode.ENABLED })
         }
         .width("100%")
         .justifyContent(FlexAlign.SpaceBetween)
@@ -78,5 +79,20 @@ export struct SecondView {
     }
   }
 
-
+  // 年龄筛选
+  @Builder
+  ageFilterWidget() {
+    Column(){
+      ForEach(this.vm.ageRange, (item: string, index) => {
+        Text(item)
+          .borderRadius(8)
+          .padding({left: 14, right: 14, top: 8, bottom: 8})
+          .backgroundColor(this.vm.monthRange == index ? '#EFF4E1' : '#FFFFFF')
+          .fontColor(this.vm.monthRange == index ? '#95C50A' : '#000000')
+          .onClick(() => { this.vm.updateMonthRange(index) })
+      })
+    }
+    .alignItems(HorizontalAlign.Center)
+    .padding({left: 5, right: 5, top: 3, bottom: 3})
+  }
 }

+ 7 - 4
features/feature/src/main/ets/viewModel/MainViewModel.ets

@@ -7,6 +7,7 @@ import {
   BabyInfo, Cuisine, DayPlan, PurchaseList, WeeklyPlan, WeeklyPlanPurchaseList } from "../model/Index"
 import { emitter } from "@kit.BasicServicesKit"
 import { EventConstant } from "../model/Constant"
+import { faceDetector } from "@kit.CoreVisionKit"
 
 @ObservedV2
 export class MainViewModel{
@@ -68,10 +69,10 @@ export class MainViewModel{
   }
 
   // 修改选中的宝宝信息
-  async updateBabyInfo(index: number) {
-    if(index == this.selectedBabyIndex) return
-
-    this.clearDataSource()
+  async updateBabyInfo(index: number, isClick: boolean = false) {
+    if(index == this.selectedBabyIndex && isClick) return
+    if(index != this.selectedBabyIndex)
+      this.clearDataSource()
 
     BabyInfo.override(this.babyInfo, this.babyList[index])
     this.selectedBabyIndex = index
@@ -170,6 +171,7 @@ export class MainViewModel{
         this.planList = this.allPlan.weeklyPlan
         this.planList!.id = this.allPlan.id
       } catch (e){
+        this.planList = {}
         console.log(`e = ${JSON.stringify(e)}`)
       }
   }
@@ -199,6 +201,7 @@ export class MainViewModel{
     try {
       this.purchaseList = await BabyFoodApi.getWeeklyPurchaseList(this.babyInfo.id!)
     } catch (e) {
+      this.purchaseList = []
       console.log(`e = ${JSON.stringify(e)}`)
     }
   }

+ 6 - 2
features/feature/src/main/ets/viewModel/RecipeSearchViewModel.ets

@@ -1,9 +1,8 @@
 import { IBestToast, userInfo, UserInfo, YTAvoid, yTRouter } from "basic"
-import { AppStorageV2, PersistenceV2 } from "@kit.ArkUI"
+import { AppStorageV2, curves, PersistenceV2 } from "@kit.ArkUI"
 import { RecipSearch } from "../model/Persistence"
 import { Cuisine, Recipe } from "../model/Index"
 import { BabyFoodApi } from "../Apis/BabyFoodApi"
-import { DiaLogPageEnum, DiaLogParam, YTDiaLogModel } from "basic/src/main/ets/models/YTDiaLogModel"
 
 @ObservedV2
 export class RecipeSearchViewModel{
@@ -53,4 +52,9 @@ export class RecipeSearchViewModel{
     this.keyWord = ''
     this.searchList = []
   }
+
+  _onBackPress(){
+    yTRouter.pop('')
+    return true
+  }
 }

+ 13 - 3
features/feature/src/main/ets/viewModel/SecondViewModel.ets

@@ -3,19 +3,23 @@ import { DiaLogPageEnum, DiaLogParam, YTDiaLogModel } from "basic/src/main/ets/m
 import { BabyFoodApi } from "../Apis/BabyFoodApi"
 import { Recipe } from "../model/Index"
 import { routerUtils } from "../utils/RouterUtils"
-import { AppStorageV2 } from "@kit.ArkUI"
+import { AppStorageV2, curves } from "@kit.ArkUI"
 
 @ObservedV2
 export class SecondViewModel{
   safeTop: number = 0
   // 选择的年龄段
-  @Trace monthRange: string = ''
+  @Trace monthRange: number = 3
   // 搜索关键字
   @Trace keyword: string = ''
   @Trace recipe: Recipe[] = []
   // 用户信息
   @Trace userInfo: UserInfo = AppStorageV2.connect<UserInfo>(UserInfo, 'UserInfo', () => userInfo)!
 
+  // 年龄分段
+  ageRange: string[] = ['6个月', '8个月', '12个月', '全部年龄']
+  valueRange: string[] = ['6', '8', '12', '']
+
   constructor() {
     this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
     this.getRecipeList()
@@ -26,10 +30,16 @@ export class SecondViewModel{
     routerUtils.router2RecipeSearchPage()
   }
 
+  // 修改年龄段
+  updateMonthRange(index: number){
+    this.monthRange = index
+    this.getRecipeList()
+  }
+
   // 获取食谱列表
   async getRecipeList(){
     if(this.userInfo.checkLogin())
-    this.recipe = await BabyFoodApi.getAllRecipes(this.keyword, this.monthRange)
+    this.recipe = await BabyFoodApi.getAllRecipes(this.keyword, this.valueRange[this.monthRange])
   }