loading_view.ts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import { _decorator, Component, Label, Node, ProgressBar, Animation, sys } from 'cc';
  2. import { userDataManager } from '../manager/userDataManager';
  3. import { imageCacheManager } from '../manager/imageCacheManager';
  4. import { GameManager } from '../GameManager';
  5. import { SdkUtil } from '../sdkUtil';
  6. import { area_item_data, userInfo } from '../data';
  7. import { config } from '../config';
  8. import { http } from '../http';
  9. import { uiManager } from '../manager/uiManager';
  10. import { select_area } from './select_area/select_area';
  11. import { tools } from '../tools';
  12. import { loading_view_auth } from './loading_view_auth';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('loading_view')
  15. export class loading_view extends Component {
  16. @property(Node) loading_bar:Node = null
  17. @property(Node) lab_loading_bar:Node = null
  18. @property(Node) img_ride_bike:Node = null
  19. @property(Node) auth_view:Node = null
  20. private m_finish_load_call = null
  21. private m_pause_status = false
  22. startLoading(finish_load_call) {
  23. this.m_finish_load_call = finish_load_call
  24. SdkUtil.checkAuthUserInfo((is_true)=>{
  25. if(is_true) {
  26. this.loadingData()
  27. this.auth_view.active = false
  28. } else {
  29. this.auth_view.active = true
  30. this.auth_view.getComponent(loading_view_auth).initView(()=>{
  31. this.auth_view.active = false
  32. this.loadingData()
  33. })
  34. }
  35. })
  36. }
  37. private loadingData() {
  38. let progress = 0
  39. this.loading_bar.getComponent(ProgressBar).progress = progress;
  40. this.img_ride_bike.getComponent(Animation).play()
  41. this.schedule(()=>{
  42. if(this.m_pause_status){
  43. return;
  44. }
  45. progress += 0.1
  46. progress = parseFloat(progress.toFixed(1))
  47. // console.log('progress=',progress)
  48. this.loading_bar.getComponent(ProgressBar).progress = progress
  49. this.lab_loading_bar.getComponent(Label).string = `${(progress*100).toFixed()}%`
  50. switch (progress) {
  51. case 0.1:
  52. this.m_pause_status = true
  53. this.initUserData(()=>{
  54. if(userDataManager.user_data.region_id<=0) {
  55. this.setUserSelectArea()
  56. } else {
  57. this.m_pause_status = false
  58. }
  59. GameManager.openWebScoket()
  60. })
  61. break
  62. case 0.2:
  63. this.m_pause_status = true
  64. this.initSysConfig(()=>{
  65. this.m_pause_status = false
  66. })
  67. break
  68. case 0.3:
  69. this.m_pause_status = true
  70. this.initMineRank(()=>{
  71. this.m_pause_status = false
  72. })
  73. break
  74. case 0.4:
  75. this.m_pause_status = true
  76. this.initUserCarList(()=>{
  77. this.m_pause_status = false
  78. })
  79. break
  80. case 0.5:
  81. this.m_pause_status = true
  82. this.initLevels(()=>{
  83. this.m_pause_status = false
  84. })
  85. break
  86. case 0.6:
  87. this.m_pause_status = true
  88. this.initAllCarList(()=>{
  89. this.m_pause_status = false
  90. })
  91. break
  92. case 0.7:
  93. this.m_pause_status = true
  94. imageCacheManager.start_cache(()=>{
  95. this.m_pause_status = false
  96. })
  97. break
  98. default:
  99. break;
  100. }
  101. if(progress >= 1) {
  102. if(this.m_finish_load_call!=null){
  103. this.m_finish_load_call()
  104. }
  105. this.img_ride_bike.getComponent(Animation).stop()
  106. this.node.removeFromParent()
  107. this.unscheduleAllCallbacks()
  108. return;
  109. }
  110. },0.1)
  111. }
  112. private initUserData(login_finish_cb){
  113. this.userLogin((openid)=>{
  114. // console.log('openid=',openid)
  115. SdkUtil.getUserInfo((data:userInfo)=>{
  116. let opt;
  117. let platform = GameManager.getPlatformId()
  118. if(data!=null){
  119. opt = {"openid":openid,"platform":platform,"avatarUrl":data.avatarUrl,"nickName":data.nickName}
  120. }else{
  121. opt = {"openid":openid,"platform":platform,"avatarUrl":"","nickName":"大靓仔"}
  122. }
  123. http.post(config.API.login,opt,(err,d)=>{
  124. if(!err){
  125. let nd = JSON.parse(d)
  126. if(nd.code === config.status.SUCCESS){
  127. userDataManager.user_data = nd.content
  128. console.log('用户信息=',userDataManager.user_data)
  129. GameManager.requestTTSidebarUserReward(config.USER_TT_SIDEBAR_REWARD.GET, (d_content)=>{
  130. if(d_content==null) {
  131. if(login_finish_cb!=null){ login_finish_cb() }
  132. return
  133. }
  134. userDataManager.user_data.tt_sidebar_reward_status = 0
  135. if(data!=null) {
  136. userDataManager.user_data.tt_sidebar_reward_status = d_content.status
  137. }
  138. if(login_finish_cb!=null){
  139. login_finish_cb()
  140. }
  141. })
  142. }
  143. }
  144. })
  145. })
  146. })
  147. }
  148. private userLogin(cb){
  149. SdkUtil.login((res)=>{
  150. if(res!=null){
  151. let url = config.API.get_dyopen_id //默认抖音
  152. if(sys.platform == sys.Platform.WECHAT_GAME) {
  153. if(SdkUtil.KS_GAME) {
  154. url = config.API.get_ksopen_id
  155. } else {
  156. url = config.API.get_wxopen_id
  157. }
  158. }
  159. http.post(url,res,(err,data)=>{
  160. if(!err){
  161. let d = JSON.parse(data)
  162. if(d.code === config.status.SUCCESS){
  163. cb(d.content.openid)
  164. }
  165. }
  166. })
  167. }else{
  168. cb("123")
  169. }
  170. })
  171. }
  172. private setUserSelectArea() {
  173. uiManager.Instance().showUi(config.UI.ui_select_area, this.node, (node:Node)=>{
  174. node.getComponent(select_area).initView(false, (obj:select_area, data:area_item_data)=>{
  175. GameManager.requestUserSetRegion(data.id, 1, (d_content)=>{
  176. userDataManager.user_data.region_id = d_content.region_id
  177. userDataManager.user_data.region_pid = d_content.region_pid
  178. userDataManager.user_data.province_name = d_content.province_name
  179. userDataManager.user_data.city_name = d_content.city_name
  180. userDataManager.user_data.license_code = d_content.license_code
  181. this.m_pause_status = false
  182. obj.closeSelf()
  183. })
  184. })
  185. })
  186. }
  187. private initSysConfig(cb) {
  188. http.get(config.STATIC_API.sysconfig,(err,d)=>{
  189. if(!err){
  190. let data = JSON.parse(d)
  191. if(data.code===config.status.SUCCESS){
  192. tools.sys_config = data.content
  193. // console.log('系统配置=',tools.sys_config)
  194. if(cb!=null) {
  195. cb()
  196. }
  197. }
  198. }else{
  199. console.log("initSysConfig err",err)
  200. }
  201. })
  202. }
  203. private initMineRank(cb) {
  204. GameManager.requestMineRank(0, (d_content)=>{
  205. tools.mine_rank_data = d_content
  206. if(cb!=null) {
  207. cb()
  208. }
  209. })
  210. }
  211. private initUserCarList(cb){
  212. GameManager.requestUserCarList((d_content)=>{
  213. userDataManager.user_car_list = d_content
  214. // console.log('user_car_list=',userDataManager.user_car_list)
  215. if(cb!=null) {
  216. cb()
  217. }
  218. })
  219. }
  220. private initLevels(cb) {
  221. http.get(config.STATIC_API.levels,(err,d)=>{
  222. if(!err){
  223. let data = JSON.parse(d)
  224. if(data.code===config.status.SUCCESS){
  225. tools.levels = JSON.parse(data.content.levels_info)
  226. tools.tpl_list = data.content.tpl_list
  227. tools.game_config = JSON.parse(data.content.levels_config)
  228. // console.log("tools.levels",tools.levels)
  229. // console.log("tools.tpl_list",tools.tpl_list)
  230. // console.log("tools.game_config",tools.game_config)
  231. if(cb!=null) {
  232. cb()
  233. }
  234. }
  235. }else{
  236. console.log("initLevels err",err)
  237. }
  238. })
  239. }
  240. private initAllCarList(cb) {
  241. http.get(config.STATIC_API.car_list,(err,d)=>{
  242. if(!err){
  243. let data = JSON.parse(d)
  244. if(data.code===config.status.SUCCESS){
  245. tools.all_car_list = data.content
  246. // console.log("tools.all_car_list",tools.all_car_list)
  247. let slice_size:number = 6
  248. for (let i = 0; i < tools.all_car_list.length; i += slice_size) {
  249. let group = tools.all_car_list.slice(i, i + slice_size)
  250. tools.all_car_page_list.push(group)
  251. }
  252. if(cb!=null) {
  253. cb()
  254. }
  255. }
  256. }else{
  257. console.log("init all_car_list err",err)
  258. }
  259. })
  260. }
  261. }