Parcourir la source

Merge branch 'master' of http://gogs.seec.seecoder.cn/LiuQin/SEEC-Portal-Front

yhd12345 il y a 3 ans
Parent
commit
1dcc130c05

+ 5 - 1
nginx.conf

@@ -23,4 +23,8 @@ server {
         location ~ / {
         location ~ / {
             try_files $uri $uri/ /index.html;
             try_files $uri $uri/ /index.html;
         }
         }
-}
+}
+
+http {
+        client_max_body_size 1024M;
+}

+ 11 - 1
src/api/courseWare.js

@@ -6,6 +6,10 @@ function createCourseWare(data) {
     return axios.post(`${prefix}/create`, data);
     return axios.post(`${prefix}/create`, data);
 }
 }
 
 
+function setCanDownloadById(id, canDownload) {
+    return axios.post(`${prefix}/setCanDownloadById`, null, {params: {id, canDownload}});
+}
+
 function uploadCourseWareFile(name, file) {
 function uploadCourseWareFile(name, file) {
     let data = new FormData();
     let data = new FormData();
     data.append("name", name);
     data.append("name", name);
@@ -60,8 +64,13 @@ function previewpdf(fileUrl) {
     });
     });
 }
 }
 
 
+function getCanDownloadById(id) {
+    return axios.get(`${prefix}/getCanDownloadById`, {params: {id}});
+}
+
 const courseWareAPIs = {
 const courseWareAPIs = {
     createCourseWare,
     createCourseWare,
+    setCanDownloadById,
     deleteCourseWare,
     deleteCourseWare,
     getCourseWaresByCourseId,
     getCourseWaresByCourseId,
     getCourseWareById,
     getCourseWareById,
@@ -70,7 +79,8 @@ const courseWareAPIs = {
     changeCourseWareName,
     changeCourseWareName,
     getCourseWareUrlById,
     getCourseWareUrlById,
     previewpdf,
     previewpdf,
-    getCourseIdById
+    getCourseIdById,
+    getCanDownloadById
 };
 };
 
 
 export default courseWareAPIs;
 export default courseWareAPIs;

+ 9 - 4
src/router/index.js

@@ -135,6 +135,11 @@ const routes = [
     path: "/courseWare/:courseWareId/details",
     path: "/courseWare/:courseWareId/details",
     name: "courseWareDetails",
     name: "courseWareDetails",
     component: ()=>import("../views/CourseWarePage/CourseWarePage")
     component: ()=>import("../views/CourseWarePage/CourseWarePage")
+  },
+  {
+    path: "/empty/:courseWareId",
+    name: "empty",
+    component: ()=>import("../views/CourseWarePage/pdf/Empty")
   }
   }
 ];
 ];
 
 
@@ -148,10 +153,7 @@ const unauthorizedRoutes = ["Portal", "Auth", "Course", "Test","Project", "Compl
 router.beforeEach((to, from, next) => {
 router.beforeEach((to, from, next) => {
   let token = localStorage.getItem("token");
   let token = localStorage.getItem("token");
   console.log(token);
   console.log(token);
-    if (unauthorizedRoutes.indexOf(to.name) !== -1) {
-      console.log(1);
-      next();
-    }
+
     // else if (token && to.name === "courseWareDetails") {
     // else if (token && to.name === "courseWareDetails") {
     //   console.log(localStorage);
     //   console.log(localStorage);
     //   if (localStorage.s === "true") {
     //   if (localStorage.s === "true") {
@@ -159,6 +161,9 @@ router.beforeEach((to, from, next) => {
     //     next();
     //     next();
     //   }
     //   }
     // }
     // }
+    if (unauthorizedRoutes.indexOf(to.name) !== -1) {
+      next();
+    }
     else if (!store.state.user.token) {
     else if (!store.state.user.token) {
       ElMessage({
       ElMessage({
         showClose: true,
         showClose: true,

+ 76 - 38
src/views/CourseDetailPage/tabs/CoursewareTab.vue

@@ -56,7 +56,7 @@
                   </el-col>
                   </el-col>
               </el-row>
               </el-row>
           </el-form-item>
           </el-form-item>
-          <el-form-item label="允许下载" required>
+          <el-form-item label="允许下载" required v-if="fileType === '.pdf'">
               <el-switch v-model="downloadValue" />
               <el-switch v-model="downloadValue" />
           </el-form-item>
           </el-form-item>
         </el-form>
         </el-form>
@@ -113,30 +113,27 @@
 <!--              <el-button style="color: #409EFF; margin-right: 10px" type="text">预览</el-button>-->
 <!--              <el-button style="color: #409EFF; margin-right: 10px" type="text">预览</el-button>-->
 <!--            </a>-->
 <!--            </a>-->
 
 
-                  <el-button v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'"
-                             @click="handlePreviewFile(scope.row['courseWareVO'].id)"
-                             style="color: #409EFF; margin-right: 10px" type="text">预览</el-button>
-              <a v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'"
-                 :href="getOfficeFileUrl(scope.row['courseWareVO'].fileUrl)">点击预览</a>
-
-            <a :href="scope.row['courseWareVO'].fileUrl" v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'">
-              <el-button style="color: #67C23A" type="text">下载</el-button>
-            </a>
-
+<!--            <el-button v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'"-->
+<!--                     @click="handlePreviewFile(scope.row['courseWareVO'].id)"-->
+<!--                     style="color: #409EFF; margin-right: 10px" type="text">预览</el-button>-->
+<!--            <a v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'"-->
+<!--             :href="getOfficeFileUrl(scope.row['courseWareVO'].fileUrl)">点击预览</a>-->
+<!--            <a :href="scope.row['courseWareVO'].fileUrl" v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'OFFICE'">-->
+<!--              <el-button style="color: #67C23A" type="text">下载</el-button>-->
+<!--            </a>-->
             <el-button v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'PDF'"
             <el-button v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'PDF'"
                  @click="handlePreviewFile(scope.row['courseWareVO'].id)"
                  @click="handlePreviewFile(scope.row['courseWareVO'].id)"
-                       style="color: #409EFF" type="text">预览</el-button>
-            <el-button v-if="Number(scope.row['courseWareVO'].senderId) === Number(this.$store.state.user.id) && isPdfOrPicture(scope.row['courseWareVO'].name) === 'PDF'
-                            && scope.row['courseWareVO'].canDownload === true"
-                 @click="handleDownloadPdfFile(scope.row['courseWareVO'].fileUrl)"
-                 style="color: #67C23A" type="text">下载</el-button>
-
+                       style="color: #409EFF" type="text">打开</el-button>
             <el-button v-if="scope.row['courseWareVO'].useMethod === 'SCAN' && isPdfOrPicture(scope.row['courseWareVO'].name) === 'PICTUREandATTACHMENT'"
             <el-button v-if="scope.row['courseWareVO'].useMethod === 'SCAN' && isPdfOrPicture(scope.row['courseWareVO'].name) === 'PICTUREandATTACHMENT'"
-                 @click="handlePreviewPicture(scope.row['courseWareVO'])"
-                       style="color: #409EFF; margin-right: 10px" type="text">预览</el-button>
-            <a :href="scope.row['courseWareVO'].fileUrl" v-if="isPdfOrPicture(scope.row['courseWareVO'].name) === 'PICTUREandATTACHMENT'">
-              <el-button style="color: #67C23A" type="text">下载</el-button>
-            </a>
+                     @click="handlePreviewPicture(scope.row['courseWareVO'])"
+                     style="color: #409EFF" type="text">打开</el-button>
+
+<!--              <el-button v-if="checkDownloadButton(scope.row['courseWareVO'].id, scope.row['courseWareVO'].name) === '1'"-->
+<!--            <el-button v-if="getCanDownloadById(scope.row['courseWareVO'].id) === true-->
+<!--              <el-button v-if="canDownloadList === '1'-->
+<!--                     && isPdfOrPicture(scope.row['courseWareVO'].name) === 'PDF'"-->
+<!--                     @click="handleDownloadPdfFile(scope.row['courseWareVO'].fileUrl)"-->
+<!--                     style="color: #67C23A" type="text">下载</el-button>-->
             <el-button v-if="Number(scope.row['courseWareVO'].senderId) === Number(this.$store.state.user.id)"
             <el-button v-if="Number(scope.row['courseWareVO'].senderId) === Number(this.$store.state.user.id)"
                        style="color: #F56C6C; margin-left: 10px" type="text"
                        style="color: #F56C6C; margin-left: 10px" type="text"
                        @click="handleRemoveCourseWare(scope.row['courseWareVO'].id)">删除</el-button>
                        @click="handleRemoveCourseWare(scope.row['courseWareVO'].id)">删除</el-button>
@@ -151,7 +148,10 @@
           <img :src="pictureUrl" alt="" style="width: 100%" class="image" />
           <img :src="pictureUrl" alt="" style="width: 100%" class="image" />
           <template #footer>
           <template #footer>
       <span class="dialog-footer">
       <span class="dialog-footer">
-        <el-button type="primary" @click="handleClosePreviewPicture" plain>关闭</el-button>
+          <a :href="pictureUrl">
+              <el-button type="success" style="margin-right: 10px" size="small">下载</el-button>
+          </a>
+          <el-button type="primary" @click="handleClosePreviewPicture" plain size="small">关闭</el-button>
       </span>
       </span>
           </template>
           </template>
       </el-dialog>
       </el-dialog>
@@ -173,11 +173,12 @@
 </template>
 </template>
 
 
 <script>
 <script>
-import portal from "@/utils/portal/portal";
-import {ElMessage, ElMessageBox} from "element-plus";
-import * as pdfjs from "pdfjs-dist";
-import * as pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
-pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
+    import portal from "@/utils/portal/portal";
+    import {ElMessageBox} from "element-plus";
+    import * as pdfjs from "pdfjs-dist";
+    import * as pdfjsWorker from "pdfjs-dist/build/pdf.worker.entry";
+
+    pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;
 
 
 export default {
 export default {
   name: "CoursewareTab",
   name: "CoursewareTab",
@@ -211,11 +212,13 @@ export default {
       idToBeChangeName: null,
       idToBeChangeName: null,
       newName: null,
       newName: null,
       nameAppend: null,
       nameAppend: null,
+      fileType: null,
       fileTag: null,
       fileTag: null,
       fileNum: 0,
       fileNum: 0,
-      picturesFromPDF: [],
       pdfName: "",
       pdfName: "",
-      downloadValue: true
+      downloadValue: true,
+      canDownloadList: [],
+      courseWareNum: 0
     };
     };
   },
   },
 
 
@@ -231,8 +234,8 @@ export default {
       init() {
       init() {
           this.$apis.getCourseWaresByCourseId(this.courseId).then(res => {
           this.$apis.getCourseWaresByCourseId(this.courseId).then(res => {
               this.fileEntryList = res.data.data;
               this.fileEntryList = res.data.data;
+              this.courseWareNum = this.fileEntryList.length;
           });
           });
-          console.log(this.fileEntryList);
       },
       },
 
 
       handleChangeNameWhenUpload() {
       handleChangeNameWhenUpload() {
@@ -347,6 +350,7 @@ export default {
               } else {
               } else {
                   this.isNameUnique = true;
                   this.isNameUnique = true;
                   this.fileNum = 1;
                   this.fileNum = 1;
+                  this.fileType = "." + fileType;
               }
               }
           });
           });
       },
       },
@@ -373,7 +377,7 @@ export default {
                         .then(res => {
                         .then(res => {
                             const fileUrl = res.data.data;
                             const fileUrl = res.data.data;
                             this.$apis.createCourseWare({
                             this.$apis.createCourseWare({
-                                name: this.newName === null ? this.file.name : (this.newName + this.nameAppend),
+                                name: this.newName + this.nameAppend,
                                 size: this.file.size,
                                 size: this.file.size,
                                 senderId: this.$store.state.user.id,
                                 senderId: this.$store.state.user.id,
                                 courseId: this.courseId,
                                 courseId: this.courseId,
@@ -381,11 +385,13 @@ export default {
                                 useTime: "BEFORE_CLASS",
                                 useTime: "BEFORE_CLASS",
                                 useMethod: this.form.useMethod,
                                 useMethod: this.form.useMethod,
                                 fileUrl: fileUrl,
                                 fileUrl: fileUrl,
-                                canDownload: this.downloadValue
                             }).then(res => {
                             }).then(res => {
+                                console.log(res.data.data.id);
+                                this.$apis.setCanDownloadById(res.data.data.id, this.downloadValue);
                                 this.$apis.getCourseWaresByCourseId(this.courseId)
                                 this.$apis.getCourseWaresByCourseId(this.courseId)
                                     .then(res => {
                                     .then(res => {
                                         this.fileEntryList = res.data.data;
                                         this.fileEntryList = res.data.data;
+                                        this.courseWareNum = this.fileEntryList.length;
                                         this.$message({
                                         this.$message({
                                             message: "上传课件成功",
                                             message: "上传课件成功",
                                             type: "success"
                                             type: "success"
@@ -415,7 +421,7 @@ export default {
                 .then(res => {
                 .then(res => {
                     const fileUrl = res.data.data;
                     const fileUrl = res.data.data;
                     this.$apis.createCourseWare({
                     this.$apis.createCourseWare({
-                        name: this.newName === null ? this.file.name : (this.newName + this.nameAppend),
+                        name: this.file.name,
                         size: this.file.size,
                         size: this.file.size,
                         senderId: this.$store.state.user.id,
                         senderId: this.$store.state.user.id,
                         courseId: this.courseId,
                         courseId: this.courseId,
@@ -423,11 +429,13 @@ export default {
                         useTime: "BEFORE_CLASS",
                         useTime: "BEFORE_CLASS",
                         useMethod: this.form.useMethod,
                         useMethod: this.form.useMethod,
                         fileUrl: fileUrl,
                         fileUrl: fileUrl,
-                        canDownload: this.downloadValue
                     }).then(res => {
                     }).then(res => {
+                        //console.log(res.data.data.id);
+                        this.$apis.setCanDownloadById(res.data.data.id, this.downloadValue);
                         this.$apis.getCourseWaresByCourseId(this.courseId)
                         this.$apis.getCourseWaresByCourseId(this.courseId)
                             .then(res => {
                             .then(res => {
                                 this.fileEntryList = res.data.data;
                                 this.fileEntryList = res.data.data;
+                                this.courseWareNum = this.fileEntryList.length;
                                 this.$message({
                                 this.$message({
                                     message: "上传课件成功",
                                     message: "上传课件成功",
                                     type: "success"
                                     type: "success"
@@ -441,9 +449,6 @@ export default {
                     });
                     });
                 });
                 });
         }
         }
-
-
-
       },
       },
 
 
       handleCancelUpload(done) {
       handleCancelUpload(done) {
@@ -479,6 +484,7 @@ export default {
         .then(() => {
         .then(() => {
             this.isChangeNameWhenUpload = false;
             this.isChangeNameWhenUpload = false;
             this.nameAppend = null;
             this.nameAppend = null;
+            this.fileType = null;
             this.isNameUnique = false;
             this.isNameUnique = false;
             this.file = null;
             this.file = null;
             this.fileNum = 0;
             this.fileNum = 0;
@@ -500,6 +506,7 @@ export default {
         .then(() => {
         .then(() => {
             this.$apis.deleteCourseWare(id).then(async () => {
             this.$apis.deleteCourseWare(id).then(async () => {
                 this.fileEntryList = (await this.$apis.getCourseWaresByCourseId(this.courseId)).data.data;
                 this.fileEntryList = (await this.$apis.getCourseWaresByCourseId(this.courseId)).data.data;
+                this.courseWareNum = this.fileEntryList.length;
             });
             });
             this.uploadDialogVisible = false;
             this.uploadDialogVisible = false;
             this.fileNum = 0;
             this.fileNum = 0;
@@ -562,7 +569,38 @@ export default {
             });
             });
       },
       },
 
 
+      // getCanDownloadById(id) {
+      //     this.$apis.getCanDownloadById(id).then(res => {
+      //         console.log(res.data.data);
+      //         return res.data.data;
+      //     });
+      // },
+
+      async getCanDownloadById(id) {
+          const canDownload = (await this.$apis.getCanDownloadById(id)).data.data;
+          //console.log(id + ": " + canDownload);
+          return canDownload === true;
+      },
 
 
+      checkDownloadButton(id, name){
+          this.$apis.getCanDownloadById(id).then(res => {
+              const canDownload = res.data.data;
+              const isPdf = this.isPdfOrPicture(name);
+              if ((isPdf === "PDF") && (canDownload.toString() === "true")) {
+                  return "1";
+              } else {
+                  return "0";
+              }
+          });
+          // const isPdf = this.isPdfOrPicture(name);
+          // const canDownload = (await this.$apis.getCanDownloadById(id)).data.data;
+          // if ((isPdf === "PDF") && (canDownload.toString() === "true")) {
+          //     return "1";
+          // } else {
+          //     return "0";
+          // }
+          //return "1";
+      }
 
 
   }
   }
 };
 };

+ 5 - 0
src/views/CourseWarePage/CourseWarePage.vue

@@ -40,6 +40,11 @@
                 //fileUrl: "https://seec-portal.oss-cn-hangzhou.aliyuncs.com/1/07-%E9%9C%80%E6%B1%82%E6%96%87%E6%A1%A3%E5%8C%96%E4%B8%8E%E9%AA%8C%E8%AF%81.pdf",
                 //fileUrl: "https://seec-portal.oss-cn-hangzhou.aliyuncs.com/1/07-%E9%9C%80%E6%B1%82%E6%96%87%E6%A1%A3%E5%8C%96%E4%B8%8E%E9%AA%8C%E8%AF%81.pdf",
             };
             };
         },
         },
+        watch: {
+            $route(to, from) {
+                window.location.reload(); //监测到路由发生跳转时刷新一次页面
+            },
+        },
         mounted() {
         mounted() {
             const params = {
             const params = {
                 phone: localStorage.phone,
                 phone: localStorage.phone,

+ 17 - 0
src/views/CourseWarePage/pdf/Empty.vue

@@ -0,0 +1,17 @@
+<template>
+    <div></div>
+</template>
+
+<script>
+    export default {
+        name: "Empty",
+        created(){
+            console.log(this.$route.params.courseWareId);
+            //this.$router.replace({ path: "/courseWare/" + this.$route.params.courseWareId + "/details" });
+        }
+    };
+</script>
+
+<style scoped>
+
+</style>

+ 5 - 5
src/views/CourseWarePage/pdf/PdfController.vue

@@ -28,12 +28,13 @@ export default {
       pageMarked: false,
       pageMarked: false,
       toPage: 1,
       toPage: 1,
       hide: false,
       hide: false,
-      canDownload: true,
+      canDownload: false,
       //currentPage: 1
       //currentPage: 1
     };
     };
   },
   },
   mounted() {
   mounted() {
     this.handleCanDownload();
     this.handleCanDownload();
+    //this.$router.replace({ path:"/empty/" + this.$route.params.courseWareId});
   },
   },
   computed: {
   computed: {
     ...mapState({
     ...mapState({
@@ -63,16 +64,15 @@ export default {
       }
       }
     },
     },
     handleCanDownload () {
     handleCanDownload () {
-      this.$apis.getCourseWareById(this.$route.params.courseWareId).then(res => {
-        console.log(res);
-        this.canDownload = res.data.data.canDownload;
+      this.$apis.getCanDownloadById(this.$route.params.courseWareId).then(res => {
+        this.canDownload = res.data.data;
       });
       });
     },
     },
     handleDownloadPdfFile() {
     handleDownloadPdfFile() {
       this.$apis.getCourseWareById(this.$route.params.courseWareId).then(res => {
       this.$apis.getCourseWareById(this.$route.params.courseWareId).then(res => {
         window.open(res.data.data.fileUrl, "_blank");
         window.open(res.data.data.fileUrl, "_blank");
       });
       });
-    },
+    }
   }
   }
 };
 };
 </script>
 </script>