lsc 2 年之前
父节点
当前提交
7ea8c96ae0
共有 2 个文件被更改,包括 173 次插入160 次删除
  1. 170 159
      src/views/course/components/stepsBox.vue
  2. 3 1
      src/views/home/index.vue

+ 170 - 159
src/views/course/components/stepsBox.vue

@@ -20,9 +20,17 @@
         <input
           type="file"
           accept="image/*"
+          style="display: none"
           multiple
+          @change="beforeUpload($event, step.tool[0], stepI)"
+          v-if="step.tool[0] === 50"
+        />
+        <input
+          type="file"
+          accept="image/*"
           style="display: none"
           @change="beforeUpload($event, step.tool[0], stepI)"
+          v-else
         />
       </div>
       <div class="tool-box" v-else-if="tools[step.tool[0]]">
@@ -76,10 +84,16 @@
     <div v-if="proVisible" class="mask">
       <div class="progressBox">
         <div class="lbox"><img src="@/assets/images/loading.gif" />上传中,请稍后</div>
-        <div style="margin-bottom: 10px">
+        <div style="margin-bottom: 10px" v-if="pVisible">
           <span>{{ isFinishSize }}M</span> / <span>{{ isAllSize }}M</span>
         </div>
-        <el-progress :text-inside="true" :stroke-width="20" :percentage="progress" style="width: 80%"></el-progress>
+        <el-progress
+          :text-inside="true"
+          :stroke-width="20"
+          :percentage="progress"
+          style="width: 80%"
+          v-if="pVisible"
+        ></el-progress>
       </div>
     </div>
   </div>
@@ -148,6 +162,7 @@ export default {
       fileType: 0,
       tools: tools,
       proVisible: false,
+      pVisible: false,
       progress: 0,
       isFinishSize: 0,
       isAllSize: 0,
@@ -779,158 +794,160 @@ export default {
         type: mime
       })
     },
-    async moreFile(f,t,i) {
-      var credentials = {
-        accessKeyId: 'AKIATLPEDU37QV5CHLMH',
-        secretAccessKey: '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'
-      } // 秘钥形式的登录上传
-      window.AWS.config.update(credentials)
-      window.AWS.config.region = 'cn-northwest-1' // 设置区域
-
-      // eslint-disable-next-line prettier/prettier
-      var bucket = new window.AWS.S3({ params: { Bucket: 'ccrb' } }) // 选择桶
-      var _this = this
-      _this.progress = 0
-      _this.proVisible = true
-      _this.isFinishSize = 0
-      _this.isAllSize = (f.size / 1024 / 1024).toFixed(2)
-      var photoA = ['BMP', 'GIF', 'PNG', 'JPGE', 'JPEG', 'JPG', 'TIF', 'PCX', 'TGA', 'EXIF', 'FPX', 'SVG', 'APNG']
-
-      if (
-        photoA.indexOf(f.name.split('.')[f.name.split('.').length - 1].toLocaleUpperCase()) !== -1 &&
-        t !== 4
-      ) {
-        f = await this.pngToWhiteBg(f)
-        const blob = await imageConversion.compressAccurately(f, 256)
-        f = new File([blob], f.name, { type: f.type })
-      }
-
-      if (f) {
-        var params = {
-          Key:
-            f.name.split('.')[0] +
-            new Date().getTime() +
-            '.' +
-            f.name.split('.')[f.name.split('.').length - 1],
-          ContentType: f.type,
-          Body: f,
-          'Access-Control-Allow-Credentials': '*',
-          ACL: 'public-read'
-        } // key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
-        var options = {
-          // partSize: 2048 * 1024 * 1024,
-          partSize: 1024 * 1024 * 1024,
-          queueSize: 2,
-          leavePartsOnError: true
-        }
-        bucket
-          .upload(params, options)
-          .on('httpUploadProgress', function (evt) {
-            // 这里可以写进度条
-            // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
-            _this.progress = parseInt((evt.loaded / evt.total) * 100)
-            _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2)
-          })
-          .send(function (err, data) {
-            _this.progress = 100
-            _this.isFinishSize = _this.isAllSize
-            setTimeout(() => {
-              _this.proVisible = false
-            }, 1000)
-            if (err) {
-              var a = _this.$refs.upload1.uploadFiles
-              a.splice(a.length - 1, a.length)
-              _this.$message.error('上传失败')
-            } else {
-              var b = ['PDF', 'DOC', 'DOCX', 'PPT', 'PPTX', 'XLSX', 'XLS']
-              var c = [
-                'AVI',
-                'NAVI',
-                'MPEG',
-                'ASF',
-                'MOV',
-                'WMV',
-                '3GP',
-                'RM',
-                'RMVB',
-                'FLV',
-                'F4V',
-                'H.264',
-                'H.265',
-                'REAL VIDEO',
-                'MKV',
-                'WebM',
-                'HDDVD',
-                'MP4',
-                'MPG',
-                'M4V',
-                'MGV',
-                'OGV',
-                'QTM',
-                'STR',
-                'AMC',
-                'DVX',
-                'EVO',
-                'DAT',
-                'OGG',
-                'OGM'
-              ]
-              if (t === 16) {
-                if (
-                  c.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
-                ) {
-                  _this.fileType = 2
-                } else if (
-                  b.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
-                ) {
-                  _this.fileType = 1
-                } else if (
-                  photoA.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !==
-                  -1
-                ) {
-                  _this.fileType = 0
-                } else {
-                  _this.fileType = 3
-                }
-                _this.addCourseWorks(data.Location, i)
-              } else if (t === 50) {
-                var _ftype = 1
-                if (
-                  c.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
-                ) {
-                  _ftype = 5
-                } else if (
-                  b.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
-                ) {
-                  _ftype = 4
-                } else {
-                  _ftype = 1
-                }
-                _this.addCourseWorksPl(data.Location, i, _ftype)
-              }
-              console.log(data.Location)
-            }
-          })
-      }
-    },
     async beforeUpload(event, type, i) {
       // this.$message.success('进入上传')
       var file = ''
-      if (type === 5) {
-        file = event
-      } else {
-        if (event.target.files.length > 1) {
-          file = event.target.files
+      const files = event.target.files
+      const plfile = []
+      for (let cfindex2 = 0; cfindex2 < files.length; cfindex2++) {
+        if (files.length > 1) {
+          this.pVisible = false
         } else {
-          file = event.target.files[0]
+          this.pVisible = true
         }
-      }
-      if (file.length > 1) {
-        for (var z = 0; z < file.length; z++) {
-          this.moreFile(file[z],type,i);
+        file = files[cfindex2]
+        var credentials = {
+          accessKeyId: 'AKIATLPEDU37QV5CHLMH',
+          secretAccessKey: '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'
+        } // 秘钥形式的登录上传
+        window.AWS.config.update(credentials)
+        window.AWS.config.region = 'cn-northwest-1' // 设置区域
+
+        // eslint-disable-next-line prettier/prettier
+        var bucket = new window.AWS.S3({ params: { Bucket: 'ccrb' }}) // 选择桶
+        var _this = this
+        _this.progress = 0
+        _this.proVisible = true
+        _this.isFinishSize = 0
+        _this.isAllSize = (file.size / 1024 / 1024).toFixed(2)
+        var photoA = ['BMP', 'GIF', 'PNG', 'JPGE', 'JPEG', 'JPG', 'TIF', 'PCX', 'TGA', 'EXIF', 'FPX', 'SVG', 'APNG']
+
+        if (
+          photoA.indexOf(file.name.split('.')[file.name.split('.').length - 1].toLocaleUpperCase()) !== -1 &&
+          type !== 4
+        ) {
+          file = await this.pngToWhiteBg(file)
+          const blob = await imageConversion.compressAccurately(file, 256)
+          file = new File([blob], file.name, { type: file.type })
+        }
+
+        if (file) {
+          var params = {
+            Key:
+              file.name.split('.')[0] +
+              new Date().getTime() +
+              '.' +
+              file.name.split('.')[file.name.split('.').length - 1],
+            ContentType: file.type,
+            Body: file,
+            'Access-Control-Allow-Credentials': '*',
+            ACL: 'public-read'
+          } // key可以设置为桶的相抵路径,Body为文件, ACL最好要设置
+          var options = {
+            // partSize: 2048 * 1024 * 1024,
+            partSize: 1024 * 1024 * 1024,
+            queueSize: 2,
+            leavePartsOnError: true
+          }
+          bucket
+            .upload(params, options)
+            .on('httpUploadProgress', function(evt) {
+              // 这里可以写进度条
+              // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
+              _this.progress = parseInt((evt.loaded / evt.total) * 100)
+              _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2)
+            })
+            .send(function(err, data) {
+              _this.progress = 100
+              _this.isFinishSize = _this.isAllSize
+              if (cfindex2 === files.length - 1 || cfindex2 > files.length - 1) {
+                setTimeout(() => {
+                  _this.proVisible = false
+                }, 1000)
+              }
+              if (err) {
+                var a = _this.$refs.upload1.uploadFiles
+                a.splice(a.length - 1, a.length)
+                _this.$message.error('上传失败')
+              } else {
+                var b = ['PDF', 'DOC', 'DOCX', 'PPT', 'PPTX', 'XLSX', 'XLS']
+                var c = [
+                  'AVI',
+                  'NAVI',
+                  'MPEG',
+                  'ASF',
+                  'MOV',
+                  'WMV',
+                  '3GP',
+                  'RM',
+                  'RMVB',
+                  'FLV',
+                  'F4V',
+                  'H.264',
+                  'H.265',
+                  'REAL VIDEO',
+                  'MKV',
+                  'WebM',
+                  'HDDVD',
+                  'MP4',
+                  'MPG',
+                  'M4V',
+                  'MGV',
+                  'OGV',
+                  'QTM',
+                  'STR',
+                  'AMC',
+                  'DVX',
+                  'EVO',
+                  'DAT',
+                  'OGG',
+                  'OGM'
+                ]
+                if (type === 16) {
+                  if (
+                    c.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
+                  ) {
+                    _this.fileType = 2
+                  } else if (
+                    b.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
+                  ) {
+                    _this.fileType = 1
+                  } else if (
+                    photoA.indexOf(
+                      data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()
+                    ) !== -1
+                  ) {
+                    _this.fileType = 0
+                  } else {
+                    _this.fileType = 3
+                  }
+                  _this.addCourseWorks(data.Location, i)
+                } else if (type === 50) {
+                  var _ftype = 1
+                  if (
+                    c.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
+                  ) {
+                    _ftype = 5
+                  } else if (
+                    b.indexOf(data.Location.split('.')[data.Location.split('.').length - 1].toLocaleUpperCase()) !== -1
+                  ) {
+                    _ftype = 4
+                  } else {
+                    _ftype = 1
+                  }
+                  plfile.push({
+                    fileType: _ftype,
+                    url: data.Location,
+                    username: _this.userinfo.userid
+                  })
+                  if (cfindex2 === files.length - 1 || cfindex2 > files.length - 1) {
+                    _this.addCourseWorksPl(plfile, i)
+                  }
+                }
+                console.log(data.Location)
+              }
+            })
         }
-      } else {
-        this.moreFile(file,type,i);
       }
     },
     async beforeUpload2(event, i) {
@@ -946,7 +963,7 @@ export default {
       window.AWS.config.region = 'cn-northwest-1' // 设置区域
 
       // eslint-disable-next-line prettier/prettier
-      var bucket = new window.AWS.S3({ params: { Bucket: 'ccrb' } }) // 选择桶
+      var bucket = new window.AWS.S3({ params: { Bucket: 'ccrb' }}) // 选择桶
       var _this = this
       _this.progress = 0
       _this.proVisible = true
@@ -980,13 +997,13 @@ export default {
         }
         bucket
           .upload(params, options)
-          .on('httpUploadProgress', function (evt) {
+          .on('httpUploadProgress', function(evt) {
             // 这里可以写进度条
             // console.log("Uploaded : " + parseInt((evt.loaded * 80) / evt.total) + '%');
             _this.progress = parseInt((evt.loaded / evt.total) * 100)
             _this.isFinishSize = (evt.loaded / 1024 / 1024).toFixed(2)
           })
-          .send(function (err, data) {
+          .send(function(err, data) {
             _this.progress = 100
             _this.isFinishSize = _this.isAllSize
             setTimeout(() => {
@@ -1171,14 +1188,8 @@ export default {
           console.error(err)
         })
     },
-    addCourseWorksPl(data, toolindex, fileType) {
-      const _files = [
-        {
-          fileType: fileType,
-          url: data,
-          username: this.userinfo.userid
-        }
-      ]
+    addCourseWorksPl(files, toolindex) {
+      const _files = files
 
       const params = [
         {

+ 3 - 1
src/views/home/index.vue

@@ -55,7 +55,7 @@ export default {
       page: 1,
       isLoading: false,
       loading: false,
-      finished: false
+      finished: true
     }
   },
   computed: {
@@ -111,6 +111,8 @@ export default {
       if (res[0].length === 0) {
         // 证明没有下一页数据了
         this.finished = true
+      } else {
+        this.finished = false
       }
     },
     exitLogin() {