BasePlatform.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import { IPlatform } from "../IPlatform";
  2. import { LiangLiangSDK } from "../libs/liangliangSDK";
  3. export class BasePlatform implements IPlatform{
  4. public openID:string;
  5. currentVersion:string="1.0.2";
  6. /**
  7. * 后台开关
  8. */
  9. config:any;
  10. /**
  11. * 广告与互推
  12. */
  13. adConfig:any;
  14. constructor()
  15. {
  16. }
  17. /**
  18. * 登录
  19. * @param success 成功
  20. * @param failure 失败
  21. */
  22. login(success:Function,failure:Function):void{
  23. LiangLiangSDK.Init(success,failure);
  24. }
  25. /**
  26. * 登录成功钩子,子类重写来做一些其他事情
  27. */
  28. protected __loginSuccess():void{
  29. }
  30. /**
  31. * 跳转
  32. * @param data
  33. * @param success
  34. * @param failure
  35. */
  36. navigate2Mini(data:any,success?:Function,failure?:Function):void{
  37. }
  38. /**
  39. * 分享
  40. * @param data
  41. * @param success
  42. * @param failure
  43. */
  44. shareMessage(data:any,success?:Function,failure?:Function):void{
  45. }
  46. /**
  47. * 被动分享
  48. */
  49. onShareAppMessage():void{
  50. }
  51. /**
  52. * 显示Banner
  53. * @param data
  54. */
  55. showBanner(data:any):void{
  56. }
  57. /**
  58. * 隐藏Banner
  59. */
  60. hideBanner():void{
  61. }
  62. /**
  63. * 显示激励广告
  64. * @param success
  65. * @param failure
  66. */
  67. showRewardedVideo(success?:Function,failure?:Function):void{
  68. }
  69. /**
  70. * 显示插屏广告
  71. */
  72. showInsertAd(success?:Function,failure?:Function):void{
  73. }
  74. /**
  75. * 显示原生广告
  76. */
  77. showNativeAd(success?:Function,failure?:Function):void{
  78. }
  79. /**
  80. * 打点
  81. * @param eventName
  82. * @param data
  83. */
  84. sendEvent(eventName:string,data?:any):void{
  85. }
  86. /**
  87. * 设置加载进度
  88. * @param progress
  89. */
  90. setLoadingProgress(progress:number):void{
  91. }
  92. /**
  93. * 加载完成
  94. * @param completeHandler
  95. */
  96. loadingComplete(completeHandler?:Function):void{
  97. if(completeHandler){
  98. completeHandler();
  99. }
  100. }
  101. /**
  102. * 游戏互推
  103. * @param num
  104. */
  105. getRandomPageAd(num: number): any[] {
  106. return [];
  107. }
  108. protected __getRandomAd(num: number, list: any[]): any[] {
  109. if (num > list.length) {
  110. num = list.length;
  111. }
  112. let adlist: any[] = list.slice(0);
  113. let result: any[] = [];
  114. let index: number;
  115. let adData: any;
  116. while (result.length < num) {
  117. index = Math.floor(Math.random() * adlist.length);
  118. adData = adlist[index];
  119. if (result.indexOf(adData) < 0) {
  120. result.push(adData);
  121. }
  122. }
  123. return result;
  124. }
  125. /**
  126. * 是否显示互导
  127. */
  128. get canJump():boolean{
  129. return this.zs_jump_switch==1?true:false;
  130. }
  131. /**
  132. * 配置的版本号与当前版本一致时,则下方开关对当前版本生效;配置的版本号和当前版本不一致时,则当前版本默认所有开关均关闭。
  133. */
  134. get zs_version():string{
  135. return this.config.zs_version;
  136. }
  137. /**
  138. * 配置为0时,则不展示接入此开关的导出;配置为1时,接入此开关的导出位置正常展示
  139. */
  140. get zs_jump_switch():number{
  141. if(this.currentVersion!=this.config.zs_version){
  142. return 0;
  143. }
  144. return this.config.zs_jump_switch;
  145. }
  146. /**
  147. * 配置为0时,则文字直接展示在上移后的位置/文字不延时;配置为1时,则文字上移/延时
  148. */
  149. get zs_switch():number{
  150. if(this.currentVersion!=this.config.zs_version){
  151. return 0;
  152. }
  153. return this.config.zs_switch;
  154. }
  155. /**
  156. * 配置为0时,则不展示接入此开关的导出;配置为1时,接入此开关的导出位置正常展示
  157. */
  158. get zs_full_screen_jump():number{
  159. if(this.currentVersion!=this.config.zs_version){
  160. return 0;
  161. }
  162. return this.config.zs_full_screen_jump;
  163. }
  164. /**
  165. * 按钮延迟时间
  166. */
  167. get zs_button_delay_time():number{
  168. if(this.currentVersion!=this.config.zs_version){
  169. return 0;
  170. }
  171. return this.config.zs_button_delay_time;
  172. }
  173. /**
  174. * 配置为0时,下方按钮为“点击跳过”,点击此按钮可直接关闭当前插屏式原生;配置为1时,下方按钮文字调用官方接口,点击此按钮跳转广告。(无论开关什么状态,点击插屏式原生左上角的关闭按钮均可关闭当前插屏式原生,点击广告图片均可以跳转至广告,示例发群里)
  175. */
  176. get zs_native_click_switch():number{
  177. if(this.currentVersion!=this.config.zs_version){
  178. return 0;
  179. }
  180. return this.config.zs_native_click_switch;
  181. }
  182. get zs_banner_show_time():number{
  183. return this.config.zs_banner_show_time;
  184. }
  185. /**
  186. * 延迟时间
  187. */
  188. get delayTime():number{
  189. return 2000;
  190. }
  191. /**
  192. * 是否显示原生和插屏广告
  193. */
  194. get showNativa():number{
  195. if(this.currentVersion!=this.config.zs_version){
  196. return 0;
  197. }
  198. return 1;
  199. }
  200. /**
  201. * 可显示次数
  202. */
  203. get zs_click_award_num():number{
  204. if(this.currentVersion!=this.config.zs_version){
  205. return 0;
  206. }
  207. let value:number=Number(this.config.zs_click_award_num);
  208. if(isNaN(value)){
  209. return 0;
  210. }else{
  211. if(value!=0){
  212. return value;
  213. }
  214. }
  215. return 0;
  216. }
  217. /**
  218. * 进度条上涨百分比
  219. */
  220. get zs_click_award_add():number{
  221. return this.config.zs_click_award_add;
  222. }
  223. /**
  224. * 进度条不点下降百分比
  225. */
  226. get zs_click_award_back():number{
  227. return this.config.zs_click_award_back;
  228. }
  229. /**
  230. * 砸金蛋区间
  231. */
  232. get zs_click_award_percent():number[]{
  233. let percent:number[] = [];
  234. let str:string = this.config.zs_click_award_percent;
  235. str = str.replace("[", "");
  236. str = str.replace("]", "");
  237. let items:string[] = str.split(",");
  238. for(let i:number = 0; i < items.length; i++){
  239. percent.push(Number(items[i]));
  240. }
  241. return percent;
  242. }
  243. }