|
@@ -11,11 +11,16 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
+ maxTop: 0,
|
|
|
+ top: 0, // 初始的上偏移
|
|
|
+ startY: 0, // 触摸起始点 Y 坐标
|
|
|
+ windowHeight: 0, // 屏幕高度
|
|
|
+ elementHeight: 180, // 元素高度
|
|
|
goodsImgList: [
|
|
|
- "https://oss.dayaedu.com/ktyq/1739445414362.png",
|
|
|
- "https://oss.dayaedu.com/ktyq/1739445449067.png",
|
|
|
- "https://oss.dayaedu.com/ktyq/1739445464592.png",
|
|
|
- "https://oss.dayaedu.com/ktyq/1739445477533.png"
|
|
|
+ "https://oss.dayaedu.com/ktyq/1739518565519.png",
|
|
|
+ "https://oss.dayaedu.com/ktyq/1739518602666.png",
|
|
|
+ "https://oss.dayaedu.com/ktyq/1739518623253.png",
|
|
|
+ "https://oss.dayaedu.com/ktyq/1739518638007.png"
|
|
|
],
|
|
|
serviceShow: true,
|
|
|
popupShow: false,
|
|
@@ -224,6 +229,7 @@ Page({
|
|
|
* 生命周期函数--监听页面显示
|
|
|
*/
|
|
|
onShow() {
|
|
|
+ this.initPosInfo()
|
|
|
if (!this.data.isFromPreviewImage && !this.data.popupShow) {
|
|
|
this.onInit()
|
|
|
this.setData({
|
|
@@ -243,6 +249,56 @@ Page({
|
|
|
serviceShow: false
|
|
|
})
|
|
|
},
|
|
|
+ // 初始化位置信息
|
|
|
+ initPosInfo() {
|
|
|
+ // 获取屏幕宽高
|
|
|
+ const systemInfo = wx.getWindowInfo();
|
|
|
+ const isAndroid = systemInfo.platform === 'android'
|
|
|
+ // const isDevtools = systemInfo.platform === 'devtools'
|
|
|
+ const barHeight = !isAndroid ? 44 : 48;
|
|
|
+ const globalTop = app.globalData.sectionBoxTop
|
|
|
+ this.setData({
|
|
|
+ maxTop: barHeight + systemInfo.safeArea.top,
|
|
|
+ windowHeight: systemInfo.windowHeight,
|
|
|
+ top: globalTop
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onTouchStart(e: any) {
|
|
|
+ // 记录触摸起始点的 Y 坐标
|
|
|
+ this.setData({
|
|
|
+ startY: e.touches[0].clientY
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onTouchMove(e: any) {
|
|
|
+ // 计算上下方向的偏移量
|
|
|
+ const deltaY = e.touches[0].clientY - this.data.startY;
|
|
|
+ // 更新元素的垂直位置
|
|
|
+ app.globalData.sectionBoxTop = 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.sectionBoxTop = this.data.maxTop
|
|
|
+ }); // 吸附到顶部
|
|
|
+ } else if (moveHeight >= windowHeight) {
|
|
|
+ this.setData({ top: windowHeight - elementHeight }, () => {
|
|
|
+ app.globalData.sectionBoxTop = windowHeight - elementHeight
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.setData({ top }, () => {
|
|
|
+ app.globalData.sectionBoxTop = top
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
onScroll(e: { detail: any }) {
|
|
|
// console.log(e, 'any')
|
|
|
const scrollTop = e.detail.scrollTop || 0
|