闫增涛
2025-03-31 04c7b0163caeae4ab1c5da62e301fa993101cfad
packageDomain/pages/teacherCertification/index.js
@@ -46,6 +46,8 @@
    reasonTxt: "",
    reasonTxtShow: false,
    skeletonLoding: true,
    isIos: wx.getSystemInfoSync().platform === 'ios',
    keyboardHeight: 0
  },
  /**
@@ -55,17 +57,7 @@
    //获取职称
    this.getpositionalTitle();
    this.getAgreement();
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          this.getUserRole()
        }
      })
    } else {
      this.getUserRole()
    }
  },
  /**
@@ -79,6 +71,21 @@
   * 生命周期函数--监听页面显示
   */
  onShow() {
    // 检查登录状态
    const token = wx.getStorageSync(app.config.tokenKey)
    if (!token) {
      loginInfo(app, (data) => {
        if (data) {
          this.getUserRole()
        } else {
          wx.switchTab({
            url: '/pages/home/home',
          })
        }
      })
    } else {
      this.getUserRole()
    }
  },
@@ -140,8 +147,9 @@
      })
      this.newGetTeacherInfo()
    })
  },
  //获取教师状态
  newGetTeacherInfo() {
    let that = this;
@@ -572,6 +580,14 @@
      })
      return
    }
    if (!that.data.teacherInfo.detailedAddress) {
      wx.showToast({
        title: "请填写详细地址!",
        icon: 'none',
        duration: 1000,
      })
      return
    }
    if (that.data.imgPics.length == 0) {
      wx.showToast({
        title: "请上传工作证!",
@@ -681,7 +697,75 @@
      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) {}
    }
  },
  changeParam(e) {
    this.scrollToInput(0);
  },
  /**
   * 页面上拉触底事件的处理函数
   */