Pārlūkot izejas kodu

修改上传文件

aaa 3 gadi atpakaļ
vecāks
revīzija
5c644172cd
1 mainītis faili ar 88 papildinājumiem un 80 dzēšanām
  1. 88 80
      src/views/articleManagement/videoCreate.vue

+ 88 - 80
src/views/articleManagement/videoCreate.vue

@@ -147,11 +147,13 @@
         <a-upload
           :customRequest="uploadOssVideoFile"
           list-type="picture"
-          :default-file-list="defaultVideoFileList"
+          :file-list="defaultVideoFileList"
           :remove="removeOssVideoFile"
           class="upload-list-inline"
         >
-          <a-button> <a-icon type="upload" />点击上传 </a-button>
+          <a-button>
+            <a-icon type="upload" />{{ isVideoUpload ? "上传中" : "点击上传" }}
+          </a-button>
         </a-upload>
       </div>
       <div style="margin-bottom: 10px">上传封面</div>
@@ -159,7 +161,7 @@
         <a-upload
           :customRequest="uploadOssImageFile"
           list-type="picture"
-          :default-file-list="defaultImageFileList"
+          :file-list="defaultImageFileList"
           :remove="removeOssImageFile"
           class="upload-list-inline"
         >
@@ -230,6 +232,7 @@ export default {
         color: "red"
       },
       defaultVideoFileList: [],
+      isVideoUpload: false,
       defaultImageFileList: []
     };
   },
@@ -522,91 +525,96 @@ export default {
       console.log("-------fileData--------");
       console.log(fileData);
       let that = this;
+      that.isVideoUpload = true;
       let file = fileData.file;
 
-      //   var index = file.name.indexOf("."); //(考虑严谨用lastIndexOf(".")得到)得到"."在第几位
-      //   var subfix = file.name.substring(index); //截断"."之前的,得到后缀
-      //   if (subfix != ".mp4") {
-      //     fileData.onError();
-      //     this.$message.error("只能上传mp4格式的文件");
-      //     return;
-      //   }
-
-      let bucket = "jtxt-file-public";
-      let ossPath = "file/";
-      let res = await that.$_http.get(
-        that.$_API.INTERFACE_GET_ASSUME_OSS_WRITER
-      );
-      console.log("--oss-writer--" + JSON.stringify(res));
-      const client = new OSS({
-        // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
-        region: "oss-cn-beijing",
-        // 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
-        accessKeyId: res.data.accessKeyId,
-        accessKeySecret: res.data.accessKeySecret,
-        // 从STS服务获取的安全令牌(SecurityToken)。
-        stsToken: res.data.securityToken,
-        // 填写Bucket名称。
-        bucket: bucket
-      });
-      let fileName = new Date().getTime() + "_" + file.name;
-      // 普通上传
-      // try {
-      //   client.put(ossPath + fileName, file).then(res => {
-      //     console.log(res);
-      //     let upFile = {
-      //       uid: this.getUid(),
-      //       name: fileName,
-      //       status: "done",
-      //       url: res.url
-      //     };
-      //     that.videoUrl = res.url;
-      //     that.defaultVideoFileList.push(upFile);
-      //     //   this.findvideocover(file);
-      //     fileData.onSuccess();
-      //   });
-      // } catch (e) {
-      //   fileData.onError();
-      //   console.error(e);
-      // }
-      // 分片上传
-      console.log("---upload-start--" + new Date().getTime());
-      let options = {
-        progress: function(p) {
-          // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
-          console.log("-----" + JSON.stringify(p));
-          //   console.log("-----" + JSON.stringify(checkpoint));
-        },
-        patrtSize: 1000 * 1024, // 设置分片大小
-        timeout: 1000 * 60 * 10 // 超时时间
-      };
-      try {
-        client.multipartUpload(ossPath + fileName, file, options).then(res => {
-          console.log("---upload-end--" + new Date().getTime());
-          console.log(res);
-          let fileUrl = res.res.requestUrls[0].split("?")[0];
-          console.log(fileUrl);
-          let upFile = {
-            uid: this.getUid(),
-            name: fileName,
-            status: "done",
-            url: fileUrl
-          };
-          that.videoUrl = fileUrl;
-          that.defaultVideoFileList.push(upFile);
-          //   this.findvideocover(file);
-          fileData.onSuccess();
+      var index = file.name.indexOf("."); //(考虑严谨用lastIndexOf(".")得到)得到"."在第几位
+      var subfix = file.name.substring(index); //截断"."之前的,得到后缀
+      if (subfix != ".mp4" && subfix != ".mov") {
+        console.log(file);
+        // console.log("--" + JSON.stringify(upFile));
+        that.isVideoUpload = false;
+        this.$message.error("只能上传mp4格式的文件");
+      } else {
+        let bucket = "jtxt-video-public";
+        let ossPath = "file/";
+        let res = await that.$_http.get(
+          that.$_API.INTERFACE_GET_ASSUME_OSS_WRITER
+        );
+        console.log("--oss-writer--" + JSON.stringify(res));
+        const client = new OSS({
+          // yourRegion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
+          region: "oss-cn-beijing",
+          // 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。
+          accessKeyId: res.data.accessKeyId,
+          accessKeySecret: res.data.accessKeySecret,
+          // 从STS服务获取的安全令牌(SecurityToken)。
+          stsToken: res.data.securityToken,
+          // 填写Bucket名称。
+          bucket: bucket
         });
-      } catch (e) {
-        fileData.onError();
-        console.error("-aaaaaaaaaa---");
-        console.error(e);
+        let fileName = new Date().getTime() + "_" + file.name;
+        // 普通上传
+        // try {
+        //   client.put(ossPath + fileName, file).then(res => {
+        //     console.log(res);
+        //     let upFile = {
+        //       uid: this.getUid(),
+        //       name: fileName,
+        //       status: "done",
+        //       url: res.url
+        //     };
+        //     that.videoUrl = res.url;
+        //     that.defaultVideoFileList.push(upFile);
+        //     //   this.findvideocover(file);
+        //     fileData.onSuccess();
+        //   });
+        // } catch (e) {
+        //   fileData.onError();
+        //   console.error(e);
+        // }
+        // 分片上传
+        console.log("---upload-start--" + new Date().getTime());
+        let options = {
+          progress: function(p) {
+            // 断点记录点。浏览器重启后无法直接继续上传,您需要手动触发上传操作。
+            console.log("-----" + JSON.stringify(p));
+            //   console.log("-----" + JSON.stringify(checkpoint));
+          },
+          patrtSize: 1000 * 1024, // 设置分片大小
+          timeout: 1000 * 60 * 10 // 超时时间
+        };
+        try {
+          client
+            .multipartUpload(ossPath + fileName, file, options)
+            .then(res => {
+              console.log("---upload-end--" + new Date().getTime());
+              console.log(res);
+              let fileUrl = res.res.requestUrls[0].split("?")[0];
+              console.log(fileUrl);
+              let upFile = {
+                uid: this.getUid(),
+                name: fileName,
+                status: "done",
+                url: fileUrl
+              };
+              that.videoUrl = fileUrl;
+              that.defaultVideoFileList.push(upFile);
+              fileData.onSuccess();
+              that.isVideoUpload = false;
+            });
+        } catch (e) {
+          fileData.onError();
+          console.error("-aaaaaaaaaa---");
+          console.error(e);
+          that.isVideoUpload = false;
+        }
       }
     },
     async uploadOssImageFile(fileData) {
       let that = this;
       let file = fileData.file;
-      let bucket = "jtxt-file-public";
+      let bucket = "jtxt-video-public";
       let ossPath = "file/";
       let res = await that.$_http.get(
         that.$_API.INTERFACE_GET_ASSUME_OSS_WRITER