Browse Source

ghsApp -- 修掉npm run dev:h5 时,报 extConfig is not defined 的根因

shizhongqi 2 months ago
parent
commit
826fe1c521

+ 4 - 2
ghsApp/src/admin/jc/video.vue

@@ -8,6 +8,8 @@
 </template>
 </template>
 
 
 <script>
 <script>
+import { getExtConfig } from '@/utils/extConfig'
+
 export default {
 export default {
   name: "jc",
   name: "jc",
   components: {},
   components: {},
@@ -26,7 +28,7 @@ export default {
       this.videoContext.requestFullScreen({direction: 0})
       this.videoContext.requestFullScreen({direction: 0})
     },
     },
     init(){
     init(){
-      let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
+      let extConfig = getExtConfig()
       this.videoUrl = extConfig.apiHost+'/jc/'+this.option.url
       this.videoUrl = extConfig.apiHost+'/jc/'+this.option.url
     }
     }
   },
   },
@@ -45,4 +47,4 @@ export default {
         }
         }
     }
     }
 }
 }
-</style>
+</style>

+ 3 - 10
ghsApp/src/constant/index.js

@@ -1,12 +1,5 @@
-import { ProjectName,APIHOST,IMGHOST } from '@/config'
-
-// #ifdef MP-WEIXIN
-const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
-// #endif
-
-// #ifdef APP-PLUS
-const extConfig = {apiHost:APIHOST,imgHost:IMGHOST,}
-// #endif
+import { ProjectName } from '@/config'
+import extConfig from '@/utils/extConfig'
 
 
 // 常量索引
 // 常量索引
 const envVal = {
 const envVal = {
@@ -29,4 +22,4 @@ envVal.formal = process.env.NODE_ENV == 'development' ? '/api' : `${window.locat
 envVal.hostUrl = process.env.NODE_ENV == 'development' ? '/api' : `${window.location.protocol}//api.${window.location.host}`
 envVal.hostUrl = process.env.NODE_ENV == 'development' ? '/api' : `${window.location.protocol}//api.${window.location.host}`
 // #endif
 // #endif
 
 
-export default envVal
+export default envVal

+ 24 - 0
ghsApp/src/utils/extConfig.js

@@ -0,0 +1,24 @@
+import { APIHOST, IMGHOST } from '@/config'
+import extJson from '@/ext.json'
+
+const defaultExtConfig = {
+	...(extJson.ext || {}),
+	apiHost: (extJson.ext && extJson.ext.apiHost) || APIHOST,
+	imgHost: (extJson.ext && extJson.ext.imgHost) || IMGHOST,
+	socketApiHost: (extJson.ext && extJson.ext.socketApiHost) || ''
+}
+
+export function getExtConfig() {
+	// #ifdef MP-WEIXIN
+	if (typeof wx !== 'undefined' && wx.getExtConfigSync) {
+		return {
+			...defaultExtConfig,
+			...wx.getExtConfigSync()
+		}
+	}
+	// #endif
+
+	return defaultExtConfig
+}
+
+export default getExtConfig()

+ 1 - 1
ghsApp/src/utils/socket.js

@@ -1,4 +1,4 @@
-const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
+import extConfig from '@/utils/extConfig'
 const SocketConfig = {
 const SocketConfig = {
 	retry: 20,
 	retry: 20,
 	timeout: 10000,
 	timeout: 10000,