Bladeren bron

多媒体转义&&课纲资源单独下载问题

OnePsycho 3 jaren geleden
bovenliggende
commit
f79f466f4f

+ 1 - 1
TEAMModelOS/ClientApp/src/utils/editorTools.js

@@ -577,7 +577,7 @@ export default {
 						srcList.forEach(src => {
 							let withSas = src.split('/')[src.split('/').length - 1]
 							let j = withSas.lastIndexOf('?')
-							richTextObj[key] = richTextObj[key].replace(src, withSas.slice(0,j));
+							richTextObj[key] = richTextObj[key].replace(src, decodeURI(withSas.slice(0,j)));
 						})
 						if (key === 'answer' && Array.isArray(exerciseItem.answer) && exerciseItem.answer.length) {
 							exerciseItem.answer[0] = richTextObj[key]

+ 1 - 1
TEAMModelOS/ClientApp/src/utils/evTools.js

@@ -274,7 +274,7 @@ export default {
 						console.log('要添加list',srcList)
 						let curHost = this.getBlobHost()
 						for(let i = 0;i<srcList.length;i++){
-							let src = srcList[i]
+							let src = decodeURI(srcList[i])
 							/* 如果是来自试卷的题目 则需要匹配试卷HOST */
 							if(paperItem && paperItem.examId){
 								let examContainer = paperItem.examId

+ 57 - 43
TEAMModelOS/ClientApp/src/utils/public.js

@@ -557,6 +557,21 @@ export default {
 		})
 	},
 
+	/* 弹窗下载文件操作 */
+	doDownloadByUrl(url,fileName) {
+		const downloadRes = async () => {
+		      let response = await fetch(url); // 内容转变成blob地址
+		      let blob = await response.blob();  // 创建隐藏的可下载链接
+		      let objectUrl = window.URL.createObjectURL(blob);
+		      let a = document.createElement('a');
+		      a.href = objectUrl;
+		      a.download = fileName;
+		      a.click()
+		      a.remove(); 
+		   }
+		  downloadRes();
+	},
+
 	/* 获取视频第一帧 */
 	getVideoBase64(url) {
 		return new Promise(function(resolve, reject) {
@@ -588,42 +603,42 @@ export default {
 			});
 		})
 	},
-	
+
 	/* 获取视频文件的持续时长 */
-	getVideoDuration(file,url) {
-		return new Promise((resolve,reject) => {
+	getVideoDuration(file, url) {
+		return new Promise((resolve, reject) => {
 			var vid = document.createElement('video');
 			var fileURL = url || URL.createObjectURL(file);
 			vid.src = fileURL;
 			vid.addEventListener('loadedmetadata', function() {
-			    resolve(vid.duration);
+				resolve(vid.duration);
 			});
 			vid.remove()
 		})
 	},
 
 	/* 将文件MD5 Uint8Array格式转换成字符串 */
-	convertFileMD5ToString(fileData){
+	convertFileMD5ToString(fileData) {
 		var dataString = "";
 		for (var i = 0; i < fileData.length; i++) {
-		  dataString += fileData[i].toString(16);
+			dataString += fileData[i].toString(16);
 		}
 		return dataString
 	},
 	/* 将二进制流字符串转换成Uint8Array */
-	stringToUint8Array(str){
-	    var arr = [];
-	    for (var i = 0, j = str.length; i < j; ++i) {
-	      arr.push(str.charCodeAt(i));
-	    }
-	  
-	    var tmpUint8Array = new Uint8Array(arr);
-	    return tmpUint8Array
-	  },
+	stringToUint8Array(str) {
+		var arr = [];
+		for (var i = 0, j = str.length; i < j; ++i) {
+			arr.push(str.charCodeAt(i));
+		}
+
+		var tmpUint8Array = new Uint8Array(arr);
+		return tmpUint8Array
+	},
 	/* 获取文件的MD5 */
-	getFileMD5(file){
-		return new Promise((r,j) => {
-			const CHUNK_SIZE = 4194304;  // 大文件获取数前4M大小
+	getFileMD5(file) {
+		return new Promise((r, j) => {
+			const CHUNK_SIZE = 4194304; // 大文件获取数前4M大小
 			const fileReader = new FileReader();
 			const chunkFile = file.slice(0, CHUNK_SIZE);
 			fileReader.readAsBinaryString(chunkFile);
@@ -636,9 +651,9 @@ export default {
 			};
 		})
 	},
-	
+
 	/* 获取时间差异 */
-	getDateDiff(dateTimeStamp){
+	getDateDiff(dateTimeStamp) {
 		var result = ''
 		var minute = 1000 * 60;
 		var hour = minute * 60;
@@ -647,28 +662,26 @@ export default {
 		var month = day * 30;
 		var now = new Date().getTime();
 		var diffValue = now - dateTimeStamp;
-		if(diffValue < 0){return;}
-		var monthC =diffValue/month;
-		var weekC =diffValue/(7*day);
-		var dayC =diffValue/day;
-		var hourC =diffValue/hour;
-		var minC =diffValue/minute;
-		if(monthC>=1){
-			result="" + parseInt(monthC) + "月前";
-		}
-		else if(weekC>=1){
-			result="" + parseInt(weekC) + "周前";
-		}
-		else if(dayC>=1){
-			result=""+ parseInt(dayC) +"天前";
+		if (diffValue < 0) {
+			return;
 		}
-		else if(hourC>=1){
-			result=""+ parseInt(hourC) +"小时前";
-		}
-		else if(minC>=1){
-			result=""+ parseInt(minC) +"分钟前";
-		}else
-		result="刚刚";
+		var monthC = diffValue / month;
+		var weekC = diffValue / (7 * day);
+		var dayC = diffValue / day;
+		var hourC = diffValue / hour;
+		var minC = diffValue / minute;
+		if (monthC >= 1) {
+			result = "" + parseInt(monthC) + "月前";
+		} else if (weekC >= 1) {
+			result = "" + parseInt(weekC) + "周前";
+		} else if (dayC >= 1) {
+			result = "" + parseInt(dayC) + "天前";
+		} else if (hourC >= 1) {
+			result = "" + parseInt(hourC) + "小时前";
+		} else if (minC >= 1) {
+			result = "" + parseInt(minC) + "分钟前";
+		} else
+			result = "刚刚";
 		return result;
 	},
 
@@ -710,7 +723,8 @@ export default {
 			let blobFile = await containerClient.upload(file, 'item/' + id)
 			// 获取blob链接以及视频封面截图
 			const fileSas = await this.getFileSas(blobFile.url)
-			const fileBlobUrl = fileSas.url
+			// const fileBlobUrl = encodeURI(blobFile.url) + '?' + fileSas.sas
+			const fileBlobUrl = encodeURI(blobFile.url) + '?' + fileSas.sas
 			// const posterBase64 = await this.getVideoBase64(fileBlobUrl)
 			editor.selection.getSelectionStartElem().elems[0].innerHTML += '<span><span>&nbsp;</span><video src=' +
 				fileBlobUrl +
@@ -718,7 +732,7 @@ export default {
 			editor.change.emit()
 			vm.$EventBus.$emit('noSave', {
 				path: blobFile.blob,
-				size: blobFile.size,
+				size: blobFile.size, 
 				scope: scope
 			})
 			vm.$Spin.hide();

+ 2 - 1
TEAMModelOS/ClientApp/src/view/evaluation/index/CreatePaper.vue

@@ -659,7 +659,7 @@
 					}
 					Promise.all(promiseArr).then(async result => {
 						// 如果是入库 则批量保存所有试题
-						if (isToItemBank) {
+						if (isToItemBank && !this.isEditPaper) {
 							try {
 								await this.$api.evaluation.upsertAll({
 									option: 'insert',
@@ -667,6 +667,7 @@
 								})
 							} catch (e) {
 								this.isLoading = false
+								console.error(e)
 								this.$Message.error(this.$t(
 									'evaluation.paperList.saveItemsFailTip'))
 							}

+ 39 - 24
TEAMModelOS/ClientApp/src/view/syllabus/Syllabus.vue

@@ -94,25 +94,29 @@
       <div class="syllabus-right">
         <div class="syllabus-content-header">
           <span>{{ $t('syllabus.relate') }}</span>
-          <span class="syllabus-content-header-tools" v-if="curNode.id && (hasSyllabusAuth || hasEditAuth(curNode)) && !inShareView">
-            <!-- <Icon type="md-add" @click="onAddResource" v-if="curNode.id"/> -->
-            <Tooltip :content="$t('tip.addVolumeResource')" class="common-toolTip" placement="bottom" theme="light" max-width="200">
-              <Icon type="ios-information-circle-outline" />
-            </Tooltip>
-            <Dropdown @on-click="onAddResource">
-              <a href="javascript:void(0)" style="color: #757575;">
-                {{ $t('syllabus.addResource') }}
-                <Icon type="ios-arrow-down"></Icon>
-              </a>
-              <DropdownMenu slot="list">
-                <DropdownItem name="content">+{{ $t('syllabus.type1') }}</DropdownItem>
-                <DropdownItem name="question">+{{ $t('syllabus.type2') }}</DropdownItem>
-                <DropdownItem name="paper">+{{ $t('syllabus.type3') }}</DropdownItem>
-                <DropdownItem name="file">+{{ $t('syllabus.type4') }}</DropdownItem>
-                <DropdownItem name="link">+{{ $t('syllabus.type5') }}</DropdownItem>
-              </DropdownMenu>
-            </Dropdown>
-          </span>
+		  <span>
+			  <span class="syllabus-content-header-tools" v-if="curNode.id && (hasSyllabusAuth || hasEditAuth(curNode)) && !inShareView">
+			    <!-- <Icon type="md-add" @click="onAddResource" v-if="curNode.id"/> -->
+				<!-- <span>批量下载</span> -->
+			    <Tooltip :content="$t('tip.addVolumeResource')" class="common-toolTip" placement="bottom" theme="light" max-width="200">
+			      <Icon type="ios-information-circle-outline" />
+			    </Tooltip>
+			    <Dropdown @on-click="onAddResource">
+			      <a href="javascript:void(0)" style="color: #757575;">
+			        {{ $t('syllabus.addResource') }}
+			        <Icon type="ios-arrow-down"></Icon>
+			      </a>
+			      <DropdownMenu slot="list">
+			        <DropdownItem name="content">+{{ $t('syllabus.type1') }}</DropdownItem>
+			        <DropdownItem name="question">+{{ $t('syllabus.type2') }}</DropdownItem>
+			        <DropdownItem name="paper">+{{ $t('syllabus.type3') }}</DropdownItem>
+			        <DropdownItem name="file">+{{ $t('syllabus.type4') }}</DropdownItem>
+			        <DropdownItem name="link">+{{ $t('syllabus.type5') }}</DropdownItem>
+			      </DropdownMenu>
+			    </Dropdown>
+			  </span>
+		  </span>
+          
         </div>
         <div class="syllabus-tree-box">
           <EmptyData v-if="curNode.rnodes && !curNode.rnodes.length"></EmptyData>
@@ -133,10 +137,10 @@
               <img src="../../assets/source/unknow.png" v-else="item.type === 'other'" />
               <span v-html="item.title" class="text-cut" style="max-width: 70%;cursor: pointer;"></span>
               <div class="node-resource-tools">
-                <!-- <div class="node-resource-tool" >
-									<Icon type="md-eye" />
-									<span>{{ $t('syllabus.preview') }}</span>
-								</div> -->
+                <div class="node-resource-tool" @click.stop="onDownload(item,index)">
+					<Icon type="md-download" />
+					<span>下载</span>
+				</div>
                 <div class="node-resource-tool" @click.stop="onDeleteResource(item,index)" :title="$t('teachContent.tips7')" v-if="(hasSyllabusAuth || hasEditAuth(curNode)) && !inShareView">
                   <Icon type="md-trash" />
                   <span>{{ $t('syllabus.remove') }}</span>
@@ -1703,7 +1707,18 @@ export default {
     openPdf(url) {
       window.open('/web/viewer.html?file=' + encodeURIComponent(url));
     },
-    /* 删除关联资源 */
+	/* 下载资源 */
+	async onDownload(item,index){
+		let sasObj = item.scope === 'school' ? await this.$tools.getSchoolSas() : await this.$evTools.getBlobPrivateSas(item.code)
+		let fullLink = this.$evTools.getBlobHost() + '/' + item.cntr + item.link + sasObj.sas
+		this.$tools.doDownloadByUrl(fullLink,item.title)
+	},
+    
+	/* 资源打包下载 */
+	async onBatchDownload(){
+		
+	},
+	/* 删除关联资源 */
     onDeleteResource(item, index) {
       this.$Modal.confirm({
         title: this.$t('settings.modalTip4'),