Parcourir la source

Merge branch 'develop3.0' of http://106.12.23.251:10080/TEAMMODEL/TEAMModelOS into develop3.0

李思淳 il y a 5 ans
Parent
commit
1c3d19a5c5

+ 2 - 0
TEAMModelOS.Service/Models/Syllabus/Volume.cs

@@ -4,6 +4,7 @@ using System.Text;
 using TEAMModelOS.SDK.Context.Attributes.Azure;
 using System.Text.Json.Serialization;
 using System.ComponentModel.DataAnnotations;
+using Newtonsoft.Json;
 
 namespace TEAMModelOS.Service.Models.Syllabus
 {
@@ -33,6 +34,7 @@ namespace TEAMModelOS.Service.Models.Syllabus
         public string volumeName { get; set; }
         public string volumeCode { get; set; }
         [JsonPropertyName("TEAMModelId")]
+        [JsonProperty("TEAMModelId")]
         public string TEAMModelId { get; set; }
         public string[] editors { get; set; }
     }

+ 73 - 54
TEAMModelOS/ClientApp/src/common/UploadFile.vue

@@ -44,6 +44,10 @@
         default: '',
         type: String
       },
+      quality: {
+        default: 0.2,
+        type: Number
+      }
 
     },
     methods: {
@@ -52,7 +56,7 @@
       },
       initBlob() {
         this.containerURL = new window.azblob.ContainerURL(
-          `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName + this.pathName}?${this.sasString}`,
+          `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName}/${this.pathName}?${this.sasString}`,
           window.azblob.StorageURL.newPipeline(new window.azblob.AnonymousCredential())
         )
       },
@@ -64,23 +68,70 @@
         }
         return new File([u8arr], filename, { type: mime });
       },
-      compressFile(file,fileInfo) {
-        let reader = new FileReader()
-        reader.readAsDataURL(file)
-        reader.onload = (e) => {
-          let dataUrl = e.target.result
-          let img = new Image()
-          img.src = dataUrl
-          img.onload = () => {
+      compressFile(file, fileInfo) {
+        if (fileInfo.type == 'picture') {
+          let reader = new FileReader()
+          reader.readAsDataURL(file)
+          reader.onload = (e) => {
+            let dataUrl = e.target.result
+            let img = new Image()
+            img.src = dataUrl
+            img.onload = () => {
+              let canvas = document.createElement('canvas')
+              canvas.width = 300
+              canvas.height = 300 * img.height / img.width
+              let ctx = canvas.getContext('2d')
+              ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height)
+              let newImgData = canvas.toDataURL(file.type, this.quality)
+              var resultFile = this.dataURLtoFile(newImgData, file.name)
+              this.initBlob()
+              const compressBlobURL = window.azblob.BlockBlobURL.fromContainerURL(
+                this.containerURL,
+                'compress' + file.name
+              )
+              let options = {
+                blockSize: 10 * 1024 * 1024
+              }
+              window.azblob.uploadBrowserDataToBlockBlob(
+                window.azblob.Aborter.none,
+                resultFile,
+                compressBlobURL,
+                options
+              ).then(
+                res => {
+                  fileInfo['compressUrl'] = `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName}/${this.pathName}/compress${file.name}`
+                  this.$emit("successData", fileInfo)
+                },
+                err => {
+                  fileInfo['status'] = 2
+                  console.log(err)
+                }
+              )
+            }
+          }
+        } else {
+          let video = document.createElement('video')
+          video.setAttribute("width", "300")
+          video.setAttribute("controls", "controls")
+          video.setAttribute("crossOrigin",'*')
+          video.setAttribute("src", fileInfo.blobUrl + this.sasString)
+          video.addEventListener('loadeddata', () => {
+            console.log(video.width)
+            console.log(video.height)
+            console.log(video.videoWidth)
+            console.log(video.videoHeight)
             let canvas = document.createElement('canvas')
+            canvas.width = 300
+            canvas.height = 300 * video.videoHeight / video.videoWidth
             let ctx = canvas.getContext('2d')
-            ctx.drawImage(img, 0, 0, canvas.width, canvas.height)
-            let newImgData = canvas.toDataURL(file.type, 0.2)
-            var resultFile = this.dataURLtoFile(newImgData, file.name)
+            ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight, 0, 0, canvas.width, canvas.height)
+            let newVideoData = canvas.toDataURL('image/png', this.quality)
+            let resultFile = this.dataURLtoFile(newVideoData, file.name)
             this.initBlob()
+            let posterName = 'compress' + file.name.replace(fileInfo.extension, 'png')
             const compressBlobURL = window.azblob.BlockBlobURL.fromContainerURL(
               this.containerURL,
-              'compress' + file.name
+              posterName
             )
             window.azblob.uploadBrowserDataToBlockBlob(
               window.azblob.Aborter.none,
@@ -88,8 +139,7 @@
               compressBlobURL
             ).then(
               res => {
-                fileInfo['compressUrl'] = `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName + this.pathName}/compress${file.name}`
-                console.log(fileInfo)
+                fileInfo['compressUrl'] = `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName}/${this.pathName}/${posterName}`
                 this.$emit("successData", fileInfo)
               },
               err => {
@@ -97,7 +147,7 @@
                 console.log(err)
               }
             )
-          }
+          })
         }
       },
       uploadToBlob(file) {
@@ -107,7 +157,7 @@
         )
         let fileItem = {}
         fileItem['fileName'] = file.name
-        fileItem['blobUrl'] = `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName + this.pathName}/${file.name}`
+        fileItem['blobUrl'] = `https://${this.accountName}.blob.core.chinacloudapi.cn/${this.containerName}/${this.pathName}/${file.name}`
         fileItem['extension'] = file.name.substring(file.name.lastIndexOf('.') + 1)
         fileItem['size'] = file.size
         fileItem['status'] = 0
@@ -146,14 +196,18 @@
               try {
                 let fileRes = ev.target.result
                 let str = sha1(fileRes)
-                console.log(str)
                 let index = this.getIndex(this.uploadedList, fileItem)
                 this.uploadedList[index].status = 1
                 this.uploadedList[index]['createTime'] = Date.parse(res.lastModified)
                 this.uploadedList[index]['sha1Code'] = str
                 if (this.uploadedList[index].type == 'picture' || this.uploadedList[index].type == 'video') {
-                  console.log(this.uploadedList[index])
                   this.compressFile(file,this.uploadedList[index])
+                  //if (this.uploadedList[index].type == 'video') {
+                  //  console.log('bug is here!!!')
+                  //} else {
+                  //  this.compressFile(file,this.uploadedList[index])
+                  //}
+                  
                 } else {
                   this.$emit("successData", this.uploadedList[index])
                 }
@@ -171,7 +225,6 @@
         return false
       },
       beforeUpload(file) {
-        console.log(file)
         let url =  file.name
         this.$api.uploadFile.getContainerSAS().then(
           (res) => {
@@ -189,39 +242,6 @@
         )
         return false
       },
-      canvasDataURL(path, obj) {
-        var img = new Image()
-        img.src = path
-        img.onload = function () {
-          var that = this
-          // 默认按比例压缩
-          var w = that.width,
-            h = that.height,
-            scale = w / h
-          w = obj.width || w
-          h = obj.height || (w / scale)
-          var quality = 0.7  // 默认图片质量为0.7
-          //生成canvas
-          var canvas = document.createElement('canvas')
-          var ctx = canvas.getContext('2d')
-          // 创建属性节点
-          var anw = document.createAttribute("width")
-          anw.nodeValue = w
-          var anh = document.createAttribute("height")
-          anh.nodeValue = h
-          canvas.setAttributeNode(anw)
-          canvas.setAttributeNode(anh)
-          ctx.drawImage(that, 0, 0, w, h)
-          // 图像质量
-          if (obj.quality && obj.quality <= 1 && obj.quality > 0) {
-            quality = obj.quality
-          }
-          // quality值越小,所绘制出的图像越模糊
-          var base64 = canvas.toDataURL('image/jpeg', quality)
-          // 回调函数返回base64的值
-          return base64
-        }
-      },
       getIndex(_arr, _obj) {
         var len = _arr.length;
         for (let i = 0; i < len; i++) {
@@ -234,7 +254,6 @@
       isObjEqual(o1, o2) {
         var props1 = Object.keys(o1);
         var props2 = Object.keys(o2);
-        console.log(props1);
         if (props1.length != props2.length) {
           return false;
         }

+ 14 - 3
TEAMModelOS/ClientApp/src/utils/azure-storage-blob.js

@@ -17176,6 +17176,8 @@
      * @returns {Promise<BlobUploadCommonResponse>}
      */
     function uploadBrowserDataToBlockBlob(aborter, browserData, blockBlobURL, options) {
+        console.log('----------')
+        console.log(options)
         return __awaiter(this, void 0, void 0, function () {
             var browserBlob;
             return __generator(this, function (_a) {
@@ -17245,7 +17247,11 @@
                         if (size <= options.maxSingleShotSize) {
                             return [2 /*return*/, blockBlobURL.upload(aborter, blobFactory(0, size), size, options)];
                         }
-                        numBlocks = Math.floor((size - 1) / options.blockSize) + 1;
+                        console.log(options)
+                        let test = 10 * 1024 * 1024
+                        numBlocks = Math.floor((size - 1) / test) + 1;
+                        //numBlocks = Math.floor((size - 1) / options.blockSize) + 1;
+                        console.log(numBlocks)
                         if (numBlocks > BLOCK_BLOB_MAX_BLOCKS) {
                             throw new RangeError("The buffer's size is too big or the BlockSize is too small;" +
                                 ("the number of blocks must be <= " + BLOCK_BLOB_MAX_BLOCKS));
@@ -17261,8 +17267,10 @@
                                     switch (_a.label) {
                                         case 0:
                                             blockID = generateBlockID(blockIDPrefix, i);
-                                            start = options.blockSize * i;
-                                            end = i === numBlocks - 1 ? size : start + options.blockSize;
+                                            let mySize = 10*1024*1024
+                                            start = mySize * i;
+                                            //start = options.blockSize * i;
+                                            end = i === numBlocks - 1 ? size : start + mySize;
                                             contentLength = end - start;
                                             blockList.push(blockID);
                                             return [4 /*yield*/, blockBlobURL.stageBlock(aborter, blockID, blobFactory(start, contentLength), contentLength, {
@@ -17286,6 +17294,9 @@
                         for (i = 0; i < numBlocks; i++) {
                             _loop_1(i);
                         }
+                        
+                        console.log('blockList')
+                        console.log(blockList.length)
                         return [4 /*yield*/, batch.do()];
                     case 1:
                         _a.sent();

+ 10 - 10
TEAMModelOS/ClientApp/src/view/coursemgmt/CourseBaseSetting.vue

@@ -43,7 +43,7 @@
                     <Input prefix="ios-search" placeholder="ID或姓名搜索" size="small" class="search-course-teacher" />
                 </div>
                 <CheckboxGroup v-model="courseInfo.assistTeacher">
-                    <Checkbox :label="item.teamModelId" class="course-teacher-item" v-for="(item,index) in teacherList">{{item.teacherName}}</Checkbox>
+                    <Checkbox :label="item.TEAMModelId" class="course-teacher-item" v-for="(item,index) in teacherList">{{item.teacherName}}</Checkbox>
                 </CheckboxGroup>
             </div>
         </div>
@@ -104,39 +104,39 @@
                 teacherList: [
                     {
                         teacherName: '张飞',
-                        teamModelId:'001#0101'
+                        TEAMModelId:'001#0101'
                     },
                     {
                         teacherName:'狄仁杰',
-                        teamModelId:'001#0111'
+                        TEAMModelId:'001#0111'
                     },
                     {
                         teacherName:'诸葛亮',
-                        teamModelId:'001#0102'
+                        TEAMModelId:'001#0102'
                     },
                     {
                         teacherName:'码云',
-                        teamModelId:'001#0103'
+                        TEAMModelId:'001#0103'
                     },
                     {
                         teacherName:'马可波罗',
-                        teamModelId:'001#0104'
+                        TEAMModelId:'001#0104'
                     },
                     {
                         teacherName:'刘备',
-                        teamModelId:'001#0105'
+                        TEAMModelId:'001#0105'
                     },
                     {
                         teacherName:'关羽',
-                        teamModelId:'001#0106'
+                        TEAMModelId:'001#0106'
                     },
                     {
                         teacherName:'王昭君',
-                        teamModelId:'001#0107'
+                        TEAMModelId:'001#0107'
                     },
                     {
                         teacherName:'貂蝉',
-                        teamModelId:'001#0108'
+                        TEAMModelId:'001#0108'
                     }
 
                 ],

+ 1 - 1
TEAMModelOS/ClientApp/src/view/coursemgmt/CourseManage.vue

@@ -51,7 +51,7 @@
                 addCourseStatus: false,
                 demoLoginInfo: {
                     user: "admin",
-                    teamModelId: "habook#0001",
+                    TEAMModelId: "habook#0001",
                     school: "醍摩豆书院",
                     schoolCode: "HBCN"
                 }

+ 1 - 1
TEAMModelOS/ClientApp/src/view/school-mgmt/ClassroomSetting/ClassroomSetting.vue

@@ -213,7 +213,7 @@
                 currentPIndex: 0,
                 demoLoginInfo: {
                     user: 'admin',
-                    teamModelId: 'habook#0001',
+                    TEAMModelId: 'habook#0001',
                     school: '醍摩豆书院',
                     schoolCode: 'HBCN'
                 },

+ 1 - 1
TEAMModelOS/ClientApp/src/view/school-mgmt/SystemSetting/SystemSetting.vue

@@ -190,7 +190,7 @@
                 dataDefault: {},
                 demoLoginInfo: {
                     user: 'admin',
-                    teamModelId: 'habook#0001',
+                    TEAMModelId: 'habook#0001',
                     school: '醍摩豆书院',
                     schoolCode: 'HBCN'
                 },

+ 1 - 1
TEAMModelOS/ClientApp/src/view/student-account/Index.vue

@@ -123,7 +123,7 @@
         authorizationStatus: false,
         demoLoginInfo: {
           user: 'admin',
-          teamModelId: 'habook#0001',
+          TEAMModelId: 'habook#0001',
           school: '醍摩豆书院',
           schoolCode: 'HBCN'
         },

+ 2 - 2
TEAMModelOS/ClientApp/src/view/teachcontent/index.less

@@ -290,7 +290,7 @@
     border-radius: 5px;
 
     &:hover::before {
-        background: rgba(20, 20, 20, 0.2);
+        /*background: rgba(20, 20, 20, 0.2);*/
         transition: background .5s;
     }
 
@@ -323,7 +323,7 @@
         content: "";
         width: 100%;
         height: 100%;
-        background: rgba(20, 20, 20, 0.3);
+        /*background: rgb(20, 20, 20);*/
         position: absolute;
         left: 0px;
         top: 0px;

+ 64 - 53
TEAMModelOS/ClientApp/src/view/teachcontent/index.vue

@@ -94,20 +94,20 @@
               <div class="card-item animated fadeIn" v-for="(item,index) in fileListShow" :key="index">
                 <span class="file-name">{{item.fileName}}</span>
                 <img :src="item.compressUrl+sasString"
-                     width="300" />
+                     width="300" style="border-radius:5px;"/>
                 <div class="item-tools">
                   <Icon type="md-download"
                         size="18"
                         color="white"
-                        title="下载文件" />
+                        title="下载文件" @click="downloadFile(index)"/>
                   <Icon type="md-eye"
                         size="18"
                         color="white"
-                        title="预览文件" />
+                        title="预览文件" @click="openPreviewFile(index)"/>
                   <Icon type="md-infinite" size="18" color="white" title="绑定知识点" />
-                  <Icon type="md-trash" size="18" color="white" title="删除文件" />
+                  <Icon type="md-trash" size="18" color="white" title="删除文件" @click="delFile(index)"/>
                   <span style="color:white; float:right;">{{formatDate(item.createTime)}}</span>
-                  <span style="color:white; float:right;margin-right:10px;">{{item.size/1204 > 1024 ? (item.size/1204/1204).toFixed(1) + 'M': (item.size/1204).toFixed(1) + 'KB'}}</span>
+                  <span style="color:white; float:right;margin-right:10px;">{{item.size/1024 > 1024 ? (item.size/1024/1024).toFixed(1) + 'M': (item.size/1024).toFixed(1) + 'KB'}}</span>
                 </div>
               </div>
             </div>
@@ -117,24 +117,21 @@
     </div>
     <Modal v-model="uploadStatus"
            title="上传教学资源" class="upload-modal" @on-ok="confirmUpload" width="660" :mask-closable="false">
-      <!--<Upload type="drag" :action="uploadUrl" multiple :on-success="getFileUrl" :before-upload="checkSize">
-        <p style="margin:20px 0px;font-size:20px;">点击或者拖拽上传</p>
-        <Icon type="ios-cloud-upload" size="50" style="margin-bottom:30px;" />
-      </Upload>-->
-      <UploadFile @successData="getFileUrl" :uploadUrl="uploadUrl" :pathName="demoLoginInfo.teamModelId.replace('#','')"></UploadFile>
+      <UploadFile @successData="getFileUrl" :uploadUrl="uploadUrl" :pathName="demoLoginInfo.TEAMModelId.replace('#','')" :quality="1"></UploadFile>
     </Modal>
     <Modal v-model="previewStatus"
-           :title="previewFile.fileName" width="800px">
-      <video v-if="previewFile.type == 'video'" :src="previewFile.blobUrl" width="780">
+           :title="previewFile.fileName" width="800px" class="upload-modal">
+      <video v-if="previewFile.type == 'video'" :src="previewFile.blobUrl+sasString" width="780" controls="controls">
         您的浏览器不支持 video 标签。
       </video>
-      <img v-if="previewFile.type == 'picture'" :src="previewFile.blobUrl" width="780" />
-      <embed v-if="previewFile.type == 'document'" :src="previewFile.blobUrl" width="780" height="600" />
+      <img v-if="previewFile.type == 'picture'" :src="previewFile.blobUrl+sasString" width="780" style="border-radius:5px;"/>
+      <embed v-if="previewFile.type == 'document'" :src="previewFile.blobUrl+sasString" width="780" height="600" />
       <div slot="footer"></div>
     </Modal>
   </div>
 </template>
 <script>
+  import axios from 'axios'
   import EditableLabel from '@/common/EditableLabel.vue'
   import UploadFile from '@/common/UploadFile.vue'
   export default {
@@ -196,7 +193,7 @@
         ],
         previewFile: {
           id: 'sha1Code+contentType+size',
-          teamModelId: 'habook#0001',
+          TEAMModelId: 'habook#0001',
           fileName: '测试文件类型列表PPT01',
           extension: 'ppt',
           contentType: 'image/jpeg',
@@ -216,7 +213,7 @@
         keyWord: '',
         demoLoginInfo: {
           user: 'admin',
-          teamModelId: 'habook#0001',
+          TEAMModelId: 'habook#0001',
           school: '醍摩豆书院',
           schoolCode: 'HBCN'
         },
@@ -229,7 +226,7 @@
         schoolFileList: [
           {
             id: 'sha1Code+contentType+size',
-            teamModelId: 'habook#0001',
+            TEAMModelId: 'habook#0001',
             fileName: '校本资源PPT01',
             extension: 'ppt',
             contentType: 'image/jpeg',
@@ -303,27 +300,37 @@
         }
       },
       delFile(index) {
-        this.$api.teachContent.deleteResource(
-          {
-            id: this.fileListShow[index].id
-          }
-        ).then(
-          (res) => {
-            if (res.error == null) {
-              let originalIndex = this.fileList.indexOf(this.fileListShow[index])
-              this.fileList.splice(originalIndex, 1)
-              this.fileListShow.splice(index, 1)
-              this.$Message.success('文件删除成功!');
-              this
-            } else {
-              this.$Message.error('文件删除失败!');
-            }
+        this.$Modal.confirm({
+          title: '确认删除',
+          content: "<p class='dialog-p'>" +this.fileListShow[index].fileName + "</p>",
+          onOk: () => {
+            this.$api.teachContent.deleteResource(
+              {
+                id: this.fileListShow[index].id
+              }
+            ).then(
+              (res) => {
+                if (res.error == null) {
+                  let originalIndex = this.fileList.indexOf(this.fileListShow[index])
+                  this.fileList.splice(originalIndex, 1)
+                  this.fileListShow.splice(index, 1)
+                  this.$Message.success('文件删除成功!');
+                  this
+                } else {
+                  this.$Message.error('文件删除失败!');
+                }
 
-          },
-          (err) => {
+              },
+              (err) => {
 
+              }
+            )
+          },
+          onCancel: () => {
+            this.$Message.info('取消删除!');
           }
-        )
+        })
+        
       },
       handleEditFileName(val, index) {
         if (this.rangeType == 1) {
@@ -343,24 +350,27 @@
         }
       },
       setFileNameEdit(index) {
-        console.log(this.$refs)
         this.$refs['fileNameLabel' + index].handleEdit()
       },
-      previewOrDownloadFile(index) {
-        if (this.fileListShow[index].type == 'video' || this.fileListShow[index].type == 'picture' || this.fileListShow[index].extension == 'pdf') {
-          this.previewFile = this.fileListShow[index]
-          this.previewStatus = true
-        } else {
-          window.location.href = this.fileListShow[index].blobUrl
-          this.$Message.warning('抱歉,此文件不支持预览')
-        }
-      },
       downloadFile(index) {
         window.location.href = this.fileListShow[index].blobUrl + this.sasString
+        //axios.get(this.fileListShow[index].blobUrl + this.sasString,
+        //  {
+        //    //params: true,
+        //    headers: {
+        //      'Content-Type': 'application/octet-stream'
+        //    }
+        //  }).then(
+        //    res => {
+
+        //    },
+        //    err => {
+        //    }
+        //  )
       },
       openPreviewFile(index) {
         this.previewFile = this.fileListShow[index]
-        this.previewFile.blobUrl = this.previewFile.blobUrl + this.sasString
+        this.previewFile.blobUrl = this.previewFile.blobUrl
         this.previewStatus = true
       },
       formatDate(timestamp) {
@@ -370,7 +380,7 @@
       findFileList() {
         this.$api.teachContent.findResourceByDict(
           {
-            teamModelId: this.demoLoginInfo.teamModelId
+            TEAMModelId: this.demoLoginInfo.TEAMModelId
           }
         ).then(
           (res) => {
@@ -393,7 +403,6 @@
         )
       },
       confirmUpload() {
-        console.log(this.uploadFileList)
         this.$api.teachContent.saveOrUpdateResource(this.uploadFileList).then(
           (res) => {
             if (res.error == null) {
@@ -411,9 +420,11 @@
         this.uploadStatus = !this.uploadStatus
       },
       getFileUrl(file) {  //获取文件地址
+        console.log('-------')
+        console.log(file)
         this.uploadFileList.push({
           schoolCode: this.demoLoginInfo.schoolCode,
-          teamModelId: this.demoLoginInfo.teamModelId,
+          TEAMModelId: this.demoLoginInfo.TEAMModelId,
           fileName: file.fileName,
           extension: file.extension,
           contentType: file.contentType,
@@ -426,8 +437,6 @@
           sha1Code: file.sha1Code,
           compressUrl: file.compressUrl
         })
-        console.log('111111111111111')
-        console.log(this.uploadFileList)
       },
       groupByKey(array, key) {
         const groups = {}
@@ -505,7 +514,7 @@
     mounted() {
       this.findFileList()
       //this.uploadUrl = '//' + window.location.host + '/api/File/uploadFile';
-      this.uploadUrl = 'https://teammodelostest.blob.core.chinacloudapi.cn/spatest/' + this.demoLoginInfo.teamModelId.replace('#','')
+      this.uploadUrl = 'https://teammodelostest.blob.core.chinacloudapi.cn/spatest/' + this.demoLoginInfo.TEAMModelId.replace('#','')
       let box = document.getElementsByClassName('content-file-list')
       this.boxWidth = box[0].clientWidth
       Date.prototype.toLocaleString = function () {
@@ -527,7 +536,9 @@
     /*height:24px;*/
     color: white;
   }
-
+  .dialog-p {
+    word-wrap:break-word;
+  }
   .key-word-search {
     width: 240px;
     float: right;