main.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.userData = {
  11. httpData : {
  12. data: {
  13. avatarUrl: "https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83eohXLEIOV99ic2JosrQDgIgL4cU4ZlmmvkWzGpygkNV9aEJ6nCC2mVf4kYBDHogNOHgXo2wZhv85jA/132",
  14. city: "Harbin",
  15. gender: 1,
  16. nickName: "汪汪Husky",
  17. openid: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY",
  18. province: "Heilongjiang",
  19. id : 0
  20. },
  21. },
  22. // oGxOa5bd61v9jI_indIdQtI2T5P8 大佬
  23. // oGxOa5bjKLaCSbkPev09yVze0WSA 晓明
  24. // oGxOa5del9BkzJ3e8fLVzI4mlvEI 小狐仙
  25. // oGxOa5eZUuWCNCoEUQIjtu2uN9BM 9527
  26. // oGxOa5SQ1ltBWWsVRirUvXUBGRRY 汪汪
  27. openId: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY"
  28. }
  29. cc.Class({
  30. extends: cc.Component,
  31. properties: {
  32. // foo: {
  33. // // ATTRIBUTES:
  34. // default: null, // The default value will be used only when the component attaching
  35. // // to a node for the first time
  36. // type: cc.SpriteFrame, // optional, default is typeof default
  37. // serializable: true, // optional, default is true
  38. // },
  39. // bar: {
  40. // get () {
  41. // return this._bar;
  42. // },
  43. // set (value) {
  44. // this._bar = value;
  45. // }
  46. // },
  47. },
  48. // LIFE-CYCLE CALLBACKS:
  49. // onLoad () {},
  50. start () {
  51. this.Display = UtilsPrefabs.getNode("layout",this.node);
  52. // this.Display = UtilsPrefabs.getNode("Display",this.node);
  53. if (cc.sys.platform === cc.sys.WECHAT_GAME){
  54. wx.onMessage(function (data) {
  55. if (data.message != null) {
  56. var message = data.message;
  57. // console.log("主域 过来的数据",data.message);
  58. switch (message.name) {
  59. case "showFriend":
  60. this.showFriend();
  61. break;
  62. case "hideFriend":
  63. this.hideFriend();
  64. break;
  65. case "Whoareyou":
  66. userData.openId = message.openId;
  67. // userData.httpData.data.id = parseInt(message.id);
  68. this.getRankingchao();
  69. break;
  70. case "Whoareme":
  71. userData.openId = message.openId;
  72. // userData.httpData.data.id = parseInt(message.id);
  73. this.getRanking();
  74. break;
  75. }
  76. }
  77. }.bind(this));
  78. }else{
  79. this.showFriend();
  80. // this.getRanking();
  81. }
  82. },
  83. showFriend : function () {
  84. this.Display.getChildByName("Display").active = true;
  85. this.Display.getComponent("launch").getFriend();
  86. },
  87. hideFriend : function () {
  88. this.Display.getChildByName("Display").active = false;
  89. this.Display.getComponent("launch").removeAll();
  90. },
  91. getIndex : function (openId) {
  92. },
  93. getRanking : function () {
  94. this.Display.getComponent("launch").getRanking(function (list) {
  95. //添加排行榜为 自己的条目在下面
  96. // console.log("我在统计数组1",list,userData.openId);
  97. for (var i = 0; i <list.length ; i++) {
  98. // console.log("我在统计数组2",list,userData.openId);
  99. if (list[i].openId ==userData.openId) {
  100. // console.log("我在统计数组3",list,userData.openId);
  101. //超越
  102. // this.curr(i,list);
  103. //找排名前后的两人
  104. this.getCurr(i,list);
  105. }
  106. }
  107. }.bind(this));
  108. },
  109. getRankingchao : function () {
  110. this.ischao = true;
  111. this.Display.getComponent("launch").getRanking(function (list) {
  112. //添加排行榜为 自己的条目在下面
  113. // console.log("超越1",this.ischao,list);
  114. if (this.ischao) {
  115. this.ischao = false;
  116. // console.log("超越2",this.ischao,list);
  117. for (var i = 0; i <list.length ; i++) {
  118. if (list[i].openId ==userData.openId) {
  119. // console.log("超越3",this.ischao,list);
  120. //超越
  121. this.curr(i,list);
  122. }
  123. }
  124. }
  125. }.bind(this));
  126. },
  127. curr : function (i,list) {
  128. // if (this.myCurr == null) {
  129. // this.myCurr = i;oGxOa5SQ1ltBWWsVRirUvXUBGRRY
  130. // }else{
  131. // // console.log("原来名次",this.myCurr);
  132. // // console.log("当前名次",i);
  133. // //当前名次 无变动
  134. // if (i-this.myCurr == 0) {
  135. // // console.log("当前名次",i,"排名无变动",this.myCurr);
  136. // }else if (i-this.myCurr < 0 ) {
  137. // // console.log("当前名次",i,"排名超越","被超越的索引是",this.myCurr);
  138. // // console.log("当前名次数据是",list[i],"排名超越","被超越的索引是",list[this.myCurr]);
  139. //
  140. // this.Display.getComponent("launch").Transcendfun(list[i],list[this.myCurr]);
  141. // }else if (i-this.myCurr > 0 ) {
  142. // // console.log("当前名次",i,"排名下降");
  143. // }
  144. // //播放动画
  145. //
  146. //
  147. // this.myCurr = i;
  148. // }
  149. // console.log("超越4",this.ischao,list[i],i - 1);
  150. if (i - 1 >= 0) {
  151. // console.log("我前面的数据",list[i-1],"我的数据",list[i]);
  152. // if (list[i - 1].id - list[i].id <= 15000) {
  153. this.Display.getComponent("launch").curr(list[i-1]);
  154. // }
  155. }
  156. },
  157. getCurr : function (i,list) {
  158. this.Display.getComponent("launch").getCurrs(i,list);
  159. },
  160. // update (dt) {},
  161. });