ios
litian
2024-04-15 fd1520952c180dc15ec28319dae93ed666c8943e
packageDomain/pages/teacherCertification/index.js
@@ -46,6 +46,8 @@
    reasonTxt: "",
    reasonTxtShow: false,
    skeletonLoding: true,
    isIos: wx.getSystemInfoSync().platform === 'ios',
    keyboardHeight: 0
  },
  /**
@@ -681,7 +683,73 @@
      this.getUserRole()
    }
  },
  // 监听页面软键盘弹起手动推动页面
  bindkeyboardheightchange(e) {
    // 只对ios 处理
    if (!this.data.isIos === 'ios') {
      return
    }
    // 键盘高度
    const height = e.detail.height;
    const className = e.target.dataset.class;
    if (height === 0) {
      this.scrollToInput(0);
      return;
    }
    try {
      this.createSelectorQuery()
        .select(`.${className}`)
        .boundingClientRect((res) => {
          // 可使用窗口高度
          const windowHeight = wx.getSystemInfoSync().windowHeight;
          // 除去键盘的剩余高度
          let restHeight = windowHeight - height;
          // 元素左下角坐标
          let bottom = res.bottom;
          // 只有当元素被软键盘覆盖的时候才上推页面
          if (bottom <= restHeight) return;
          // 现阶段需要滚动的大小
          let scrollTop = bottom - restHeight;
          this.scrollToInput(height, scrollTop);
        })
        .exec();
    } catch (error) {}
  },
  // 获取页面滚动条位置
  getScrollOffset() {
    return new Promise((resolve) => {
      try {
        wx.createSelectorQuery()
          .selectViewport()
          .scrollOffset((res) => {
            resolve(res.scrollTop);
          })
          .exec();
      } catch (error) {
        resolve(0);
      }
    });
  },
  // 监听页面软键盘弹起手动推动页面
  scrollToInput(keyboardHeight, scrollTop) {
    this.setData({
      keyboardHeight,
    });
    if (scrollTop) {
      try {
        this.getScrollOffset().then((lastScrollTop) => {
          wx.pageScrollTo({
            // 如果已经存在滚动,在此基础上继续滚
            scrollTop: lastScrollTop ? lastScrollTop + scrollTop : scrollTop,
            duration: 300,
          });
        });
      } catch (error) {}
    }
  },
  /**
   * 页面上拉触底事件的处理函数
   */