12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- const app = getApp<IAppOption>()
- Component({
-
- data: {
- popShow: false,
- btnShow: true,
- maxTop: 0,
- top: 0,
- startY: 0,
- windowWidth: 0,
- windowHeight: 0,
- elementHeight: 60
- },
- lifetimes: {
- attached() {
-
- const systemInfo = wx.getWindowInfo();
- const isAndroid = systemInfo.platform === 'android'
-
- const barHeight = !isAndroid ? 44 : 48;
- const globalTop = app.globalData.top
- this.setData({
- maxTop: barHeight + systemInfo.safeArea.top,
- windowWidth: systemInfo.windowWidth,
- windowHeight: systemInfo.windowHeight,
- top: globalTop
- });
- }
- },
-
- methods: {
- onClose() {
-
- this.setData({
- popShow: false
- })
- },
- onOpen() {
-
- },
- onShow() {
- this.setData({
- popShow: true
- })
- },
- onTouchStart(e: any) {
-
- this.setData({
- startY: e.touches[0].clientY
- });
- },
-
- onTouchMove(e: any) {
-
- const deltaY = e.touches[0].clientY - this.data.startY;
-
-
- app.globalData.top = this.data.top + deltaY
- this.setData({
- top: this.data.top + deltaY,
- startY: e.touches[0].clientY
- });
- },
-
- onTouchEnd() {
- const { top, windowHeight, elementHeight } = this.data;
-
- const distanceTop = top;
- const moveHeight = top + elementHeight
-
- if (distanceTop < this.data.maxTop) {
- this.setData({ top: this.data.maxTop }, () => {
- app.globalData.top = this.data.maxTop
- });
- } else if(moveHeight >= windowHeight) {
- this.setData({ top: windowHeight - elementHeight }, () => {
- app.globalData.top = windowHeight - elementHeight
- })
- } else {
- this.setData({ top }, () => {
- app.globalData.top = top
- })
- }
- }
- }
- })
|