science-info.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. console.log(this.data, "this.data===获取宣教传来的参数111");
  12. const channel = this.getOpenerEventChannel();
  13. channel.on?.("load", (data: AnyObject) => {
  14. console.log(data, "data===获取宣教传来的参数");
  15. // 支持直接传入外链 URL,直接使用 web-view 打开 新加的
  16. if (data?.url) {
  17. this.setData({
  18. dataset: { content: data.url },
  19. title: data?.title ?? "",
  20. });
  21. return;
  22. }
  23. // ===end===
  24. this.setData({ title: data?.title ?? "" });
  25. });
  26. if (this.data.id) {
  27. this.load();
  28. }
  29. // this.load();
  30. },
  31. },
  32. properties: {
  33. id: { type: String, value: "" },
  34. },
  35. data: {
  36. title: "",
  37. },
  38. methods: {
  39. async load() {
  40. wx.showLoading({ title: "加载中" });
  41. try {
  42. const dataset = await getScienceMethod(this.data.id);
  43. this.setData({ dataset, title: dataset.name });
  44. } catch (error) {
  45. getTickleContext.call(this).showWarnMessage(error.errMsg);
  46. }
  47. wx.hideLoading();
  48. },
  49. },
  50. });