indexHead.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { prefixPagePath } from "../../../../core/utils";
  2. import { createSubscribe } from "applet-page-component";
  3. import { reportCmPV_YL } from "../../utils/cloudMonitorHelper";
  4. const app = getApp();
  5. const getRect = (id) =>
  6. new Promise((resolve) => {
  7. my.createSelectorQuery()
  8. .select(`#${id}`)
  9. .boundingClientRect()
  10. .exec(resolve);
  11. });
  12. const getExtInfo = (item) => {
  13. const { componentExtInfo } = item;
  14. return componentExtInfo;
  15. };
  16. Component(
  17. createSubscribe({
  18. // eslint-disable-next-line no-unused-vars
  19. async onPageScroll(_, { scrollTop }) {
  20. const { id, isScrollOver } = this.data;
  21. let contentHeight = 0;
  22. if (this.contentHeight) {
  23. // eslint-disable-next-line prefer-destructuring
  24. contentHeight = this.contentHeight;
  25. } else {
  26. const res = await getRect(id);
  27. const [rect] = res;
  28. const { height = 0 } = rect || {};
  29. contentHeight = height;
  30. }
  31. /* 这里动态设置标题栏 */
  32. // if (scrollTop > contentHeight) {
  33. // if (!isScrollOver) {
  34. // const { componentData } = this.props;
  35. // const { title } = getExtInfo(componentData);
  36. // my.setNavigationBar({
  37. // title,
  38. // });
  39. // this.setData({
  40. // isScrollOver: true,
  41. // });
  42. // }
  43. // } else if (isScrollOver) {
  44. // my.setNavigationBar({
  45. // title: " ",
  46. // });
  47. // this.setData({
  48. // isScrollOver: false,
  49. // });
  50. // } else {
  51. // my.setNavigationBar({
  52. // title: " ",
  53. // });
  54. // }
  55. },
  56. })({
  57. props: {
  58. componentData: {},
  59. },
  60. data: {
  61. navHeight: 72,
  62. /* 消息通知是否显示 */
  63. showMsg: true,
  64. isScrollOver: false,
  65. id: `index_heart_${Date.now()}`,
  66. imgSrcPrefix: app.globalData.imgSrcPrefix,
  67. },
  68. didMount() {},
  69. methods: {
  70. /**
  71. * 关闭消息通知
  72. */
  73. closeMsgBtn() {
  74. this.setData({
  75. showMsg: false,
  76. });
  77. },
  78. /**
  79. * 跳转到医院特色
  80. */
  81. goToDetail() {
  82. const pageCode = "hospital-characteristics";
  83. my.navigateTo({
  84. url: `${prefixPagePath}/one/index?pageCode=${pageCode}`,
  85. });
  86. /* 服务预警,医院介绍 */
  87. reportCmPV_YL({
  88. title: "医院介绍",
  89. });
  90. },
  91. /**
  92. * 获取头部初始头部初始padding-top
  93. */
  94. onCallback({ height }) {
  95. this.setData({
  96. navHeight: height,
  97. });
  98. },
  99. },
  100. })
  101. );