LoadScene.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html
  7. import PopManger from "./GameUI/PopManger";
  8. import Sdk from "./SDK/SDK";
  9. import { Debug, Leave_Days } from "./Template/Const";
  10. import HTTPS, { NetGet, NetPost } from "./Template/HTTPS";
  11. import LocalData, { WorkState } from "./Template/LocalData";
  12. const { ccclass, property } = cc._decorator;
  13. @ccclass
  14. export default class LoadScene extends cc.Component {
  15. //开始按钮
  16. @property(cc.Node)
  17. StartGameNode: cc.Node = null
  18. //开始按钮
  19. @property(cc.ProgressBar)
  20. progress: cc.ProgressBar = null
  21. progressNum: number = null
  22. @property(cc.Label)
  23. launchDesc: cc.Label = null
  24. @property(cc.Node)
  25. Login: cc.Node = null
  26. start() {
  27. console.error('现在的值是');
  28. console.error(CC_DEBUG);
  29. this.Login.active = false
  30. this.StartGameNode.active = false
  31. console.time('LoadBundle');
  32. PopManger.getInstance().LoadBundle('sub').then((e) => {
  33. console.timeEnd('LoadBundle');
  34. console.time('Start');
  35. cc.director.preloadScene("Start", (curcomplete, totalcount) => {
  36. this.progress.progress = (((curcomplete / totalcount) / 2) + 0.5)
  37. this.updatelaunchDesc()
  38. }, () => {
  39. console.timeEnd('Start');
  40. if (Debug) {
  41. this.initNet('res.code')
  42. } else {
  43. //得到微信Code
  44. Sdk.getInstance().Login(res => {
  45. //微信给的数据
  46. console.error('微信给的数据');
  47. console.error(res);
  48. // res.code
  49. this.initNet(res.code)
  50. })
  51. }
  52. })
  53. })
  54. }
  55. protected update(dt: number): void {
  56. if (this.progress.progress < 0.5) {
  57. this.progress.progress += 0.01
  58. this.updatelaunchDesc()
  59. }
  60. }
  61. updatelaunchDesc() {
  62. this.launchDesc.string = `${(this.progress.progress * 100).toFixed(0)}%`;
  63. }
  64. StartGame() {
  65. cc.director.loadScene("Start")
  66. }
  67. initNet(Code: string) {
  68. console.error(111);
  69. Sdk.getInstance().getLaunchOptions()
  70. console.error(222);
  71. HTTPS.Instance.get(NetGet.Map).then((resp) => {
  72. // 初始化地图数据
  73. // SetMap(resp.Data)
  74. if (Debug) {
  75. let _openId = 152281
  76. //邀请ID
  77. let _InviterId = null
  78. return HTTPS.Instance.post(NetPost.TestLogin, {
  79. OpenId: _openId,
  80. InviterId: _InviterId ? _InviterId : null,
  81. })
  82. } else {
  83. return HTTPS.Instance.post(NetPost.Login, {
  84. Code: Code,
  85. InviterId: Sdk.getInstance().inviteID ? Sdk.getInstance().inviteID : null,
  86. })
  87. }
  88. }).then((resp) => {
  89. // 处理登录信息
  90. HTTPS.Instance.token = 'Bearer ' + resp?.Data?.SsoToken
  91. Sdk.getInstance().setOpenID(resp?.Data?.OpenId)
  92. if (resp?.Data?.Day >= Leave_Days) {
  93. LocalData.getInstance().setWorkState(WorkState.引导)
  94. } else {
  95. LocalData.getInstance().setWorkState(WorkState.上班)
  96. }
  97. return HTTPS.Instance.post(NetPost.GetUserInfo, {})
  98. }).then((resp) => {
  99. console.error('resp');
  100. console.error(resp);
  101. console.error(resp);
  102. // 处理登个人信息
  103. LocalData.getInstance().setMyWorkplaceLevel(resp?.Data?.PositionLevelId)
  104. this.Login.active = true
  105. Sdk.getInstance().getUserInfo(this.Login, (res: wx.types.UserInfo) => {
  106. //succeed
  107. this.StartGameNode.active = true
  108. this.Login.active = false
  109. // console.error('来了????');
  110. Sdk.getInstance().getFuzzyLocation().then((res: any) => {
  111. if (res.OK == true) {
  112. console.error('成功了');
  113. console.error(res.latitude);
  114. console.error(res.longitude);
  115. } else {
  116. console.error('失败了');
  117. console.error(res.latitude);
  118. console.error(res.longitude);
  119. }
  120. })
  121. HTTPS.Instance.post(NetPost.Authorisation, {
  122. OpenId: Sdk.getInstance().getOpenID(),
  123. Name: res.nickName,
  124. Tel: '',
  125. City: res.city,
  126. Picture: res.avatarUrl,
  127. })
  128. }, () => {
  129. //fail
  130. this.StartGameNode.active = true
  131. this.Login.active = false
  132. })
  133. })
  134. }
  135. }