// component/ad-dialog/ad-dialog.js Component({ properties: { // 广告图片 URL imageUrl: { type: String, value: '' }, // 是否显示弹窗 visible: { type: Boolean, value: false }, coupons: { type: Object, value: null } }, data: { checked: false, initPosition: { left: 50, top: 50 }, animation: {}, screenWidth: 0, screenHeight: 0 }, lifetimes: { ready() { const systemInfo = wx.getWindowInfo() this.screenWidth = systemInfo.windowWidth; this.screenHeight = systemInfo.windowHeight; this.setData({ screenHeight: systemInfo.windowHeight, screenWidth: systemInfo.windowWidth }) } }, methods: { toggleCheck() { this.setData({ checked: !this.data.checked }) }, // 关闭弹窗 onClose() { this.setData({ visible: false }); this.triggerEvent('close', this.data.checked); // 触发关闭事件 }, onFurl() { this.startAnimation() this.triggerEvent('furl', this.data.checked); //触发收下试卷 }, startAnimation() { // 先重置元素状态 this.setData({ showBox: true, animation: {} }); // 短暂延迟确保重置完成 setTimeout(() => { const animation = wx.createAnimation({ duration: 1000, timingFunction: 'ease-in-out' }); const targetLeft = this.data.screenWidth - 170; const targetTop = this.data.screenHeight - 170; console.log(this.data.screenHeight) console.log(this.data.screenWidth) animation .translate(targetLeft - this.data.initPosition.left, targetTop - this.data.initPosition.top) .scale(0.03) .rotate(180) .skew(10, 10) .opacity(0) .step(); this.setData({ animation: animation.export() }); // 动画结束后隐藏元素 setTimeout(() => { this.setData({ visible: false, initPosition: { left: 50, top: 50 }, animation: {} }); }, 1000); }, 50); } } })