channel.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * 应用商店渠道检测工具
  3. */
  4. // 应用商店渠道配置
  5. const STORE_CONFIG = {
  6. vivo: {
  7. channel: 'vivo',
  8. name: 'VIVO',
  9. package: 'com.vivo.appstore'
  10. },
  11. oppo: {
  12. channel: 'oppo',
  13. name: 'OPPO',
  14. package: 'com.oppo.market'
  15. },
  16. huawei: {
  17. channel: 'huawei',
  18. name: '华为应用商店',
  19. package: 'com.huawei.appmarket'
  20. },
  21. honor: {
  22. channel: 'honor',
  23. name: '荣耀',
  24. package: 'com.hihonor.appmarket'
  25. },
  26. yyb: {
  27. channel: 'yyb',
  28. name: '应用宝',
  29. package: 'com.tencent.android.qqdownloader'
  30. },
  31. xiaomi: {
  32. channel: 'xiaomi',
  33. name: '小米应用商店',
  34. package: 'com.xiaomi.market'
  35. },
  36. appstore: {
  37. channel: 'appstore',
  38. name: 'App Store',
  39. package: 'com.apple.AppStore'
  40. },
  41. none: {
  42. channel: 'none',
  43. name: '无',
  44. package: ''
  45. },
  46. googleplay: {
  47. channel: 'googleplay',
  48. name: 'Google Play(AAB)',
  49. package: 'com.android.vending'
  50. },
  51. wandoujia: {
  52. channel: 'wandoujia',
  53. name: '豌豆荚',
  54. package: 'com.wandoujia.phoenix2'
  55. },
  56. shichangbu: {
  57. channel: 'shichangbu',
  58. name: '市场部',
  59. package: ''
  60. },
  61. _360: {
  62. channel: '360',
  63. name: '360应用市场',
  64. package: 'com.qihoo.appstore'
  65. },
  66. default: {
  67. channel: 'default',
  68. name: '默认渠道',
  69. package: ''
  70. }
  71. };
  72. // 获取当前应用商店信息
  73. export function getCurrentStore() {
  74. let store = STORE_CONFIG.default;
  75. // #ifdef APP-PLUS
  76. const systemInfo = uni.getSystemInfoSync();
  77. if (systemInfo.platform === 'ios') {
  78. store = STORE_CONFIG.appstore;
  79. } else {
  80. const channel = plus.runtime.channel;
  81. if (channel && STORE_CONFIG[channel]) {
  82. store = STORE_CONFIG[channel];
  83. }
  84. }
  85. // #endif
  86. return store;
  87. }
  88. // 获取当前应用商店名称
  89. export function getCurrentStoreName() {
  90. return getCurrentStore().name;
  91. }
  92. // 判断是否为特定应用商店
  93. export function isStore(targetStore) {
  94. return getCurrentStore().channel === targetStore;
  95. }
  96. // 判断是否为应用商店渠道
  97. export function isAppStore() {
  98. const currentStore = getCurrentStore();
  99. return currentStore.channel !== 'default';
  100. }
  101. export default {
  102. getCurrentStore,
  103. getCurrentStoreName,
  104. isStore,
  105. isAppStore
  106. };