science-info.ts 1.6 KB

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