PlatformManager.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { IPlatform } from "./IPlatform";
  2. export class PlatformManager {
  3. static impl: IPlatform;
  4. /**
  5. * 初始化
  6. * @param impl
  7. */
  8. static init(impl: IPlatform): void {
  9. this.impl = impl;
  10. }
  11. /**
  12. * 登录
  13. * @param success 成功
  14. * @param failure 失败
  15. */
  16. static login(success: Function, failure?: Function): void {
  17. this.impl.login(success, failure);
  18. }
  19. /**
  20. * 跳转
  21. * @param data
  22. * @param success
  23. * @param failure
  24. */
  25. static navigate2Mini(data: any, success?: Function, failure?: Function): void {
  26. this.impl.navigate2Mini(data, success, failure);
  27. }
  28. /**
  29. * 随机跳转
  30. * @param success
  31. * @param failure
  32. */
  33. static randomNavigate2Mini(success?: Function, failure?: Function):void{
  34. let list:any[]=this.getRandomPageAd(20);
  35. let index:number=Math.floor(Math.random()*list.length);
  36. let data:any=list[index];
  37. this.navigate2Mini(data,success,failure);
  38. }
  39. /**
  40. * 分享
  41. * @param data
  42. * @param success
  43. * @param failure
  44. */
  45. static shareMessage(data: any, success?: Function, failure?: Function): void {
  46. this.impl.shareMessage(data, success, failure);
  47. }
  48. /**
  49. * 被动分享
  50. */
  51. static onShareAppMessage(): void {
  52. this.impl.onShareAppMessage();
  53. }
  54. /**
  55. * 显示Banner
  56. * @param data
  57. */
  58. static showBanner(data?: any): void {
  59. this.impl.showBanner(data);
  60. }
  61. /**
  62. * 隐藏Banner
  63. */
  64. static hideBanner(): void {
  65. this.impl.hideBanner();
  66. }
  67. /**
  68. * 显示激励广告
  69. * @param data
  70. * @param success
  71. * @param failure
  72. */
  73. static showRewardedVideo(success?: Function, failure?: Function): void {
  74. this.impl.showRewardedVideo(success, failure);
  75. }
  76. /**
  77. * 显示插屏广告
  78. */
  79. static showInsertAd(success?: Function, failure?: Function): void {
  80. this.impl.showInsertAd(success, failure);
  81. }
  82. /**
  83. * 显示原生广告
  84. */
  85. static showNativeAd(success?: Function, failure?: Function): void {
  86. this.impl.showNativeAd(success, failure);
  87. }
  88. /**
  89. * 打点
  90. * @param eventName
  91. * @param data
  92. */
  93. static sendEvent(eventName: string, data?: any): void {
  94. this.impl.sendEvent(eventName, data);
  95. }
  96. /**
  97. * 设置加载进度
  98. * @param progress
  99. */
  100. static setLoadingProgress(progress: number): void {
  101. this.impl.setLoadingProgress(progress);
  102. }
  103. /**
  104. * 加载完成
  105. * @param completeHandler
  106. */
  107. static loadingComplete(completeHandler?: Function): void {
  108. this.impl.loadingComplete(completeHandler);
  109. }
  110. /**
  111. * 游戏互推
  112. * @param num
  113. */
  114. static getRandomPageAd(num: number): any[] {
  115. return this.impl.getRandomPageAd(num);
  116. }
  117. }