platform.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /** 枚举EPlatform */
  2. enum EPlatform {
  3. /** App */
  4. AppPlus = 'APP-PLUS',
  5. /** App nvue */
  6. AppPlusNvue = 'APP-PLUS-NVUE',
  7. /** H5 */
  8. H5 = 'H5',
  9. /** 微信小程序 */
  10. MpWeixin = 'MP-WEIXIN',
  11. /** 支付宝小程序 */
  12. MpAlipay = 'MP-ALIPAY',
  13. /** 百度小程序 */
  14. MpBaidu = 'MP-BAIDU',
  15. /** 字节跳动小程序 */
  16. MpToutiao = 'MP-TOUTIAO',
  17. /** QQ小程序 */
  18. MpQq = 'MP-QQ',
  19. /** 360小程序 */
  20. Mp360 = 'MP-360',
  21. /** 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/QQ小程序/360小程序 */
  22. Mp = 'MP',
  23. /** 快应用通用(包含联盟、华为) */
  24. QuickappWebview = 'quickapp-webview',
  25. /** 快应用联盟 */
  26. QuickappWebviewUnion = 'quickapp-webview-union',
  27. /** 快应用华为 */
  28. QuickappWebviewHuawei = 'quickapp-webview-huawei'
  29. }
  30. /** 使用条件编译获取平台信息 */
  31. function ifDefPlatform(): EPlatform {
  32. let platform: EPlatform;
  33. // #ifdef APP-PLUS
  34. platform = EPlatform.AppPlus;
  35. // #endif
  36. // #ifdef APP-PLUS-NVUE
  37. platform = EPlatform.AppPlusNvue;
  38. // #endif
  39. // #ifdef H5
  40. platform = EPlatform.H5;
  41. // #endif
  42. // #ifdef MP-WEIXIN
  43. platform = EPlatform.MpWeixin;
  44. // #endif
  45. // #ifdef MP-ALIPAY
  46. platform = EPlatform.MpAlipay;
  47. // #endif
  48. // #ifdef MP-BAIDU
  49. platform = EPlatform.MpBaidu;
  50. // #endif
  51. // #ifdef MP-TOUTIAO
  52. platform = EPlatform.MpToutiao;
  53. // #endif
  54. // #ifdef MP-QQ
  55. platform = EPlatform.MpQq;
  56. // #endif
  57. // #ifdef MP-360
  58. platform = EPlatform.Mp360;
  59. // #endif
  60. // #ifdef MP
  61. platform = EPlatform.Mp;
  62. // #endif
  63. // #ifdef quickapp-webview
  64. platform = EPlatform.QuickappWebview;
  65. // #endif
  66. // #ifdef quickapp-webview-union
  67. platform = EPlatform.QuickappWebviewUnion;
  68. // #endif
  69. // #ifdef quickapp-webview-huawei
  70. platform = EPlatform.QuickappWebviewHuawei;
  71. // #endif
  72. return platform;
  73. }
  74. /** 平台类型 */
  75. export const platform: EPlatform = ifDefPlatform();
  76. /** H5 */
  77. export const isH5 = platform === EPlatform.H5;
  78. /** 微信小程序 */
  79. export const isMpWeixin = platform === EPlatform.MpWeixin;
  80. /** 支付宝小程序 */
  81. export const isMpAlipay = platform === EPlatform.MpAlipay;
  82. /** 百度小程序 */
  83. export const isMpBaidu = platform === EPlatform.MpBaidu;
  84. /** 字节跳动小程序 */
  85. export const isMpToutiao = platform === EPlatform.MpToutiao;
  86. /** QQ小程序 */
  87. export const isMpQq = platform === EPlatform.MpQq;
  88. /** 360小程序 */
  89. export const isMp360 = platform === EPlatform.Mp360;
  90. /** 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/QQ小程序/360小程序 */
  91. export const isMp = platform === EPlatform.Mp;
  92. /** 快应用通用(包含联盟、华为) */
  93. export const isQuickappWebview = platform === EPlatform.QuickappWebview;
  94. /** 快应用联盟 */
  95. export const isQuickappWebviewUnion =
  96. platform === EPlatform.QuickappWebviewUnion;
  97. /** 快应用华为 */
  98. export const isQuickappWebviewHuawei =
  99. platform === EPlatform.QuickappWebviewHuawei;