science-info.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import PageContainerBehavior from "../../../../core/behavior/page-container.behavior";
  2. import tickleBehavior, {
  3. getTickleContext,
  4. } from "../../../../core/behavior/tickle.behavior";
  5. import { getScienceMethod } from "../../request";
  6. // module/diet/pages/science-info/science-info.ts
  7. Component({
  8. behaviors: [PageContainerBehavior, tickleBehavior],
  9. lifetimes: {
  10. attached() {
  11. const channel = this.getOpenerEventChannel();
  12. channel.on?.("load", (data: AnyObject) => {
  13. // 支持直接传入外链 URL,直接使用 web-view 打开 新加的
  14. if (data?.url) {
  15. this.setData({
  16. dataset: { content: data.url },
  17. title: data?.title ?? "",
  18. });
  19. return;
  20. }
  21. // ===end===
  22. this.setData({ title: data?.title ?? "" });
  23. });
  24. if (this.data.id) {
  25. this.load();
  26. }
  27. // this.load();
  28. },
  29. },
  30. properties: {
  31. id: { type: String, value: "" },
  32. },
  33. data: {
  34. title: "",
  35. },
  36. methods: {
  37. async load() {
  38. wx.showLoading({ title: "加载中" });
  39. try {
  40. const dataset = await getScienceMethod(this.data.id);
  41. this.setData({ dataset, title: dataset.name });
  42. } catch (error) {
  43. getTickleContext.call(this).showWarnMessage(error.errMsg);
  44. }
  45. wx.hideLoading();
  46. },
  47. },
  48. });