view_launch.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import { _decorator, Button, Component, Label, Node, ProgressBar, sys } from 'cc';
  2. import { http } from '../http/http';
  3. import { config } from '../config';
  4. import { gameManager } from '../gameManager';
  5. import { ClientEvent } from '../framework/clientEvent';
  6. import { StorageManager } from '../framework/storageManager';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('launch_view')
  9. export class launch_view extends Component {
  10. @property(Node) progress;
  11. @property(Node) lab_progress;
  12. private isStop = false;
  13. private PageList = [null,1,1,1];
  14. start() {
  15. this.progress.getComponent(ProgressBar).progress = 0;
  16. // this.Interval_id=setInterval(this.setupLoading.bind(this),200);
  17. this.schedule(this.setupLoading,0.05)
  18. }
  19. setupLoading(){
  20. let self = this;
  21. let progress_number = Math.floor(this.progress.getComponent(ProgressBar).progress *100);
  22. if(self.isStop){
  23. return;
  24. }
  25. if(progress_number==10){
  26. self.isStop = true;
  27. http.get(config.static_url.category,(err,data)=>{
  28. if(!err){
  29. self.isStop = false;
  30. let _data = JSON.parse(data);
  31. if(_data.code==config.MSG_CODE.SUCCESS){
  32. gameManager.set_server_play_list_data( _data.content);
  33. }
  34. }
  35. })
  36. }
  37. if(progress_number==20){
  38. this.isStop = true;
  39. let login_call_back = ()=>{
  40. http.post(config.api_url.login,formData,(err,data)=>{
  41. if(!err){
  42. let _data = JSON.parse(data);
  43. // console.log("config.api_url.login",data)
  44. if(_data.code==config.MSG_CODE.SUCCESS){
  45. gameManager.set_server_user_data(_data.content)
  46. this.isStop = false;
  47. }
  48. return
  49. }
  50. })
  51. }
  52. let formData = null;
  53. let user_id =gameManager.getUserId();
  54. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
  55. if(user_id==""||user_id==null||user_id==undefined){
  56. console.log("本地没有数据")
  57. tt.login({
  58. force: true,
  59. success(res) {
  60. let code = res.code;
  61. let anonymousCode = res.anonymousCode;
  62. console.log(`login 调用成功${res.code} ${res.anonymousCode}`);
  63. // console.log("code==",code);
  64. // console.log("anonymousCode==",anonymousCode);
  65. http.post(config.api_url.get_open_id,{"code":code,"anonymous_code":anonymousCode},(err,data)=>{
  66. if(!err){
  67. let _data = JSON.parse(data);
  68. if(_data.code==config.MSG_CODE.SUCCESS){
  69. gameManager.setUserId( _data.content.openid)
  70. // StorageManager.instance.setUserId(_data.content.openid);
  71. formData = {"openid":gameManager.getUserId(),"avatarUrl": ""}
  72. login_call_back();
  73. // console.log("_data.content.data.openid",_data.content.openid)
  74. }
  75. return
  76. }
  77. })
  78. },
  79. fail(res) {
  80. console.log(`login 调用失败`);
  81. },
  82. });
  83. }else{
  84. console.log("本地有数据")
  85. formData = {"openid":gameManager.getUserId(),"avatarUrl": ""}
  86. login_call_back();
  87. }
  88. }else{
  89. formData = new FormData();
  90. formData.append("openid", "123");
  91. formData.append("avatarUrl", "");
  92. login_call_back();
  93. }
  94. }
  95. if(progress_number===30){
  96. if(gameManager.userInfo.unlock_levels==""){
  97. gameManager.init_unlock_levels();
  98. this.isStop = true;
  99. let form_Data = null;
  100. if(sys.platform==sys.Platform.BYTEDANCE_MINI_GAME){
  101. form_Data = {"coin": gameManager.userInfo.coin+"","unlock_levels": gameManager.get_unlock_levels()}
  102. }else{
  103. form_Data = new FormData();
  104. form_Data.append("coin", gameManager.userInfo.coin+"");
  105. form_Data.append("unlock_levels", gameManager.get_unlock_levels());
  106. }
  107. http.post(config.api_url.sync_data,form_Data,(_err,c_data)=>{
  108. console.log("c__data _err:",_err)
  109. if(!_err){
  110. let c__data = JSON.parse(c_data);
  111. console.log("c__data",c__data)
  112. if(c__data.code==config.MSG_CODE.SUCCESS){
  113. this.isStop = false;
  114. }
  115. }
  116. })
  117. }else{
  118. gameManager.update_unlock_levels()
  119. }
  120. }
  121. if(progress_number==40){
  122. // this.isStop = true;
  123. // let all = 0;
  124. // const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE);
  125. // let item = gameManager.get_cur_level_by_categoryid(element.id);
  126. // let key = `${element.id}_${item.level}`;
  127. // let str = StorageManager.instance.getGlobalData(key);
  128. // if(str===""||str===undefined||str===null){
  129. // all++;
  130. // gameManager.loadLevelImg(element.id,item.level,()=>{
  131. // this.isStop = false;
  132. // })
  133. // }
  134. // if(all===0){
  135. // this.isStop = false;
  136. // }
  137. // gameManager.loadLevelImg(element.id,item.level,()=>{
  138. // this.isStop = false;
  139. // })
  140. }
  141. if(progress_number==50){
  142. this.isStop = true;
  143. let all = 0;
  144. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG);
  145. let item = gameManager.get_cur_level_by_categoryid(element.id);
  146. // let key = `${element.id}_${item.level}`;
  147. // let str = StorageManager.instance.getGlobalData(key);
  148. // if(str===""||str===undefined||str===null){
  149. // all++;
  150. // gameManager.loadLevelImg(element.id,item.level,()=>{
  151. // this.isStop = false;
  152. // })
  153. // }
  154. // if(all===0){
  155. // this.isStop = false;
  156. // }
  157. gameManager.loadLevelImg(element.id,item.level,()=>{
  158. this.isStop = false;
  159. })
  160. }
  161. if(progress_number==60){
  162. this.isStop = true;
  163. let all = 0;
  164. const element = gameManager.get_play_list_item_by_categoryid(config.PLAY_TYPE.YI_QI_ZHAO_CHA);
  165. let item = gameManager.get_cur_level_by_categoryid(element.id);
  166. // let key = `${element.id}_${item.level}`;
  167. // let str = StorageManager.instance.getGlobalData(key);
  168. // if(str===""||str===undefined||str===null){
  169. // all++;
  170. // gameManager.loadLevelImg(element.id,item.level,()=>{
  171. // this.isStop = false;
  172. // })
  173. // }
  174. // if(all===0){
  175. // this.isStop = false;
  176. // }
  177. gameManager.loadLevelImg(element.id,item.level,()=>{
  178. this.isStop = false;
  179. })
  180. }
  181. if(progress_number==70){
  182. this.isStop = true;
  183. let call = ()=>{
  184. this.isStop = false;
  185. }
  186. gameManager.loadSysMusic(call);
  187. }
  188. if(progress_number==75){
  189. this.isStop = true;
  190. let call = ()=>{
  191. this.isStop = false;
  192. }
  193. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.YI_QI_ZHAO_CHA,call);
  194. }
  195. if(progress_number==80){
  196. self.isStop = true;
  197. http.get(config.static_url.user_test,(err,data)=>{
  198. if(!err){
  199. self.isStop = false;
  200. let _data = JSON.parse(data);
  201. if(_data.code==config.MSG_CODE.SUCCESS){
  202. gameManager.init_test_user_list( _data.content);
  203. }
  204. }
  205. })
  206. }
  207. if(progress_number==85){
  208. this.isStop = true;
  209. let call = ()=>{
  210. this.isStop = false;
  211. }
  212. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.MEI_NV_ZHAO_XI_JIE,call);
  213. }
  214. if(progress_number==85){
  215. this.isStop = true;
  216. let call = ()=>{
  217. this.isStop = false;
  218. }
  219. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.HAN_ZI_ZHAO_BU_TONG,call);
  220. }
  221. if(progress_number==90){
  222. this.isStop = true;
  223. let call = ()=>{
  224. this.isStop = false;
  225. }
  226. gameManager.loadPlayMusicByCategoryId(config.PLAY_TYPE.YI_QI_ZHAO_CHA,call);
  227. }
  228. if(progress_number>=100){
  229. this.finishLoading();
  230. this.unschedule(this.setupLoading)
  231. progress_number = 100;
  232. gameManager.isFinishLoad = true;
  233. }
  234. this.lab_progress.getComponent(Label).string = `加载中... ${progress_number} %`;
  235. this.progress.getComponent(ProgressBar).progress += 0.025;
  236. }
  237. finishLoading(){
  238. console.log("finish");
  239. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_BACK_HOME_VIEW);
  240. ClientEvent.dispatchEvent(config.EVENT_MSG.ON_CHANGE_COIN_NUMBER);
  241. this.node.removeFromParent();
  242. }
  243. }