浏览代码

feat: checkDeviceAndRedirect

chenlei 5 月之前
父节点
当前提交
c80976fa75
共有 1 个文件被更改,包括 22 次插入0 次删除
  1. 22 0
      web/src/main.js

+ 22 - 0
web/src/main.js

@@ -5,6 +5,28 @@ import vuex from 'vuex'
 import VueChatScroll from "vue-chat-scroll";
 import 'viewerjs/dist/viewer.css'
 import Viewer from 'v-viewer'
+
+var isProduction = process.env.NODE_ENV === "production";
+isProduction && checkDeviceAndRedirect();
+
+function isMobile() {
+  const userAgent = navigator.userAgent.toLowerCase();
+  return /iphone|ipod|android|windows phone|blackberry|mobile/i.test(userAgent);
+}
+
+function checkDeviceAndRedirect() {
+  const isMobileDevice = isMobile();
+  const currentPath = window.location.pathname;
+  const isInMobilePath = currentPath.includes("/mobile/");
+  const isInPCPath = currentPath.includes("/web/");
+
+  if (isMobileDevice && !isInMobilePath) {
+    window.location.href = currentPath.replace("/web/", "/mobile/");
+  } else if (!isMobileDevice && !isInPCPath) {
+    window.location.href = currentPath.replace("/mobile/", "/web/");
+  }
+}
+
 Vue.use(Viewer,{
   defaultOptions: {
     navbar:false,