Browse Source

评测修改

liushengqiang 2 years ago
parent
commit
02e6099543

+ 21 - 10
src/components/The-error/index.tsx

@@ -1,13 +1,24 @@
-import { Button, Empty } from "vant";
+import { Button, Empty, NavBar } from "vant";
 import { defineComponent } from "vue";
+import { api_back } from "/src/helpers/communication";
 
 export default defineComponent({
-    name: 'The-error',
-    setup(props, ctx) {
-        return () => <div>
-            <Empty image="error" description="网络开小差,再刷新看看">
-                <Button type="primary" size="small" onClick={() => history.go(0)}>重新加载</Button>
-            </Empty>
-        </div>
-    },
-})
+	name: "The-error",
+	setup(props, ctx) {
+		return () => (
+			<div>
+				<NavBar
+                    leftArrow
+					onClickLeft={() => {
+						api_back();
+					}}
+				/>
+				<Empty image="error" description="网络开小差,请稍后重试">
+					<Button type="primary" size="small" onClick={() => history.go(0)}>
+						重新加载
+					</Button>
+				</Empty>
+			</div>
+		);
+	},
+});

+ 3 - 1
src/page-orchestra/detail/index.tsx

@@ -227,6 +227,8 @@ export default defineComponent({
 		onBeforeUnmount(() => {
 			window.removeEventListener("resize", resetMusicScore);
 		});
+
+		const guideShow = !localStorage.getItem("isFirstTip") || !localStorage.getItem("isFirstModel")
 		return () => (
 			<div
 				class={[styles.detail, state.setting.eyeProtection && "eyeProtection"]}
@@ -280,7 +282,7 @@ export default defineComponent({
 							{/* 后台课后训练小节选择 */}
 							{storeData.platformType === "WEB" && <AfterClassTraining />}
 							{/* 引导 */}
-							<GuidePage />
+							{guideShow && <GuidePage />}
 						</>
 					)}
 				</div>

+ 4 - 4
src/page-orchestra/evaluat-model/index.tsx

@@ -133,8 +133,8 @@ export default defineComponent({
 			}
 			return datas;
 		};
-		/** 连接websocket */
-		const handleConnect = async () => {
+		/** 生成数据 */
+		const hanldeCreateData = async () => {
 			const query = getQuery()
 			const behaviorId = localStorage.getItem("behaviorId") || undefined;
 			const rate = state.speed / state.originSpeed;
@@ -216,8 +216,8 @@ export default defineComponent({
 			() => evaluatingData.checkEnd,
 			() => {
 				if (evaluatingData.checkEnd) {
-					console.log("检测结束,连接websocket");
-					handleConnect();
+					console.log("检测结束,生成评测数据");
+					hanldeCreateData();
 				}
 			}
 		);

+ 1 - 1
src/utils/request.ts

@@ -54,7 +54,7 @@ request.interceptors.response.use(
 		if (data.code !== 200 && data.errCode !== 0) {
 			const msg = data.msg || data.message || "处理失败,请重试";
 			if (!(data.code === 403 || data.code === 401)) {
-				// storeData.status = 'error'
+				storeData.status = 'error'
 				showToast(msg);
 			}
 			if (data.code === 403) {

+ 77 - 75
src/view/evaluating/index.tsx

@@ -12,7 +12,7 @@ import {
 	sendResult,
 	startEvaluating,
 	startSoundCheck,
-    api_openWebView,
+	api_openWebView,
 	api_startRecording,
 	api_stopRecording,
 } from "/src/helpers/communication";
@@ -20,8 +20,9 @@ import state, { clearSelection, handleStopPlay, resetPlaybackToStart, togglePlay
 import { IPostMessage } from "/src/utils/native-message";
 import { usePageVisibility } from "@vant/use";
 export const evaluatingData = reactive({
-    /** 评测模块是否加载完成 */
-    rendered: false,
+	contentData: {} as any,
+	/** 评测模块是否加载完成 */
+	rendered: false,
 	earphone: false, // 是否插入耳机
 	soundEffect: false, // 是否效音
 	soundEffectFrequency: 0, // 效音频率
@@ -34,25 +35,25 @@ export const evaluatingData = reactive({
 	backtime: 0, // 延迟时间
 	/** 已经评测的数据 */
 	evaluatings: {} as IEvaluatings,
-    /** 评测结果 */
-    resultData: {} as any,
-    /** 评测结果弹窗 */
-    resulstMode: false
+	/** 评测结果 */
+	resultData: {} as any,
+	/** 评测结果弹窗 */
+	resulstMode: false,
 });
 
 /** 点击开始评测按钮 */
 export const handleStartEvaluat = () => {
-    if (state.modeType === 'evaluating') {
-        handleCancelEvaluat()
-    } else {
-        handleStopPlay()
-    }
-    state.modeType = state.modeType === 'evaluating' ? 'practise' : 'evaluating'
-    if (state.modeType !== 'evaluating') {
-        // 切换到练习模式,卸载评测模块
-        evaluatingData.rendered = false
-    }
-}
+	if (state.modeType === "evaluating") {
+		handleCancelEvaluat();
+	} else {
+		handleStopPlay();
+	}
+	state.modeType = state.modeType === "evaluating" ? "practise" : "evaluating";
+	if (state.modeType !== "evaluating") {
+		// 切换到练习模式,卸载评测模块
+		evaluatingData.rendered = false;
+	}
+};
 
 /** 开始播放发送延迟时间 */
 export const sendEvaluatingOffsetTime = (currentTime: number) => {
@@ -96,17 +97,8 @@ export const handleEndSoundCheck = () => {
 
 /** 连接websocket */
 export const connectWebsocket = async (content: any) => {
-	evaluatingData.websocketState = false;
-	try {
-		console.log("🚀 ~ content:", content,JSON.stringify(content))
-	} catch (error) {}
-	const res = await startEvaluating(content);
-	// console.log("🚀 ~ res:", res)
-	if (res?.api === "startEvaluating") {
-		evaluatingData.websocketState = true;
-	} else {
-        Snackbar.error("请在APP端进行评测")
-	}
+	evaluatingData.contentData = content;
+	evaluatingData.websocketState = true;
 };
 
 /**
@@ -140,7 +132,7 @@ export const handlePerformDetection = async () => {
 	if (evaluatingData.checkStep === 10) {
 		// 连接websocket
 		evaluatingData.checkEnd = true;
-        evaluatingData.checkStep = 0
+		evaluatingData.checkStep = 0;
 	}
 };
 
@@ -169,12 +161,12 @@ const handleScoreResult = (res?: IPostMessage) => {
 		// 评测结束返回
 		if (header?.commond === "overall") {
 			// console.log("评测结束", body);
-            evaluatingData.resulstMode = true
-            evaluatingData.resultData = {
-                ...body,
-                ...getLeveByScore(body.score)
-            }
-            // console.log("🚀 ~ evaluatingData.resultData:", evaluatingData.resultData)
+			evaluatingData.resulstMode = true;
+			evaluatingData.resultData = {
+				...body,
+				...getLeveByScore(body.score),
+			};
+			// console.log("🚀 ~ evaluatingData.resultData:", evaluatingData.resultData)
 			closeToast();
 		}
 	}
@@ -183,27 +175,37 @@ const handleScoreResult = (res?: IPostMessage) => {
 /** 开始评测 */
 export const handleStartBegin = async () => {
 	evaluatingData.startBegin = true;
-    evaluatingData.evaluatings = {};
-    evaluatingData.resultData = {};
+	evaluatingData.evaluatings = {};
+	evaluatingData.resultData = {};
 	evaluatingData.backtime = Date.now();
-	resetPlaybackToStart()
-	const playState = await togglePlay("play");
-	// 取消播放
-	if (!playState){
+	resetPlaybackToStart();
+	try {
+		console.log("🚀 ~ content:", evaluatingData.contentData, JSON.stringify(evaluatingData.contentData));
+	} catch (error) {}
+	const res = await startEvaluating(evaluatingData.contentData);
+	if (res?.api !== "startEvaluating") {
+		Snackbar.error("请在APP端进行评测");
 		evaluatingData.startBegin = false;
-		return
+		return;
 	}
 	// 开始录音
 	api_startRecording();
+	const playState = await togglePlay("play");
+	// 取消播放
+	if (!playState) {
+		evaluatingData.startBegin = false;
+		handleCancelEvaluat();
+		return;
+	}
 };
 
 /**
  * 结束评测
  */
 export const handleEndEvaluat = () => {
-	console.log('触发结束')
+	console.log("触发结束");
 	// 没有开始评测 , 不是评测模式 , 不评分
-	if (!evaluatingData.startBegin || state.modeType !== 'evaluating') return
+	if (!evaluatingData.startBegin || state.modeType !== "evaluating") return;
 	evaluatingData.startBegin = false;
 	// 结束录音
 	api_stopRecording();
@@ -216,14 +218,14 @@ export const handleEndEvaluat = () => {
 		duration: 0,
 		forbidClick: true,
 	});
-}
+};
 
 /**
  * 结束评测
  * @param isEnd 是否是自动播放停止, 默认: false
  */
 export const handleEndBegin = () => {
-	handleEndEvaluat()
+	handleEndEvaluat();
 	handleStopPlay();
 };
 
@@ -232,9 +234,9 @@ export const handleEndBegin = () => {
  */
 export const handleCancelEvaluat = () => {
 	evaluatingData.evaluatings = {};
-    // 关闭提示
-    closeToast();
-    // 取消记录
+	// 关闭提示
+	closeToast();
+	// 取消记录
 	api_proxyServiceMessage({
 		header: {
 			commond: "recordCancel",
@@ -242,21 +244,21 @@ export const handleCancelEvaluat = () => {
 			status: 200,
 		},
 	});
-    // 取消评测
+	// 取消评测
 	cancelEvaluating();
-    // 停止播放
-    handleStopPlay();
+	// 停止播放
+	handleStopPlay();
 };
 
 /** 查看报告 */
 export const handleViewReport = () => {
-    api_openWebView({
-        url: location.origin + "/accompany/#/report/" + evaluatingData.resultData?.recordId || "",
-        orientation: 0,
-        isHideTitle: true, // 此处兼容安卓,意思为隐藏全部头部
-        statusBarTextColor: false,
-        isOpenLight: true,
-    });
+	api_openWebView({
+		url: location.origin + "/accompany/#/report/" + evaluatingData.resultData?.recordId || "",
+		orientation: 0,
+		isHideTitle: true, // 此处兼容安卓,意思为隐藏全部头部
+		statusBarTextColor: false,
+		isOpenLight: true,
+	});
 };
 export default defineComponent({
 	name: "evaluating",
@@ -264,26 +266,26 @@ export default defineComponent({
 		const pageVisibility = usePageVisibility();
 
 		watch(pageVisibility, (value) => {
-			if (value == 'hidden' && evaluatingData.startBegin){
-				handleEndBegin()
+			if (value == "hidden" && evaluatingData.startBegin) {
+				handleEndBegin();
 			}
 		});
-        onMounted(() => {
-			evaluatingData.resultData = {}
-            // evaluatingData.resultData = {...getLeveByScore(90), score: 30, intonation: 10, cadence: 30, integrity: 40}
-            // console.log("🚀 ~ evaluatingData.resultData:", evaluatingData.resultData)
-            evaluatingData.evaluatings = {}
-            evaluatingData.soundEffectFrequency = 0
-            evaluatingData.checkStep = 0
-            evaluatingData.rendered = true
+		onMounted(() => {
+			evaluatingData.resultData = {};
+			// evaluatingData.resultData = {...getLeveByScore(90), score: 30, intonation: 10, cadence: 30, integrity: 40}
+			// console.log("🚀 ~ evaluatingData.resultData:", evaluatingData.resultData)
+			evaluatingData.evaluatings = {};
+			evaluatingData.soundEffectFrequency = 0;
+			evaluatingData.checkStep = 0;
+			evaluatingData.rendered = true;
 			sendResult(handleScoreResult);
-			if (!state.isSelectMeasureMode){
-				clearSelection()
+			if (!state.isSelectMeasureMode) {
+				clearSelection();
 			}
-        })
+		});
 		onUnmounted(() => {
-			removeResult(handleScoreResult)
-		})
+			removeResult(handleScoreResult);
+		});
 		return () => <div></div>;
 	},
 });