浏览代码

排查vuex刷新流程,解决缓存数据bug

liqk 4 年之前
父节点
当前提交
e86060c764
共有 1 个文件被更改,包括 46 次插入22 次删除
  1. 46 22
      TEAMModelOS/ClientApp/src/view/student-account/ClassMgt.vue

+ 46 - 22
TEAMModelOS/ClientApp/src/view/student-account/ClassMgt.vue

@@ -206,7 +206,8 @@ export default {
             }
         }
         return {
-            roomList: [],
+            tableHeight:400,
+            // roomList: [],
             filterYear: 'all',
             studentColumn: [
                 {
@@ -247,9 +248,9 @@ export default {
             ],
             editIndex: -1,
             resetNoBef: 0,
-            schoolBase: {
-                period: []
-            },
+            // schoolBase: {
+            //     period: []
+            // },
             delSelections: [],//需要移除的学生
             selections: [],//添加的学生
             addStuStatus: false,
@@ -265,7 +266,7 @@ export default {
             isSaveLoading: false,
             isInit: true,
             updated: false,
-            classList: [],
+            // classList: [],
             classListShow: [],
             curClassIndex: 0,
             keyword: '',
@@ -299,6 +300,9 @@ export default {
     computed: {
         ...mapGetters({
             periods: 'user/getPeriods', // 學制s
+            schoolBase: 'user/getSchoolBase',
+            classList: 'user/getClasses',
+            roomList: 'user/getRooms'
         }),
         filterYearName() {
             if (this.filterYear == 'all') {
@@ -679,7 +683,7 @@ export default {
                         )
                     }
                 })
-            }else{
+            } else {
                 this.$Message.error(this.$t('system.authErr'))
             }
         },
@@ -817,27 +821,47 @@ export default {
         }
     },
     created() {
-        this.isListLoading = true
-        this.$store.dispatch('user/getSchoolProfile').then(
-            res => {
-                this.schoolBase = res.school_base
-                this.classList = res.school_classes
-                this.roomList = res.school_rooms
+        // this.isListLoading = true
+        // this.$store.dispatch('user/getSchoolProfile').then(
+        //     res => {
+        //         // this.schoolBase = res.school_base
+        //         this.classList = res.school_classes
+        //         this.roomList = res.school_rooms
+        //         if (this.classList.length > 0) {
+        //             this.updateBefore = JSON.stringify(this.classList[0])
+        //         }
+        //         this.filterClassname()
+        //         // 預設搜尋給第一個
+        //         if (this.periods) this.filterPeriod = this.periods[0].id
+        //         this.filterByPeriod()
+        //     }
+        // ).finally(() => {
+        //     setTimeout(() => {
+        //         this.isListLoading = false
+        //     }, 500)
+        // })
+        if (this.$access.can('admin.*|classroom-upd')) this.editStatus = this.noStatus
+        this.$store.dispatch('teachers/getTeacherList').then(res => { })
+    },
+    watch: {
+        classList: {
+            handler(n, o) {
                 if (this.classList.length > 0) {
                     this.updateBefore = JSON.stringify(this.classList[0])
                 }
                 this.filterClassname()
-                // 預設搜尋給第一個
-                if (this.periods) this.filterPeriod = this.periods[0].id
+            },
+            deep: true,
+            immediate: true
+        },
+        periods: {
+            handler(n, o) {
+                if (this.periods && this.periods.length) this.filterPeriod = this.periods[0].id
                 this.filterByPeriod()
-            }
-        ).finally(() => {
-            setTimeout(() => {
-                this.isListLoading = false
-            }, 500)
-        })
-        if (this.$access.can('admin.*|classroom-upd')) this.editStatus = this.noStatus
-        this.$store.dispatch('teachers/getTeacherList').then(res => { })
+            },
+            deep: true,
+            immediate: true
+        }
     }
 }
 </script>