science-info.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. this.load();
  25. },
  26. },
  27. properties: {
  28. id: { type: String, value: "" },
  29. },
  30. data: {
  31. title: "",
  32. },
  33. methods: {
  34. async load() {
  35. wx.showLoading({ title: "加载中" });
  36. try {
  37. const dataset = await getScienceMethod(this.data.id);
  38. this.setData({ dataset, title: dataset.name });
  39. } catch (error) {
  40. getTickleContext.call(this).showWarnMessage(error.errMsg);
  41. }
  42. wx.hideLoading();
  43. },
  44. },
  45. });