Jelajahi Sumber

试卷保存时访问

OnePsycho 4 tahun lalu
induk
melakukan
9d872d9849

+ 2 - 3
TEAMModelOS/ClientApp/src/utils/blobTool.js

@@ -305,12 +305,11 @@ export default class BlobTool {
      * @param {string} scope 校本/个人 school / private
      * return true/false
      */
-    async isContainerFull(scope) {
+    async isContainerFull() {
         return new Promise(async (r, j) => {
             try {
-                let space = scope == 'school' ? GLOBAL.SCHOOL_SPACE : GLOBAL.PRIVATE_SPACE
                 let size = await this.getContainerSize()
-                if (size > space) {
+                if (size > this.blobSpace) {
                     r(true)
                 } else {
                     r(false)

+ 37 - 8
TEAMModelOS/ClientApp/src/view/evaluation/index/CreatePaper.vue

@@ -232,7 +232,7 @@
 					let subjectId = this.isSchool ? this.subjectList[this.evaluationInfo.paperSubject].id : null
 					let periodId = this.isSchool ? this.schoolInfo.period[this.evaluationInfo.paperPeriod].id : null
 					list.forEach(i => {
-						if(i.blob) return
+						if (i.blob) return
 						/* 如果是导入的试题 没有ID 则试题的信息和当前试卷的学段信息保持一致 */
 						i.id = this.$tools.guid()
 						i.code = code
@@ -399,7 +399,7 @@
 									let file = new File([JSON.stringify(itemJsonFile)], composeItem.id + ".json");
 									try {
 										// 等待上传blob的返回结果
-										let blobFile = await containerClient.upload(file, 'item')
+										let blobFile = await containerClient.upload(file, 'item', undefined, false)
 										if (blobFile.blob) {
 											// 保存试题JSON文件到试卷文件夹需要
 											itemJsonFiles.push(file)
@@ -428,7 +428,7 @@
 								let file = new File([JSON.stringify(itemJsonFile)], exerciseItem.id + ".json");
 								try {
 									// 等待上传blob的返回结果
-									let blobFile = await containerClient.upload(file, 'item')
+									let blobFile = await containerClient.upload(file, 'item', undefined, false)
 									if (blobFile.blob) {
 										// 保存试题JSON文件到试卷文件夹需要
 										itemJsonFiles.push(file)
@@ -518,7 +518,26 @@
 						}
 					)
 				})
+			},
 
+			// 判断试卷是否存在于Blob中
+			isContainerFull() {
+				return new Promise(async (r, j) => {
+					let scope = this.isSchool ? 'school' : 'private'
+					// 获取初始化Blob需要的数据
+					let sasData = this.isSchool ? await this.$tools.getSchoolSas() : await this.$tools.getPrivateSas()
+					//初始化Blob
+					let containerClient = new blobTool(sasData.url, sasData.name, sasData.sas, scope)
+					containerClient.isContainerFull(scope).then(
+						(res) => {
+							r(res)
+						},
+						(err) => {
+							j(err)
+							this.$Message.error('API Error')
+						}
+					)
+				})
 			},
 
 			/** 保存当前试卷数据 */
@@ -538,6 +557,7 @@
 					if (hasSurplus === 0) {
 						if (!noScoreList.length) {
 							let isPaperExist = await this.isPaperExist(this.evaluationInfo.name)
+							let isContainerFull = await this.isContainerFull()
 							if (!isPaperExist) {
 								if (list.length) {
 									// 拿到题型顺序的试题数组进行拼接
@@ -546,7 +566,11 @@
 										arr = arr.concat(i.list)
 									})
 									if (!this.checkComposeScore(arr)) return
-									this.doSavePaper(arr)
+									if (isContainerFull) {
+										this.$Message.warning('空间已满!')
+									} else {
+										this.doSavePaper(arr)
+									}
 								} else {
 									this.$Message.warning('未选择任何试题!')
 								}
@@ -566,7 +590,11 @@
 										let blobList = await this.getPaperFiles('paper/' + this.evaluationInfo.name)
 										let files = blobList.blobList.map(i => i.blob)
 										this.onDeleteBlobPaper(files).then(r => {
-											this.doSavePaper(arr)
+											if (isContainerFull) {
+												this.$Message.warning('空间已满!')
+											} else {
+												this.doSavePaper(arr)
+											}
 										})
 									},
 									onCancel: () => {
@@ -699,13 +727,13 @@
 						// 放入试题json文件以及index.json文件
 						for (let i = 0; i < res.files.length; i++) {
 							promiseArr.push(new Promise(async (r, j) => {
-								let result = await containerClient.upload(res.files[i], 'paper/' + paperItem.name)
+								let result = await containerClient.upload(res.files[i], 'paper/' + paperItem.name, undefined, false)
 								r(result)
 							}))
 						}
 						promiseArr.push(new Promise(async (r, j) => {
 							try {
-								blobFile = await containerClient.upload(paperFile, 'paper/' + paperItem.name)
+								blobFile = await containerClient.upload(paperFile, 'paper/' + paperItem.name, undefined, false)
 								r(blobFile)
 							} catch (e) {
 								j(e)
@@ -847,7 +875,8 @@
 				return this.evaluationInfo.type === 'school'
 			},
 			propSubject() {
-				return this.evaluationInfo.type === 'school' && this.subjectList.length ? this.subjectList[this.evaluationInfo.paperSubject].id : null
+				return this.evaluationInfo.type === 'school' && this.subjectList.length ? this.subjectList[this.evaluationInfo.paperSubject]
+					.id : null
 			}
 		},