소스 검색

feat: 跨域问题

TIANYONG 1 년 전
부모
커밋
889848aed2
3개의 변경된 파일26개의 추가작업 그리고 13개의 파일을 삭제
  1. 1 1
      src/state.ts
  2. 24 11
      src/utils/request.ts
  3. 1 1
      vite.config.ts

+ 1 - 1
src/state.ts

@@ -783,9 +783,9 @@ const setState = (data: any, index: number) => {
       console.error("解析扩展字段错误:", error);
     }
   }
-  state.isOpenMetronome = data.isPlayBeat ? true : false;
   // 曲子包含节拍器,就不开启节拍器
   state.needTick = data.isUseSystemBeat ? true : false;
+  state.isOpenMetronome = data.isUseSystemBeat ? false : true;
   state.isShowFingering = data.isShowFingering ? true : false;
   state.music = data.music;
   state.accompany = data.accompany;

+ 24 - 11
src/utils/request.ts

@@ -16,33 +16,46 @@ const request = extend({
 	requestType: "form",
 	timeout: 10000,
 	//prefix: 'https://www.baidu.com',
-	credentials: 'omit'
 });
 // 返回各应用实际的接口api地址
-const domainUrl = matchProductApiUrl()
-if (!import.meta.env.DEV) {
-	request.extendOptions({ prefix: domainUrl})
-}
-console.log('api地址',domainUrl)
+// if (!import.meta.env.DEV) {
+// 	const domainUrl = matchProductApiUrl()
+// 	request.extendOptions({ prefix: domainUrl})
+// }
+
 request.interceptors.request.use(
 	(url, options) => {
 		// console.log(9999,storeData.proxy,storeData.platformApi,options)
 		// 内容平台的前缀为cbs-app
 		const platformApi = options.isContentCenter ? '/cbs-app' : storeData.platformApi
 		const _prefix = storeData.proxy + platformApi;
-		// 只有后台才去设置
-		if (storeData.platformType === "WEB" && (apiRouter as any)[url]) {
-			url = (apiRouter as any)[url];
+		/** 
+		 * 只有后台才去设置
+		 * 暂时没有用到,先注释掉(2024.1.19)
+		 */
+		// if (storeData.platformType === "WEB" && (apiRouter as any)[url]) {
+		// 	url = (apiRouter as any)[url];
+		// }
+
+		/**
+		 * 区分开发环境和非开发环境
+		 * 
+		 */
+		if (!import.meta.env.DEV) {
+			const domainUrl = matchProductApiUrl()
+			url = domainUrl + url
+		} else {
+			url = _prefix + url
 		}
+
 		const Authorization = getToken();
 		const authHeaders: any = {};
 		// 内容平台的接口不需要传token,需要传签名
 		if (Authorization && !options.isContentCenter) {
 			authHeaders.Authorization = Authorization;
 		}
-		console.log(6666,_prefix + url)
 		return {
-			url: _prefix + url,
+			url: url,
 			options: {
 				...options,
 				params: cleanDeep(options.params),

+ 1 - 1
vite.config.ts

@@ -67,7 +67,7 @@ export default defineConfig({
 				// target: "https://kt.colexiu.com",
 				// target: "https://test.lexiaoya.cn",
 				// target: "https://dev.kt.colexiu.com",
-				target: "http://dev.resource.colexiu.com", // 内容平台开发环境
+				target: "https://dev.resource.colexiu.com", // 内容平台开发环境
 				changeOrigin: true,
 				rewrite: (path) => path.replace(/^\/instrument/, ""),
 			},