From 3b7181ccc8f3e9c233de96fc1221d8ffe73ac001 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期五, 17 五月 2024 10:10:28 +0800
Subject: [PATCH] 张先强改文件

---
 src/components/UploadC.vue     |   16 +++++++++++++++-
 src/views/onlineStudy/file.vue |   34 +++++++++++++++++++++++++---------
 2 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/src/components/UploadC.vue b/src/components/UploadC.vue
index 4a1e0c7..951adc9 100644
--- a/src/components/UploadC.vue
+++ b/src/components/UploadC.vue
@@ -4,6 +4,7 @@
         :action="uploadUrl"
         :show-file-list="true"
         :limit="uploadNum"
+        :accept="acceptList"
         multiple
         :file-list="fileUrl"
         :on-remove="handleRemove"
@@ -13,7 +14,7 @@
       <el-button size="small" type="primary">鐐瑰嚮涓婁紶</el-button>
       <div slot="tip" class="el-upload__tip">鍙兘涓婁紶pdf銆乵p4銆乵p3銆乸ng銆乯pg銆乯pge鏂囦欢锛屼笖涓嶈秴杩噞{fileSizeLimitM}}M</div>
       <div v-if="fileUrl && fileUrl.length > 0 && uploadNum === 1">
-        <video class="returnShow" v-if="fileType === 'video'" :src="'/api/files/' + fileUrl[0].url"></video>
+        <video controls class="returnShow" v-if="fileType === 'video'" :src="'/api/files/' + fileUrl[0].url"></video>
         <img class="returnShow" v-if="fileType === 'img'" :src="'/api/files/' + fileUrl[0].url"/>
       </div>
     </el-upload>
@@ -64,6 +65,7 @@
       this.$emit('getUploadUrl', this.fileUrl);
     },
     beforeUpload(file) {
+
       const limit = file.size / 1024 / 1024 < this.fileSizeLimitM;
       if (!limit) {
         this.$message.error(`涓婁紶鏂囦欢澶у皬涓嶈兘瓒呰繃 ${this.fileSizeLimitM}MB!`);
@@ -71,6 +73,18 @@
       return limit;
     },
   },
+  computed: {
+    acceptList: () => {
+      let temp = '.jgp,.png,.jpeg'
+      if(this.fileType === 'video') {
+        temp = '.mp4,.avi'
+      }
+      if(this.fileType === 'pdf') {
+        temp = '.pdf'
+      }
+      return temp;
+    }
+  }
 }
 </script>
 
diff --git a/src/views/onlineStudy/file.vue b/src/views/onlineStudy/file.vue
index 01003ca..9acc54a 100644
--- a/src/views/onlineStudy/file.vue
+++ b/src/views/onlineStudy/file.vue
@@ -33,7 +33,7 @@
       </el-table-column>
       <el-table-column label="鏂囦欢鍐呭">
         <template slot-scope="scope">
-          <video v-if="scope.row.contentType === 'video'" :src="'/api/files/' + scope.row.contentUrl.url"
+          <video controls v-if="scope.row.contentType === 'video'" :src="'/api/files/' + scope.row.contentUrl.url"
             class="showContent" />
           <img v-if="scope.row.contentType === 'img'" :src="'/api/files/' + scope.row.contentUrl.url"
             class="showContent" />
@@ -74,7 +74,7 @@
           </el-select>
         </el-form-item>
         <el-form-item label="鏂囦欢绫诲瀷" prop="contentType">
-          <el-select v-model="form.contentType" placeholder="涓嶅悓绫诲瀷鐨勬枃浠堕槄瑙堟柟寮忎笉鍚岋紝澶氫綑鏂囦欢璇蜂互闄勪欢褰㈠紡涓婁紶">
+          <el-select v-model="form.contentType" placeholder="涓嶅悓绫诲瀷鐨勬枃浠堕槄瑙堟柟寮忎笉鍚岋紝澶氫綑鏂囦欢璇蜂互闄勪欢褰㈠紡涓婁紶" @change="fileChange">
             <el-option label="瑙嗛" value="video"></el-option>
             <el-option label="PDF" value="pdf"></el-option>
             <el-option label="鍥剧墖" value="img"></el-option>
@@ -148,6 +148,10 @@
     };
   },
   methods: {
+    fileChange() {
+      console.log(1111111)
+      this.form.contentUrl = [];
+    },
     handleSelectionChange(val) {
       this.ids = val.map(item => item.id);
     },
@@ -176,7 +180,7 @@
       this.form.attachment = uploadData;
     },
     getUploadUrl(uploadData) {
-      this.form.contentUrl = uploadData[0];
+      this.form.contentUrl = uploadData;
     },
     remove(id) {
       OnlineStudyAPI.remove([id]).then(res => {
@@ -202,9 +206,11 @@
     handlerSubmit() {
       this.$refs['form'].validate((valid) => {
         if (valid) {
-          this.form.contentUrl = this.form.contentUrl[0]
-          if (this.form.id) {
-            OnlineStudyAPI.update(this.form).then(res => {
+          const temp = JSON.parse(JSON.stringify(this.form));
+          // this.form.contentUrl = this.form.contentUrl[0]
+          temp.contentUrl = temp.contentUrl[0];
+          if (temp.id) {
+            OnlineStudyAPI.update(temp).then(res => {
               if (res.code === 1) {
                 this.$message.success('淇敼鎴愬姛');
                 this.open = false;
@@ -212,7 +218,7 @@
               }
             });
           } else {
-            OnlineStudyAPI.add(this.form).then(res => {
+            OnlineStudyAPI.add(temp).then(res => {
               if (res.code === 1) {
                 this.$message.success('娣诲姞鎴愬姛');
                 this.open = false;
@@ -223,12 +229,22 @@
         }
       });
     },
+    resetForm() {
+      this.form = {
+        contentType: 'video',
+        subject: '',
+        belongType: 2,
+        contentUrl: [],
+        attachment: [],
+        temp: []
+      }
+    },
     handleClose() {
       this.open = false;
-      this.form = {};
+      this.resetForm();
     },
     handlerAdd() {
-      this.form = {};
+      this.resetForm();
       this.open = true;
       this.dialogTitle = '娣诲姞瀛︿範鍐呭';
     },

--
Gitblit v1.8.0