loginjs.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. appNode.loginBtn = UtilsNode.getNode("logint",this.node);
  52. // console.log('准备去游戏 准备跳转到下个页面');
  53. // this.setInfo("准备加载背景");
  54. UtilsPrefabs
  55. .init(this.node)
  56. .addPrefabs(UtilsPrefabs.PrefabsName[2], null, function (node) {
  57. // this.setInfo("加载背景完成 去微信登录");
  58. // console.log('现在的都有啥',this.node);
  59. UtilsWX.wxgameLogin(function () {
  60. this.showLoadDialog();
  61. }.bind(this));
  62. // UtilsWX.wxgameLogin(function (res) {
  63. // console.log('获取玩家信息 准备跳转到下个页面',res);
  64. // // this.setInfo("获取到 用户信息"+res);
  65. // UtilsWX.wxlogin(res, function () {
  66. // // this.setInfo("访问后台登陆 游戏"+res);
  67. // UtilsWX.removeUserInfoButton();
  68. //
  69. // this.showLoadDialog();
  70. // }.bind(this), function () {
  71. // // console.log('访问自己后台服务器登录账号错误');
  72. // // this.setInfo("访问自己后台服务器登录账号错误");
  73. // }.bind(this));
  74. //
  75. //
  76. // }.bind(this))
  77. if (cc.sys.platform != cc.sys.WECHAT_GAME) {
  78. // this.setInfo("加载 dialog 准备使用本地id 登录游戏");
  79. this.showLoadDialog();
  80. }
  81. }.bind(this));
  82. // node.y = -200;
  83. //
  84. // var GivePrize = UtilsPrefabs.getNode("GivePrize",node);
  85. // //转
  86. // var Sunshine = UtilsPrefabs.getNode("Sunshine",GivePrize);
  87. // //物品
  88. // var Rewards = UtilsPrefabs.getNode("Rewards",GivePrize);
  89. // //关闭按钮
  90. // var close = UtilsPrefabs.getNode("close",node);
  91. //
  92. // Rewards.getComponent(cc.Sprite).spriteFrame = this.getNode("ItemSprite",this.TodayNode).getComponent(cc.Sprite).spriteFrame
  93. // Rewards.scale = 2;
  94. //
  95. // Sunshine.stopAllActions();
  96. // var repeat = cc.repeatForever(cc.rotateBy(5.0, 360));
  97. // Sunshine.runAction(repeat);
  98. // this.EveryDaySignView.active=false;
  99. //
  100. // UtilsPrefabs.setOn(close,function () {
  101. //
  102. //
  103. // this.ManageUI.getComponent("ManageUI").onButtonEvent_EveryDay_Close();
  104. // UtilsPrefabs.setOff(close);
  105. // UtilsPrefabs.removePrefabs(this.EveryDaySignContainer,node.name);
  106. // }.bind(this));
  107. //
  108. // UtilsPrefabs
  109. // .init(this.EveryDaySignContainer)
  110. // .addPrefabs(UtilsPrefabs.PrefabsName[0],null,function (node) {
  111. // node.y = -200;
  112. // var gosharebtn = UtilsPrefabs.getNode("gosharebtn",node);
  113. // var img1 = UtilsPrefabs.getNode("img1",node);
  114. // var NewLabel1 = UtilsPrefabs.getNode("New Label",img1);
  115. // var img2 = UtilsPrefabs.getNode("img2",node);
  116. // var NewLabel2 = UtilsPrefabs.getNode("New Label",img2);
  117. // NewLabel1.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[0];
  118. // NewLabel2.getComponent(cc.Label).string = 'x'+GlobalD.GameData.signInGive[1];
  119. //
  120. //
  121. // UtilsPrefabs.setOn(gosharebtn,function () {
  122. // console.log("点击分享按钮");
  123. // UtilsWX.sharebtn();
  124. // UtilsPrefabs.setOff(gosharebtn);
  125. // UtilsPrefabs.removePrefabs(this.EveryDaySignContainer,node.name);
  126. // GlobalD.GameData.PlusGolden(GlobalD.GameData.signInGive[0]);
  127. // GlobalD.GameData.PlusDiamond(GlobalD.GameData.signInGive[1]);
  128. // }.bind(this))
  129. // }.bind(this));
  130. // this.initTest();
  131. },
  132. setInfo : function(string){
  133. this.info.getComponent(cc.Label).string +=string+"^_^";
  134. },
  135. showLoadDialog: function () {
  136. // this.setInfo("获取游戏的网络数据");
  137. //开局初始化的数据
  138. this.getNetworkData((res) => {
  139. cc.log('初始化数据1',res);
  140. // this.setInfo("获取成功"+res.code);
  141. //获取网络数据后处理
  142. if (res.code == 0) {
  143. //记录读取的数据到内存里面
  144. userData.readData = res.data.userdata;
  145. } else {
  146. userData.readData = null;
  147. }
  148. UtilsPrefabs
  149. .init(this.node)
  150. .addPrefabs(UtilsPrefabs.PrefabsName[3], null, function (node) {
  151. node.y = -500;
  152. var bgbar = UtilsPrefabs.getNode("bgbar", node);
  153. this.progressNode = UtilsPrefabs.getNode("progress", bgbar);
  154. // this.progressNode.getComponent(cc.ProgressBar).progress = this.progress;
  155. this.progressTag = true;
  156. }.bind(this));
  157. // cc.game.off(cc.game.EVENT_HIDE);
  158. // cc.game.off(cc.game.EVENT_SHOW);
  159. // this.setInfo("真的是去 下个页面了"+res.code);
  160. // this.Button.active = true;
  161. // return;
  162. console.log("准备开始游戏了");
  163. cc.director.loadScene('MyCityScene - 004', function () {
  164. this.progressTag = false;
  165. }.bind(this));
  166. });
  167. // cc.director.loadScene('NewScene',function () {
  168. // this.progressTag = false;
  169. //
  170. // }.bind(this));
  171. },
  172. // start() {
  173. // },
  174. // update (dt) {},
  175. getNetworkData: function (callback) {
  176. var data = {
  177. openid : userData.openId
  178. };
  179. // data["userdata"] = JSON.stringify(datas);
  180. httpUtils.Post(httpUtils.getUserData, data, function (data) {
  181. callback(data);
  182. }.bind(this), function (data) {
  183. // console.log("失败", data);
  184. callback(data);
  185. }.bind(this));
  186. },
  187. });