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

364 lines
8.6KB

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