浏览代码

酷乐秀统计时长

liushengqiang 2 年之前
父节点
当前提交
0ea03c44b8

+ 2 - 2
src/page-colexiu/App.tsx

@@ -3,7 +3,7 @@ import { computed, defineComponent, onBeforeMount, onMounted } from "vue";
 import { RouterView } from "vue-router";
 import TheError from "../components/The-error";
 import { setUserInfo, storeData } from "../store";
-import { getRandomKey, setToken } from "../utils";
+import { getRandomKey, setBehaviorId, setToken } from "../utils";
 import { getQuery } from "../utils/queryString";
 import Notfind from "../view/notfind";
 import { employeeQueryUserInfo, studentQueryUserInfo, teacherQueryUserInfo } from "./api";
@@ -34,7 +34,7 @@ export default defineComponent({
 				setToken(query.Authorization);
 			}
 			setUser();
-			localStorage.setItem("behaviorId", getRandomKey());
+			setBehaviorId(getRandomKey())
 		});
 		onMounted(() => {
 			document.getElementById("loading")!.className = "";

+ 3 - 9
src/page-colexiu/api.ts

@@ -18,13 +18,7 @@ export const sysMusicScoreAccompanimentQueryPage = (sysMusicScoreId: string) =>
 	return request.get("/music/sheet/detail/" + sysMusicScoreId);
 };
 
-/** 获取曲谱分类 */
-export const sysMusicScoreCategoriesQueryTree = (enable = false) => {
-	return request.get(`/sysMusicScoreCategories/queryTree`, {
-		params: {
-			parentId: 0,
-			// 后台详情忽略是否启用分类
-			enable,
-		},
-	});
+/** 记录训练时长 */
+export const sysMusicRecordAdd = (data: any) => {
+	return request.post("/sysMusicRecord/add", { data });
 };

+ 50 - 0
src/page-colexiu/custom-plugins/recording-time/index.tsx

@@ -0,0 +1,50 @@
+import { defineComponent, reactive, watch } from "vue";
+import state from "/src/state";
+import { sysMusicRecordAdd } from "../../api";
+import { browser, getBehaviorId, getCampId } from "/src/utils";
+
+const recordData = reactive({
+	starTime: 0,
+});
+const handleRecord = () => {
+	// 不是练习模式不记录
+	if (state.modeType !== "practise") return;
+	let total = Date.now() - recordData.starTime;
+	recordData.starTime = Date.now();
+	if (total < 0) total = 0;
+	const body = {
+		musicSheetId: state.examSongId,
+		sysMusicScoreId: state.examSongId,
+		feature: "CLOUD_STUDY_TRAIN",
+		playTime: total / 1000,
+		deviceType: browser().android ? "ANDROID" : "IOS",
+		behaviorId: getBehaviorId()
+	};
+	sysMusicRecordAdd(body);
+};
+
+export const handleNoEndExit = () => {
+    if (state.playState === 'play') {
+        handleRecord()
+    }
+}
+
+/**
+ * 记录练习时长, 仅记录练习模式的时长
+ */
+export default defineComponent({
+	name: "recordingTime",
+	setup() {
+		watch(
+			() => state.playState,
+			() => {
+				if (state.playState === "play") {
+					recordData.starTime = Date.now();
+				} else {
+					handleRecord();
+				}
+			}
+		);
+		return () => <div></div>;
+	},
+});

+ 0 - 4
src/page-colexiu/detail/index.module.less

@@ -52,10 +52,6 @@
     }
 }
 
-.plugins {
-    display: none;
-}
-
 :global {
     #cursorImg-0 {
         min-height: 58PX;

+ 4 - 1
src/page-colexiu/detail/index.tsx

@@ -8,7 +8,7 @@ import { storeData } from "../../store";
 import { setGlobalData } from "../../utils";
 import AudioList from "../../view/audio-list";
 import MusicScore, { resetMusicScore } from "../../view/music-score";
-import { sysMusicScoreAccompanimentQueryPage, sysMusicScoreCategoriesQueryTree } from "../api";
+import { sysMusicScoreAccompanimentQueryPage } from "../api";
 import EvaluatModel from "../evaluat-model";
 import HeaderTop from "../header-top";
 import styles from "./index.module.less";
@@ -22,6 +22,7 @@ import store from "store";
 import Tick, { handleInitTick } from "/src/view/tick";
 import FollowPractice from "/src/view/follow-practice";
 import FollowModel from "../follow-model";
+import RecordingTime from "../custom-plugins/recording-time";
 
 export default defineComponent({
 	name: "music-list",
@@ -252,6 +253,8 @@ export default defineComponent({
 					{state.musicRendered && (
 						<>
 							<MeasureSpeed />
+							{/* 统计训练时长 */}
+							<RecordingTime />
 						</>
 					)}
 				</div>