Ver código fonte

课后训练选段

skyblued 2 anos atrás
pai
commit
97082b40ab

+ 34 - 5
src/subpages/colexiu/App.tsx

@@ -1,10 +1,13 @@
-import { defineComponent, onMounted } from 'vue'
+import { defineComponent, onMounted, reactive, ref } from 'vue'
 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 { browser, getPlatform, getRequestHostname } from '/src/helpers/utils'
+import HomeIndex from './index'
+import Empty from '/src/components/empty'
+import styles from './index.module.less'
 
 let startTime = Date.now()
 let timer = null as any
@@ -62,23 +65,49 @@ export const sendBackRecordTotalTime = () => {
   clearInterval(timer)
   recordTotalTime()
 }
+interface IUserInfo {
+  id?: string
+}
+export const userInfo = reactive<IUserInfo>({})
+export const renderError = ref(false)
 export default defineComponent({
   setup() {
     const route = useRoute()
-    // console.log("🚀 ~ APP里面的Authorization", route.query)
     if (route?.query?.Authorization) {
       sessionStorage.setItem('Authorization', route.query.Authorization as string)
     }
+    const getUserInfo = async () => {
+      try {
+        const res: any = await request.get(`/user/getUserInfo`)
+        Object.assign(userInfo, res?.data || {})
+      } catch (error) {
+        console.log(error)
+        renderError.value = true
+      }
+    }
 
     onMounted(() => {
+      getUserInfo()
       clearInterval(timer)
-      if (!route.name) return
-
       timer = setInterval(() => {
         recordTotalTime()
       }, 60 * 1000)
     })
 
-    return () => <router-view></router-view>
+    return () => (
+      <>
+        {userInfo.id && (
+          <>
+            <HomeIndex />
+          </>
+        )}
+        {/* 加载错误 */}
+        {renderError.value && (
+          <div class={styles.errorWrap}>
+            <Empty />
+          </div>
+        )}
+      </>
+    )
   },
 })

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

@@ -44,6 +44,7 @@ import AfterClassTraining from './afterClassTraining'
 import ModelWraper from './buttons/model-wraper'
 import Follow from './popups/follow'
 import UnitTest from './unitTest'
+import { renderError } from './App'
 
 // json化曲谱的note信息和svg
 export const musicJSON = reactive({
@@ -65,7 +66,6 @@ export default defineComponent({
     // console.log("🚀 ~ route", route.query, search)
     detailState.midiPlayIniting = true
     const renderLoading = ref(true)
-    const renderError = ref(false)
     const compulsionEvaluating = ref(false)
     const score = ref<string>('')
     const fingeringStatus: Ref<string> = ref('init')
@@ -386,12 +386,6 @@ export default defineComponent({
             {/* 引导 */}
             {tipShow.value && !error && <Tips />}
 
-            {/* 加载错误 */}
-            {error && (
-              <div class={styles.errorWrap}>
-                <Empty />
-              </div>
-            )}
           </div>
           {/* 效音 */}
           <Transition name="van-slide-up">{soundEffectShow.value && <SoundEffect />}</Transition>

+ 1 - 8
src/subpages/colexiu/router.ts

@@ -4,14 +4,7 @@ const routes: RouteRecordRaw[] = [
   {
     path: '/',
     name:'home',
-    component: () => import('./App'),
-    children:[
-      {
-        path: '',
-        name:'musicScore',
-        component: () => import('./index')
-      }
-    ]
+    component: () => import('./App')
   },
   {
     path: '/:path(.*)*',

+ 38 - 15
src/subpages/colexiu/unitTest/index.tsx

@@ -2,17 +2,20 @@ import { defineComponent, onMounted, reactive, ref } from 'vue'
 import { useOriginSearch } from '../uses'
 import request from '/src/helpers/request'
 import SettingState from '/src/pages/detail/setting-state'
-import runtime, { sectionChange } from '/src/pages/detail/runtime'
+import runtime, { changeSpeed } from '/src/pages/detail/runtime'
 import state from '/src/pages/detail/state'
 import { Toast } from 'vant'
+import { userInfo } from '../App'
 
 interface IquestionExtendsInfo {
   /** 评测难度 */
-  difficulty: 'ONE' | 'TWO' | 'THREE' | '1' | '2' | '3' | ''
+  difficulty?: 'ONE' | 'TWO' | 'THREE' | '1' | '2' | '3' | ''
   /** 开始小节 */
-  start: string | number
+  start?: string | number
   /** 结束小节 */
-  end: string | number
+  end?: string | number
+  /** 速度 */
+  speed?: number
 }
 const difficultyData: { [_: string]: any } = {
   ONE: 'BEGINNER',
@@ -31,11 +34,7 @@ export const unitTestData = reactive({
 export default defineComponent({
   name: 'unitTest',
   setup() {
-    const questionExtendsInfo = ref<IquestionExtendsInfo>({
-      difficulty: '',
-      start: '',
-      end: '',
-    })
+    const questionExtendsInfo = ref<IquestionExtendsInfo>({difficulty: ''})
     /**
      * 如果是课后训练或者单元测验,获取数据
      * @param xml 获取的xml数据
@@ -44,7 +43,7 @@ export default defineComponent({
     const getUnitData = async () => {
       const search = useOriginSearch()
       if (!search.questionId) return ''
-
+      
       try {
         const res: any = await request.get(`/examinationQuestion/detail?examinationQuestionId=${search.questionId}`)
         questionExtendsInfo.value = JSON.parse(res?.data?.questionExtendsInfo) || {}
@@ -53,6 +52,26 @@ export default defineComponent({
       } catch (error) {
         console.error('解析单元测验曲谱题目失败', error)
       }
+      setSection()
+    }
+    
+    const getlessonTrainingData = async () => {
+      const search = useOriginSearch()
+      if (!search.lessonTrainingId) return
+      try {
+        const res: any = await request.post(`/studentLessonTraining/trainingRecord/${search.courseScheduleId}?userId=${userInfo.id}`)
+        if (Array.isArray(res?.data?.trainings)){
+          const train = res.data.trainings.find((n: any) => n.materialId == search.materialId)
+          const info = JSON.parse(train.trainingContent)
+          // console.log("🚀 ~ info", info)
+          questionExtendsInfo.value.start = Number(info.startSection)
+          questionExtendsInfo.value.end = Number(info.endSection)
+          questionExtendsInfo.value.speed = isNaN(info.speed) ? 0 : Number(info.speed)
+        }
+      } catch (error) {
+        console.error('解析课后训练曲谱题目失败', error)
+      }
+      setSection()
     }
 
     /**设置小节 */
@@ -72,14 +91,18 @@ export default defineComponent({
         state.sectionStatus = true
         state.section = [startNote, endNote]
         // 设置评测难度
-        if (difficultyData[questionExtendsInfo.value.difficulty]) {
-          SettingState.eva.difficulty = difficultyData[questionExtendsInfo.value.difficulty]
+        if (difficultyData[questionExtendsInfo.value.difficulty!]) {
+          SettingState.eva.difficulty = difficultyData[questionExtendsInfo.value.difficulty!]
+        }
+        //设置速度
+        if (questionExtendsInfo.value.speed) {
+          changeSpeed(questionExtendsInfo.value.speed)
         }
       }
     }
-    onMounted(async () => {
-      await getUnitData()
-      setSection()
+    onMounted(() => {
+      getUnitData()
+      getlessonTrainingData()
     })
     return () => <div></div>
   },