diet-info.ts 1003 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import tickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  3. import { getDietMethod } from "../../request";
  4. // module/diet/pages/diet-info/diet-info.ts
  5. Component({
  6. behaviors: [
  7. PageContainerBehavior,
  8. tickleBehavior,
  9. ],
  10. lifetimes: {
  11. attached() {
  12. const channel = this.getOpenerEventChannel();
  13. channel.on?.('load', (data: AnyObject) => {
  14. this.setData({ title: data?.name ?? '' });
  15. })
  16. this.load();
  17. }
  18. },
  19. properties: {
  20. id: { type: String, value: '' },
  21. },
  22. data: {
  23. title: ''
  24. },
  25. methods: {
  26. async load() {
  27. wx.showLoading({ title: '加载中' });
  28. try {
  29. const dataset = await getDietMethod(this.data.id);
  30. this.setData({ dataset, title: dataset.name });
  31. } catch (error) {
  32. getTickleContext.call(this).showWarnMessage(error.errMsg);
  33. }
  34. wx.hideLoading();
  35. },
  36. }
  37. })