Jelajahi Sumber

直播课和视频课声部过滤

skyblued 2 tahun lalu
induk
melakukan
2546ab21ef
2 mengubah file dengan 28 tambahan dan 30 penghapusan
  1. 14 14
      src/views/live-class/index.tsx
  2. 14 16
      src/views/video-class/index.tsx

+ 14 - 14
src/views/live-class/index.tsx

@@ -45,20 +45,20 @@ export default defineComponent({
     } catch {
     } catch {
       //
       //
     }
     }
-    let subjectName = ''
-    this.subjectList.forEach((item: any) => {
-      item.subjects?.forEach((child: any) => {
-        if (child.id === Number(this.params.subjectId)) {
-          subjectName = child.name
-        }
-        if (!this.params.subjectId) {
-          subjectName = child.name
-          this.params.subjectId = child.id
-        }
-      })
-    })
-    const subjectNameList = state.user.data?.subjectName || ''
-    this.params.subjectName = subjectName || subjectNameList.split(',')[0] || ''
+    const list = this.subjectList.map((n: any) => n.subjects).flat()
+    const userSubjectId = this.params.subjectId
+    let isRest = true
+    for(let i = 0; i < list.length; i++){
+      if (list[i].id == userSubjectId) {
+        this.params.subjectName = list[i].name
+        isRest = false
+        break;
+      }
+    }
+    if (isRest && list.length){
+      this.params.subjectId = list[0].id
+      this.params.subjectName = list[0].name
+    }
     sessionStorage.removeItem('liveClassSubjectId')
     sessionStorage.removeItem('liveClassSubjectId')
     this.getList()
     this.getList()
   },
   },

+ 14 - 16
src/views/video-class/index.tsx

@@ -45,22 +45,20 @@ export default defineComponent({
     } catch {
     } catch {
       //
       //
     }
     }
-    let subjectName = ''
-    // console.log(this.params.lessonSubject)
-    this.subjectList.forEach((item: any) => {
-      item.subjects?.forEach((child: any) => {
-        if (child.id === Number(this.params.lessonSubject)) {
-          subjectName = child.name
-        }
-        // console.log(this.params.lessonSubject)
-        if (!this.params.lessonSubject) {
-          subjectName = child.name
-          this.params.lessonSubject = child.id
-        }
-      })
-    })
-    const subjectNameList = state.user.data?.subjectName || ''
-    this.params.subjectName = subjectName || subjectNameList.split(',')[0] || ''
+    const list = this.subjectList.map((n: any) => n.subjects).flat()
+    const userSubjectId = this.params.lessonSubject
+    let isRest = true
+    for(let i = 0; i < list.length; i++){
+      if (list[i].id == userSubjectId) {
+        this.params.subjectName = list[i].name
+        isRest = false
+        break;
+      }
+    }
+    if (isRest && list.length){
+      this.params.lessonSubject = list[0].id
+      this.params.subjectName = list[0].name
+    }
     sessionStorage.removeItem('videoClassSubjectId')
     sessionStorage.removeItem('videoClassSubjectId')
     this.getList()
     this.getList()
   },
   },