WarnTipData.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import JsbSystem from "../../../mk/system/JsbSystem";
  2. const { ccclass } = cc._decorator;
  3. @ccclass
  4. export default class WarnTipData {
  5. //当前状态 0-无处理;1-警告;2-封广告30分钟;3-封广告12小时;4-用户拉黑
  6. curSolution = 0;
  7. tipArr = ['',
  8. '您点击广告太频繁了,请降低点击广告频率以免被封!',
  9. '您点击广告太频繁了,禁止看广告30分钟!',
  10. '您点击广告太频繁了,禁止看广告12小时!',
  11. '系统检测到您的账号存在异常,禁止登陆游戏!']
  12. /** 屏蔽广告源数组 */
  13. shutdown_ads = null;
  14. /** topon广告位数组 */
  15. AdIDArr = [];
  16. setSolution(solution) {
  17. if (this.curSolution != solution) {
  18. //除了状态0,其他状态只有级别比当前状态高才会赋值,避免异步导致低级状态覆盖高级状态
  19. if (solution == 0 || this.curSolution < solution) {
  20. this.curSolution = solution;
  21. }
  22. mk.storage.setStorage('solution', this.curSolution);
  23. }
  24. if (this.curSolution == 4) {
  25. mk.ui.openPanel('module/warnTip/WarnTipPanel');
  26. }
  27. }
  28. /** 设置屏蔽广告位 */
  29. setShutdownAds(stAds) {
  30. if (this.shutdown_ads != stAds) {
  31. this.shutdown_ads = stAds;
  32. if (this.shutdown_ads && this.shutdown_ads.length > 0) {
  33. let tempArr = this.AdIDArr.slice();
  34. let len = this.shutdown_ads.length;
  35. for (let i = 0; i < len; i++) {
  36. let adData = this.shutdown_ads[i];
  37. let index = tempArr.indexOf(adData.placementId);
  38. if (index != -1) {
  39. JsbSystem.setFilterAdSourceIdList(adData.placementId, adData.adsourceIds.join(','));
  40. console.log('屏蔽广告位:', adData.placementId + " 广告源拼接:" + adData.adsourceIds.join(','));
  41. tempArr.splice(index, 1);
  42. }
  43. else {
  44. console.error('没有对应的广告位:', adData.placementId)
  45. }
  46. }
  47. let len1 = tempArr.length;
  48. if (len1 > 0) {
  49. console.log('未屏蔽广告位拼接:', tempArr.join(','));
  50. for (let i = 0; i < len1; i++) {
  51. JsbSystem.setFilterAdSourceIdList(tempArr[i], '');
  52. }
  53. }
  54. }
  55. else {
  56. console.log('不需要屏蔽广告:', this.AdIDArr.join(','));
  57. let len2 = this.AdIDArr.length;
  58. for (let i = 0; i < len2; i++) {
  59. JsbSystem.setFilterAdSourceIdList(this.AdIDArr[i], '');
  60. }
  61. }
  62. }
  63. }
  64. async getUserShutdownAds(callback) {
  65. console.log('getUserShutdownAds ', '调用getUserShutdownAds ');
  66. let data = {}
  67. let response = await mk.http.sendData('getUserShutdownAds', data)
  68. if (response && response.errcode == 0) {
  69. mk.console.logSingle('getUserShutdownAds ', response);
  70. if (response.data) {
  71. gData.warnTipData.setShutdownAds(response.data.shutdown_ads);
  72. }
  73. callback();
  74. }
  75. else {
  76. mk.console.logSingle('getUserShutdownAds 无返回 ', response);
  77. }
  78. }
  79. }