东风启辰小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

292 lines
6.9KB

  1. // pages/luckyStar/luckyStar.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgUrl: app.globalData.urlStatic,//图片路径
  9. ruleShow: true,//是否显示游戏玩法
  10. ruleCloseShow: false,//是否显示游戏玩法关闭按钮
  11. clawTop:95,//爪子的top值
  12. clawLeft: 293,//爪子的left值
  13. clawScale: 1,//爪子的scale值
  14. downNum:30,//倒计时时间
  15. setInt:null,//倒计时元素
  16. pizeTip:0,//抓奖提示框
  17. setGroup:{
  18. left:null,
  19. right: null,
  20. top: null,
  21. bottom: null,
  22. },
  23. gameSign: null, //游戏结束时需要
  24. gameState:false,//游戏状态
  25. endGameData:null,//中奖数据
  26. isRegister:false,//是否已注册
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. app.globalData.nowPage = 3;
  33. if (app.globalData.openid) {
  34. this.getOrderInfo();
  35. this.endGame();
  36. } else {
  37. app.globalData.openidSuccessFuc = this.getOrderInfo;
  38. }
  39. },
  40. /**
  41. * 生命周期函数--监听页面初次渲染完成
  42. */
  43. onReady: function () {
  44. },
  45. /**
  46. * 生命周期函数--监听页面显示
  47. */
  48. onShow: function () {
  49. },
  50. /**
  51. * 生命周期函数--监听页面隐藏
  52. */
  53. onHide: function () {
  54. },
  55. /**
  56. * 生命周期函数--监听页面卸载
  57. */
  58. onUnload: function () {
  59. },
  60. /**
  61. * 页面相关事件处理函数--监听用户下拉动作
  62. */
  63. onPullDownRefresh: function () {
  64. },
  65. /**
  66. * 页面上拉触底事件的处理函数
  67. */
  68. onReachBottom: function () {
  69. },
  70. /**
  71. * 用户点击右上角分享
  72. */
  73. onShareAppMessage: function () {
  74. return app.sharePack();
  75. },
  76. closeRule:function(){//关闭游戏玩法
  77. this.setData({
  78. ruleShow:false
  79. })
  80. },
  81. openGameRule: function () {//打开游戏玩法
  82. console.log(this.data.gameState);
  83. if(!this.data.gameState){
  84. this.setData({
  85. ruleShow: true
  86. })
  87. }
  88. },
  89. gameStart: function () {//开始游戏按钮
  90. this.setData({
  91. ruleShow: false,
  92. ruleCloseShow: true
  93. })
  94. this.beginGame();
  95. },
  96. beginGame: function () {//开始游戏
  97. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  98. console.log(res);
  99. if(res.code==200){
  100. this.data.gameSign = res.data.sign;
  101. this.endGame();
  102. if (this.data.gameSign) {
  103. this.downTimeFun();
  104. }
  105. }else{
  106. wx.showToast({
  107. title: res.msg,
  108. icon:"none"
  109. })
  110. }
  111. },this)
  112. },
  113. endGame:function(){//结束游戏
  114. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  115. if(res.code=200){
  116. this.setData({
  117. endGameData: res.data
  118. })
  119. }else{
  120. console.log(res);
  121. }
  122. }, this,"POST")
  123. },
  124. startClaw:function(e){//开始控制爪子方向
  125. let direction = e.currentTarget.dataset.direction;
  126. if (direction == "L") {//向左
  127. if (this.data.clawLeft <= 130) {
  128. return;
  129. }
  130. this.data.setGroup.left = setInterval(() => {
  131. this.setData({
  132. clawLeft: this.data.clawLeft-=2
  133. })
  134. if (this.data.clawLeft <= 130) {
  135. clearInterval(this.data.setGroup.left);
  136. }
  137. },20);
  138. } else if (direction == "R") {//向右
  139. if (this.data.clawLeft >= 445) {
  140. return;
  141. }
  142. this.data.setGroup.right = setInterval(() => {
  143. this.setData({
  144. clawLeft: this.data.clawLeft += 2
  145. })
  146. if (this.data.clawLeft >= 445) {
  147. clearInterval(this.data.setGroup.right);
  148. }
  149. }, 20);
  150. } else if (direction == "T") {//向后
  151. if (this.data.clawScale <= 0.5) {
  152. return;
  153. }
  154. this.data.setGroup.top = setInterval(() => {
  155. this.setData({
  156. clawScale: this.data.clawScale -= 0.01
  157. })
  158. if (this.data.clawScale <= 0.5) {
  159. clearInterval(this.data.setGroup.top);
  160. }
  161. }, 20);
  162. } else if (direction == "B") {//向前
  163. if (this.data.clawScale >= 1.5) {
  164. return;
  165. }
  166. this.data.setGroup.bottom = setInterval(() => {
  167. this.setData({
  168. clawScale: this.data.clawScale += 0.01
  169. })
  170. if (this.data.clawScale >= 1.5) {
  171. clearInterval(this.data.setGroup.bottom);
  172. }
  173. }, 20);
  174. }
  175. },
  176. endClaw:function(e){//结束爪子动作
  177. let direction = e.currentTarget.dataset.direction;
  178. if (direction == "L") {//向左
  179. clearInterval(this.data.setGroup.left);
  180. } else if (direction == "R") {//向右
  181. clearInterval(this.data.setGroup.right);
  182. } else if (direction == "T") {//向后
  183. clearInterval(this.data.setGroup.top);
  184. } else if (direction == "B") {//向前
  185. clearInterval(this.data.setGroup.bottom);
  186. }
  187. },
  188. getClaw:function(){//抓取
  189. this.setData({
  190. clawTop: this.data.clawScale > 1 ? 490 - (2 * (this.data.clawScale-1) * 90) : 490 + (2 * (1 - this.data.clawScale) * 90 )
  191. })
  192. this.closeSetInt();
  193. setTimeout(() => {
  194. this.data.gameState = false;
  195. if (this.data.endGameData) {
  196. this.setData({
  197. pizeTip: 1
  198. })
  199. } else {
  200. if (this.data.isRegister) {
  201. this.setData({
  202. pizeTip: 2
  203. })
  204. } else {
  205. this.setData({
  206. pizeTip: 3
  207. })
  208. }
  209. }
  210. },1000)
  211. },
  212. downTimeFun: function () {//游戏倒计时
  213. this.data.gameState = true;
  214. this.data.setInt = setInterval(()=>{
  215. this.data.downNum -= 1;
  216. if (this.data.downNum<10){
  217. this.data.downNum = '0' + this.data.downNum;
  218. }
  219. this.setData({
  220. downNum: this.data.downNum
  221. })
  222. if (this.data.downNum < 1) {
  223. // this.closeSetInt();
  224. this.getClaw();
  225. }
  226. },1000);
  227. },
  228. closeSetInt: function () {//关闭倒计时
  229. clearInterval(this.data.setInt);
  230. this.setData({
  231. downNum: 30,
  232. clawTop: this.data.clawScale > 1 ? 455 - (2 * (this.data.clawScale - 1) * 90) : 455 + (2 * (1 - this.data.clawScale) * 90)
  233. })
  234. setTimeout(()=>{
  235. this.setData({
  236. downNum: 30,
  237. clawTop: 95,
  238. clawLeft: 293,
  239. clawScale:1
  240. })
  241. }, 1200);
  242. },
  243. prizeLook:function(){//活动奖品
  244. if(!this.data.gameState){
  245. wx.navigateTo({
  246. url: '../prizes/prizes'
  247. })
  248. }
  249. },
  250. getOrderInfo: function () {//查询是否已注册
  251. app.wxRequest(app.globalData.urlRoot +"userInfo/getOrderInfo",{},res=>{
  252. if(res.code==200){
  253. if (res.data) {
  254. this.data.isRegister = true;
  255. }
  256. }
  257. },this)
  258. },
  259. receive:function(){//立即领取
  260. wx.redirectTo({
  261. url: '../myCenter/myCenter',
  262. })
  263. },
  264. invitation: function () {//邀请好友一起来玩
  265. },
  266. userRegister: function () {//立即注册,探索更多星探好礼
  267. wx.navigateTo({
  268. url: '../receiveRegister/receiveRegister',
  269. })
  270. },
  271. closeWindow:function(){//关闭中奖
  272. this.setData({
  273. pizeTip:0
  274. })
  275. }
  276. })