浏览代码

优化声部

skyblued 2 年之前
父节点
当前提交
bab7d290e4
共有 2 个文件被更改,包括 25 次插入18 次删除
  1. 13 9
      src/views/live-class/index.tsx
  2. 12 9
      src/views/video-class/index.tsx

+ 13 - 9
src/views/live-class/index.tsx

@@ -47,20 +47,24 @@ export default defineComponent({
     } catch {
       //
     }
-    const list = this.subjectList.map((n: any) => n.subjects).flat().filter(n => typeof n === 'object').sort((a,b) => a.id - b.id)
+    const list = this.subjectList
     const userSubjectId = state.user.data?.subjectId.split(',').map(n => parseInt(n)) || [this.params.subjectId]
     let isRest = true
     for(let i = 0; i < list.length; i++){
-      if (userSubjectId.includes(list[i].id)) {
-        this.params.subjectId = list[i].id
-        this.params.subjectName = list[i].name
-        isRest = false
-        break;
+      const subjects = (list[i] as any).subjects || []
+      for(let j = 0; j < subjects.length; j++){
+        if (userSubjectId.includes(subjects[j].id)) {
+          this.params.subjectId = subjects[j].id
+          this.params.subjectName = subjects[j].name
+          isRest = false
+          break;
+        }
       }
+      
     }
-    if (isRest && list.length){
-      this.params.subjectId = list[0].id
-      this.params.subjectName = list[0].name
+    if (isRest && list.length && (list[0] as any).subjects){
+      this.params.subjectId = (list[0] as any).subjects[0].id
+      this.params.subjectName = (list[0] as any).subjects[0].name
     }
     sessionStorage.removeItem('liveClassSubjectId')
     this.getList()

+ 12 - 9
src/views/video-class/index.tsx

@@ -47,20 +47,23 @@ export default defineComponent({
     } catch {
       //
     }
-    const list = this.subjectList.map((n: any) => n.subjects).flat().filter(n => typeof n === 'object').sort((a,b) => a.id - b.id)
+    const list = this.subjectList
     const userSubjectId = state.user.data?.subjectId.split(',').map(n => parseInt(n)) || [this.params.lessonSubject]
     let isRest = true
     for(let i = 0; i < list.length; i++){
-      if (userSubjectId.includes(list[i].id)) {
-        this.params.lessonSubject = list[i].id
-        this.params.subjectName = list[i].name
-        isRest = false
-        break;
+      const subjects = (list[i] as any).subjects || []
+      for(let j = 0; j < subjects.length; j++){
+        if (userSubjectId.includes(subjects[j].id)) {
+          this.params.lessonSubject = subjects[j].id
+          this.params.subjectName = subjects[j].name
+          isRest = false
+          break;
+        }
       }
     }
-    if (isRest && list.length){
-      this.params.lessonSubject = list[0].id
-      this.params.subjectName = list[0].name
+    if (isRest && list.length && (list[0] as any).subjects){
+      this.params.lessonSubject = (list[0] as any).subjects[0].id
+      this.params.subjectName = (list[0] as any).subjects[0].name
     }
     sessionStorage.removeItem('videoClassSubjectId')
     this.getList()