indexHead.js 2.3 KB

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