Bladeren bron

支持本地化部署

任一存 2 jaren geleden
bovenliggende
commit
b66d5b2c20
7 gewijzigde bestanden met toevoegingen van 49 en 4 verwijderingen
  1. 2 1
      .env.dev
  2. 4 0
      .env.localdeploy
  3. 2 1
      .env.test
  4. 1 0
      package.json
  5. 26 0
      src/utils/other.js
  6. 7 1
      src/views/HomeMobile.vue
  7. 7 1
      src/views/HomeWeb.vue

+ 2 - 1
.env.dev

@@ -1,3 +1,4 @@
 CLI_MODE=dev
 NODE_ENV=development
-PUBLIC_PATH=/
+PUBLIC_PATH=./
+VUE_APP_G_PREFIX=https://super.4dage.com/

+ 4 - 0
.env.localdeploy

@@ -0,0 +1,4 @@
+CLI_MODE=local
+NODE_ENV=production
+VUE_APP_PUBLIC_PATH=./
+VUE_APP_G_PREFIX=http://127.0.0.1:8085/

+ 2 - 1
.env.test

@@ -1,3 +1,4 @@
 CLI_MODE=test
 NODE_ENV=production
-PUBLIC_PATH=/hotspot/
+PUBLIC_PATH=./
+VUE_APP_G_PREFIX=https://super.4dage.com/

+ 1 - 0
package.json

@@ -5,6 +5,7 @@
   "scripts": {
     "serve": "vue-cli-service serve --mode dev",
     "build-test": "vue-cli-service build --mode test",
+    "build-local-deploy": "vue-cli-service build --mode localdeploy",
     "build": "vue-cli-service build",
     "lint": "vue-cli-service lint"
   },

+ 26 - 0
src/utils/other.js

@@ -0,0 +1,26 @@
+export function deepProcess(obj, detailWork) {
+  if (obj === null || obj === undefined) {
+    return
+  }
+
+  if (Array.isArray(obj)) {
+    for (let index = 0; index < obj.length; index++) {
+      const element = obj[index]
+      if (typeof element === 'string') {
+        obj[index] = detailWork(element)
+      } else if (typeof element === 'object') {
+        deepProcess(element, detailWork)
+      }
+    }
+  } else if (typeof obj === 'object') {
+    for (const key in obj) {
+      if (Object.hasOwnProperty.call(obj, key)) {
+        if (typeof obj[key] === 'string') {
+          obj[key] = detailWork(obj[key])
+        } else if (typeof obj[key] === 'object') {
+          deepProcess(obj[key], detailWork)
+        }
+      }
+    }
+  }
+}

+ 7 - 1
src/views/HomeMobile.vue

@@ -244,6 +244,7 @@
 import Swiper from 'swiper/swiper-bundle.esm.js'
 import 'swiper/swiper-bundle.css'
 import bgImg from "@/assets/images/bg.png"
+import { deepProcess } from "@/utils/other.js"
 // import browser from "@/utils/browser";
 
 export default {
@@ -342,9 +343,14 @@ export default {
     })
   },
   methods: {
+    changeSubStr(str) {
+      return str.replace('https://super.4dage.com/', process.env.VUE_APP_G_PREFIX)
+    },
     async getData() {
-      let url = `https://super.4dage.com/data/${this.$route.query.id}/hot/js/data.js?time=${Math.random()}`
+      let url = `${process.env.VUE_APP_G_PREFIX}/data/${this.$route.query.id}/hot/js/data.js?time=${Math.random()}`
       let result = (await this.$http.get(url)).data
+      deepProcess(result, this.changeSubStr)
+
       this.hotspotData = result[this.$route.query.m]
       if (!this.hotspotData) {
         return alert("热点解析错误")

+ 7 - 1
src/views/HomeWeb.vue

@@ -248,6 +248,7 @@ import Swiper from 'swiper/swiper-bundle.esm.js'
 import 'swiper/swiper-bundle.css'
 import bgImg from "@/assets/images/bg.png"
 import titleBottomLine from "@/assets/images/title-bottom-line.png"
+import { deepProcess } from "@/utils/other.js"
 // import browser from "@/utils/browser";
 
 export default {
@@ -358,9 +359,14 @@ export default {
     }
   },
   methods: {
+    changeSubStr(str) {
+      return str.replace('https://super.4dage.com/', process.env.VUE_APP_G_PREFIX)
+    },
     async getData() {
-      let url = `https://super.4dage.com/data/${this.$route.query.id}/hot/js/data.js?time=${Math.random()}`
+      let url = `${process.env.VUE_APP_G_PREFIX}/data/${this.$route.query.id}/hot/js/data.js?time=${Math.random()}`
       let result = (await this.$http.get(url)).data
+      deepProcess(result, this.changeSubStr)
+
       this.hotspotData = result[this.$route.query.m]
       if (!this.hotspotData) {
         return alert("热点解析错误")