App.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {
  2. computed,
  3. defineComponent,
  4. onMounted,
  5. ref,
  6. onBeforeUnmount
  7. } from 'vue';
  8. import { NConfigProvider, zhCN, dateZhCN, NModal } from 'naive-ui';
  9. import { AppProvider } from './components/Application';
  10. import { RouterView } from 'vue-router';
  11. import setting from './settings/designSetting';
  12. import { lighten } from './utils';
  13. import RouterError from './components/RouterError';
  14. import { tryOnUnmounted } from '@vueuse/core';
  15. export default defineComponent({
  16. name: 'App',
  17. setup() {
  18. const isIOSChrome = ref();
  19. const getThemeOverrides = computed(() => {
  20. const appTheme = setting.appTheme;
  21. const lightenStr = lighten(setting.appTheme, 6);
  22. return {
  23. common: {
  24. primaryColor: appTheme,
  25. primaryColorHover: lightenStr,
  26. primaryColorPressed: lightenStr
  27. },
  28. LoadingBar: {
  29. colorLoading: appTheme
  30. }
  31. };
  32. });
  33. // const showModal = ref(false);
  34. const showModalMsg = ref('');
  35. // 判断浏览器
  36. // 是否是360
  37. const check360 = () => {
  38. const result = false;
  39. for (const key in navigator.plugins) {
  40. // np-mswmp.dll只在360浏览器下存在
  41. if (navigator.plugins[key].filename == 'internal-nacl-plugin') {
  42. return !result;
  43. }
  44. }
  45. return result;
  46. };
  47. //
  48. const isChrome = () => {
  49. const isChromium = window.chrome,
  50. winNav = window.navigator,
  51. vendorName = winNav.vendor,
  52. isOpera = winNav.userAgent.indexOf('OPR') > -1,
  53. isIEedge = winNav.userAgent.indexOf('Edge') > -1,
  54. isIOSChrome = winNav.userAgent.match('CriOS'),
  55. // QQ
  56. isQQBriwser =
  57. winNav.userAgent.indexOf('QQBrowser') > -1 ||
  58. winNav.userAgent.indexOf('QQ') > -1,
  59. // 搜狗
  60. isSouggou =
  61. winNav.userAgent.indexOf('se 2.x') > -1 ||
  62. winNav.userAgent.indexOf('MetaSr') > -1,
  63. // 360
  64. is360 = check360() && winNav.userAgent.indexOf('Safari') > -1,
  65. // 遨游
  66. isMaxthon = winNav.userAgent.indexOf('Maxthon') > -1,
  67. // 是否为2345浏览器
  68. is2345Explorer = winNav.userAgent.includes('2345Explorer'),
  69. // 世界之窗
  70. isTheWorld = winNav.userAgent.indexOf('TheWorld') > -1,
  71. // 猎豹
  72. isLiebao = winNav.userAgent.indexOf('LBBROWSER') > -1;
  73. console.log(isQQBriwser, isSouggou, is360, isMaxthon, is2345Explorer, isTheWorld, isLiebao)
  74. if (isIOSChrome) {
  75. return true;
  76. } else if (
  77. isChromium !== null &&
  78. typeof isChromium !== 'undefined' &&
  79. vendorName === 'Google Inc.' &&
  80. isOpera === false &&
  81. isIEedge === false &&
  82. isQQBriwser === false &&
  83. isSouggou === false &&
  84. is360 === false &&
  85. isMaxthon === false &&
  86. is2345Explorer === false &&
  87. isTheWorld === false &&
  88. isLiebao === false
  89. ) {
  90. return true;
  91. } else {
  92. return false;
  93. }
  94. };
  95. // 获取谷歌版本
  96. const getChromeVersion = () => {
  97. const arr = navigator.userAgent.split(' ');
  98. let chromeVersion = '' as any;
  99. for (let i = 0; i < arr.length; i++) {
  100. if (/chrome/i.test(arr[i])) chromeVersion = arr[i];
  101. }
  102. if (chromeVersion) {
  103. return Number(chromeVersion.split('/')[1].split('.')[0]);
  104. } else {
  105. return false;
  106. }
  107. };
  108. const isChromeFlag = isChrome();
  109. console.log('isChromeFlag', isChromeFlag);
  110. if (isChromeFlag) {
  111. const chromeVersion = getChromeVersion();
  112. if (!chromeVersion || (chromeVersion && chromeVersion < 100)) {
  113. showModalMsg.value =
  114. '您当前的chrome版本过低,为了保证您的用户体验请升级后使用';
  115. // showModal.value = true;
  116. }
  117. // if (chromeVersion) {
  118. // return Number(chromeVersion.split('/')[1].split('.')[0]);
  119. // } else {
  120. // return false;
  121. // }
  122. } else {
  123. showModalMsg.value = '为了保证您的用户体验,请使用chrome打开,点击确定下载';
  124. // showModal.value = true;
  125. console.log('---');
  126. }
  127. const submitCallback = () => {
  128. window.open('https://www.google.cn/intl/zh-CN/chrome/');
  129. };
  130. return () => (
  131. <>
  132. <NConfigProvider
  133. locale={zhCN}
  134. themeOverrides={getThemeOverrides.value}
  135. // :theme="getDarkTheme"
  136. // :theme-overrides="getThemeOverrides"
  137. dateLocale={dateZhCN}>
  138. <AppProvider>
  139. <RouterView />
  140. <RouterError />
  141. </AppProvider>
  142. </NConfigProvider>
  143. {/* <NModal
  144. show={showModal.value}
  145. closeOnEsc={false}
  146. closable={false}
  147. maskClosable={false}
  148. preset="dialog"
  149. title="确认"
  150. content={showModalMsg.value}
  151. positive-text="确认"
  152. onPositiveClick={submitCallback}></NModal> */}
  153. </>
  154. );
  155. }
  156. });