lq_platform_util.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import {LQByteDanceType, LQPlatformType} from "../data/lq_const";
  2. export class LQPlatformUtil {
  3. private static platform_type: LQPlatformType;
  4. private static byte_dance_type: LQByteDanceType;
  5. public static init() {
  6. if (typeof qq !== 'undefined') {
  7. this.platform_type = LQPlatformType.qq;
  8. } else if (typeof swan !== 'undefined') {
  9. this.platform_type = LQPlatformType.baidu;
  10. } else if (typeof tt !== 'undefined') {
  11. this.platform_type = LQPlatformType.tt;
  12. const info = tt.getSystemInfoSync();
  13. switch (info.appName) {
  14. case 'Toutiao':
  15. this.byte_dance_type = LQByteDanceType.tt;
  16. break;
  17. case 'news_article_lite':
  18. this.byte_dance_type = LQByteDanceType.tt_lite;
  19. break;
  20. case 'Douyin':
  21. this.byte_dance_type = LQByteDanceType.douyin;
  22. break;
  23. case 'douyin_lite':
  24. this.byte_dance_type = LQByteDanceType.douyin_lite;
  25. break;
  26. case 'PPX':
  27. this.byte_dance_type = LQByteDanceType.ppx;
  28. break;
  29. case 'devtools':
  30. this.byte_dance_type = LQByteDanceType.devtools;
  31. break;
  32. }
  33. } else if (typeof qg !== 'undefined') {
  34. if (!!qg.getBattle) {
  35. this.platform_type = LQPlatformType.oppo;
  36. } else {
  37. this.platform_type = LQPlatformType.vivo;
  38. }
  39. } else if (typeof wx !== 'undefined') {
  40. this.platform_type = LQPlatformType.wx;
  41. } else if (typeof jsb !== 'undefined') {
  42. if (cc.sys.os === cc.sys.OS_ANDROID) {
  43. this.platform_type = LQPlatformType.android;
  44. } else if (cc.sys.os === cc.sys.OS_IOS) {
  45. this.platform_type = LQPlatformType.ios;
  46. } else {
  47. this.platform_type = LQPlatformType.unknown;
  48. }
  49. } else if (cc.sys.isBrowser) {
  50. this.platform_type = LQPlatformType.browser;
  51. }
  52. }
  53. public static get_platform(): LQPlatformType {
  54. return this.platform_type;
  55. }
  56. public static get_byte_dance(): LQByteDanceType {
  57. return this.byte_dance_type;
  58. }
  59. public static is_wx() {
  60. return this.platform_type === LQPlatformType.wx;
  61. }
  62. public static is_tt() {
  63. return this.platform_type === LQPlatformType.tt;
  64. }
  65. public static is_oppo() {
  66. return this.platform_type === LQPlatformType.oppo;
  67. }
  68. public static is_vivo() {
  69. return this.platform_type === LQPlatformType.vivo;
  70. }
  71. public static is_ov() {
  72. return this.platform_type === LQPlatformType.oppo || this.platform_type === LQPlatformType.vivo;
  73. }
  74. public static is_browser() {
  75. return this.platform_type === LQPlatformType.browser;
  76. }
  77. public static is_android() {
  78. return this.platform_type === LQPlatformType.android;
  79. }
  80. public static is_ios() {
  81. return this.platform_type === LQPlatformType.ios;
  82. }
  83. public static is_native() {
  84. return this.platform_type === LQPlatformType.android || this.platform_type === LQPlatformType.ios;
  85. }
  86. public static is_qq() {
  87. return this.platform_type === LQPlatformType.qq;
  88. }
  89. public static is_baidu() {
  90. return this.platform_type === LQPlatformType.baidu;
  91. }
  92. public static is_kwaigame() {
  93. return this.platform_type === LQPlatformType.kwaigame;
  94. }
  95. }
  96. LQPlatformUtil.init();
  97. if (LQPlatformUtil.is_tt()) {
  98. console.log('---------当前平台:' + LQPlatformUtil.get_byte_dance());
  99. } else {
  100. console.log('---------当前平台:' + LQPlatformUtil.get_platform());
  101. }