SecondViewModel.ets 940 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { YTAvoid, yTRouter } from "basic"
  2. import { DiaLogPageEnum, DiaLogParam, YTDiaLogModel } from "basic/src/main/ets/models/YTDiaLogModel"
  3. import { BabyFoodApi } from "../Apis/BabyFoodApi"
  4. import { Recipe } from "../model/Index"
  5. import { routerUtils } from "../utils/RouterUtils"
  6. @ObservedV2
  7. export class SecondViewModel{
  8. safeTop: number = 0
  9. // 选择的年龄段
  10. @Trace monthRange: string = ''
  11. // 搜索关键字
  12. @Trace keyword: string = ''
  13. @Trace recipe: Recipe[] = []
  14. constructor() {
  15. this.safeTop = AppStorage.get(YTAvoid.SAFE_TOP_KEY) as number
  16. this.getRecipeList()
  17. }
  18. // 去搜索页
  19. goToSearchPage(){
  20. routerUtils.router2RecipeSearchPage()
  21. }
  22. // 获取食谱列表
  23. async getRecipeList(){
  24. this.recipe = await BabyFoodApi.getAllRecipes(this.keyword, this.monthRange)
  25. }
  26. /**
  27. * 重写的返回逻辑
  28. * @returns
  29. */
  30. _onBackPressed(){
  31. yTRouter.pop('')
  32. return true;
  33. }
  34. }