help.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import common from '../../utils/util';
  2. import main from '../../utils/main';
  3. const app = getApp();
  4. Page({
  5. data: {
  6. scrollTop: 0,
  7. showReturnBtn: false, // 控制返回顶部按钮的显示/隐藏
  8. },
  9. onLoad: function (options) {
  10. let that = this;
  11. //debugger;
  12. let arr=[];
  13. for(let i=0;i<42;i++){
  14. let id=i.toString();
  15. if (i<10)
  16. id="0"+id;
  17. let obj={};
  18. obj.ID=id;
  19. arr.push(obj);
  20. }
  21. that.setData({
  22. Containnerheight: main.getWindowHeight(),
  23. List:arr,
  24. });
  25. main.checkGenerating();
  26. if (options.ID){
  27. setTimeout(function(){
  28. that.handleImageTap({currentTarget:{dataset:{id:options.ID}}});
  29. },1000);
  30. }
  31. },
  32. // 处理图片点击事件,实现锚点功能
  33. handleImageTap: function(e) {
  34. const id = e.currentTarget.dataset.id;
  35. let targetId="",offsetY=0;
  36. switch(id) {
  37. case "02":
  38. targetId = "img10";
  39. offsetY=50;
  40. break;
  41. case "03":
  42. targetId = "img14";
  43. offsetY=190;
  44. break;
  45. case "04":
  46. targetId = "img21";
  47. offsetY=-20;
  48. break;
  49. case "05":
  50. targetId = "img26";
  51. offsetY=130;
  52. break;
  53. case "06":
  54. targetId = "img29";
  55. offsetY=210;
  56. break;
  57. case "07":
  58. targetId = "img32";
  59. offsetY=50;
  60. break;
  61. case "08":
  62. targetId = "img35";
  63. offsetY=100;
  64. break;
  65. case "09":
  66. targetId = "img38";
  67. offsetY=200;
  68. break;
  69. default:
  70. targetId = "";
  71. offsetY=0;
  72. break;
  73. }
  74. // 使用微信小程序的API滚动到目标元素
  75. wx.createSelectorQuery()
  76. .select('#' + targetId)
  77. .boundingClientRect(function(rect){
  78. if(rect){
  79. wx.pageScrollTo({
  80. scrollTop: rect.top+offsetY,
  81. duration: 300
  82. });
  83. }
  84. })
  85. .exec();
  86. },
  87. returnTop:function(){
  88. wx.pageScrollTo({
  89. scrollTop: 0,
  90. duration: 300
  91. });
  92. },
  93. // 监听页面滚动
  94. onPageScroll: function(e) {
  95. // 获取当前的scrollTop
  96. const scrollTop = e.scrollTop;
  97. // 更新scrollTop数据
  98. this.setData({
  99. scrollTop: scrollTop
  100. });
  101. // 当滚动距离超过一屏(这里以屏幕高度的一半为例)时显示返回顶部按钮
  102. // 获取系统信息来确定屏幕高度
  103. const screenHeight = wx.getSystemInfoSync().windowHeight;
  104. const threshold = screenHeight / 2; // 设置阈值为屏幕高度的一半
  105. // 根据scrollTop决定是否显示返回按钮
  106. if (scrollTop > threshold && !this.data.showReturnBtn) {
  107. this.setData({
  108. showReturnBtn: true
  109. });
  110. } else if (scrollTop <= threshold && this.data.showReturnBtn) {
  111. this.setData({
  112. showReturnBtn: false
  113. });
  114. }
  115. },
  116. onShareAppMessage: function () {
  117. return {
  118. title: app.globalData.ShareTitle,
  119. path: app.globalData.SharePath + '?UserID=' + app.globalData.userInfo.UserID,
  120. imageUrl: app.globalData.ShareImage,
  121. }
  122. },
  123. })