Переглянути джерело

Merge branch 'develop-rc' of http://52.130.252.100:10000/TEAMMODEL/TEAMModelOS into develop-rc

CrazyIter_Bin 2 роки тому
батько
коміт
d98c2d7e65

+ 210 - 178
TEAMModelOS/ClientApp/src/common/BaseUpload.vue

@@ -1,187 +1,219 @@
 <template>
-	<div class="base-upload-container">
-		<Upload multiple type="drag" action="" :disabled="isLoading" :before-upload="onBeforeUpload" :show-upload-list="false">
-			<div style="padding: 40px 0">
-				<Icon type="ios-cloud-upload" size="100"
-					style="color: #40A8F0;margin: 40px 0;"></Icon>
-				<p style="color: #757575">{{ $t("knowledge.import.tip1") }}</p>
-				<p style="color: #ddd" v-if="acceptTypes.length">({{ $t("knowledge.import.tip2") }}:{{ acceptTypes.join(' / ') }})</p>
-			</div>
-		</Upload>
-		<div class="file-list-box" v-if="!simpleUpload">
-			<div class="file-item" v-for="(item,index) in fileArr" :key="index">
-				<p>
-					<span>{{ item.name }}</span>
-					<span class="tool-remove" v-if="isShowTool">
-						<Icon type="md-close" @click="onRemoveFile(index)"/>
-					</span>
-				</p>
-				<Progress :percent="progressArr[index]" :stroke-width="12"/>
-			</div>
-		</div>
-		<Button  @click="onConfirmUpload" :loading="isLoading"  v-if="!simpleUpload" style="width: 100%;margin: 0 auto;" class="modal-btn" :disabled="!fileArr.length">{{ $t("knowledge.import.tip3") }}</Button>
-	</div>
+  <div class="base-upload-container">
+    <Upload multiple type="drag" action="" :disabled="isLoading" :before-upload="onBeforeUpload" :show-upload-list="false">
+      <div style="padding: 40px 0">
+        <Icon type="ios-cloud-upload" size="100" style="color: #40A8F0;margin: 40px 0;"></Icon>
+        <p style="color: #757575">{{ $t("knowledge.import.tip1") }}</p>
+        <p style="color: #ddd" v-if="acceptTypes.length">({{ $t("knowledge.import.tip2") }}:{{ acceptTypes.join(' / ') }})</p>
+      </div>
+    </Upload>
+    <div class="file-list-box" v-if="!simpleUpload">
+      <div class="file-item" v-for="(item,index) in fileArr" :key="index">
+        <p>
+          <span>{{ item.name }}</span>
+          <span class="tool-remove" v-if="isShowTool">
+            <Icon type="md-close" @click="onRemoveFile(index)" />
+          </span>
+        </p>
+        <Progress :percent="progressArr[index]" :stroke-width="12" />
+      </div>
+    </div>
+    <Button @click="onConfirmUpload" :loading="isLoading" v-if="!simpleUpload" style="width: 100%;margin: 0 auto;" class="modal-btn" :disabled="!fileArr.length">{{ $t("knowledge.import.tip3") }}</Button>
+  </div>
 </template>
 
 <script>
-	import BlobTool from '@/utils/blobTool.js'
-	export default {
-		props: {
-			auth: {
-				type: Object,
-				default: () => {
-					return {
-						sas: '',
-						url: '',
-						name: ''
-					}
-				}
-			},
-			scope: {
-				type: String,
-				default: 'school'
-			},
-			prefix: {
-				type: String,
-				default: ''
-			},
-			simpleUpload:{
-				type:Boolean,
-				default:false
-			},
-			acceptTypes:{
-				type:Array,
-				default:() => []
-			}
-		},
-		data() {
-			return {
-				isLoading:false,
-				isShowTool:true,
-				containerClient: null,
-				fileArr:[],
-				progressArr:[]
-			}
-		},
-		created() {
+import axios from 'axios'
+import BlobTool from '@/utils/blobTool.js'
+export default {
+  props: {
+    auth: {
+      type: Object,
+      default: () => {
+        return {
+          sas: '',
+          url: '',
+          name: ''
+        }
+      }
+    },
+    scope: {
+      type: String,
+      default: 'school'
+    },
+    prefix: {
+      type: String,
+      default: ''
+    },
+    simpleUpload: {
+      type: Boolean,
+      default: false
+    },
+    acceptTypes: {
+      type: Array,
+      default: () => []
+    }
+  },
+  data() {
+    return {
+      isLoading: false,
+      isShowTool: true,
+      containerClient: null,
+      fileArr: [],
+      progressArr: []
+    }
+  },
+  created() {
 
-		},
-		methods: {
-			async onBeforeUpload(file) {
-				let nameType = file.name.split('.')[file.name.split('.').length - 1]
-				if(this.$GLOBAL.NotSupport.includes(nameType.toUpperCase())){
-					this.$Message.warning(this.$t('learnActivity.notSupportType')); // 黑名单文件格式不能上传
-					return false
-				}
-				if(this.simpleUpload){
-					this.$emit('uploadFinish',file)
-					return
-				}
-				file.progress = 0
-				this.fileArr.push(file)
-				this.progressArr.push(0)
-				return false
-				
-			},
-			
-			onRemoveFile(index){
-				this.fileArr.splice(index,1)
-			},
-			
-			async onConfirmUpload(){
-				this.isShowTool = false
-				let result = []
-				let containerClient = this.containerClient
-				let list = this.fileArr
-				let that = this
-				let promiseArr = []
-				that.isLoading = true
-				for(let i = 0 ; i < list.length; i++){
-					let file = list[i]
-					promiseArr.push(new Promise(async (r,j) => {
-						try{
-							let blobFile = await containerClient.upload(file, { path:this.prefix },{
-								onProgress: function (e) {
-									that.$set(that.progressArr,i,parseInt(e.loadedBytes * 100 / file.size))
-								}
-							});
-							// 如果上传的是视频文件 则需要获取视频的时长信息和MD5信息
-							if (blobFile.type === 'video' && blobFile.extension.toLowerCase() === 'mp4') {
-								blobFile.duration = await this.$tools.getVideoDuration(file)
-							}
-							if (blobFile.type === 'video' && blobFile.extension.toLowerCase() !== 'mp4') {
-								this.$Message.warning(blobFile.name + this.$t('syllabus.playFailTip'))
-							}
-							let fileMD5 = await this.$tools.getFileMD5(file)
-							blobFile.hash = this.$tools.convertFileMD5ToString(fileMD5)
-							console.log('BaseUpload > md5',blobFile.hash);
-							r(blobFile)
-						}catch(e){
-							this.$Message.error(e.spaceError || 'upload Fail')
-							j(e)
-						}
-					}))
-				}
-				
-				Promise.all(promiseArr).then(result => {
-					this.$emit('uploadFinish',result)
-				}).catch(e => {
-					this.$Message.error('upload Fail!')
-				}).finally(() => {
-					this.fileArr = []
-					this.progressArr = []
-					that.isLoading = false
-				})
-				
-			}
-		},
-		mounted() {
-			if(this.auth.sas){
-				let n = this.auth
-				this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
-			}
-		},
-		watch: {
-			auth: {
-				handler(n, o) {
-					this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
-				}
-			}
-		}
-	}
+  },
+  methods: {
+    async onBeforeUpload(file) {
+      let nameType = file.name.split('.')[file.name.split('.').length - 1]
+      if (this.$GLOBAL.NotSupport.includes(nameType.toUpperCase())) {
+        this.$Message.warning(this.$t('learnActivity.notSupportType')); // 黑名单文件格式不能上传
+        return false
+      }
+      if (this.simpleUpload) {
+        this.$emit('uploadFinish', file)
+        return
+      }
+      file.progress = 0
+      this.fileArr.push(file)
+      this.progressArr.push(0)
+      return false
+
+    },
+
+    onRemoveFile(index) {
+      this.fileArr.splice(index, 1)
+    },
+
+    async onConfirmUpload() {
+      this.isShowTool = false
+      let result = []
+      let containerClient = this.containerClient
+      let list = this.fileArr
+      let that = this
+      let promiseArr = []
+      that.isLoading = true
+      for (let i = 0; i < list.length; i++) {
+        let file = list[i]
+        promiseArr.push(new Promise(async (r, j) => {
+          try {
+            let blobFile = await containerClient.upload(file, { path: this.prefix }, {
+              onProgress: function (e) {
+                that.$set(that.progressArr, i, parseInt(e.loadedBytes * 100 / file.size))
+              }
+            });
+            // 如果上传的是视频文件 则需要获取视频的时长信息和MD5信息
+            if (blobFile.type === 'video' && blobFile.extension.toLowerCase() === 'mp4') {
+              blobFile.duration = await this.$tools.getVideoDuration(file)
+            }
+            if (blobFile.type === 'video' && blobFile.extension.toLowerCase() !== 'mp4') {
+              this.$Message.warning(blobFile.name + this.$t('syllabus.playFailTip'))
+            }
+            let fileMD5 = await this.$tools.getFileMD5(file)
+            blobFile.hash = this.$tools.convertFileMD5ToString(fileMD5)
+            console.log('BaseUpload > md5', blobFile.hash);
+            console.error(blobFile)
+            console.error(this.prefix)
+            // 如果上传的是HTEX文件 则需要访问解压接口后 再删除原压缩包
+            if (blobFile.extension.toLowerCase() === 'htex') {
+              let htexUploadStatus = await this.doUploadHTEX(blobFile)
+              if (htexUploadStatus !== 200) {
+                j(500)
+              }
+            }
+            r(blobFile)
+          } catch (e) {
+            this.$Message.error(e.spaceError || 'upload Fail')
+            j(e)
+          }
+        }))
+      }
+      Promise.all(promiseArr).then(result => {
+        this.$emit('uploadFinish', result)
+      }).catch(e => {
+        this.$Message.error('upload Fail!')
+      }).finally(() => {
+        this.fileArr = []
+        this.progressArr = []
+        that.isLoading = false
+      })
+
+    },
+    /* 处理HTEX文件的上传 */
+    doUploadHTEX(blobFile) {
+      return new Promise(async (r, j) => {
+        axios({
+          method: 'post',
+          url: `${window.location.protocol}//${window.location.host}/import/parse-doc`,
+          data: {
+            file: blobFile.url,
+            scope: this.scope,
+            target: this.prefix,
+          },
+          timeout: 10 * 60 * 1000, //十分钟
+        }).then(
+          parseRes => {
+            r(200)
+          },
+          parseErr => {
+            j(500)
+          }
+        ).finally(() => {
+          this.containerClient.deleteBlob(blobFile.blob)
+        })
+      })
+    }
+  },
+  mounted() {
+    if (this.auth.sas) {
+      let n = this.auth
+      this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
+    }
+  },
+  watch: {
+    auth: {
+      handler(n, o) {
+        this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
+      }
+    }
+  }
+}
 </script>
 
 <style lang="less">
-	.base-upload-container{
-		padding-bottom: 40px;
-		.file-list-box{
-			margin: 20px 5px;
-			width: 100%;
-			max-height: 200px;
-			overflow: auto;
-			
-			.file-item{
-				margin: 10px 0;
-				
-				.tool-remove{
-					color: #b3b3b3;
-					margin-left: 15px;
-					font-size: 14px;
-					cursor: pointer;
-				}
-			}
-			
-			.ivu-progress{
-				margin-top: 10px;
-			}
-			
-			.ivu-progress-text-inner{
-				color: #ddd;
-			}
-			
-			&::-webkit-scrollbar-thumb{
-				background:#dadada !important;
-			}
-		}
-	}
+.base-upload-container {
+  padding-bottom: 40px;
+  .file-list-box {
+    margin: 20px 5px;
+    width: 100%;
+    max-height: 200px;
+    overflow: auto;
+
+    .file-item {
+      margin: 10px 0;
+
+      .tool-remove {
+        color: #b3b3b3;
+        margin-left: 15px;
+        font-size: 14px;
+        cursor: pointer;
+      }
+    }
+
+    .ivu-progress {
+      margin-top: 10px;
+    }
+
+    .ivu-progress-text-inner {
+      color: #ddd;
+    }
+
+    &::-webkit-scrollbar-thumb {
+      background: #dadada !important;
+    }
+  }
+}
 </style>

+ 2 - 2
TEAMModelOS/ClientApp/src/utils/public.js

@@ -1235,7 +1235,7 @@ export default {
 		return tmpUint8Array
 	},
 	/* 批量打包下载 */
-	async doBatchDownloadZip(urls, zipName) {
+	async doBatchDownloadZip(urls, zipName, isHTEX) {
 		const zip = new JSZip();
 		const cache = {};
 		const promises = [];
@@ -1258,7 +1258,7 @@ export default {
 				type: "blob"
 			}).then(content => {
 				// 生成二进制流
-				FileSaver.saveAs(content, zipName + ".zip"); // 利用file-saver保存文件
+				FileSaver.saveAs(content, isHTEX ? zipName : zipName + ".zip"); // 利用file-saver保存文件
 			})
 				.catch(err => {
 					console.log(err);

+ 28 - 14
TEAMModelOS/ClientApp/src/view/syllabus/Syllabus.vue

@@ -1479,6 +1479,7 @@ export default {
     },
     /* 上传本地文件成功回调 */
     uploadFinish(result) {
+      console.log(result)
       result.forEach(file => {
         this.$refs.treeRef.curData.rnodes.push({
           code: this.curCode,
@@ -2087,6 +2088,9 @@ export default {
         case 'link':
           window.open(/^(http:|https:)/i.test(item.link) ? item.link : "http://" + item.link)
           break;
+        case 'res':
+          this.$Message.warning(this.$t('syllabus.noPreview'))
+          break;
         case 'other':
           this.$Message.warning(this.$t('syllabus.noPreview'))
           break;
@@ -2103,9 +2107,6 @@ export default {
           if (this.getSuffix(item.title) === 'pdf') {
             this.openPdf(fullLink, item.title)
           } else {
-            // this.previewFile = JSON.parse(JSON.stringify(item))
-            // this.previewFile.link = escape(fullLink)
-            // this.previewStatus = true
             this.openDoc(escape(fullLink))
           }
           break;
@@ -2155,11 +2156,21 @@ export default {
     },
     /* 下载资源 */
     async onDownload(item, index) {
-      let sasObj = item.scope === 'school' ? await this.$tools.getSchoolSas() : await this.$evTools
-        .getBlobPrivateSas(item.cntr)
-      let fullLink = this.$evTools.getBlobHost() + '/' + item.cntr + item.link + (item.scope === 'school' ?
-        sasObj.sas : sasObj)
-      this.$tools.doDownloadByUrl(fullLink, item.title)
+      let sasObj = item.scope === 'school' ? await this.$tools.getSchoolSas() : await this.$evTools.getBlobPrivateSas(item.cntr)
+      if (this.getSuffix(item.title).toLowerCase() === 'htex') {
+        let sasString = item.scope === 'school' ? sasObj.sas : sasObj
+        this.containerClient.listBlob({
+          prefix: item.link.replace('.HTEX', '').substr(1),
+        }, false).then(
+          res => {
+            let urls = res.blobList.map(i => i.url + sasString)
+            this.$tools.doBatchDownloadZip(urls, item.title, true)
+          }
+        )
+      } else {
+        let fullLink = this.$evTools.getBlobHost() + '/' + item.cntr + item.link + (item.scope === 'school' ? sasObj.sas : sasObj)
+        this.$tools.doDownloadByUrl(fullLink, item.title)
+      }
     },
     /* 资源打包下载 */
     async doBatchDownload() {
@@ -2200,9 +2211,10 @@ export default {
     deleteBlobPrefix(item) {
       return new Promise((resolve, reject) => {
         console.log(item);
+        let isHTEX = this.getSuffix(item.title).toLowerCase() === 'htex'
         this.$api.blob.deletePrefix({
           "cntr": item.cntr,
-          "prefix": item.link.substring(1)
+          "prefix": isHTEX ? item.link.substring(1).replace('.HTEX', '') : item.link.substring(1)
         }).then(
           (res) => {
             if (!res.error) {
@@ -2248,11 +2260,7 @@ export default {
           "syllabusIds": []
         }
 
-        if (this.isSaveSyllabus) {
-          addVolumeParams = this.curVolume
-          addVolumeParams.syllabusIds = this.allChapterIds || []
-          this.isSaveSyllabus = false
-        }
+
 
         if ((this.isEditVolume && this.curVolume)) {
           addVolumeParams.id = this.curVolume.id
@@ -2265,6 +2273,12 @@ export default {
           addVolumeParams.order = this.volumeList.length + 1
         }
 
+        if (this.isSaveSyllabus) {
+          addVolumeParams = this.curVolume
+          addVolumeParams.syllabusIds = this.allChapterIds || []
+          this.isSaveSyllabus = false
+        }
+
         // 发送新增或者编辑册别请求
         this.$api.syllabus.SaveOrUpdateVolume(addVolumeParams).then(res => {
           if (!res.error) {

Різницю між файлами не показано, бо вона завелика
+ 595 - 593
TEAMModelOS/ClientApp/src/view/teachcontent/UploadModal.vue