mjh 4 лет назад
Родитель
Сommit
bdd9d02c0c

+ 1 - 0
src/components/CourseCard.vue

@@ -114,6 +114,7 @@ export default {
   left: 0;
   outline: solid 1px #eeeeee;
   min-height: 60px;
+  object-fit: cover;
 }
 
 .name {

+ 93 - 8
src/views/CoursePage/CourseDetail.vue

@@ -1,5 +1,6 @@
 <template>
   <div class="course-detail-page">
+    <!--课程信息-->
     <div v-if="courseInfo!==null" class="course-detail-container">
       <!--课程基本信息-->
       <el-card>
@@ -66,7 +67,7 @@
                 <el-button>添加测试</el-button>
               </template>
             </el-popover>
-            <el-popover v-if="tabName==='notice'"
+            <el-popover v-else-if="tabName==='notice'"
                         v-model:visible="noticePopover"
                         :width="160"
                         placement="bottom">
@@ -103,15 +104,19 @@
                 </el-button>
               </template>
             </el-popover>
-            <el-button v-if="tabName==='group'&&isRuleExisted!==null"
-                       plain type="primary" :disabled="isRuleExisted" @click="setRule">
-              {{ isRuleExisted ? '已开放组队' : '开放组队' }}
+            <el-button v-else-if="tabName==='group'"
+                       plain type="primary" :disabled="isRuleExisted||isRuleExisted===null" @click="setRule">
+              {{ isRuleExisted === null ? null : (isRuleExisted ? '已开放组队' : '开放组队') }}
             </el-button>
-            <el-upload v-if="tabName==='courseware'" :http-request="handleFileUploading"
+            <el-upload v-else-if="tabName==='courseware'" :http-request="handleFileUploading"
                        :on-success="handleFileUploadSuccess"
                        :show-file-list="false" action="">
               <el-button plain type="primary">上传课件</el-button>
             </el-upload>
+            <el-button v-else-if="tabName==='project'" @click="projectDialogVisible=true"
+                       plain type="primary">
+              新建项目
+            </el-button>
           </div>
         </div>
         <!--tab内容-->
@@ -252,6 +257,24 @@
               </div>
             </div>
           </div>
+          <div v-else-if="tabName==='project'">
+            <el-tabs v-if="projects!==null" v-model="projectTabName" type="border-card">
+              <el-tab-pane label="公开项目" name="public">
+                <div v-if="projects.public.length===0">
+                  当前没有公开项目
+                </div>
+                <div v-else>
+                  {{ projects.public }}
+                </div>
+              </el-tab-pane>
+              <el-tab-pane label="私有项目" name="private">
+                <div v-if="projects.private.length===0">
+                  当前没有私有项目
+                </div>
+                <div v-else>{{ projects.private }}</div>
+              </el-tab-pane>
+            </el-tabs>
+          </div>
         </div>
       </el-card>
     </div>
@@ -293,6 +316,29 @@
         <el-button plain type="danger" @click="beforeRuleFormClose">我再想想</el-button>
       </div>
     </el-dialog>
+    <!--新建项目-->
+    <el-dialog v-model="projectDialogVisible" title="新建项目"
+               :before-close="handleProjectFormCancel">
+      <el-form :model="projectForm" ref="projectFormRef">
+        <el-form-item label="项目名称" prop="name">
+          <el-input v-model="projectForm.name" placeholder="请输入项目名称"/>
+        </el-form-item>
+        <el-form-item label="项目描述" prop="description">
+          <el-input v-model="projectForm.description" placeholder="请输入项目描述"/>
+        </el-form-item>
+        <el-form-item label="是否公开" prop="isPublic">
+          <el-select v-model="projectForm.isPublic">
+            <el-option label="公开" :value="true" />
+            <el-option label="私有" :value="false" />
+          </el-select>
+        </el-form-item>
+      </el-form>
+      <template #footer>
+        <el-button type="primary" @click="handleProjectFormConfirm">
+          确认
+        </el-button>
+      </template>
+    </el-dialog>
   </div>
 </template>
 
@@ -398,6 +444,15 @@ export default {
           uploadTime: "2021-12-12 08:22:23",
           url: ""
         }],
+      // project
+      projects: null,
+      projectTabName: "public",
+      projectDialogVisible: false,
+      projectForm: {
+        name: "",
+        description: "",
+        isPublic: false,
+      }
     };
   },
   computed: {
@@ -782,6 +837,7 @@ export default {
     },
     // tab页相关
     async switchTab(tabName) {
+      const _this = this;
       switch (tabName) {
         case "task":
           if (this.isTeacher) {
@@ -809,11 +865,16 @@ export default {
           this.commentTree = (await this.$apis.getCommentsByCourseId(this.$route.params.id)).data.data;
           break;
         case "project":
-          //todo
+          const projectRes = (await _this.$apis.findProjectsByCourse(_this.courseInfo.id)).data;
+          if (projectRes.code) {
+            ElMessage.error(projectRes.message);
+          } else {
+            _this.projects = projectRes.data;
+          }
           break;
         case "group":
-          const res = (await this.$apis.findGroupRule(this.courseInfo.id)).data;
-          this.isRuleExisted = !res.code;
+          const groupRes = (await this.$apis.findGroupRule(this.courseInfo.id)).data;
+          this.isRuleExisted = !groupRes.code;
           break;
       }
     },
@@ -884,6 +945,30 @@ export default {
           }
         });
     },
+    // project
+    handleProjectFormCancel(){
+      const _this = this;
+      _this.projectDialogVisible = false;
+      _this.$refs.projectFormRef.resetFields();
+    },
+    async handleProjectFormConfirm(){
+      const _this = this;
+      const res = (await _this.$apis.createProject({
+        courseId: _this.courseInfo.id,
+        ..._this.projectForm,
+      })).data;
+      if(res.code){
+        ElMessage.error(res.message);
+      }else{
+        if(_this.projectForm.isPublic){
+          _this.projects.public.push(res.data);
+        }else{
+          _this.projects.private.push(res.data);
+        }
+        _this.projectDialogVisible = false;
+        _this.$refs.projectFormRef.resetFields();
+      }
+    }
   },
 };
 </script>

+ 3 - 3
src/views/CoursePage/style/CourseDetail.css

@@ -36,14 +36,14 @@
 
 .course-img {
     width: 400px;
-    height: 225px;
-    object-fit: contain;
-    object-position: center center;
+    height: 230px;
 }
 
 .course-img > img {
     width: 100%;
     height: 100%;
+    object-fit: cover;
+    object-position: center center;
 }
 
 .course-info {

+ 15 - 14
src/views/ManagePage/ManagePage.vue

@@ -365,12 +365,7 @@ export default {
             }).then(async (res) => {
               const createdCourse = res.data.data;
               if (createdCourse) {
-                if (_this.form.fileList.length !== 0) {
-                  const imageUrl = (await _this.$apis.uploadCourseImage(createdCourse.name, this.form.fileList[0].raw)).data.data;
-                  if (imageUrl) {
-                    createdCourse.imageUrl = imageUrl;
-                  }
-                }
+                await uploadImage(createdCourse);
                 _this.myCourseList.push(createdCourse);
                 _this.dialogVisible = false;
                 _this.clearForm();
@@ -396,18 +391,13 @@ export default {
             }).then(async (res) => {
               const updatedCourse = res.data.data;
               if (updatedCourse) {
-                if (_this.form.fileList.length !== 0) {
-                  const imageUrl = (await _this.$apis.uploadCourseImage(createdCourse.name, this.form.fileList[0].raw)).data.data;
-                  if (imageUrl) {
-                    updatedCourse.imageUrl = imageUrl;
-                  }
-                }
+                await uploadImage(updatedCourse);
                 for (let i = 0; i < _this.myCourseList.length; i++) {
                   if (_this.myCourseList[i].id === _this.form.id) {
-                    _this.myCourseList[i] = createdCourse;
+                    _this.myCourseList[i] = updatedCourse;
                   }
                 }
-                _this.$refs["courseCard" + _this.form.id][0].$props.courseVO = createdCourse;
+                _this.$refs["courseCard" + _this.form.id][0].$props.courseVO = updatedCourse;
                 _this.dialogVisible = false;
                 _this.clearForm();
                 ElMessage.success("更新课程成功");
@@ -416,6 +406,17 @@ export default {
           }
         }
       });
+
+      async function uploadImage(course){
+        if (_this.form.fileList.length !== 0) {
+          const imageUrl = (await _this.$apis.uploadCourseImage(course.name, _this.form.fileList[0].raw)).data;
+          if (imageUrl.code) {
+            ElMessage.error(imageUrl.message);
+          }else{
+            course.imageUrl = imageUrl;
+          }
+        }
+      }
     },
     handleFormCancel() {
       ElMessageBox.confirm("是否确认退出?退出后将不保存表格信息。", "提示", {