瀏覽代碼

feat: 跟练模式增加时长统计

TIANYONG 1 年之前
父節點
當前提交
e0d6a47d2a
共有 1 個文件被更改,包括 21 次插入0 次删除
  1. 21 0
      src/view/follow-practice/index.tsx

+ 21 - 0
src/view/follow-practice/index.tsx

@@ -8,6 +8,8 @@ import { handleStartTick } from "/src/view/tick";
 import { metronomeData } from "/src/helpers/metronome";
 import { getDuration } from "/src/helpers/formateMusic";
 import { OpenSheetMusicDisplay } from "/osmd-extended/src";
+import { browser, getBehaviorId } from "/src/utils";
+import { api_musicPracticeRecordSave } from "../../page-instrument/api";
 
 export const followData = reactive({
 	list: [] as any, // 频率列表
@@ -18,6 +20,24 @@ export const followData = reactive({
 	earphone: false,
 });
 
+// 记录跟练时长
+const handleRecord = (total: number) => {
+	if (total < 0) total = 0;
+	const totalTime = total / 1000;
+
+	const body = {
+		clientType: storeData.user.clientType,
+		musicSheetId: state.examSongId,
+		sysMusicScoreId: state.examSongId,
+		feature: "FOLLOW_UP_TRAINING",
+		practiceSource: "FOLLOW_UP_TRAINING",
+		playTime: totalTime,
+		deviceType: browser().android ? "ANDROID" : "IOS",
+		behaviorId: getBehaviorId(),
+	};
+	api_musicPracticeRecordSave(body);
+};
+
 /** 点击跟练模式 */
 export const toggleFollow = (notCancel = true) => {
 	state.modeType = state.modeType === "follow" ? "practise" : "follow";
@@ -40,6 +60,7 @@ const openToggleRecord = async (open: boolean = true) => {
 	} else {
 		const playTime = Date.now() - followTime.value;
 		if (followTime.value !== 0 && playTime > 0) {
+			handleRecord(playTime);
 			followTime.value = 0;
 		}
 	}