From eeaef4fa1a06616e41ae8013c95e99bb3895aac5 Mon Sep 17 00:00:00 2001 From: litian <C21AF165> Date: 星期三, 17 四月 2024 18:10:10 +0800 Subject: [PATCH] 1 --- packageDomain/pages/sampleBookList/applicationForm/index.js | 111 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 95 insertions(+), 16 deletions(-) diff --git a/packageDomain/pages/sampleBookList/applicationForm/index.js b/packageDomain/pages/sampleBookList/applicationForm/index.js index b1831f9..bcb4620 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 }, /** @@ -34,17 +36,21 @@ * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鏄剧ず */ onShow() { + let that = this; + that.setData({ + bookList: [] + }) if (wx.getStorageSync(app.config.userInfoKey)) { - this.setData({ + that.setData({ userInfo: JSON.parse(wx.getStorageSync(app.config.userInfoKey)) }) - if (this.data.userInfo.role == 'Teacher') { - this.setData({ - 'teacherInfo.schoolName': JSON.parse(this.data.userInfo.data).schoolName, - 'teacherInfo.courseName': JSON.parse(this.data.userInfo.data).courseName, - 'contactInfo.fullName': JSON.parse(this.data.userInfo.data).fullName, - 'contactInfo.phone': JSON.parse(this.data.userInfo.data).phone, - 'contactInfo.detailedAddress': JSON.parse(this.data.userInfo.data).detailedAddress, + if (that.data.userInfo.role == 'Teacher') { + that.setData({ + 'teacherInfo.schoolName': JSON.parse(that.data.userInfo.data).schoolName, + 'teacherInfo.courseName': JSON.parse(that.data.userInfo.data).courseName, + 'contactInfo.fullName': JSON.parse(that.data.userInfo.data).fullName, + 'contactInfo.phone': JSON.parse(that.data.userInfo.data).phone, + 'contactInfo.detailedAddress': JSON.parse(that.data.userInfo.data).detailedAddress, }) } else { wx.showModal({ @@ -55,24 +61,26 @@ wx.navigateTo({ url: "/packageDomain/pages/teacherCertification/index", }); + } else { + wx.navigateBack(); } } }) } if (wx.getStorageSync("paperBookList")) { - this.setData({ - paperBookList: wx.getStorageSync("paperBookList"), - bookList: wx.getStorageSync("paperBookList") + that.setData({ + paperBookList: JSON.parse(wx.getStorageSync("paperBookList")), + bookList: JSON.parse(wx.getStorageSync("paperBookList")) }) } if (wx.getStorageSync("electronicBookList")) { - this.setData({ - electronicBookList: wx.getStorageSync("electronicBookList") + that.setData({ + electronicBookList: JSON.parse(wx.getStorageSync("electronicBookList")) }) } - this.getSelectBookCount(); - this.getSelectPaperBookCount(); - this.getPaperType(); + that.getSelectBookCount(); + that.getSelectPaperBookCount(); + that.getPaperType(); } }, @@ -320,6 +328,77 @@ }) }, + // 鐩戝惉椤甸潰杞敭鐩樺脊璧锋墜鍔ㄦ帹鍔ㄩ〉闈� + bindkeyboardheightchange(e) { + // 鍙ios 澶勭悊 + if (!this.data.isIos === 'ios') { + return + } + // 閿洏楂樺害 + const height = e.detail.height; + const className = e.target.dataset.class; + console.log(height, className) + 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; + console.log(scrollTop, 1) + 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); + }, /** * 椤甸潰鐩稿叧浜嬩欢澶勭悊鍑芥暟--鐩戝惉鐢ㄦ埛涓嬫媺鍔ㄤ綔 */ -- Gitblit v1.9.1