GuideToWxData.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import Util from "../../../before/util/Util";
  2. /** 引导到微信数据类 */
  3. const { ccclass } = cc._decorator;
  4. @ccclass
  5. export default class GuideToWxData {
  6. //开关
  7. public guideToWxSwith = false;
  8. public guideState: GuideState = GuideState.none;
  9. public money = '';
  10. public ghId = '';
  11. public ghIdPath = '';
  12. public init_state = false;
  13. checkPop() {
  14. if (!this.guideToWxSwith) {
  15. return;
  16. }
  17. if (this.guideState < GuideState.gotMoney) {
  18. mk.ui.openPanel('module/guideToWx/guideToWx');
  19. }
  20. }
  21. setGhId() {
  22. let arr = gData.gameData.configs.ServerConfig.ghId.split(';');
  23. let localId = mk.storage.getStorage('ghId');
  24. let len = arr.length;
  25. let ghArr = null;
  26. if (!localId) {
  27. let index = Util.rnd(0, len - 1);
  28. ghArr = arr[index].split(',');
  29. gData.guideToWxData.ghId = ghArr[0];
  30. gData.guideToWxData.ghIdPath = ghArr[1];
  31. mk.storage.setStorage('ghId', gData.guideToWxData.ghId);
  32. }
  33. else {
  34. let has = false;
  35. for (let i = 0; i < len; i++) {
  36. ghArr = arr[i].split(',');
  37. if (ghArr[0] == localId) {
  38. gData.guideToWxData.ghId = ghArr[0];
  39. gData.guideToWxData.ghIdPath = ghArr[1];
  40. has = true;
  41. break;
  42. }
  43. }
  44. if (!has) {
  45. let index = Util.rnd(0, len - 1);
  46. ghArr = arr[index].split(',');
  47. gData.guideToWxData.ghId = ghArr[0];
  48. gData.guideToWxData.ghIdPath = ghArr[1];
  49. mk.storage.setStorage('ghId', gData.guideToWxData.ghId);
  50. }
  51. }
  52. }
  53. }
  54. export enum GuideState {
  55. none = 0,
  56. addService,
  57. sendApply,
  58. waitForPass,
  59. canGetMoney,
  60. gotMoney
  61. }