东风启辰小程序端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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