Przeglądaj źródła

更新localstorage

liqk 4 lat temu
rodzic
commit
af09a1997c

+ 12 - 12
TEAMModelOS/ClientApp/src/store/module/user.js

@@ -232,29 +232,29 @@ export default {
         setSchoolCode(state, data) {
             state.schoolCode = data
         },
-        addClasses(state, data) {
+        addRoom(state, data) {
             let school_profile = localStorage.getItem('school_profile')
             if(school_profile){
                 let schoolProfile = JSON.parse(decodeURIComponent(school_profile,"utf-8"))
-                schoolProfile.school_classes.unshift(data)
-                state.schoolProfile.school_classes = schoolProfile.school_classes
+                schoolProfile.school_rooms.unshift(data)
+                state.schoolProfile.school_rooms = schoolProfile.school_rooms
                 localStorage.setItem('school_profile', encodeURIComponent(JSON.stringify(schoolProfile), "utf-8"))
             }
         },
-        delClasses(state, id) {
+        delRoom(state, id) {
             let school_profile = localStorage.getItem('school_profile')
             if(school_profile){
                 let schoolProfile = JSON.parse(decodeURIComponent(school_profile,"utf-8"))
                 let orgIndex = -1;
 
-                for (let i in schoolProfile.school_classes) {
-                    if (schoolProfile.school_classes[i].id == id) {
+                for (let i in schoolProfile.school_rooms) {
+                    if (schoolProfile.school_rooms[i].id == id) {
                         orgIndex = i
                         break
                     }
                 }
-                schoolProfile.school_classes.splice(orgIndex, 1) // 刪掉指定教室
-                state.schoolProfile.school_classes = schoolProfile.school_classes
+                schoolProfile.school_rooms.splice(orgIndex, 1) // 刪掉指定教室
+                state.schoolProfile.school_rooms = schoolProfile.school_rooms
                 localStorage.setItem('school_profile', encodeURIComponent(JSON.stringify(schoolProfile), "utf-8"))
             }
         },
@@ -734,13 +734,13 @@ export default {
         },
         
         // 新增教室
-        addSchoolClasses(context, data) {
-            context.commit('addClasses', data)
+        addSchoolRoom(context, data) {
+            context.commit('addRoom', data)
         },
 
         // 刪除教室
-        delSchoolClasses(context, id) {
-            context.commit('delClasses', id)
+        delSchoolRoom(context, id) {
+            context.commit('delRoom', id)
         },
     }
 }

+ 10 - 9
TEAMModelOS/ClientApp/src/view/schoolmgmt/ClassroomSetting/ClassroomSetting.vue

@@ -569,7 +569,7 @@ export default {
         },
         selectTab(index) {
             this.currentTabIndex = index
-            if(index == 4){
+            if (index == 4) {
                 this.findClassCus()
             }
         },
@@ -815,17 +815,14 @@ export default {
                 res => {
                     if (res) {
                         if (res.error) {
-                            this.roomListShow[this.curClassIndex].option = option
                             this.$Message.error(res.v)
                         } else {
                             this.$Message.success(this.$t('schoolBaseInfo.csTips3'))
                             this.updated = false
                             this.updHiteachLink = []
-                            if (option == 'insert') {
-                                this.roomListShow[this.curClassIndex].code = 'Class-' + this.roomListShow[this.curClassIndex].code
-                                this.roomList.unshift(this.roomListShow[this.curClassIndex])
-                                this.$store.dispatch('user/addSchoolClasses', this.roomListShow[this.curClassIndex]);
-                            }
+                            this.roomListShow[this.curClassIndex].code = 'Class-' + this.roomListShow[this.curClassIndex].code
+                            // this.roomList.unshift(this.roomListShow[this.curClassIndex])
+                            // this.$store.dispatch('user/addSchoolRoom', this.roomListShow[this.curClassIndex])
                         }
                     } else {
                         this.$Message.error('API error!')
@@ -937,6 +934,7 @@ export default {
             }
             this.$api.room.DelRoom(requestData).then(
                 res => {
+                    this.curClassIndex = 0
                     this.$Message.success(this.$t('schoolBaseInfo.csTips7'))
                     let originIndex = -1
                     for (let i in this.roomList) {
@@ -947,6 +945,7 @@ export default {
                     }
                     this.roomList.splice(originIndex, 1)
                     this.roomListShow.splice(index, 1)
+                    this.$store.dispatch('user/delSchoolRoom', this.roomListShow[index].id);
                 },
                 err => {
                     this.$Message.error('API error!')
@@ -988,7 +987,7 @@ export default {
                     this.drawSchoolPlan('')
                     this.initIcon()
                 }
-                if(this.currentTabIndex == 4){
+                if (this.currentTabIndex == 4) {
                     this.findClassCus()
                 }
             }
@@ -1028,7 +1027,9 @@ export default {
                     if (!res.error) {
                         this.$Message.success(this.$t('schoolBaseInfo.csTips3'))
                         this.roomListShow.unshift(this._.cloneDeep(res.room))
-                        console.log(this.roomListShow)
+                        this.roomList.unshift(this.roomListShow[this.curClassIndex])
+                        this.$store.dispatch('user/addSchoolRoom', res.room)
+                        this.updated = false
                     } else {
                         this.$Message.error('API error!')
                     }