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

444 satır
10KB

  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: true,//是否显示游戏玩法关闭按钮
  11. clawTop:-440,//爪子的top值
  12. clawLeft: 268,//爪子的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. btnGroup:{
  24. left: false,
  25. right: false,
  26. top: false,
  27. bottom: false,
  28. claw:false
  29. },
  30. gameSign: null, //游戏结束时需要
  31. gameState:false,//游戏状态
  32. endGameData:null,//中奖数据
  33. isAddress:false,//是否有地址
  34. configure:{
  35. page:1,
  36. count:10
  37. },
  38. gameAwardList:[],
  39. userData:null,
  40. scrollNum:0,
  41. setInt:null,
  42. isMore:true,
  43. startDown:-1,//游戏开始倒计时
  44. clawType:false,//是否正在抓取
  45. },
  46. /**
  47. * 生命周期函数--监听页面加载
  48. */
  49. onLoad: function (options) {
  50. app.globalData.nowPage = 3;
  51. if (app.globalData.openid) {
  52. this.loadFun();
  53. } else {
  54. app.globalData.openidSuccessFuc = this.loadFun;
  55. }
  56. },
  57. loadFun: function () {
  58. if (app.globalData.userInfoData) {
  59. this.setData({
  60. userData: app.globalData.userInfoData
  61. })
  62. }
  63. this.getAddress();
  64. this.getGameAwardList();
  65. },
  66. /**
  67. * 生命周期函数--监听页面初次渲染完成
  68. */
  69. onReady: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面显示
  73. */
  74. onShow: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面隐藏
  78. */
  79. onHide: function () {
  80. },
  81. /**
  82. * 生命周期函数--监听页面卸载
  83. */
  84. onUnload: function () {
  85. },
  86. /**
  87. * 页面相关事件处理函数--监听用户下拉动作
  88. */
  89. onPullDownRefresh: function () {
  90. },
  91. /**
  92. * 页面上拉触底事件的处理函数
  93. */
  94. onReachBottom: function () {
  95. },
  96. /**
  97. * 用户点击右上角分享
  98. */
  99. onShareAppMessage: function () {
  100. return app.sharePack();
  101. },
  102. closeRule:function(){//关闭游戏玩法
  103. this.setData({
  104. ruleShow:false
  105. })
  106. },
  107. openGameRule: function () {//打开游戏玩法
  108. if(!this.data.gameState){
  109. this.setData({
  110. ruleShow: true
  111. })
  112. }
  113. },
  114. gameStart: function () {//开始游戏按钮
  115. this.setData({
  116. ruleShow: false,
  117. ruleCloseShow: true
  118. })
  119. this.beginGame();
  120. },
  121. beginGame: function () {//开始游戏
  122. app.wxRequest(app.globalData.urlRoot + "dollGame/beginGame", {}, res => {
  123. if(res.code==200){
  124. this.setData({
  125. startDown: 3
  126. })
  127. var setInt2 = setInterval(() => {
  128. if (this.data.startDown > -1) {
  129. this.setData({
  130. startDown: this.data.startDown -= 1
  131. })
  132. } else {
  133. this.setData({
  134. startDown: -1
  135. })
  136. clearInterval(setInt2);
  137. this.data.gameSign = res.data.sign;
  138. this.endGame();
  139. if (this.data.gameSign) {
  140. this.downTimeFun();
  141. }
  142. }
  143. }, 1000);
  144. }else{
  145. wx.showToast({
  146. title: res.msg,
  147. icon:"none"
  148. })
  149. }
  150. },this)
  151. },
  152. endGame:function(){//结束游戏
  153. app.wxRequest(app.globalData.urlRoot + "dollGame/endGame", { sign:this.data.gameSign}, res => {
  154. if(res.code=200){
  155. this.setData({
  156. endGameData: res.data
  157. })
  158. }else{
  159. console.log(res);
  160. }
  161. }, this,"POST")
  162. },
  163. startClaw:function(e){//开始控制爪子方向
  164. if(!this.data.gameState){
  165. return;
  166. }
  167. let direction = e.currentTarget.dataset.direction;
  168. if (direction == "L") {//向左
  169. this.data.btnGroup.left = true;
  170. this.setData({
  171. btnGroup: this.data.btnGroup
  172. })
  173. if (this.data.clawLeft <= 130) {
  174. return;
  175. }
  176. this.data.setGroup.left = setInterval(() => {
  177. this.setData({
  178. clawLeft: this.data.clawLeft-=2
  179. })
  180. if (this.data.clawLeft <= 130) {
  181. clearInterval(this.data.setGroup.left);
  182. }
  183. },20);
  184. } else if (direction == "R") {//向右
  185. this.data.btnGroup.right = true;
  186. this.setData({
  187. btnGroup: this.data.btnGroup
  188. })
  189. if (this.data.clawLeft >= 445) {
  190. return;
  191. }
  192. this.data.setGroup.right = setInterval(() => {
  193. this.setData({
  194. clawLeft: this.data.clawLeft += 2
  195. })
  196. if (this.data.clawLeft >= 445) {
  197. clearInterval(this.data.setGroup.right);
  198. }
  199. }, 20);
  200. } else if (direction == "T") {//向后
  201. this.data.btnGroup.top = true;
  202. this.setData({
  203. btnGroup: this.data.btnGroup
  204. })
  205. if (this.data.clawScale <= 0.8) {
  206. return;
  207. }
  208. this.data.setGroup.top = setInterval(() => {
  209. this.setData({
  210. clawScale: this.data.clawScale -= 0.01
  211. })
  212. if (this.data.clawScale <= 0.8) {
  213. clearInterval(this.data.setGroup.top);
  214. }
  215. }, 20);
  216. } else if (direction == "B") {//向前
  217. this.data.btnGroup.bottom = true;
  218. this.setData({
  219. btnGroup: this.data.btnGroup
  220. })
  221. if (this.data.clawScale >= 1.2) {
  222. return;
  223. }
  224. this.data.setGroup.bottom = setInterval(() => {
  225. this.setData({
  226. clawScale: this.data.clawScale += 0.01
  227. })
  228. if (this.data.clawScale >= 1.2) {
  229. clearInterval(this.data.setGroup.bottom);
  230. }
  231. }, 20);
  232. }
  233. },
  234. endClaw: function (e) {//结束爪子动作
  235. if (!this.data.gameState) {
  236. return;
  237. }
  238. let direction = e.currentTarget.dataset.direction;
  239. if (direction == "L") {//向左
  240. this.data.btnGroup.left = false;
  241. this.setData({
  242. btnGroup: this.data.btnGroup
  243. })
  244. clearInterval(this.data.setGroup.left);
  245. } else if (direction == "R") {//向右
  246. this.data.btnGroup.right = false;
  247. this.setData({
  248. btnGroup: this.data.btnGroup
  249. })
  250. clearInterval(this.data.setGroup.right);
  251. } else if (direction == "T") {//向后
  252. this.data.btnGroup.top = false;
  253. this.setData({
  254. btnGroup: this.data.btnGroup
  255. })
  256. clearInterval(this.data.setGroup.top);
  257. } else if (direction == "B") {//向前
  258. this.data.btnGroup.bottom = false;
  259. this.setData({
  260. btnGroup: this.data.btnGroup
  261. })
  262. clearInterval(this.data.setGroup.bottom);
  263. }
  264. },
  265. getClaw:function(){//抓取
  266. this.setData({
  267. clawType:true
  268. })
  269. this.setData({
  270. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440 )
  271. })
  272. this.closeSetInt();
  273. setTimeout(() => {
  274. this.setData({
  275. clawType: false
  276. })
  277. this.data.gameState = false;
  278. if (this.data.endGameData) {
  279. this.setData({
  280. pizeTip: 1
  281. })
  282. } else {
  283. if (this.data.isAddress) {
  284. this.setData({
  285. pizeTip: 2
  286. })
  287. } else {
  288. this.setData({
  289. pizeTip: 3
  290. })
  291. }
  292. }
  293. },1000)
  294. },
  295. downTimeFun: function () {//游戏倒计时
  296. this.data.gameState = true;
  297. this.data.setInt = setInterval(()=>{
  298. this.data.downNum -= 1;
  299. if (this.data.downNum<10){
  300. this.data.downNum = '0' + this.data.downNum;
  301. }
  302. this.setData({
  303. downNum: this.data.downNum
  304. })
  305. if (this.data.downNum < 1) {
  306. this.getClaw();
  307. }
  308. },1000);
  309. },
  310. closeSetInt: function () {//关闭倒计时
  311. clearInterval(this.data.setInt);
  312. this.setData({
  313. downNum: 30,
  314. clawTop: this.data.clawScale > 1 ? -100 - (2 * (this.data.clawScale - 1) * 440) : -100 + (2 * (1 - this.data.clawScale) * 440)
  315. })
  316. setTimeout(()=>{
  317. this.setData({
  318. downNum: 30,
  319. clawTop: -440,
  320. clawLeft: 268,
  321. clawScale:1
  322. })
  323. }, 1200);
  324. },
  325. prizeLook:function(){//活动奖品
  326. if(!this.data.gameState){
  327. wx.navigateTo({
  328. url: '../prizes/prizes'
  329. })
  330. }
  331. },
  332. getAddress: function () {//获取地址
  333. app.wxRequest(app.globalData.urlRoot + "address/getAddress", {}, res => {
  334. if (res.code == 200) {
  335. if (res.data) {
  336. this.setData({
  337. isAddress:true
  338. })
  339. }
  340. }
  341. }, this)
  342. },
  343. receive:function(){//立即领取
  344. wx.redirectTo({
  345. url: '../myCenter/myCenter',
  346. })
  347. },
  348. invitation: function () {//邀请好友一起来玩
  349. },
  350. userRegister: function () {//立即注册,探索更多星探好礼
  351. wx.navigateTo({
  352. url: '../address/address',
  353. })
  354. },
  355. closeWindow:function(){//关闭中奖
  356. this.setData({
  357. pizeTip:0,
  358. ruleShow:true
  359. })
  360. },
  361. getGameAwardList: function () {//获取游戏中奖数据
  362. app.wxRequest(app.globalData.urlRoot + "award/getGameAwardList", this.data.configure,res=>{
  363. if(res.code==200){
  364. if(res.data.length<this.data.configure.count){
  365. this.data.isMore = false;
  366. }
  367. console.log(this.data.isMore);
  368. for(let i=0;i<res.data.length;i++){
  369. this.data.gameAwardList.push(res.data[i]);
  370. }
  371. this.setData({
  372. gameAwardList: this.data.gameAwardList
  373. })
  374. if(this.data.configure.page==1){
  375. this.changeScroll();
  376. }
  377. }
  378. },this)
  379. },
  380. getUserWxMsg: function (e) {//通过微信获取用户信息
  381. if (e.detail.errMsg == "getUserInfo:ok") {
  382. this.gameStart();
  383. this.setData({
  384. userData: e.detail.userInfo
  385. })
  386. app.submitUserMsg(e.detail.userInfo.avatarUrl, e.detail.userInfo.nickName);
  387. }else{
  388. this.gameStart();
  389. }
  390. },
  391. changeScroll:function(){
  392. this.data.setInt = setInterval(()=>{
  393. this.setData({
  394. scrollNum: this.data.scrollNum+=1
  395. })
  396. },30);
  397. },
  398. getMore:function(){
  399. if (!this.data.isMore){
  400. this.setData({
  401. scrollNum: 0
  402. })
  403. return;
  404. }
  405. this.data.configure.page+=1;
  406. this.getGameAwardList();
  407. },
  408. cutPage:function(){//500元待领取
  409. wx.redirectTo({
  410. url: '/pages/star/star',
  411. })
  412. },
  413. openClaw:function(){
  414. if (!this.data.gameState) {
  415. return;
  416. }
  417. this.data.btnGroup.claw = true;
  418. this.setData({
  419. btnGroup: this.data.btnGroup
  420. })
  421. setTimeout(()=>{
  422. this.data.btnGroup.claw = false;
  423. this.setData({
  424. btnGroup: this.data.btnGroup
  425. })
  426. this.getClaw();
  427. },200);
  428. }
  429. })