Bläddra i källkod

评测视频上传

liushengqiang 2 år sedan
förälder
incheckning
02f30feac1
2 ändrade filer med 41 tillägg och 25 borttagningar
  1. 17 13
      src/helpers/communication.ts
  2. 24 12
      src/page-gym/evaluat-model/index.tsx

+ 17 - 13
src/helpers/communication.ts

@@ -72,16 +72,20 @@ export const api_proxyServiceMessage = (content: any): Promise<IPostMessage | un
 /** 监听app真正开始录音 */
 export const api_recordStartTime = (callback: CallBack) => {
 	listenerMessage("recordStartTime", callback);
-}
+};
 /** 卸载监听app真正开始录音 */
 export const api_remove_recordStartTime = (callback: CallBack) => {
 	removeListenerMessage("recordStartTime", callback);
-}
+};
 
-/** 上传评测 音 视频 */
-export const api_videoUpdate = () => {
-	if (!storeData.isApp) return Promise.resolve({} as any);
-	return promisefiyPostMessage({ api: "videoUpdate" });
+/** 上传评测视频 */
+export const api_videoUpdate = (callback: CallBack) => {
+	postMessage(
+		{
+			api: "videoUpdate",
+		},
+		callback
+	);
 };
 
 /** 分享 */
@@ -187,18 +191,18 @@ export const api_setCache = (content: any) => {
 /** app切换到后台 */
 export const api_suspendPlay = (callback: CallBack) => {
 	listenerMessage("suspendPlay", callback);
-}
+};
 
 /** 开始录制视频 */
 export const api_startCapture = () => {
 	postMessage({
-		api: 'startCapture'
-	})
-}
+		api: "startCapture",
+	});
+};
 
 /** 结束录制视频 */
 export const api_endCapture = () => {
 	postMessage({
-		api: 'endCapture'
-	})
-}
+		api: "endCapture",
+	});
+};

+ 24 - 12
src/page-gym/evaluat-model/index.tsx

@@ -20,7 +20,7 @@ import { Icon, NoticeBar, Popup, showToast, Swipe, SwipeItem } from "vant";
 import iconStudent from "./icons/student.png";
 import EvaluatResult from "./evaluat-result";
 import EvaluatAudio from "./evaluat-audio";
-import { api_openWebView, api_proxyServiceMessage, api_videoUpdate } from "/src/helpers/communication";
+import {  api_proxyServiceMessage, api_videoUpdate } from "/src/helpers/communication";
 import EvaluatShare from "./evaluat-share";
 
 // frequency 频率, amplitude 振幅, decibels 分贝
@@ -180,29 +180,41 @@ export default defineComponent({
 				evaluatModel.evaluatUpdateAudio = false;
 				return;
 			}
-			let res = null;
 			if (state.setting.camera && state.setting.saveToAlbum) {
-				console.log(1);
-				res = await api_videoUpdate();
-				console.log(2);
+				evaluatModel.evaluatUpdateAudio = false;
+				api_videoUpdate((res: any) => {
+					if (res) {
+						if (res?.content?.type === 'success'){
+							handleSaveResult({
+								recordId: evaluatingData.resultData?.recordId,
+								filePath: res?.content?.filePath,
+							})
+						} else if (res?.content?.type === 'error') {
+							showToast({
+								message: res.content?.message || "上传失败",
+							});
+						}
+					}
+				});
+				return;
 			}
-			console.log(3);
+			evaluatModel.evaluatUpdateAudio = false;
+			handleSaveResult({
+				recordId: evaluatingData.resultData?.recordId,
+			});
+		};
+		const handleSaveResult = (_body: any) => {
 			api_proxyServiceMessage({
 				header: {
 					commond: "videoUpload",
 					status: 200,
 					type: "SOUND_COMPARE",
 				},
-				body: {
-					filePath: res?.content?.filePath,
-					recordId: evaluatingData.resultData?.recordId,
-				},
+				body: _body,
 			});
 			showToast({
-				position: "top",
 				message: "上传成功",
 			});
-			evaluatModel.evaluatUpdateAudio = false;
 		};
 
 		onMounted(() => {