Global.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. window.Global = {
  11. //Urls
  12. storeUrl:'https://api-touhu.duowan.com/product/getByType.do',
  13. skinBuyUrl:'https://api-touhu.duowan.com/product/buy.do',
  14. loginUrl:'https://api-touhu.duowan.com/auth/loginByGame.do',
  15. addReviveBoth:'https://api-touhu.duowan.com/user/addReviveBoth.do',
  16. userReport:'https://api-touhu.duowan.com/user/report.do',
  17. //SystemInfo
  18. ver:100,
  19. os:1,
  20. channel:"wexin",
  21. //皮肤ID
  22. bottleSkinId:-1,
  23. bottleSkinIndex:0,
  24. arrowSkinId:-1,
  25. arrowSkinIndex:0,
  26. //userInfo
  27. user:null,
  28. // user = {
  29. // token:data.token,
  30. // uid:user.id,
  31. // openId:user.openId,
  32. // nick:userInfo.nickName,
  33. // avatarUrl:userInfo.avatarUrl,
  34. // gender:userInfo.gender,
  35. // gold:user.coin,
  36. // score:user.score,
  37. // revivedCount:0
  38. // };
  39. //分享过来的用户Id
  40. shareUid:-1,
  41. //
  42. showLoginPage:true,
  43. showTotalRank:false,
  44. showFriendRank:false,
  45. //处理分享加复活卡的方法
  46. dealAddReviveBoth(){
  47. if(this.shareUid!=-1){
  48. if(this.shareUid!=this.user.uid){
  49. console.log('addReviveBoth');
  50. wx.request({
  51. url:Global.addReviveBoth,
  52. header: {
  53. "Content-Type": "application/x-www-form-urlencoded"
  54. },
  55. method:"POST",
  56. data:{
  57. token:this.user.token,
  58. uid:this.user.uid,
  59. channel:this.channel,
  60. os:this.os,
  61. ver:this.ver,
  62. targetUid:this.shareUid
  63. },
  64. success:(response)=>{
  65. if(response.data.code!=undefined&&response.data.code==0){
  66. this.user.revivedCount = this.user.revivedCount+1;
  67. // wx.showToast({title:'复活卡:'+this.user.revivedCount,icon:null})
  68. }
  69. },
  70. complete:()=>{
  71. this.shareUid=-1;
  72. }
  73. })
  74. }
  75. }
  76. },
  77. useReviveCard(){
  78. wx.request({
  79. url:'https://api-touhu.duowan.com//user/useRevive.do',
  80. header: {
  81. "Content-Type": "application/x-www-form-urlencoded"
  82. },
  83. method:"POST",
  84. data:{
  85. token:this.user.token,
  86. uid:this.user.uid,
  87. channel:this.channel,
  88. os:this.os,
  89. ver:this.ver,
  90. },
  91. success:(response)=>{
  92. if(response.data.code!=undefined&&response.data.code==0){
  93. this.user.revivedCount = this.user.revivedCount-1;
  94. }
  95. },
  96. complete:()=>{
  97. this.shareUid=-1;
  98. }
  99. })
  100. },
  101. };
  102. wx.onShow(res => {
  103. // let shareTicket = res.shareTicket;
  104. // console.log(shareTicket);
  105. // if(shareTicket!=undefined){
  106. // wx.showToast({
  107. // title:shareTicket,
  108. // })
  109. // }else{
  110. // wx.showToast({
  111. // title:'undefind',
  112. // })
  113. // }
  114. if (typeof wx.getUpdateManager === 'function') {
  115. const updateManager = wx.getUpdateManager()
  116. updateManager.onCheckForUpdate(function (res) {
  117. // 请求完新版本信息的回调
  118. console.log(res.hasUpdate)
  119. })
  120. updateManager.onUpdateReady(function () {
  121. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  122. updateManager.applyUpdate()
  123. })
  124. updateManager.onUpdateFailed(function () {
  125. // 新的版本下载失败
  126. })
  127. }
  128. wx.checkSession({
  129. success: function(){
  130. //session_key 未过期,并且在本生命周期一直有效
  131. },
  132. fail: function(){
  133. // session_key 已经失效,需要重新执行登录流程
  134. Global.showLoginPage = true;
  135. cc.director.loadScene("mainMenu");
  136. }
  137. })
  138. console.log('onShow res:');
  139. console.log(res);
  140. if(res!=null&&res.query!=null&&res.query.uid!=undefined){
  141. console.log('onShow query uid:'+res.query.uid);
  142. Global.shareUid = res.query.uid;
  143. if(Global.user!=null){
  144. Global.dealAddReviveBoth();
  145. }
  146. }
  147. });