Browse Source

fix: 修改原先在不同课程详情页之间跳转不会刷新Notice列表的bug

ChenYangfan 6 years ago
parent
commit
c32912d1fe

+ 10 - 8
src/App.vue

@@ -86,14 +86,16 @@ export default {
   },
   },
   methods: {
   methods: {
     fetchUserInfo () {
     fetchUserInfo () {
-      return getUserInfo().then(res => {
-        this.$store.commit(SET_USER_INFO, { userInfo: res })
-        if (res.role === userType.student) {
-          this.$router.push({ name: 'student-explore' })
-        } else {
-          this.$router.push({ name: 'teacher-explore' })
-        }
-      }).catch(err => this.$setErrorMessage(err.response.data.msg))
+      setTimeout(() => {
+        getUserInfo().then(res => {
+          this.$store.commit(SET_USER_INFO, { userInfo: res })
+          if (res.role === userType.student) {
+            this.$router.push({ name: 'student-explore' })
+          } else {
+            this.$router.push({ name: 'teacher-explore' })
+          }
+        }).catch(err => this.$setErrorMessage(err.response.data.msg))
+      }, 5000)
     }
     }
   }
   }
 }
 }

+ 3 - 2
src/components/Cards/NoticeCard.vue

@@ -31,11 +31,12 @@ export default {
   components: { CButton, CIcon, ShowTransition, ShowTransitionSmall },
   components: { CButton, CIcon, ShowTransition, ShowTransitionSmall },
   props: {
   props: {
     notice: Object,
     notice: Object,
-    canEdit: Boolean
+    canEdit: Boolean,
+    show: Boolean
   },
   },
   data () {
   data () {
     return {
     return {
-      showMore: false
+      showMore: this.show
     }
     }
   },
   },
   methods: {
   methods: {

+ 21 - 6
src/views/student/components/StudentCourseDetail.vue

@@ -7,11 +7,12 @@
         {{showMore ? '收起' : '显示'}}详情
         {{showMore ? '收起' : '显示'}}详情
       </c-button>
       </c-button>
     </back-title>
     </back-title>
+    <div class="course-name-bar">{{course.name}}</div>
     <show-transition>
     <show-transition>
       <course-detail v-if="showMore" :course="course"></course-detail>
       <course-detail v-if="showMore" :course="course"></course-detail>
     </show-transition>
     </show-transition>
     <template v-for="notice of notices">
     <template v-for="notice of notices">
-      <notice-card :key="'notice-' + notice.id"
+      <notice-card show :key="'notice-' + notice.id"
                    :notice="notice">
                    :notice="notice">
       </notice-card>
       </notice-card>
     </template>
     </template>
@@ -50,14 +51,22 @@ export default {
       return momentFromNow(this.course.createAt)
       return momentFromNow(this.course.createAt)
     }
     }
   },
   },
+  watch: {
+    course () {
+      this.fetchNotices()
+    }
+  },
   mounted () {
   mounted () {
-    getNotices({ courseId: this.course.id }).then(res => {
-      this.notices = res.data
-    }).catch(err => {
-      this.$setErrorMessage(err.response.data.msg)
-    })
+    this.fetchNotices()
   },
   },
   methods: {
   methods: {
+    fetchNotices () {
+      getNotices({ courseId: this.course.id }).then(res => {
+        this.notices = res.data
+      }).catch(err => {
+        this.$setErrorMessage(err.response.data.msg)
+      })
+    },
     handleCheckSlideList () {
     handleCheckSlideList () {
       this.$router.push({ name: 'student-course-slides' })
       this.$router.push({ name: 'student-course-slides' })
     },
     },
@@ -99,4 +108,10 @@ export default {
 .course-detail {
 .course-detail {
   transform: translateY(-16px);
   transform: translateY(-16px);
 }
 }
+
+.course-name-bar {
+  position: relative;
+  margin-bottom: 10px;
+  top: -12px;
+}
 </style>
 </style>

+ 12 - 4
src/views/teacher/components/TeacherCourseDetail.vue

@@ -12,7 +12,7 @@
     </show-transition>
     </show-transition>
     <template v-if="notices">
     <template v-if="notices">
       <template v-for="notice of notices">
       <template v-for="notice of notices">
-        <notice-card can-edit :notice="notice" :key="'notice-' + notice.id"></notice-card>
+        <notice-card show can-edit :notice="notice" :key="'notice-' + notice.id"></notice-card>
       </template>
       </template>
     </template>
     </template>
     <div class="vertical-center mt-24">
     <div class="vertical-center mt-24">
@@ -61,12 +61,20 @@ export default {
       return momentFromNow(this.course.createAt)
       return momentFromNow(this.course.createAt)
     }
     }
   },
   },
+  watch: {
+    course () {
+      this.fetchNotices()
+    }
+  },
   mounted() {
   mounted() {
-    getNotices({ courseId: this.course.id }).then(res => {
-      this.notices = res.data
-    })
+    this.fetchNotices()
   },
   },
   methods: {
   methods: {
+    fetchNotices () {
+      getNotices({ courseId: this.course.id }).then(res => {
+        this.notices = res.data
+      })
+    },
     handleCheckSlideList () {
     handleCheckSlideList () {
       this.$router.push({ name: 'teacher-course-slides' })
       this.$router.push({ name: 'teacher-course-slides' })
     },
     },