From fd1520952c180dc15ec28319dae93ed666c8943e Mon Sep 17 00:00:00 2001
From: litian <C21AF165>
Date: 星期一, 15 四月 2024 16:14:49 +0800
Subject: [PATCH] ios

---
 packageDomain/pages/sampleBookList/applicationForm/index.js |   69 ++++++++++++++++++++++++++++++++++
 1 files changed, 69 insertions(+), 0 deletions(-)

diff --git a/packageDomain/pages/sampleBookList/applicationForm/index.js b/packageDomain/pages/sampleBookList/applicationForm/index.js
index baf669e..e4cd26a 100644
--- a/packageDomain/pages/sampleBookList/applicationForm/index.js
+++ b/packageDomain/pages/sampleBookList/applicationForm/index.js
@@ -24,6 +24,8 @@
     ebookCount: 0,
     paperBookCount: 0,
     bookList: [],
+    isIos: wx.getSystemInfoSync().platform === 'ios',
+    keyboardHeight: 0
   },
 
   /**
@@ -324,6 +326,73 @@
     })
   },
 
+  // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈�
+  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) => {
+          // 鍙娇鐢ㄧ獥鍙i珮搴�
+          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) {}
+    }
+  },
   /**
    * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔
    */

--
Gitblit v1.9.1