Sfoglia il codice sorgente

fix(static): 封装常量

lanxin 11 mesi fa
parent
commit
3abf45fe14
5 ha cambiato i file con 34 aggiunte e 22 eliminazioni
  1. 1 0
      web/.env
  2. 9 19
      web/src/App.vue
  3. 3 1
      web/src/utils/request.js
  4. 18 0
      web/src/utils/static.js
  5. 3 2
      web/src/views/tab1/index.vue

+ 1 - 0
web/.env

@@ -1,2 +1,3 @@
 VUE_APP_STATIC_DIR=static
 VUE_APP_ISBENDI=''
+

+ 9 - 19
web/src/App.vue

@@ -13,33 +13,23 @@
 <script>
 import '@/assets/style/reset.less'
 import '@/assets/style/public.less'
-import axios from '@/utils/request'
+import { isPROD, isMobile } from '@/utils/static'
 export default {
   data() {
     return {
-      baseURL: ''
+
     }
   },
   // 移动端和pc端切换
   created() {
-    console.log(axios.defaults.baseURL, 'axios.defaults.baseURL')
-    this.baseURL = axios.defaults.baseURL
     // pc代码,但是手机端进来
-    if (
-      window.navigator.userAgent.match(
-        /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
-      )
-    ) {
-      if (this.baseURL === 'http://192.168.20.245:8005/' || '') {
-        console.log(window.location.href, 'window.location.hre1f')
-        if (window.location.href.includes('webM')) return
-        window.location.href = window.location.href.replace("web", "webM")
-      }
-    } else {
-      // 移动端代码,但是pc端进来
-      if (this.baseURL === 'http://192.168.20.245:8005/' || '') {
-        console.log(window.location.href, 'window.location.hre2f')
-        window.location.href = window.location.href.replace("webM", "web")
+    if (isMobile) {
+      if (isPROD) {
+        window.location.href = window.location.href.replace("web/index.html", "webM/index.html")
+        // 记得强刷一次页面
+        // setTimeout(() => {
+        //   location.reload(true)
+        // }, 200)
       }
     }
   },

+ 3 - 1
web/src/utils/request.js

@@ -1,8 +1,10 @@
 import axios from 'axios'
+import { currentEnv } from './static'
 const service = axios.create({
   // baseURL: 'http://192.168.20.135:8005/', // 本地调试
   // baseURL: 'http://192.168.20.245:8005/', // 线上调试
-  baseURL: '', // build
+  // baseURL: '', // build
+  baseURL: currentEnv,
   timeout: 5000
 })
 // 请求拦截器

+ 18 - 0
web/src/utils/static.js

@@ -0,0 +1,18 @@
+const isDEV = process.env.NODE_ENV === 'development'
+const isPROD = process.env.NODE_ENV !== 'development'
+
+const currentEnv = isDEV ? 'http://192.168.20.245:8005/' : ''
+
+const IFrameUrl = isDEV ? 'http://192.168.20.245:8005/scene/index.html?m=1564' : '/scene/index.html?m=1564'
+
+const isMobile = window.navigator.userAgent.match(
+  /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
+)
+
+export {
+  isDEV,
+  isPROD,
+  currentEnv,
+  IFrameUrl,
+  isMobile
+}

+ 3 - 2
web/src/views/tab1/index.vue

@@ -1,18 +1,19 @@
 <!--  -->
 <template>
   <div class='tab1'>
-    <iframe :src="`/scene/index.html?m=1564`" frameborder="0"></iframe>
+    <iframe :src="IFrameUrl" frameborder="0"></iframe>
   </div>
 </template>
 
 <script>
+import { IFrameUrl } from '@/utils/static'
 export default {
   name: 'tab1',
   components: {},
   data() {
     // 这里存放数据
     return {
-
+      IFrameUrl
     }
   },
   // 监听属性 类似于data概念