|
@@ -1,35 +1,30 @@
|
|
|
// components/service/service.ts
|
|
|
+// 获取应用实例
|
|
|
+const app = getApp<IAppOption>()
|
|
|
Component({
|
|
|
/**
|
|
|
- * 组件的属性列表
|
|
|
- */
|
|
|
- // properties: {
|
|
|
- // popShow: {
|
|
|
- // type: Boolean,
|
|
|
- // default: false
|
|
|
- // }
|
|
|
- // },
|
|
|
-
|
|
|
- /**
|
|
|
* 组件的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
popShow: false,
|
|
|
+ btnShow: true,
|
|
|
top: 0, // 初始的上偏移
|
|
|
- startX: 0, // 触摸起始点 X 坐标
|
|
|
startY: 0, // 触摸起始点 Y 坐标
|
|
|
windowWidth: 0, // 屏幕宽度
|
|
|
windowHeight: 0, // 屏幕高度
|
|
|
elementHeight: 60 // 元素高度
|
|
|
},
|
|
|
- attached() {
|
|
|
- // 获取屏幕宽高
|
|
|
- const systemInfo = wx.getWindowInfo();
|
|
|
- this.setData({
|
|
|
- windowWidth: systemInfo.windowWidth,
|
|
|
- windowHeight: systemInfo.windowHeight,
|
|
|
- top: systemInfo.windowHeight - 180
|
|
|
- });
|
|
|
+ lifetimes: {
|
|
|
+ attached() {
|
|
|
+ // 获取屏幕宽高
|
|
|
+ const systemInfo = wx.getWindowInfo();
|
|
|
+ const globalTop = app.globalData.top
|
|
|
+ this.setData({
|
|
|
+ windowWidth: systemInfo.windowWidth,
|
|
|
+ windowHeight: systemInfo.windowHeight,
|
|
|
+ top: globalTop
|
|
|
+ });
|
|
|
+ }
|
|
|
},
|
|
|
/**
|
|
|
* 组件的方法列表
|
|
@@ -61,6 +56,7 @@ Component({
|
|
|
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
|
|
@@ -75,11 +71,17 @@ Component({
|
|
|
const moveHeight = top + elementHeight
|
|
|
// 判断元素与顶部和底部的距离,选择最近的边界
|
|
|
if (distanceTop < 0) {
|
|
|
- this.setData({ top: 0 }); // 吸附到顶部
|
|
|
+ this.setData({ top: 0 }, () => {
|
|
|
+ app.globalData.top = 0
|
|
|
+ }); // 吸附到顶部
|
|
|
} else if(moveHeight >= windowHeight) {
|
|
|
- this.setData({ top: windowHeight - elementHeight })
|
|
|
+ this.setData({ top: windowHeight - elementHeight }, () => {
|
|
|
+ app.globalData.top = windowHeight - elementHeight
|
|
|
+ })
|
|
|
} else {
|
|
|
- this.setData({ top })
|
|
|
+ this.setData({ top }, () => {
|
|
|
+ app.globalData.top = top
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|