aamin 1 год назад
Родитель
Сommit
1d20a8665a
1 измененных файлов с 43 добавлено и 28 удалено
  1. 43 28
      src/main.js

+ 43 - 28
src/main.js

@@ -65,45 +65,60 @@ const userAgent = navigator.userAgent
 // } else {
 //   window.location.href = './mobile.html'
 // }
-
-
-// 检测是否为移动设备
-const isMobile = /Mobi|Android/i.test(userAgent)
-
-// 检测是否为平板设备
-const isTablet = /iPad|Tablet|Kindle|Silk|Galaxy Tab|Nexus 7|Mi Pad|Redmi Pad |MediaPad/i.test(userAgent)
-
-function isIPad(userAgent) {
-  const userAgentLowerCase = userAgent.toLowerCase()
-  return (
-    userAgentLowerCase.includes('IPad') ||
-    (userAgentLowerCase.includes('Macintosh') &&
-      userAgentLowerCase.includes('Mac OS X') &&
-      !userAgentLowerCase.includes('IPhone') &&
-      !userAgentLowerCase.includes('IPod'))
-  )
-}
-
-if (!(isTablet || isMobile || isIPad)) {
-  // console.log('isMobile: ', isMobile)
+// alert(userAgent)
+
+if (
+  uaInfo.device.type === 'mobile' ||
+  (uaInfo.browser.name === 'Edge' && uaInfo.os.name === 'Linux' && window.innerWidth < 1024 ) || // 尽量判断出移动端edge
+  /Mobi|Android|iPhone|SymbianOS|Windows Phone|iPad|iPod|MIUI|Mi Pad|Redmi Pad|Macintosh/i.test(navigator.userAgent)
+) {
+  // app.provide('$isMobile', true)
+  // window.location.assign(process.env.VUE_APP_MOBILE_URL)
+} else {
   const appDom = document.getElementById('app')
   appDom.style.maxWidth = '100%'
   window.location.assign(process.env.VUE_APP_PC_URL)
-} else {
-  // console.log('!isMobile: ', !isMobile)
-  // const appDom = document.getElementById('app')
-  // appDom.style.maxWidth = '100%'
-  // window.location.assign(process.env.VUE_APP_PC_URL)
 }
 
-// if (/Mobi|Android/i.test(navigator.userAgent)) {
 
-// } else {
+
+// // 检测是否为移动设备
+// const isMobile = /Mobi|Android/i.test(userAgent)
+
+// // 检测是否为平板设备
+// const isTablet = /iPad|Tablet|Kindle|Silk|Galaxy Tab|Nexus 7|Mi Pad|Redmi Pad |MediaPad/i.test(userAgent)
+
+// function isIPad(userAgent) {
+//   const userAgentLowerCase = userAgent.toLowerCase()
+//   return (
+//     userAgentLowerCase.includes('IPad') ||
+//     (userAgentLowerCase.includes('Macintosh') &&
+//       userAgentLowerCase.includes('Mac OS X') &&
+//       !userAgentLowerCase.includes('IPhone') &&
+//       !userAgentLowerCase.includes('IPod'))
+//   )
+// }
+
+// if (!(isTablet || isMobile || isIPad)) {
+//   // console.log('isMobile: ', isMobile)
 //   const appDom = document.getElementById('app')
 //   appDom.style.maxWidth = '100%'
 //   window.location.assign(process.env.VUE_APP_PC_URL)
+// } else {
+//   // console.log('!isMobile: ', !isMobile)
+//   // const appDom = document.getElementById('app')
+//   // appDom.style.maxWidth = '100%'
+//   // window.location.assign(process.env.VUE_APP_PC_URL)
 // }
 
+// // if (/Mobi|Android/i.test(navigator.userAgent)) {
+
+// // } else {
+// //   const appDom = document.getElementById('app')
+// //   appDom.style.maxWidth = '100%'
+// //   window.location.assign(process.env.VUE_APP_PC_URL)
+// // }
+
 // 处理resize事件
 let windowWidthLast = window.innerWidth
 let windowHeightLast = window.innerHeight