PreviewScene.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 { PopName } from "./EventName/EventName";
  8. import { SetMap, SetPreviewMap } from "./GameLogic/DataConfig";
  9. import PopManger from "./GameUI/PopManger";
  10. import HTTPS from "./Template/HTTPS";
  11. interface MapDataResponse {
  12. code: number;
  13. msg: string;
  14. data: MapData;
  15. }
  16. interface MapData {
  17. Id: string;
  18. DifficultyLevel: string;
  19. MapDataBusTypes: string;
  20. MapData: number[][]; // 二维数组
  21. MapDataRoloQueues: number[]; // 一维数组
  22. MapDataGraySitDownColor: string;
  23. MapDataCountDown: string;
  24. Status: string;
  25. }
  26. const { ccclass, property } = cc._decorator;
  27. @ccclass
  28. export default class PreviewScene extends cc.Component {
  29. onLoad() {
  30. // // 获取网址内携带的参数 账号 签名等数据
  31. let data = this.getUrlData(window.location.href);
  32. if (!data) {
  33. return
  34. }
  35. PopManger.getInstance().LoadBundle('sub').then((e) => {
  36. // 第一个 then 中的逻辑
  37. return HTTPS.Instance.get(`http://shangbansys.ranwenkeji.com/backend/site/map?PreviewID=${data.PreviewID}&PreviewType=${data.PreviewType}`);
  38. }).then((resp: MapDataResponse) => {
  39. // 第二个 then 中的逻辑
  40. // 处理 resp
  41. SetPreviewMap(resp.data)
  42. PopManger.getInstance().Pop(PopName.StartAnim, { animation: false })
  43. }).catch((error) => {
  44. // 处理可能出现的错误
  45. console.error(error);
  46. });
  47. }
  48. getUrlData(url: string): any {
  49. let arr = url.split("?");
  50. if (arr.length == 1) {
  51. return null
  52. }
  53. let arr1 = arr[1].split("&");
  54. let data = {};
  55. arr1.forEach(v => {
  56. let temp = v.split('=');
  57. if (!temp[1] || data[temp[0]]) {
  58. } else
  59. data[temp[0]] = temp[1];
  60. });
  61. return data;
  62. }
  63. }