ソースを参照

优化首页课表

liqk 3 年 前
コミット
afca7e23c8

+ 3 - 2
TEAMModelOS/ClientApp/src/view/homepage/HomePage.vue

@@ -292,7 +292,9 @@ export default {
             return icon
         },
         getTmwCus(data) {
-            this.tmwCus = data
+            this.tmwCus = []
+            console.log('明日课程:', JSON.stringify(data))
+            this.tmwCus = this._.cloneDeep(data)
         },
         toAc(type, scope) {
             // if(scope == 'school'){
@@ -392,7 +394,6 @@ export default {
     watch:{
         '$store.state.userInfo.schoolCode':{
             handler(n,o){
-                console.log(n)
                 this.getAcCount()
             }
         }

+ 50 - 51
TEAMModelOS/ClientApp/src/view/homepage/MinTable.vue

@@ -62,7 +62,7 @@ export default {
             // schoolBase: {
             //     period: []
             // },
-            tabalLoading:false,
+            tabalLoading: false,
             courseList: [],
             courseListShow: [],
             fullCus: [],
@@ -119,7 +119,7 @@ export default {
         }),
     },
     watch: {
-        schoolBase: {
+        '$store.state.userInfo.schoolCode': {
             handler(n, o) {
                 this.getCourseList()
             },
@@ -135,6 +135,8 @@ export default {
         },
         //获取个人和校本课程列表,API调整后没有进行分开处理
         getCourseList(schoolCode) {
+            this.cusData = []
+            this.fullCus = []
             this.tabalLoading = true
             let requestData = {
                 'code': this.$store.state.userInfo.TEAMModelId,
@@ -160,6 +162,7 @@ export default {
                         })
                         Promise.all(promises).then(
                             async resAll => {
+                                let listIds = []
                                 for (const res of resAll) {
                                     if (res.courses && res.courses.length > 0) {
                                         res.courses[0].schedule = res.courses[0].schedule ? res.courses[0].schedule : []
@@ -171,47 +174,49 @@ export default {
                                         let ids = res.courses[0].schedule.map(item => {
                                             return item.stulist
                                         })
-                                        for (let i = 0; i < ids.length; i++) {
-                                            if (!ids[i]) {
-                                                ids.splice(i, 1)
-                                                i--
-                                            }
-                                        }
-                                        let stuList = []
-                                        if (ids.length) {
-                                            try {
-                                                let listRes = await this.getListInfo([...ids])
-                                                if (listRes) stuList.push(...listRes.stuList)
-                                            } catch (e) {
-                                                this.$Message.error('API ERROR!')
-                                            }
-                                        }
-
-                                        res.courses[0].schedule.forEach(item => {
-                                            //补充教室信息
-                                            if (item.classId) {
-                                                let classInfo = this.classList.find(classItem => {
-                                                    return classItem.id == item.classId
-                                                })
-                                                item.classInfo = {
-                                                    id: item.classId,
-                                                    name: classInfo ? classInfo.name : '--'
-                                                }
-                                            }
-                                            //补充名单信息
-                                            if (ids.length && item.stulist) {
-                                                let listInfo = stuList.find(listItem => {
-                                                    return listItem.id == item.stulist
-                                                })
-                                                item.listName = listInfo ? listInfo.name : '--'
-                                                item.students = listInfo ? listInfo.students : []
-                                                item.fullStu = false
+                                        ids.forEach(i => {
+                                            if (i && !listIds.includes(i)) {
+                                                listIds.push(i)
                                             }
                                         })
                                     }
                                     this.fullCus.push(res.courses[0])
                                 }
-                                console.log('处理表格数据')
+                                console.log('名单ids', listIds)
+                                let stuList = []
+                                if (listIds.length) {
+                                    try {
+                                        let listRes = await this.getListInfo(listIds)
+                                        if (listRes) {
+                                            stuList.push(...listRes.stuList)
+                                            this.fullCus.forEach(cusitem => {
+                                                cusitem.schedule.forEach(item => {
+                                                    //补充教室信息
+                                                    if (item.classId) {
+                                                        let classInfo = this.classList.find(classItem => {
+                                                            return classItem.id == item.classId
+                                                        })
+                                                        item.classInfo = {
+                                                            id: item.classId,
+                                                            name: classInfo ? classInfo.name : '--'
+                                                        }
+                                                    }
+                                                    //补充名单信息
+                                                    if (item.stulist) {
+                                                        let listInfo = stuList.find(listItem => {
+                                                            return listItem.id == item.stulist
+                                                        })
+                                                        item.listName = listInfo ? listInfo.name : '--'
+                                                        item.students = listInfo ? listInfo.students : []
+                                                        item.fullStu = false
+                                                    }
+                                                })
+                                            })
+                                        }
+                                    } catch (e) {
+                                        this.$Message.error('API ERROR!')
+                                    }
+                                }
                                 this.dataToTable()
                             },
                             err => {
@@ -242,7 +247,9 @@ export default {
         //根据schedule处理数据进行渲染
         dataToTable() {
             //目前默认显示第一个学段的课程
-            this.cusData = []
+            this.tmwCus.length = 0
+            this.$emit('tmwCus', this.tmwCus)
+            console.log('初始化课程', JSON.stringify(this.tmwCus))
             let period = ''
             if (this.schoolBase.period && this.schoolBase.period.length) {
                 period = this.schoolBase.period[0].id
@@ -253,7 +260,7 @@ export default {
             if (pdData) {
                 let times = pdData.timetable
                 if (times && times.length) {
-                    
+
                     this.cusData = Array.apply(null, { length: times.length }).map(() => ({
                         MON: '',
                         TUE: '',
@@ -265,7 +272,7 @@ export default {
                     }))
                     let tmw = this.getNextDay()
                     console.log('今天', tmw)
-                    // let tmw = 'WED'
+                    let tmwc = []
                     this.fullCus.forEach((cusItem) => {
                         cusItem.schedule.forEach(schedItem => {
                             schedItem.time.forEach(timeItem => {
@@ -284,7 +291,7 @@ export default {
                                         return i.id == timeItem.id
                                     })
                                     if (t) {
-                                        this.tmwCus.push(
+                                        tmwc.push(
                                             {
                                                 time: t.time,
                                                 timeLabel: t.label,
@@ -297,6 +304,7 @@ export default {
                             })
                         })
                     })
+                    this.tmwCus = tmwc
                     this.$emit('tmwCus', this.tmwCus)
                 }
             } else {
@@ -341,17 +349,8 @@ export default {
         }
     },
     mounted() {
-        // this.$EventBus.$off('onChangeSchool')
-        // this.$EventBus.$on('onChangeSchool', (data) => {
-        //     console.log('切换学校', data)
-        //     this.getCourseList(data.schoolCode)
-        // })
     },
     created() {
-        //直接读取登录成功拿到得学校基础信息
-        this.$store.dispatch('user/getSchoolProfile').then(res => {
-            this.getCourseList()
-        })
     }
 }
 </script>