东风启辰小程序端
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.

300 line
7.0KB

  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. if(res.code==200){
  99. this.data.gameSign = res.data.sign;
  100. this.endGame();
  101. if (this.data.gameSign) {
  102. this.downTimeFun();
  103. }
  104. }else{
  105. wx.showToast({
  106. title: res.msg,
  107. icon:"none"
  108. })
  109. }
  110. },this)
  111. },
  112. endGame:function(){//结束游戏
  113. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  114. if(res.code=200){
  115. this.setData({
  116. endGameData: res.data
  117. })
  118. }else{
  119. console.log(res);
  120. }
  121. }, this,"POST")
  122. },
  123. startClaw:function(e){//开始控制爪子方向
  124. if(!this.data.gameState){
  125. return;
  126. }
  127. let direction = e.currentTarget.dataset.direction;
  128. if (direction == "L") {//向左
  129. if (this.data.clawLeft <= 130) {
  130. return;
  131. }
  132. this.data.setGroup.left = setInterval(() => {
  133. this.setData({
  134. clawLeft: this.data.clawLeft-=2
  135. })
  136. if (this.data.clawLeft <= 130) {
  137. clearInterval(this.data.setGroup.left);
  138. }
  139. },20);
  140. } else if (direction == "R") {//向右
  141. if (this.data.clawLeft >= 445) {
  142. return;
  143. }
  144. this.data.setGroup.right = setInterval(() => {
  145. this.setData({
  146. clawLeft: this.data.clawLeft += 2
  147. })
  148. if (this.data.clawLeft >= 445) {
  149. clearInterval(this.data.setGroup.right);
  150. }
  151. }, 20);
  152. } else if (direction == "T") {//向后
  153. if (this.data.clawScale <= 0.5) {
  154. return;
  155. }
  156. this.data.setGroup.top = setInterval(() => {
  157. this.setData({
  158. clawScale: this.data.clawScale -= 0.01
  159. })
  160. if (this.data.clawScale <= 0.5) {
  161. clearInterval(this.data.setGroup.top);
  162. }
  163. }, 20);
  164. } else if (direction == "B") {//向前
  165. if (this.data.clawScale >= 1.5) {
  166. return;
  167. }
  168. this.data.setGroup.bottom = setInterval(() => {
  169. this.setData({
  170. clawScale: this.data.clawScale += 0.01
  171. })
  172. if (this.data.clawScale >= 1.5) {
  173. clearInterval(this.data.setGroup.bottom);
  174. }
  175. }, 20);
  176. }
  177. },
  178. endClaw: function (e) {//结束爪子动作
  179. if (!this.data.gameState) {
  180. return;
  181. }
  182. let direction = e.currentTarget.dataset.direction;
  183. if (direction == "L") {//向左
  184. clearInterval(this.data.setGroup.left);
  185. } else if (direction == "R") {//向右
  186. clearInterval(this.data.setGroup.right);
  187. } else if (direction == "T") {//向后
  188. clearInterval(this.data.setGroup.top);
  189. } else if (direction == "B") {//向前
  190. clearInterval(this.data.setGroup.bottom);
  191. }
  192. },
  193. getClaw:function(){//抓取
  194. if (!this.data.gameState){
  195. return;
  196. }
  197. this.setData({
  198. clawTop: this.data.clawScale > 1 ? 490 - (2 * (this.data.clawScale-1) * 90) : 490 + (2 * (1 - this.data.clawScale) * 90 )
  199. })
  200. this.closeSetInt();
  201. setTimeout(() => {
  202. this.data.gameState = false;
  203. if (this.data.endGameData) {
  204. this.setData({
  205. pizeTip: 1
  206. })
  207. } else {
  208. if (this.data.isRegister) {
  209. this.setData({
  210. pizeTip: 2
  211. })
  212. } else {
  213. this.setData({
  214. pizeTip: 3
  215. })
  216. }
  217. }
  218. },1000)
  219. },
  220. downTimeFun: function () {//游戏倒计时
  221. this.data.gameState = true;
  222. this.data.setInt = setInterval(()=>{
  223. this.data.downNum -= 1;
  224. if (this.data.downNum<10){
  225. this.data.downNum = '0' + this.data.downNum;
  226. }
  227. this.setData({
  228. downNum: this.data.downNum
  229. })
  230. if (this.data.downNum < 1) {
  231. // this.closeSetInt();
  232. this.getClaw();
  233. }
  234. },1000);
  235. },
  236. closeSetInt: function () {//关闭倒计时
  237. clearInterval(this.data.setInt);
  238. this.setData({
  239. downNum: 30,
  240. clawTop: this.data.clawScale > 1 ? 455 - (2 * (this.data.clawScale - 1) * 90) : 455 + (2 * (1 - this.data.clawScale) * 90)
  241. })
  242. setTimeout(()=>{
  243. this.setData({
  244. downNum: 30,
  245. clawTop: 95,
  246. clawLeft: 293,
  247. clawScale:1
  248. })
  249. }, 1200);
  250. },
  251. prizeLook:function(){//活动奖品
  252. if(!this.data.gameState){
  253. wx.navigateTo({
  254. url: '../prizes/prizes'
  255. })
  256. }
  257. },
  258. getOrderInfo: function () {//查询是否已注册
  259. app.wxRequest(app.globalData.urlRoot +"userInfo/getOrderInfo",{},res=>{
  260. if(res.code==200){
  261. if (res.data) {
  262. this.data.isRegister = true;
  263. }
  264. }
  265. },this)
  266. },
  267. receive:function(){//立即领取
  268. wx.redirectTo({
  269. url: '../myCenter/myCenter',
  270. })
  271. },
  272. invitation: function () {//邀请好友一起来玩
  273. },
  274. userRegister: function () {//立即注册,探索更多星探好礼
  275. wx.navigateTo({
  276. url: '../receiveRegister/receiveRegister',
  277. })
  278. },
  279. closeWindow:function(){//关闭中奖
  280. this.setData({
  281. pizeTip:0
  282. })
  283. }
  284. })