// pagesPublic/pages/tdcr/index.js const {imgUrl} = require('../api/request') Page({ /** * 页面的初始数据 */ data: { imgPath: imgUrl + 'tdcr/', cursorGuys: [{ left: 48, top: 1.5 }, { left: 20, top: 4 }], cursors: [{ txt: '弹子石组团\nB8-1、B8-3、B9', top: -12, left: 28, dropTop: 3.5, dropLeft: 12 }, { txt: '四公里\n棚户区地块', top: -16, left: 20, dropTop: 5, dropLeft: 5 }, { txt: '茶园组团\nC01-16/02、\nC01-17/02', top: -32, left: 61, dropTop: 4, dropLeft: 5 }], list: [{ icon: 'icon-quyu.png', txt: '区域中心 得天独厚', top: 0, left: 12 }, { icon: 'icon-house.png', txt: '南岸新区 宜居宜业', top: 1, left: 5 }, { icon: 'icon-ai.png', txt: '资源富集 优势明显', top: 1, left: 0 }, { icon: 'icon-car.png', txt: '立体交通 四通八达', top: 1, left: 12 }, { icon: 'icon-bod.png', txt: '产业坚实 人才汇聚', top: 1, left: 20 }], touchData: { flag: 0, lastX: 0, lastY: 0 }, animationData: {}, currentIndex: 0, isAnimating: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { wx.showTabBar({ fail: (e) => { console.log(e); } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { this.initAnimations(); setTimeout(() => { this.startAnimationLoop(); }, 500); }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { return { title: '2024年土地出让', imageUrl: imgUrl + '/tdcr/share.jpg' } }, handleTouchend() { let touchData = this.data.touchData touchData.flag = 0 //停止滑动 this.setData({ touchData }) }, handleTouchstart(event) { this.setData({ touchData: { flag: 0, lastX: event.changedTouches[0].pageX, lastY: event.changedTouches[0].pageY } }) }, handleTouchmove(event) { let touchData = this.data.touchData if (touchData.flag !== 0) { return; } let currentX = event.changedTouches[0].pageX; let currentY = event.changedTouches[0].pageY; let tx = currentX - touchData.lastX; let ty = currentY - touchData.lastY; //左右方向偏移大于上下偏移认为是左右滑动 if (Math.abs(tx) - Math.abs(ty) > 5) { // 向左滑动 if (tx < 0) { // 如果到最右侧 console.log('向左滑动'); touchData.flag = 1; wx.navigateTo({ url: './tdcr-list/index', }) } else if (tx > 0) { // 如果到最左侧 touchData.flag = 2; console.log('向右滑动'); } } //将当前坐标进行保存以进行下一次计算 touchData.lastX = currentX; touchData.lastY = currentY; this.setData({ touchData }) }, initAnimations: function() { const list = this.data.list; list.forEach((item, index) => { this.createAnimation(index); }); }, createAnimation: function(index) { const animation = wx.createAnimation({ duration: 1000, // 动画持续时间 timingFunction: 'ease', // 动画效果 }); this.setData({ ['animationData[' + index + ']']: animation.export(), }); }, startAnimationLoop: function() { const list = this.data.list; const currentIndex = this.data.currentIndex; if (currentIndex < list.length) { if (this.data.isAnimating) return; this.setData({ isAnimating: true }) // 获取当前索引的动画对象 const animation = wx.createAnimation({ duration: 1000, timingFunction: 'linear', }); // 放大动画 animation.scale(1.2, 1.2).step(); // 更新动画数据 this.setData({ ['animationData[' + currentIndex + ']']: animation.export(), isAnimating: this.data.isAnimating }); // 设置动画结束后回调 setTimeout(() => { // 恢复到原始大小 const restoreAnimation = wx.createAnimation({ duration: 1000, timingFunction: 'linear', }); restoreAnimation.scale(1, 1).step(); this.setData({ ['animationData[' + currentIndex + ']']: restoreAnimation.export(), isAnimating: false }); // 动画结束后,索引递增,如果到达列表末尾,则重置为0 this.setData({ currentIndex: (currentIndex + 1) % list.length, }); if ((currentIndex + 1) % list.length == 0 && currentIndex != 0) { setTimeout(() => { this.startAnimationLoop(); }, 2000); } else { this.startAnimationLoop(); } }, 1500); } }, })