|
|
@@ -27,6 +27,13 @@
|
|
|
<div class="card">
|
|
|
<div class="title">新建课程</div>
|
|
|
<div class="content">
|
|
|
+ <b-notification
|
|
|
+ class="notification-self"
|
|
|
+ type="is-danger"
|
|
|
+ :active.sync="isServerError"
|
|
|
+ >
|
|
|
+ {{ errorMassage }}
|
|
|
+ </b-notification>
|
|
|
<b-field
|
|
|
label="课程名"
|
|
|
:type="$v.coursename.$error ? 'is-danger' : ''"
|
|
|
@@ -115,17 +122,24 @@ export default {
|
|
|
username: "",
|
|
|
coursename: "",
|
|
|
coursenum: "",
|
|
|
- submitting: false
|
|
|
+ submitting: false,
|
|
|
+ isServerError: false,
|
|
|
+ errorMassage: "服务器错误,请稍后再试"
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- getTeacherCourses().then(value => (this.courses = value.data));
|
|
|
+ this.getCourses();
|
|
|
},
|
|
|
methods: {
|
|
|
+ getCourses() {
|
|
|
+ getTeacherCourses().then(value => (this.courses = value.data));
|
|
|
+ },
|
|
|
//新建课程
|
|
|
newSubject() {
|
|
|
+ if (this.submitting) return;
|
|
|
this.$v.$touch();
|
|
|
if (!this.$v.$invalid) {
|
|
|
+ this.isServerError = false;
|
|
|
let subjectInfo = {
|
|
|
name: this.coursename,
|
|
|
code: this.coursenum
|
|
|
@@ -134,18 +148,18 @@ export default {
|
|
|
postTeacherCourse(subjectInfo)
|
|
|
.then(res => {
|
|
|
this.submitting = false;
|
|
|
- console.log(res);
|
|
|
this.$toast.open({
|
|
|
- message: `${res.res.name}创建成功`,
|
|
|
+ message: `${res.data.name}创建成功`,
|
|
|
type: "is-success"
|
|
|
});
|
|
|
this.newSubjectActive = false;
|
|
|
+ this.getCourses();
|
|
|
})
|
|
|
.catch(e => {
|
|
|
- this.$toast.open({
|
|
|
- message: e.message,
|
|
|
- type: "is-danger"
|
|
|
- });
|
|
|
+ if (this.errorMassage) {
|
|
|
+ this.errorMassage = e.message;
|
|
|
+ }
|
|
|
+ this.isServerError = true;
|
|
|
});
|
|
|
}
|
|
|
}
|