loginjs.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. cc.Class({
  11. extends: cc.Component,
  12. properties: {
  13. // foo: {
  14. // // ATTRIBUTES:
  15. // default: null, // The default value will be used only when the component attaching
  16. // // to a node for the first time
  17. // type: cc.SpriteFrame, // optional, default is typeof default
  18. // serializable: true, // optional, default is true
  19. // },
  20. // bar: {
  21. // get () {
  22. // return this._bar;
  23. // },
  24. // set (value) {
  25. // this._bar = value;
  26. // }
  27. // },
  28. },
  29. // LIFE-CYCLE CALLBACKS:
  30. onLoad() {
  31. this.info = cc.find("info");
  32. this.Button = cc.find("New Button");
  33. UtilsPrefabs.setOn(this.Button,function () {
  34. cc.director.loadScene('MyCityScene - 004', function () {
  35. this.progressTag = false;
  36. }.bind(this));
  37. }.bind(this))
  38. cc.audioEngine.stopAll();
  39. // this.setInfo("停止声音");
  40. this.progressTag = false;
  41. this.oldprogressTag = -99;
  42. cc.loader.onProgress = function (completeCount, totalCount) {
  43. if (this.progressTag) {
  44. this.progress = (1 * completeCount / totalCount).toFixed(1);
  45. // console.log("进度条",this.progress + '%',this.progressNode);
  46. if (this.progressNode != null) {
  47. this.progressNode.getComponent(cc.ProgressBar).progress = this.progress;
  48. }
  49. }
  50. }.bind(this);
  51. // console.log('准备去游戏 准备跳转到下个页面');
  52. // this.setInfo("准备加载背景");
  53. UtilsPrefabs
  54. .init(this.node)
  55. .addPrefabs(UtilsPrefabs.PrefabsName[2], null, function (node) {
  56. // this.setInfo("加载背景完成 去微信登录");
  57. UtilsWX.wxgameLogin(function (res) {
  58. console.log('获取玩家信息 准备跳转到下个页面',res);
  59. // this.setInfo("获取到 用户信息"+res);
  60. UtilsWX.wxlogin(res, function () {
  61. // this.setInfo("访问后台登陆 游戏"+res);
  62. UtilsWX.removeUserInfoButton();
  63. this.showLoadDialog();
  64. }.bind(this), function () {
  65. // console.log('访问自己后台服务器登录账号错误');
  66. // this.setInfo("访问自己后台服务器登录账号错误");
  67. }.bind(this));
  68. }.bind(this))
  69. if (cc.sys.platform != cc.sys.WECHAT_GAME) {
  70. // this.setInfo("加载 dialog 准备使用本地id 登录游戏");
  71. this.showLoadDialog();
  72. }
  73. }.bind(this));
  74. // node.y = -200;
  75. //
  76. // var GivePrize = UtilsPrefabs.getNode("GivePrize",node);
  77. // //转
  78. // var Sunshine = UtilsPrefabs.getNode("Sunshine",GivePrize);
  79. // //物品
  80. // var Rewards = UtilsPrefabs.getNode("Rewards",GivePrize);
  81. // //关闭按钮
  82. // var close = UtilsPrefabs.getNode("close",node);
  83. //
  84. // Rewards.getComponent(cc.Sprite).spriteFrame = this.getNode("ItemSprite",this.TodayNode).getComponent(cc.Sprite).spriteFrame
  85. // Rewards.scale = 2;
  86. //
  87. // Sunshine.stopAllActions();
  88. // var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  89. // Sunshine.runAction(repeat);
  90. // this.EveryDaySignView.active=false;
  91. //
  92. // UtilsPrefabs.setOn(close,function () {
  93. //
  94. //
  95. // this.ManageUI.getComponent("ManageUI").onButtonEvent_EveryDay_Close();
  96. // UtilsPrefabs.setOff(close);
  97. // UtilsPrefabs.removePrefabs(this.EveryDaySignContainer,node.name);
  98. // }.bind(this));
  99. //
  100. // UtilsPrefabs
  101. // .init(this.EveryDaySignContainer)
  102. // .addPrefabs(UtilsPrefabs.PrefabsName[0],null,function (node) {
  103. // node.y = -200;
  104. // var gosharebtn = UtilsPrefabs.getNode("gosharebtn",node);
  105. // var img1 = UtilsPrefabs.getNode("img1",node);
  106. // var NewLabel1 = UtilsPrefabs.getNode("New Label",img1);
  107. // var img2 = UtilsPrefabs.getNode("img2",node);
  108. // var NewLabel2 = UtilsPrefabs.getNode("New Label",img2);
  109. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[0];
  110. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[1];
  111. //
  112. //
  113. // UtilsPrefabs.setOn(gosharebtn,function () {
  114. // console.log("点击分享按钮");
  115. // UtilsWX.sharebtn();
  116. // UtilsPrefabs.setOff(gosharebtn);
  117. // UtilsPrefabs.removePrefabs(this.EveryDaySignContainer,node.name);
  118. // GlobalD.GameData.PlusGolden(GlobalD.GameData.signInGive[0]);
  119. // GlobalD.GameData.PlusDiamond(GlobalD.GameData.signInGive[1]);
  120. // }.bind(this))
  121. // }.bind(this));
  122. // this.initTest();
  123. },
  124. setInfo : function(string){
  125. this.info.getComponent(cc.Label).string +=string+"^_^";
  126. },
  127. showLoadDialog: function () {
  128. // this.setInfo("获取游戏的网络数据");
  129. //开局初始化的数据
  130. this.getNetworkData((res) => {
  131. cc.log('初始化数据1',res);
  132. // this.setInfo("获取成功"+res.code);
  133. //获取网络数据后处理
  134. if (res.code == 0) {
  135. //记录读取的数据到内存里面
  136. userData.readData = res.data.userdata;
  137. } else {
  138. userData.readData = null;
  139. }
  140. UtilsPrefabs
  141. .init(this.node)
  142. .addPrefabs(UtilsPrefabs.PrefabsName[3], null, function (node) {
  143. node.y = -500;
  144. var bgbar = UtilsPrefabs.getNode("bgbar", node);
  145. this.progressNode = UtilsPrefabs.getNode("progress", bgbar);
  146. // this.progressNode.getComponent(cc.ProgressBar).progress = this.progress;
  147. this.progressTag = true;
  148. }.bind(this));
  149. // cc.game.off(cc.game.EVENT_HIDE);
  150. // cc.game.off(cc.game.EVENT_SHOW);
  151. // this.setInfo("真的是去 下个页面了"+res.code);
  152. // this.Button.active = true;
  153. // return;
  154. console.log("准备开始游戏了");
  155. cc.director.loadScene('MyCityScene - 004', function () {
  156. this.progressTag = false;
  157. }.bind(this));
  158. });
  159. // cc.director.loadScene('NewScene',function () {
  160. // this.progressTag = false;
  161. //
  162. // }.bind(this));
  163. },
  164. // start() {
  165. // },
  166. // update (dt) {},
  167. getNetworkData: function (callback) {
  168. var data = [];
  169. data["openid"] = userData.openId;
  170. // data["userdata"] = JSON.stringify(datas);
  171. httpUtils.Post(httpUtils.getUserData, data, function (data) {
  172. callback(data);
  173. }.bind(this), function (data) {
  174. // console.log("失败", data);
  175. callback(data);
  176. }.bind(this));
  177. },
  178. });