Kaynağa Gözat

增加练习时长统计

skyblued 2 yıl önce
ebeveyn
işleme
75280e9099

+ 39 - 4
src/subpages/colexiu/App.tsx

@@ -1,8 +1,11 @@
-import { defineComponent, onMounted } from 'vue'
+import { defineComponent, onBeforeUnmount, onMounted, onUnmounted } from 'vue'
 import qs from 'query-string'
 import '../../vue-tsx-shim.d'
 import '../../app.d'
 import { useRoute } from 'vue-router'
+import { useClientType, useOriginSearch } from './uses'
+import request from '/src/helpers/request'
+import { getPlatform, getRequestHostname } from '/src/helpers/utils'
 
 export default defineComponent({
   setup() {
@@ -11,8 +14,40 @@ export default defineComponent({
     if (route?.query?.Authorization) {
       sessionStorage.setItem('Authorization', route.query.Authorization as string)
     }
-  },
-  render() {
-    return <router-view></router-view>
+
+    const startTime = Date.now()
+    const initBehaviorId = '' + new Date().valueOf()
+    /** 学生端记录在云教练里面的时长 */
+    const recordTotalTime = async () => {
+      const client = useClientType()
+      if (client != 'student') return
+      const search = useOriginSearch()
+      const behaviorId = sessionStorage.getItem('behaviorId') || search.behaviorId || initBehaviorId
+      const prefix = getRequestHostname()
+      const totalTime = Date.now() - startTime
+      const res = await request.post('/musicPracticeRecord/save', {
+        prefix: prefix,
+        requestType: 'json',
+        data: {
+          musicSheetId: search.id,
+          sysMusicScoreId: search.id,
+          feature: search.feature,
+          playTime: totalTime / 1000,
+          deviceType: getPlatform(),
+          behaviorId,
+        },
+      })
+    }
+    let timer = null as any
+    onMounted(() => {
+      clearInterval(timer)
+      if (!route.name) return
+      console.log('进入云教练')
+      timer = setInterval(() => {
+        recordTotalTime()
+      }, 10 * 1000)
+    })
+
+    return () => <router-view></router-view>
   },
 })

+ 1 - 1
src/subpages/colexiu/afterClassTraining/index.tsx

@@ -16,6 +16,6 @@ export default defineComponent({
         // onMounted(() => {
 
         // })
-        return (<></>)
+        return () => <div></div>
     }
 })

+ 4 - 2
src/subpages/colexiu/buttons/evaluating.tsx

@@ -33,7 +33,7 @@ import styles from './index.module.less'
 
 let backtime = 0
 
-const search = useOriginSearch()
+
 const initBehaviorId = '' + new Date().valueOf()
 const evaluating = ref(false)
 const playStatus: Ref<'connecting' | 'play' | 'stop'> = ref('stop')
@@ -132,6 +132,7 @@ const formatTimes = () => {
   return datas
 }
 const connect = async () => {
+  const search = useOriginSearch()
   connentLoading.value = true
   const behaviorId = sessionStorage.getItem('behaviorId') || search.behaviorId || initBehaviorId
   const rate = runtime.speed / detailState.baseSpeed //1
@@ -206,6 +207,7 @@ const sendOffsetTime = (offsetTime: number) => {
 }
 
 const cancelTheEvaluation = () => {
+  const search = useOriginSearch()
   RuntimeUtils.resetPlayStatus()
   RuntimeUtils.clearIntervalTimeline()
   RuntimeUtils.setCurrentTime(0)
@@ -511,7 +513,7 @@ const cloudMetronome = (evt: any) => {
 }
 
 export default defineComponent({
-  name: 'ColexiuEvaluating',
+  name: 'ColexiuButtonEvaluating',
   directives: { animate },
   setup(props, { expose }) {
     onMounted(async () => {

+ 2 - 1
src/subpages/colexiu/buttons/index.tsx

@@ -28,7 +28,7 @@ import { useRoute } from 'vue-router'
 import styles from './index.module.less'
 export const confirmShow: Ref<boolean> = ref(false)
 
-const search = useOriginSearch()
+
 export const startButtonShow = ref(true)
 
 export const evaluatingRef: Ref<any> = ref({})
@@ -61,6 +61,7 @@ export const animate: Directive = {
  * @returns
  */
 const beforeCheck = (cb: (status: boolean) => void) => {
+  const search = useOriginSearch()
   const setting = (search.setting || {}) as any
   const chargeType = detailState.activeDetail?.paymentType
   const orderStatus = detailState.activeDetail?.orderStatus

+ 2 - 3
src/subpages/colexiu/popups/evaluating/content.tsx

@@ -59,11 +59,9 @@ const scoreInfos: any = {
 
 export const evaluatingShow = ref<boolean>(false)
 
-const search = useOriginSearch()
-
 //效音组件
 export default defineComponent({
-  name: 'ColexiuEvaluating',
+  name: 'ColexiuEvaluatingContent',
   props: {
     data: {
       type: Object as () => ResultContent | null,
@@ -72,6 +70,7 @@ export default defineComponent({
   },
   emits: ['restart', 'upload'],
   setup(props, { emit }) {
+    const search = useOriginSearch()
     const shareShow = ref(false)
     const shareLoadedPngData = ref('')
     const { data } = toRefs(props)

+ 1 - 2
src/subpages/colexiu/popups/part/index.tsx

@@ -5,11 +5,10 @@ import detailState from '/src/pages/detail/state'
 import styles from './index.module.less'
 import { useOriginSearch } from '../../uses'
 
-const search = useOriginSearch()
-
 export default defineComponent({
   name: 'ColexiuPart',
   setup() {
+    const search = useOriginSearch()
     const index = Number(search['part-index']) || 0
     const active = ref<string>(detailState.partListNames[index])
 

+ 2 - 2
src/subpages/colexiu/uses/use-user.ts

@@ -12,10 +12,10 @@ const browserInfo = browser()
 
 export type ClientType = 'student' | 'teacher' | 'web'
 
-export const useClientType = () => {
+export const useClientType = (): ClientType => {
   const search = useOriginSearch()
   // console.log("🚀 ~ search", search)
-  if (search.client) return search.client
+  if (search.client) return (search.client as ClientType)
   /**
    * pathname 不可能是student | teacher
    */