Explorar o código

feat: 返回各应用实际的接口api地址

TIANYONG hai 1 ano
pai
achega
abbea205e4
Modificáronse 3 ficheiros con 45 adicións e 2 borrados
  1. 1 1
      src/page-instrument/App.tsx
  2. 41 0
      src/utils/index.ts
  3. 3 1
      src/utils/request.ts

+ 1 - 1
src/page-instrument/App.tsx

@@ -18,7 +18,7 @@ export default defineComponent({
     };
     const setUser = async () => {
       try {
-        const res = query.isCreateImg ? {code:200,data:{}} : await getUserInfo();
+        const res = query.isCbs ? {code:200,data:{}} : await getUserInfo();
         if (res?.code === 5000) {
           const browserInfo = browser();
           showToast(res.message);

+ 41 - 0
src/utils/index.ts

@@ -1,4 +1,6 @@
 import store from 'store'
+import { getQuery } from "./queryString";
+
 /** 获取浏览器信息 */
 export const browser = () => {
 	const u = navigator.userAgent;
@@ -97,3 +99,42 @@ export const getStorageSpeed = (id: any) => {
 	const speeds = store.get(SPEEDKEY) || {}
 	return speeds[id] || 0
 }
+
+/** 返回各产品应用对应的服务接口地址 */
+export const matchProductApiUrl = () => {
+	const query: any = getQuery();
+	const apiUrls = {
+		'cbs': {
+			'dev': 'http://dev.resource.colexiu.com',
+			'test': 'https://test.resource.colexiu.com',
+			'online': 'https://online.resource.colexiu.com'
+		},
+		'gym': {
+			'dev': 'https://dev.dayaedu.com',
+			'test': 'https://test.dayaedu.com',
+			'online': 'https://online.dayaedu.com'
+		},
+		'colexiu': {
+			'dev': 'https://dev.colexiu.com/',
+			'test': 'https://test.colexiu.com',
+			'online': 'https://online.colexiu.com'
+		},
+		'orchestra': {
+			'dev': 'https://dev.lexiaoya.cn',
+			'test': 'https://test.lexiaoya.cn',
+			'online': 'https://online.lexiaoya.cn'
+		},
+		'instrument': {
+			'dev': 'https://dev.kt.colexiu.com',
+			'test': 'https://test.lexiaoya.cn',
+			'online': 'https://kt.colexiu.com'
+		}
+	}
+	const environment = location.origin.includes('//dev') ? 'dev' : location.origin.includes('//test') ? 'test' : location.origin.includes('//online') ? 'online' : 'dev'
+	if (query.isCbs) {
+		return apiUrls.cbs[environment]
+	} else {
+		const pathName = location.pathname.includes('index') ? 'gym' : location.pathname.includes('colexiu') ? 'colexiu' : location.pathname.includes('orchestra') ? 'orchestra' : 'instrument'
+		return apiUrls[pathName][environment]
+	}
+}

+ 3 - 1
src/utils/request.ts

@@ -5,6 +5,7 @@ import whiteUrl from "../constant/whiteUrl";
 import { storeData } from "../store";
 import { browser, getToken } from ".";
 import { postMessage } from "./native-message";
+import { matchProductApiUrl } from "./index"
 
 const apiRouter = whiteUrl();
 const browserInfo = browser();
@@ -15,7 +16,8 @@ const request = extend({
 	//prefix: 'https://www.baidu.com',
 	credentials: 'omit'
 });
-const domainUrl = location.origin + storeData.platformApi
+// 返回各应用实际的接口api地址
+const domainUrl = matchProductApiUrl() + storeData.platformApi
 if (!import.meta.env.DEV) {
 	request.extendOptions({ prefix: domainUrl})
 }