// pages/turntable/turntable.js let animation = wx.createAnimation({ duration: 2000, timingFunction: 'linear' }) Page({ data: { rotate: 0, //度数 turning: false //是否点击 }, //事件处理函数 start: function () { let _this = this; let cat = 60; if (!this.data.turning) { let rdm = 0; //随机度数 rdm = Math.floor(Math.random() * 3600); //最大10圈 //rdm = 1200;//直接确定转的度数 animation.rotate(rdm).step(); this.setData({ rotate: animation.export(), turning: true }); setTimeout(() => { this.setData({ turning: false }); let num = rdm % 360; //转了多少度 //console.log(num); function showModal(str) { wx.showModal({ title: '提示', content: str, success: function () { //点击确定后还原到0度 let animation = wx.createAnimation({ duration: 100, timingFunction: 'linear' }); animation.rotate(0).step(); _this.setData({ rotate: animation.export(), turning: false }); }, fail: function (res) { console.log(res) } }) } if (num <= cat * 0.5 && num >= cat * 5.5) { showModal('今天就吃麻辣烫吧!不要再想了!GOGO'); } else if (num <= cat * 1.5 && num >= cat * 0.5) { showModal('今天就吃自选餐吧!不要再想了!GOGO'); } else if (num <= cat * 2.5 && num >= cat * 1.5) { showModal('今天就吃炸鸡吧!不要再想了!GOGO'); } else if (num <= cat * 3.5 && num >= cat * 2.5) { showModal('今天就吃火锅吧!不要再想了!GOGO'); } else if (num <= cat * 4.5 && num >= cat * 3.5) { showModal('今天就吃西餐吧!不要再想了!GOGO'); } else if (num <= cat * 5.5 && num >= cat * 4.5) { showModal('今天就吃面食吧!不要再想了!GOGO'); } console.log(num) }, 2000) } }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })