EPlatform.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**枚举EPlatform*/
  2. export 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. export 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. /**默认导出平台类型*/
  77. export default Platform
  78. /**App*/
  79. export const isAppPlus = Platform == EPlatform.AppPlus
  80. /**App nvue*/
  81. export const isAppPlusNvue = Platform == EPlatform.AppPlusNvue
  82. /**H5*/
  83. export const isH5 = Platform == EPlatform.H5
  84. /**微信小程序*/
  85. export const isMpWeixin = Platform == EPlatform.MpWeixin
  86. /**支付宝小程序*/
  87. export const isMpAlipay = Platform == EPlatform.MpAlipay
  88. /**百度小程序*/
  89. export const isMpBaidu = Platform == EPlatform.MpBaidu
  90. /**字节跳动小程序*/
  91. export const isMpToutiao = Platform == EPlatform.MpToutiao
  92. /**QQ小程序*/
  93. export const isMpQq = Platform == EPlatform.MpQq
  94. /**360小程序*/
  95. export const isMp360 = Platform == EPlatform.Mp360
  96. /**微信小程序/支付宝小程序/百度小程序/字节跳动小程序/QQ小程序/360小程序*/
  97. export const isMp = Platform == EPlatform.Mp
  98. /**快应用通用(包含联盟、华为)*/
  99. export const isQuickappWebview = Platform == EPlatform.QuickappWebview
  100. /**快应用联盟*/
  101. export const isQuickappWebviewUnion = Platform == EPlatform.QuickappWebviewUnion
  102. /**快应用华为*/
  103. export const isQuickappWebviewHuawei = Platform == EPlatform.QuickappWebviewHuawei
  104. /**是否开发环境*/
  105. export const isDevelopment = process.env.NODE_ENV == 'development'
  106. /**是否线上环境*/
  107. export const isProduction = process.env.NODE_ENV == 'production'
  108. /**抖音小程序*/
  109. export const isMpDouyinApp = uni.getSystemInfoSync().appName == 'Douyin'
  110. /**头条小程序*/
  111. export const isMpToutiaoApp = uni.getSystemInfoSync().appName == 'Toutiao'