shenchunlv 2 роки тому
батько
коміт
23c1ea1f2a
4 змінених файлів з 25 додано та 14 видалено
  1. 8 0
      layouts/default.vue
  2. 1 0
      middleware/auth.js
  3. 2 2
      nuxt.config.js
  4. 14 12
      static/js/isMobile.js

+ 8 - 0
layouts/default.vue

@@ -0,0 +1,8 @@
+<template>
+  <div>
+    <Nuxt />
+  </div>
+</template>
+
+<style> 
+</style>

+ 1 - 0
middleware/auth.js

@@ -9,6 +9,7 @@ export default function ({ isServer, req, redirect, route }) {
 // 这两个只有不同项目不同端口才用得上
 //   let pcOrigin = 'http://sincelocal.aupup.com:9003'
 //   let mobileOrigin = 'http://sincelocal.aupup.com:9004'
+// console.log('navigator',navigator)
 let isMobile = ua => {
   return !!ua.match(/AppleWebKit.*Mobile.*/)
 }

+ 2 - 2
nuxt.config.js

@@ -15,7 +15,7 @@ export default {
       { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
     ],
     script:[
-      // {src:'js/isMobile.js'}
+      {src:'js/isMobile.js'}
     ]
   },
 
@@ -52,7 +52,7 @@ export default {
   //   }
   // },
   router: {
-    middleware:'auth',
+    // middleware:'auth',
     // base: '/', //此为根目录,如果有具体目录需求按实际情况写
 
   },

+ 14 - 12
static/js/isMobile.js

@@ -1,14 +1,16 @@
-(
-  // import store from ''
-  function() {
-  console.log("判断移动端");
-  var sUserAgent = navigator.userAgent.toLowerCase();
-  if (/ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(sUserAgent)) {
-      console.log("移动端-----");
-      //跳转移动端页面
-      // window.location.href()
-      // window.location.replace("n_user");//跳转后没有后退功能 
+;(function () {
+  // 判断移动端
+  var sUserAgent = navigator.userAgent.toLowerCase()
+  if (
+    /ipad|iphone|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/.test(
+      sUserAgent
+    )
+  ) {
+    //跳转移动端页面
+    if (window.location.href.indexOf('mobile') < 0) {
+      window.location.replace('/user/m_user') //跳转后没有后退功能
+    }
   } else {
-      console.log("PC端");
+    // PC端
   }
-})();
+})()