Procházet zdrojové kódy

feat:作业附加文件上传功能

廖彦舟 před 1 rokem
rodič
revize
7a62f8084b

+ 1 - 1
src/router/index.js

@@ -40,7 +40,7 @@ const routes = [
     component: () => import("../views/HomePage/HomePage.vue"),
   },
   {
-    path: "/homework/:homeworkId/:teacherId/:type/:courseId",
+    path: "/homework/:homeworkId/:teacherId/:type/:courseId/:seCourseId",
     name: "Homework",
     component: () => import("../views/CoursePage/HomeworkPage.vue"),
   },

+ 210 - 54
src/views/CourseDetailPage/tabs/HomeworkTab.vue

@@ -34,6 +34,7 @@ export default {
         create:false,
         update:false,
       },
+      fileList: [],
       speakingDialog:{
         delete:false,
         create:false,
@@ -43,7 +44,7 @@ export default {
         assignmentName:"",
         description:"",
         type:"writing",
-        descriptionFile:"",
+        descriptionFile:null,
         attachments:[],
         timeRange:[]
       },
@@ -52,7 +53,7 @@ export default {
         assignmentName:"",
         description:"",
         type:"speaking",
-        descriptionFile:"",
+        descriptionFile:null,
         attachments:[],
         timeRange:[],
         minDuration:null,
@@ -125,8 +126,6 @@ export default {
     createHomework(){
       this.$refs.homeworkFormRef.validate((valid)=>{
         if (valid){
-          // console.log(this.dateTimeFormatter(this.writingHomeworkForm.timeRange[0]));
-          // console.log(this.dateTimeFormatter(this.writingHomeworkForm.timeRange[1]));
           let homeworkVO = {
             assignmentName:this.writingHomeworkForm.assignmentName,
             description:this.writingHomeworkForm.description,
@@ -136,21 +135,33 @@ export default {
             startTime: this.dateTimeFormatter(this.writingHomeworkForm.timeRange[0]),
             endTime: this.dateTimeFormatter(this.writingHomeworkForm.timeRange[1]),
           };
-          this.$apis.createWritingHomework(this.eaiId,homeworkVO)
-              .then(res => {
-                console.log( res);
-                if (res && res.data.code === 200){
-                  ElMessage.success("作业创建成功");
-                  this.dialog.create = false;
-                  this.init();
-                }
-                else{
-                  ElMessage.error("作业创建失败");
-                }
-              })
-              .catch(error => {
-                ElMessage.error("创建失败");
+          if (this.writingHomeworkForm.descriptionFile){
+            this.uploadFile(this.writingHomeworkForm.descriptionFile,"作业描述文件",(url)=>{
+              console.log(url);
+              homeworkVO.descriptionFile = url;
+              if (this.writingHomeworkForm.attachments.length!==0){
+                this.uploadFile(this.writingHomeworkForm.attachments[0],"作业附件",(url2)=>{
+                  homeworkVO.attachments = [url2];
+                  this.createWritingHomeworkByVO(homeworkVO);
+                });
+              }
+              else{
+                this.createWritingHomeworkByVO(homeworkVO);
+              }
+
+            });
+          }
+          else{
+            if (this.writingHomeworkForm.attachments.length!==0){
+              this.uploadFile(this.writingHomeworkForm.attachments[0],(url2)=>{
+                homeworkVO.attachments = [url2];
+                this.createWritingHomeworkByVO(homeworkVO);
               });
+            }
+            else{
+              this.createWritingHomeworkByVO(homeworkVO);
+            }
+            }
         }
       });
     },
@@ -173,22 +184,16 @@ export default {
             surveyLinks:this.speakingHomeworkForm.surveyLinks,
             surveyDuration:this.speakingHomeworkForm.surveyDuration
           };
-          this.$apis.createSpeakingHomework(this.eaiId,homeworkVO)
-              .then(res => {
-                console.log( res);
-                if (res && res.data.code === 200){
-                  ElMessage.success("作业创建成功");
-                  this.dialog.create = false;
-                  this.speakingDialog.create = false;
-                  this.init();
-                }
-                else{
-                  ElMessage.error("作业创建失败");
-                }
-              })
-              .catch(error => {
-                ElMessage.error("创建失败");
-              });
+          if (this.speakingHomeworkForm.descriptionFile){
+            this.uploadFile(this.speakingHomeworkForm.descriptionFile,"作业描述文件",(url)=>{
+              console.log(url);
+              homeworkVO.descriptionFile = url;
+              this.createSpeakingHomeworkByVO(homeworkVO);
+            });
+          }
+          else{
+              this.createSpeakingHomeworkByVO(homeworkVO);
+          }
         }
       });
     },
@@ -198,18 +203,41 @@ export default {
         cancelButtonText:"取消"
       })
           .then(() => {
+            if (this.$refs.homeworkFormRef){
+              this.$refs.homeworkFormRef.resetFields();
+
+            }
+            if (this.$refs.speakingHomeworkFormRef){
+              this.$refs.speakingHomeworkFormRef.resetFields();
+            }
+            this.writingHomeworkForm.descriptionFile = null;
+            this.writingHomeworkForm.attachments = [];
+            this.speakingHomeworkForm.descriptionFile = null;
+            this.speakingHomeworkForm.attachments = [];
             this.dialog.create = false;
             this.speakingDialog.create = false;
-            this.$refs.homeworkFormRef.resetFields();
-            this.$refs.speakingHomeworkFormRef.resetFields();
             done();
           })
           .catch(() => {
             done();
           });
     },
+    createHomeworkCancel(){
+      if (this.$refs.homeworkFormRef){
+        this.$refs.homeworkFormRef.resetFields();
+        this.writingHomeworkForm.descriptionFile = null;
+        this.writingHomeworkForm.attachments = [];
+      }
+      if (this.$refs.speakingHomeworkFormRef){
+        this.$refs.speakingHomeworkFormRef.resetFields();
+        this.speakingHomeworkForm.descriptionFile = null;
+        this.speakingHomeworkForm.attachments = [];
+      }
+      this.dialog.create = false;
+      this.speakingDialog.create = false;
+    },
     toHomeworkDetail(id,type){
-      this.$router.push("/homework/"+id+"/"+this.teacherId+"/"+type+"/"+this.eaiId);
+      this.$router.push("/homework/"+id+"/"+this.teacherId+"/"+type+"/"+this.eaiId+"/"+this.courseId);
     },
     statusInfo(status){
       if (status === "NOT_STARTED"){
@@ -276,7 +304,133 @@ export default {
     },
     checkInteraction(rule,value,callback){
       this.checkNumberRange(rule,value,callback,1,50);
-    }
+    },
+    handleUploadDesFile(file, fileList){
+      console.log(file,fileList);
+      if (file.size >= 512000){
+        ElMessage.error("文件过大");
+        if (this.dialog.create === true){
+          this.$refs.writingDesFileUploadRef.clearFiles();
+        }
+        else if (this.speakingDialog.create === true){
+          this.$refs.speakingDesFileUploadRef.clearFiles();
+        }
+        return;
+      }
+      if (file.name.endsWith(".doc")||file.name.endsWith(".docx")){
+        this.writingHomeworkForm.descriptionFile = file;
+        if (this.dialog.create === true){
+          this.writingHomeworkForm.descriptionFile = file;
+        }
+        else if (this.speakingDialog.create === true){
+          this.speakingHomeworkForm.descriptionFile = file;
+        }
+      }
+      else{
+        ElMessage.error("请上传doc或docx格式的描述文件");
+        if (this.dialog.create === true){
+          this.$refs.writingDesFileUploadRef.clearFiles();
+        }
+        else if (this.speakingDialog.create === true){
+          this.$refs.speakingDesFileUploadRef.clearFiles();
+        }
+      }
+    },
+    handleUploadAttachmentFile(file, fileList){
+      console.log(file,fileList);
+      if (file.size >= 512000){
+        ElMessage.error("文件过大");
+        if (this.dialog.create === true){
+          this.$refs.writingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        else if (this.speakingDialog.create === true){
+          this.$refs.speakingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        return;
+      }
+      if (file.name.endsWith(".doc")||file.name.endsWith(".docx")){
+        if (this.dialog.create === true){
+          this.writingHomeworkForm.attachments.push(file);
+        }
+        else if (this.speakingDialog.create === true){
+          this.speakingHomeworkForm.attachments.push(file);
+        }
+      }
+      else{
+        ElMessage.error("请上传doc或docx格式的附件");
+        if (this.dialog.create === true){
+          this.$refs.writingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        else if (this.speakingDialog.create === true){
+          this.$refs.speakingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+      }
+    },
+    handleAttachmentsExceed(files){
+      ElMessage.warning("最多只能上传一个附件");
+    },
+    handleExceedDesFile(files){
+      ElMessage.warning("最多只能上传一个描述文件");
+    },
+    createSpeakingHomeworkByVO(homeworkVO) {
+      this.$apis.createSpeakingHomework(this.eaiId,homeworkVO)
+          .then(res => {
+            console.log( res);
+            if (res && res.data.code === 200){
+              ElMessage.success("作业创建成功");
+              this.speakingDialog.create = false;
+              this.init();
+            }
+            else{
+              ElMessage.error("作业创建失败");
+            }
+          })
+          .catch(error => {
+            ElMessage.error("创建失败");
+          });
+    },
+    createWritingHomeworkByVO(homeworkVO) {
+      this.$apis.createWritingHomework(this.eaiId,homeworkVO)
+          .then(res => {
+            console.log( res);
+            if (res && res.data.code === 200){
+              ElMessage.success("作业创建成功");
+              this.dialog.create = false;
+              this.init();
+            }
+            else{
+              ElMessage.error("作业创建失败");
+            }
+          })
+          .catch(error => {
+            ElMessage.error("创建失败");
+          });
+    },
+    uploadFile(file,type,callback){
+      this.$apis.uploadCourseWareFile(this.courseId+"/"+type+":"+file.name,file.raw)
+          .then(res => {
+            let fileUrl = res.data.data;
+            this.$apis.createCourseWare({
+              name: file.name,
+              size: file.size,
+              senderId: this.$store.state.user.id,
+              courseId: this.courseId,
+              createdTime: new Date(),
+              useTime: "BEFORE_CLASS",
+              useMethod: "SCAN",
+              fileUrl: fileUrl,
+            }).then(res => {
+              //this.percentage= 100;
+              callback(fileUrl);
+            }).catch(err => {
+              ElMessage.error("上传文件失败");console.log(err);
+            });
+          })
+          .catch(error => {
+            ElMessage.error("文件上传失败");
+          });
+    },
+
   }
 };
 </script>
@@ -304,10 +458,10 @@ export default {
           @click="toHomeworkDetail(homework.assignmentId,homework.type)"
           :key="index">
         <el-row>
-          <el-tag v-if="homework['type'] ==='writing'" size="small" color="#409EFFFF" effect="dark"
+          <el-tag v-if="homework['type'] ==='writing'||homework['type'] ==='写作'" size="small" color="#409EFFFF" effect="dark"
                   id="homework-tag">W
           </el-tag>
-          <el-tag v-else-if="homework['type'] ==='speaking'" size="small" color="#50A879" effect="dark"
+          <el-tag v-else-if="homework['type'] ==='speaking'||homework['type'] ==='AI口语'" size="small" color="#50A879" effect="dark"
                   id="homework-tag" round>S
           </el-tag>
           <el-tag v-else class="timeline-content" size="small" color="#8dc9e2" effect="dark"
@@ -321,14 +475,6 @@ export default {
           </el-row>
         </el-row>
       </el-timeline-item>
-<!--      <el-timeline-item-->
-<!--          @click="toHomeworkDetail(activity.id)"-->
-<!--          v-for="(activity, index) in homeworkList"-->
-<!--          :key="index"-->
-<!--          :timestamp="activity.startTime+'~'+activity.endTime"-->
-<!--      >-->
-<!--        {{ activity.assignmentName }}-->
-<!--      </el-timeline-item>-->
     </el-timeline>
     <el-empty
         v-if="homeworkList.length===0"
@@ -385,9 +531,12 @@ export default {
             action=""
             show-file-list
             :auto-upload="false"
+            accept=""
+            :on-change="handleUploadDesFile"
+            :on-exceed="handleExceedDesFile"
             multiple
             :limit="1"
-            ref="attachmentUploadRef"
+            ref="writingDesFileUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
             <upload-filled />
@@ -411,7 +560,9 @@ export default {
             show-file-list
             :auto-upload="false"
             multiple
-            :limit="5"
+            :on-change="handleUploadAttachmentFile"
+            :on-exceed="handleAttachmentsExceed"
+            :limit="1"
             ref="attachmentUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
@@ -441,7 +592,7 @@ export default {
     </el-form>
     <template #footer>
       <div class="dialog-footer">
-        <el-button @click="dialog.create = false;">取消</el-button>
+        <el-button @click="createHomeworkCancel">取消</el-button>
         <el-button type="primary" @click="createHomework">
           创建
         </el-button>
@@ -497,9 +648,11 @@ export default {
             action=""
             show-file-list
             :auto-upload="false"
+            :on-change="handleUploadDesFile"
+            :on-exceed="handleExceedDesFile"
             multiple
             :limit="1"
-            ref="attachmentUploadRef"
+            ref="speakingDesFileUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
             <upload-filled />
@@ -515,6 +668,7 @@ export default {
         </el-upload>
       </el-form-item>
       <el-form-item label="作业附件"
+                    v-if="false"
                     prop="attachment"
                     class="homework-form-item">
         <el-upload
@@ -523,7 +677,9 @@ export default {
             show-file-list
             :auto-upload="false"
             multiple
-            :limit="5"
+            :on-change="handleUploadAttachmentFile"
+            :on-exceed="handleAttachmentsExceed"
+            :limit="1"
             ref="attachmentUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
@@ -634,7 +790,7 @@ export default {
     </el-form>
     <template #footer>
       <div class="dialog-footer">
-        <el-button @click="speakingDialog.create = false;">取消</el-button>
+        <el-button @click="createHomeworkCancel">取消</el-button>
         <el-button type="primary" @click="createSpeakingHomework">
           创建
         </el-button>

+ 255 - 42
src/views/CoursePage/HomeworkPage.vue

@@ -59,6 +59,7 @@ export default {
       homeworkList:[],
       homeworkType:"",
       assignmentId:0,
+      seCourseId:0,
       homeworkForm:{
         assignmentName:"作业2",
         description:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
@@ -110,42 +111,68 @@ export default {
   methods:{
     init() {
       this.assignmentId = this.$route.params.homeworkId;
-      this.homeworkType = this.$route.params.type === "speaking"?"口语":"写作";
+      this.seCourseId = this.$route.params.seCourseId;
+      this.homeworkType =
+          (this.$route.params.type === "speaking"||this.$route.params.type === "AI口语")?"AI口语":"写作";
       const temp = ElLoading.service();
-      this.$apis.getHomeworkDetail(this.assignmentId,this.homeworkType)
+      this.$apis.getHomeworkDetail(this.assignmentId,this.homeworkType==="AI口语"?"口语":"写作")
           .then(res => {
             console.log(res);
             if (this.homeworkType === "写作"){
               this.homeworkInfo = res.data.data;
+              if (this.homeworkInfo.attachments===null){
+                this.homeworkInfo.attachments = [];
+              }
               this.homeworkForm.assignmentName = this.homeworkInfo.assignmentName;
               this.homeworkForm.description = this.homeworkInfo.description;
               this.homeworkForm.type = this.homeworkInfo.type;
-              this.homeworkForm.descriptionFile = this.homeworkInfo.descriptionFile;
+              this.homeworkForm.descriptionFile = null;
               this.homeworkForm.attachments = this.homeworkInfo.attachments;
               this.homeworkForm.timeRange = [this.homeworkInfo.startTime,this.homeworkInfo.endTime];
+              if (this.homeworkForm.attachments.length!==0&&
+                  this.homeworkForm.attachments[0] === ""){
+                this.homeworkForm.attachments.splice(0,1);
+                this.homeworkInfo.attachments.splice(0,1);
+              }
+              if (this.homeworkForm.attachments.length!==0&&
+                  this.homeworkForm.attachments[0] === ""){
+                this.homeworkForm.attachments.splice(0,1);
+                this.homeworkInfo.attachments.splice(0,1);
+              }
+              this.homeworkForm.attachments = [];
             }
             else{
               this.speakingHomeworkInfo = res.data.data;
+              if (this.speakingHomeworkInfo.attachments===null){
+                this.speakingHomeworkInfo.attachments = [];
+              }
               this.speakingHomeworkForm.assignmentName = this.speakingHomeworkInfo.assignmentName;
               this.speakingHomeworkForm.description = this.speakingHomeworkInfo.description;
               this.speakingHomeworkForm.type = this.speakingHomeworkInfo.type;
-              this.speakingHomeworkForm.descriptionFile = this.speakingHomeworkInfo.descriptionFile;
+              this.speakingHomeworkForm.descriptionFile = null;
               this.speakingHomeworkForm.attachments = this.speakingHomeworkInfo.attachments;
               this.speakingHomeworkForm.timeRange = [this.speakingHomeworkInfo.startTime,this.speakingHomeworkInfo.endTime];
               this.speakingHomeworkForm.minDuration = this.speakingHomeworkInfo.minDuration;
               this.speakingHomeworkForm.minInteraction = this.speakingHomeworkInfo.minInteraction;
               this.speakingHomeworkForm.surveyLinks = [...this.speakingHomeworkInfo.surveyLinks];
               this.speakingHomeworkForm.surveyDuration = this.speakingHomeworkInfo.surveyDuration;
+              if (this.speakingHomeworkForm.attachments&&this.speakingHomeworkForm.attachments.length!==0&&
+                  this.speakingHomeworkForm.attachments[0] === ""){
+                this.speakingHomeworkForm.attachments.splice(0,1);
+                this.speakingHomeworkInfo.attachments.splice(0,1);
+              }
               if (this.speakingHomeworkForm.surveyLinks.length!==0&&
                   this.speakingHomeworkForm.surveyLinks[0] === ""){
                 this.speakingHomeworkForm.surveyLinks.splice(0,1);
                 this.speakingHomeworkInfo.surveyLinks.splice(0,1);
               }
+              this.speakingHomeworkForm.attachments = [];
             }
             temp.close();
           })
           .catch(_err => {
             ElMessage.error("获取作业信息失败");
+            console.log(_err);
           });
     },
     deleteHomework(){
@@ -198,6 +225,9 @@ export default {
             this.dialog.update = false;
             this.speakingDialog.update = false;
             this.recoverForm();
+            this.homeworkForm.descriptionFile = null;
+            this.homeworkForm.assignmentName = [];
+            this.speakingHomeworkForm.descriptionFile = null;
             this.$refs.homeworkFormRef.resetFields();
             this.$refs.speakingHomeworkFormRef.resetFields();
             done();
@@ -238,22 +268,49 @@ export default {
             startTime: this.dateTimeFormatter(this.homeworkForm.timeRange[0]),
             endTime: this.dateTimeFormatter(this.homeworkForm.timeRange[1]),
           };
+
           // console.log(homeworkVO);
-          this.$apis.updateHomework(this.assignmentId,homeworkVO)
-              .then(res => {
-                console.log( res);
-                if (res && res.data.code === 200){
-                  ElMessage.success("作业修改成功");
-                  this.dialog.update = false;
-                  this.init();
-                }
-                else{
-                  ElMessage.error("作业修改失败");
-                }
-              })
-              .catch(error => {
-                ElMessage.error("作业修改失败");
+          if (this.homeworkForm.descriptionFile){
+            // if (this.homeworkInfo.descriptionFile){
+            //   this.$apis.getCourseWaresByCourseId(this.seCourseId)
+            //       .then(res =>{
+            //         for (let i = 0; i < res.data.data.length; i++){
+            //           if (res.data.data[i].url === this.homeworkInfo.descriptionFile){
+            //             this.$apis.deleteCourseWare(this.seCourseId)
+            //                 .then(res2 =>{
+            //                   console.log(res2);
+            //                 });
+            //             break;
+            //           }
+            //         }
+            //       });
+            // }
+            this.uploadFile(this.homeworkForm.descriptionFile,"作业描述文件",(url)=>{
+              console.log(url);
+              homeworkVO.descriptionFile = url;
+              if (this.homeworkForm.attachments.length!==0){
+                this.uploadFile(this.homeworkForm.attachments[0],"作业附件",(url2)=>{
+                  homeworkVO.attachments = [url2];
+                  this.updateWritingHomeworkByVO(homeworkVO);
+                });
+              }
+              else{
+                this.updateWritingHomeworkByVO(homeworkVO);
+              }
+
+            });
+          }
+          else{
+            if (this.homeworkForm.attachments.length!==0){
+              this.uploadFile(this.homeworkForm.attachments[0],(url2)=>{
+                homeworkVO.attachments = [url2];
+                this.updateWritingHomeworkByVO(homeworkVO);
               });
+            }
+            else{
+              this.updateWritingHomeworkByVO(homeworkVO);
+            }
+          }
         }
       });
     },
@@ -278,21 +335,17 @@ export default {
             homeworkVO.surveyLinks = [""];
           }
           // console.log(homeworkVO);
-          this.$apis.updateSpeakingHomework(this.assignmentId,homeworkVO)
-              .then(res => {
-                console.log( res);
-                if (res && res.data.code === 200){
-                  ElMessage.success("作业修改成功");
-                  this.speakingDialog.update = false;
-                  this.init();
-                }
-                else{
-                  ElMessage.error("作业修改失败");
-                }
-              })
-              .catch(error => {
-                ElMessage.error("作业修改失败");
-              });
+          if (this.speakingHomeworkForm.descriptionFile){
+            console.log(this.speakingHomeworkForm.descriptionFile);
+            this.uploadFile(this.speakingHomeworkForm.descriptionFile,"作业描述文件",(url)=>{
+              console.log(url);
+              homeworkVO.descriptionFile = url;
+              this.updateSpeakingHomeworkByVO(homeworkVO);
+            });
+          }
+          else{
+            this.updateSpeakingHomeworkByVO(homeworkVO);
+          }
         }
       });
     },
@@ -338,6 +391,139 @@ export default {
     },
     checkInteraction(rule,value,callback){
       this.checkNumberRange(rule,value,callback,1,50);
+    },
+    handleUploadDesFile(file, fileList){
+      console.log(file,fileList);
+      if (file.size >= 512000){
+        ElMessage.error("文件过大");
+        if (this.dialog.update === true){
+          this.$refs.writingDesFileUploadRef.clearFiles();
+        }
+        else if (this.speakingDialog.update === true){
+          this.$refs.speakingDesFileUploadRef.clearFiles();
+        }
+        return;
+      }
+      if (file.name.endsWith(".doc")||file.name.endsWith(".docx")){
+        this.homeworkForm.descriptionFile = file;
+        if (this.dialog.update === true){
+          this.homeworkForm.descriptionFile = file;
+        }
+        else if (this.speakingDialog.update === true){
+          this.speakingHomeworkForm.descriptionFile = file;
+        }
+      }
+      else{
+        ElMessage.error("请上传doc或docx格式的描述文件");
+        if (this.dialog.update === true){
+          this.$refs.writingDesFileUploadRef.clearFiles();
+        }
+        else if (this.speakingDialog.update === true){
+          this.$refs.speakingDesFileUploadRef.clearFiles();
+        }
+      }
+    },
+    handleUploadAttachmentFile(file, fileList){
+      console.log(file,fileList);
+      if (file.size >= 512000){
+        ElMessage.error("文件过大");
+        if (this.dialog.update === true){
+          this.$refs.writingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        else if (this.speakingDialog.update === true){
+          this.$refs.speakingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        return;
+      }
+      if (file.name.endsWith(".doc")||file.name.endsWith(".docx")){
+        if (this.dialog.update === true){
+          this.homeworkForm.attachments.push(file);
+        }
+        else if (this.speakingDialog.update === true){
+          this.speakingHomeworkForm.attachments.push(file);
+        }
+      }
+      else{
+        ElMessage.error("请上传doc或docx格式的附件");
+        if (this.dialog.update === true){
+          this.$refs.writingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+        else if (this.speakingDialog.update === true){
+          this.$refs.speakingDesFileUploadRef.handleRemove(file,file.raw);
+        }
+      }
+    },
+    handleAttachmentsExceed(files){
+      ElMessage.warning("最多只能上传一个附件");
+    },
+    handleExceedDesFile(files){
+      ElMessage.warning("最多只能上传一个描述文件");
+    },
+    updateSpeakingHomeworkByVO(homeworkVO) {
+      this.$apis.updateSpeakingHomework(this.assignmentId,homeworkVO)
+          .then(res => {
+            console.log( res);
+            if (res && res.data.code === 200){
+              ElMessage.success("作业修改成功");
+              this.speakingDialog.update = false;
+              this.init();
+            }
+            else{
+              ElMessage.error("作业修改失败");
+            }
+          })
+          .catch(error => {
+            ElMessage.error("修改失败");
+          });
+    },
+    updateWritingHomeworkByVO(homeworkVO) {
+      this.$apis.updateHomework(this.assignmentId,homeworkVO)
+          .then(res => {
+            console.log( res);
+            if (res && res.data.code === 200){
+              ElMessage.success("作业修改成功");
+              this.dialog.update = false;
+              this.init();
+            }
+            else{
+              ElMessage.error("作业修改失败");
+            }
+          })
+          .catch(error => {
+            ElMessage.error("修改失败");
+          });
+    },
+    uploadFile(file,type,callback){
+      this.$apis.uploadCourseWareFile(this.seCourseId+"/"+type+":"+file.name,file.raw)
+          .then(res => {
+            let fileUrl = res.data.data;
+            this.$apis.createCourseWare({
+              name: file.name,
+              size: file.size,
+              senderId: this.$store.state.user.id,
+              courseId: this.seCourseId,
+              createdTime: new Date(),
+              useTime: "BEFORE_CLASS",
+              useMethod: "SCAN",
+              fileUrl: fileUrl,
+            }).then(res => {
+              //this.percentage= 100;
+              callback(fileUrl);
+            }).catch(err => {
+              ElMessage.error("上传文件失败");console.log(err);
+            });
+          })
+          .catch(error => {
+            ElMessage.error("文件上传失败");
+          });
+    },
+    cancelEdit(){
+      this.speakingDialog.update = false;
+      dialog.update = false;
+      this.homeworkForm.descriptionFile = null;
+      this.homeworkForm.assignmentName = [];
+      this.speakingHomeworkForm.descriptionFile = null;
+      this.recoverForm();
     }
   },
   computed:{
@@ -374,10 +560,20 @@ export default {
       </div>
       <el-descriptions  column="1" >
         <template v-if="isWritingType">
-          <el-descriptions-item label="作业类型">{{homeworkInfo.type==="speaking"?"AI对话":"写作"}}</el-descriptions-item>
+          <el-descriptions-item label="作业类型">{{homeworkInfo.type==="speaking"?"AI口语":"写作"}}</el-descriptions-item>
           <el-descriptions-item label="作业描述">{{homeworkInfo.description}}</el-descriptions-item>
-          <el-descriptions-item label="作业描述文件">无</el-descriptions-item>
-          <el-descriptions-item label="附件">无</el-descriptions-item>
+          <el-descriptions-item label="作业描述文件">
+            <span v-if="!homeworkInfo.descriptionFile">无</span>
+            <a v-if="homeworkInfo.descriptionFile" :href="homeworkInfo.descriptionFile" target="_blank">
+              查看描述文件
+            </a>
+          </el-descriptions-item>
+          <el-descriptions-item label="附件">
+            <span v-if="homeworkInfo.attachments.length===0">无</span>
+            <a v-if="homeworkInfo.attachments&&homeworkInfo.attachments.length!==0" :href="homeworkInfo.attachments[0]" target="_blank">
+              查看附件
+            </a>
+          </el-descriptions-item>
           <el-descriptions-item label="作业期限">
             {{(homeworkInfo.startTime.substring(0, 16) + ' ~ ' + homeworkInfo.endTime.substring(0, 16)).replaceAll("T"," ")}}
           </el-descriptions-item>
@@ -385,8 +581,18 @@ export default {
         <template v-else>
           <el-descriptions-item label="作业类型">{{speakingHomeworkInfo.type==="speaking"?"AI对话":"写作"}}</el-descriptions-item>
           <el-descriptions-item label="作业描述">{{speakingHomeworkInfo.description}}</el-descriptions-item>
-          <el-descriptions-item label="作业描述文件">无</el-descriptions-item>
-          <el-descriptions-item label="附件">无</el-descriptions-item>
+          <el-descriptions-item label="作业描述文件">
+            <span v-if="!speakingHomeworkInfo.descriptionFile">无</span>
+            <a v-if="speakingHomeworkInfo.descriptionFile"
+               :href="speakingHomeworkInfo.descriptionFile"
+               style="width: 100px;overflow: hidden;text-overflow: ellipsis"
+               target="_blank">
+              查看描述文件
+            </a>
+          </el-descriptions-item>
+          <el-descriptions-item label="附件">
+            无
+          </el-descriptions-item>
           <el-descriptions-item label="作业期限">
             {{(speakingHomeworkInfo.startTime.substring(0, 16) + ' ~ ' + speakingHomeworkInfo.endTime.substring(0, 16)).replaceAll("T"," ")}}
           </el-descriptions-item>
@@ -490,8 +696,10 @@ export default {
             show-file-list
             :auto-upload="false"
             multiple
+            :on-change="handleUploadDesFile"
+            :on-exceed="handleExceedDesFile"
             :limit="1"
-            ref="attachmentUploadRef"
+            ref="writingDesFileUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
             <upload-filled />
@@ -515,7 +723,9 @@ export default {
             show-file-list
             :auto-upload="false"
             multiple
-            :limit="5"
+            :on-change="handleUploadAttachmentFile"
+            :on-exceed="handleAttachmentsExceed"
+            :limit="1"
             ref="attachmentUploadRef"
         >
           <el-icon :size="50" style="padding-top: 30px" >
@@ -545,7 +755,7 @@ export default {
     </el-form>
     <template #footer>
       <div class="dialog-footer">
-        <el-button @click="dialog.create = false;this.recoverForm()">取消</el-button>
+        <el-button @click="cancelEdit">取消</el-button>
         <el-button type="primary" @click="updateHomework">
           保存
         </el-button>
@@ -605,6 +815,8 @@ export default {
             action=""
             show-file-list
             :auto-upload="false"
+            :on-change="handleUploadDesFile"
+            :on-exceed="handleExceedDesFile"
             multiple
             :limit="1"
             ref="attachmentUploadRef"
@@ -623,6 +835,7 @@ export default {
         </el-upload>
       </el-form-item>
       <el-form-item label="作业附件"
+                    v-if="false"
                     prop="attachment"
                     class="homework-form-item">
         <el-upload
@@ -742,7 +955,7 @@ export default {
     </el-form>
     <template #footer>
       <div class="dialog-footer">
-        <el-button @click="speakingDialog.update = false;this.recoverForm()">取消</el-button>
+        <el-button @click="cancelEdit">取消</el-button>
         <el-button type="primary" @click="updateSpeakingHomework">
           保存
         </el-button>