东风启辰小程序端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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