science-info.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. 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. dataset.briefImg = getFullImageUrl(dataset.briefImg);
  44. this.setData({ dataset, title: dataset.name });
  45. } catch (error) {
  46. getTickleContext.call(this).showWarnMessage(error.errMsg);
  47. }
  48. wx.hideLoading();
  49. },
  50. },
  51. });