main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. window.userData = {
  2. httpData: {
  3. data: {
  4. avatarUrl: "",
  5. city: "Harbin",
  6. gender: 1,
  7. nickName: "",
  8. openid: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY",
  9. province: "Heilongjiang",
  10. id: 0
  11. },
  12. },
  13. // oGxOa5bd61v9jI_indIdQtI2T5P8 大佬
  14. // oGxOa5bjKLaCSbkPev09yVze0WSA 晓明
  15. // oGxOa5del9BkzJ3e8fLVzI4mlvEI 小狐仙
  16. // oGxOa5eZUuWCNCoEUQIjtu2uN9BM 9527
  17. // oGxOa5SQ1ltBWWsVRirUvXUBGRRY 汪汪
  18. openId: "oGxOa5SQ1ltBWWsVRirUvXUBGRRY",
  19. ranking: 0,
  20. }
  21. cc.Class({
  22. extends: cc.Component,
  23. properties: {
  24. },
  25. start() {
  26. this.Display = UtilsPrefabs.getNode("layout", this.node);
  27. // this.Display = UtilsPrefabs.getNode("Display",this.node);
  28. if (cc.sys.platform === cc.sys.WECHAT_GAME) {
  29. wx.onMessage(function (data) {
  30. if (data.message != null) {
  31. var message = data.message;
  32. // console.log("主域 过来的数据",data.message);
  33. switch (message.name) {
  34. case "showFriend":
  35. this.showFriend();
  36. break;
  37. case "hideFriend":
  38. this.hideFriend();
  39. break;
  40. case "Whoareyou":
  41. userData.openId = message.openId;
  42. this.getRankingchao();
  43. break;
  44. case "Whoareme":
  45. userData.openId = message.openId;
  46. this.getRanking();
  47. break;
  48. }
  49. }
  50. }.bind(this));
  51. } else {
  52. this.showFriend();
  53. }
  54. },
  55. showFriend: function () {
  56. this.Display.getChildByName("Display").active = true;
  57. this.Display.getComponent("launch").getFriend();
  58. },
  59. hideFriend: function () {
  60. this.Display.getChildByName("Display").active = false;
  61. this.Display.getComponent("launch").removeAll();
  62. },
  63. getRanking: function () {
  64. this.Display.getComponent("launch").getRanking(function (list) {
  65. //添加排行榜为 自己的条目在下面
  66. // console.log("我在统计数组1",list,userData.openId);
  67. for (var i = 0; i < list.length; i++) {
  68. // console.log("我在统计数组2",list,userData.openId);
  69. if (list[i].openId == userData.openId) {
  70. // console.log("我在统计数组3",list,userData.openId);
  71. //超越
  72. // this.curr(i,list);
  73. //找排名前后的两人
  74. this.getCurr(i, list);
  75. }
  76. }
  77. }.bind(this));
  78. },
  79. getRankingchao: function () {
  80. this.ischao = true;
  81. this.Display.getComponent("launch").getRanking(function (list) {
  82. //添加排行榜为 自己的条目在下面
  83. // console.log("超越1",this.ischao,list);
  84. if (this.ischao) {
  85. this.ischao = false;
  86. // console.log("超越2",this.ischao,list);
  87. for (var i = 0; i < list.length; i++) {
  88. if (list[i].openId == userData.openId) {
  89. // console.log("超越3",this.ischao,list);
  90. //超越
  91. this.curr(i, list);
  92. }
  93. }
  94. }
  95. }.bind(this));
  96. },
  97. curr: function (i, list) {
  98. if (i - 1 >= 0) {
  99. this.Display.getComponent("launch").curr(list[i - 1]);
  100. }
  101. },
  102. getCurr: function (i, list) {
  103. this.Display.getComponent("launch").getCurrs(i, list);
  104. },
  105. });