Browse Source

试卷页面缓存的判断&&删除课纲节点和册别对应的资源文件

OnePsycho 4 năm trước cách đây
mục cha
commit
df29fd2266

+ 3 - 0
TEAMModelOS/ClientApp/src/api/syllabus.js

@@ -31,6 +31,9 @@ export default {
 	ShareAgree:function(data) {
 	    return post('/teacher/share/agree-share', data)
 	},
+	CheckLink:function(data) {
+	    return post('/common/syllabus/check-link', data)
+	},
 	// 查找知识块数量
 	FindBlockCount: function (data) {
 		return post('/knowledges/find-count', data)

+ 129 - 33
TEAMModelOS/ClientApp/src/components/syllabus/DragTree.vue

@@ -183,7 +183,7 @@
 					onOk: () => {
 						this.$api.syllabus.ShareAgree({
 							"code": this.$store.state.userInfo.TEAMModelId,
-							"id": data.id,
+							"ids": [data.id],
 							"type": "share",
 							"opt": "ignore"
 						}).then(res => {
@@ -241,6 +241,7 @@
 				console.log(JSON.stringify(this.flatRNodes))
 				let upsertParams = [{
 					id: this.curChapter.id,
+					codeval: this.curCode,
 					volumeId: targetVolume.id,
 					scope: targetVolume.scope,
 					trees: [this.refreshCopyChapter(this.curChapter)]
@@ -470,45 +471,130 @@
 			// 删除节点操作
 			remove(node, data) {
 				let isFirstLevel = this.isFirstLevel(data)
+				let rNodeLinks = isFirstLevel ? this.getAllRNodes(data).map(i => i.link) : data.rnodes.map(i => i.link)
+				console.log(rNodeLinks)
 				this.$Modal.confirm({
 					title: this.$t('syllabus.tree.removeTitle'),
 					content: this.$t('syllabus.tree.removeConfirm'),
-					onOk: () => {
+					onOk: async () => {
 						const parent = node.parent
 						const children = parent.data.children || parent.data
 						const index = children.findIndex(d => d.id === data.id)
-						// 如果是删除的第一层的节点 则直接访问API进行删除 如果不是 则记录子节点的PID
-						if(isFirstLevel){
-							this.$api.syllabus.DeleteTree({
-								id:data.id,
-								code:this.volume.id,
-								scope:this.volume.scope
-							}).then(res => {
-								if (!res.error) {
-									if(res.code === 404){
-										this.$parent.modifyIdArr  = this.$parent.modifyIdArr.filter(i => i !== data.id)
-									}
-									children.splice(index, 1)
-									this.$nextTick().then(() => {
-										const firstNode = document.querySelector('.el-tree-node')
-										firstNode.click();
-									})
-									this.$Message.success(this.$t('syllabus.tree.removeSucTip'))
-								} else {
-									this.$Message.warning(res.error);
-								}
-							}).catch(err => {
-								this.$Message.error(err);
-							})
-						}else{
-							children.splice(index, 1)
-							this.$Message.success(this.$t('syllabus.tree.removeSucTip'))
-							this.$parent.hasModify = true
-							this.$emit('addModifyId',this.getChapterIdById(data.id))
+						this.$parent.curNode = {
+							id:'',
+							rnodes:[]
 						}
+						this.doDeleteBlobResource(rNodeLinks,data).then(result => {
+							// 如果是删除的第一层的节点 则直接访问API进行删除 如果不是 则记录子节点的PID
+							if(isFirstLevel){
+								this.$api.syllabus.DeleteTree({
+									id:data.id,
+									code:this.curCode,
+									scope:this.volume.scope
+								}).then(res => {
+									if (!res.error) {
+										if(res.code === 404){
+											this.$parent.modifyIdArr  = this.$parent.modifyIdArr.filter(i => i !== data.id)
+										}
+										children.splice(index, 1)
+										this.$nextTick().then(() => {
+											const firstNode = document.querySelector('.el-tree-node')
+											firstNode && firstNode.click();
+										})
+										this.$Message.success(this.$t('syllabus.tree.removeSucTip'))
+									} else {
+										this.$Message.warning(res.error);
+									}
+								}).catch(err => {
+									this.$Message.error(err);
+								})
+							}else{
+								children.splice(index, 1)
+								this.$Message.success(this.$t('syllabus.tree.removeSucTip'))
+								this.$parent.hasModify = true
+								this.$emit('addModifyId',this.getChapterIdById(data.id))
+								this.$nextTick().then(() => {
+									const firstNode = document.querySelector('.el-tree-node')
+									firstNode && firstNode.click();
+								})
+							}
+						})
+					}
+				})
+			},
+			/* 删除对应关联的资源 */
+			doDeleteBlobResource(links,data){
+				return new Promise((r,j) => {
+					if(!links.length) r(200)
+					let syllabusLinks = links.filter(i => i.includes('/syllabus/'))
+					if(syllabusLinks.length){
+						this.$api.syllabus.CheckLink({
+							"links": syllabusLinks,
+							"code": this.curCode,
+							"scope": this.isSchool ? 'school' : 'private'
+						}).then(res => {
+							console.log(res)
+							let needDeleteLink = []
+							let curVolumeId = this.volume.id
+							let curChapterId = this.getChapterIdById(data.id)
+							let curNodeId = data.id
+							// 如果删除的是章节 则判断是否有其他章节引用了资源 如果没有 则要进行blob删除
+							if(curChapterId === curNodeId){
+								syllabusLinks.forEach(i => {
+									if(!res.links.filter(j => j.link === i && j.syllabusId !== curChapterId).length){
+										needDeleteLink.push(i)
+									}
+								})
+							}else{
+								syllabusLinks.forEach(i => {
+									if(!res.links.filter(j => j.link === i && j.syllabusId !== curChapterId && j.treeid !== curNodeId).length){
+										needDeleteLink.push(i)
+									}
+								})
+							}
+							if(needDeleteLink.length){
+								let promiseArr = []
+								needDeleteLink.forEach(i => {
+									promiseArr.push(this.deleteBlobPrefix(i))
+								})
+								Promise.all(promiseArr).then(result => {
+									r(result)
+								}).catch(err => {
+									j(err)
+								})
+							}else{
+								r(200)
+							}
+						}).catch(e => {
+							j(e)
+						})
+					}else{
+						r(200)
 					}
 				})
 			},
+			
+			/* 删除blob指定试题目录下所有 */
+			deleteBlobPrefix(link) {
+				return new Promise((resolve, reject) => {
+					this.$api.blob.deletePrefix({
+						"cntr": this.curCode,
+						"prefix": link.substring(1)
+					}).then(
+						(res) => {
+							if (!res.error) {
+								resolve(200)
+							} else {
+								resolve(500)
+							}
+						},
+						(err) => {
+							reject(err)
+						}
+					)
+				})
+			},
+			
 			// 点击添加展开弹窗
 			onAddNode(node,data, e) {
 				if(node.level === 3){
@@ -575,6 +661,7 @@
 			/* 获取整个树的章节与子节点归属 */
 			getAllChild(arr){
 				let result = []
+				if(!arr.length) return result
 				arr.forEach(item => {
 					result.push({
 						chapterId:item.id,
@@ -631,6 +718,9 @@
 					return nodeData.creatorId === this.$store.state.userInfo.TEAMModelId
 				}
 			},
+			curCode() {
+				return this.isSchool ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId
+			},
 			inShareView(){
 				return !this.isSchool && this.$parent.activeTab === 'fromShare'
 			},
@@ -643,15 +733,21 @@
 			// 监听课纲数据变化
 			treeData: {
 				handler: function(n, o) {
+					console.log(n);
 					// 以下为拼接树形数据以及册别数据
 					this.treeDatas = n.map(i => {
-						i.trees[0].auth = i.auth
-						return i.trees[0]
+						if(i.trees.length){
+							i.trees[0].auth = i.auth
+							return i.trees[0]
+						}else{
+							return {}
+						}
 					})
+					console.log(this.treeDatas);
 					this.getAllChild(this.treeDatas)
 					this.$nextTick().then(() => {
 						const firstNode = document.querySelector('.el-tree-node')
-						firstNode.click();
+						firstNode && firstNode.click();
 					})
 				},
 				immediate: true,

+ 3 - 0
TEAMModelOS/ClientApp/src/view/evaluation/index/CreatePaper.vue

@@ -1178,6 +1178,9 @@
 				// 设置下一个路由的 meta
 				from.meta.isKeep = true;  // 让 A 缓存,即不刷新
 			}
+			if(to.name === 'schoolBank' || to.name === 'personalBank'){
+				to.meta.isKeep = false
+			}
 			next();
 		},
 		watch: {

+ 128 - 35
TEAMModelOS/ClientApp/src/view/syllabus/Syllabus.vue

@@ -52,11 +52,11 @@
 								<span>|</span>
 								<span>{{ getSemesterName(volume.semesterId) }}</span>
 							</p>
-							<p class="volume-item-info" v-if="inShareView">
-								<!-- <span  style="display: flex;align-items: center;">
+							<p class="volume-item-info" v-if="inShareView && volume.isDel">
+								<span style="display: flex;align-items: center;" @click.stop="onDeleteShareVolume(volume)">
 									<Icon type="ios-remove-circle-outline" style="font-weight: bold;margin-right: 5px;"/>
-									忽略该分享
-								</span> -->
+									删除失效册别
+								</span>
 								<!-- <span class="volume-btn-agree" @click="onAgreeShare(volume,'agree')">
 									<Icon type="md-checkmark-circle-outline" size="20" color="#27c684" />
 									<span>接受</span>
@@ -436,7 +436,8 @@
 						this.volumeList = res.volumes.reverse()
 						this.originVolumeList = JSON.parse(JSON.stringify(this.volumeList))
 						this.myVolumeList = JSON.parse(JSON.stringify(this.volumeList))
-						let activeIndex = this.isEditVolume ? this.activeVolumeIndex : 0
+						// let activeIndex = this.isEditVolume ? this.activeVolumeIndex : 0
+						let activeIndex = this.activeVolumeIndex || 0
 						// this.isEditVolume = false
 						res.volumes.length && this.onVolumeClick(res.volumes[activeIndex], activeIndex, needRefresh)
 					} else {
@@ -488,14 +489,31 @@
 					this.$Message.error(err);
 				})
 			},
-			/* 是否接受分享的课纲 */
-			onAgreeShare(volume,type){
-				console.log(volume)
+			/* 删除已失效的册别 */
+			onDeleteShareVolume(volume){
+				let chapterIds = volume.children.length ? volume.children.map(i => i.id) : []
+				this.$Modal.confirm({
+					title: this.$t('syllabus.tree.removeTitle'),
+					content: '确认删除该失效册别吗?',
+					onOk: () => {
+						this.$api.syllabus.ShareAgree({
+							"code": this.$store.state.userInfo.TEAMModelId,
+							"ids": chapterIds,
+							"type": "share",
+							"opt": "ignore"
+						}).then(res => {
+							if(res.status === 200){
+								this.$Message.success('操作成功!')
+								this.getShareVolumeList(true)
+							}
+						})
+					}
+				})
 			},
 			/* 点击某个册别 */
 			onVolumeClick(volume, volumeIndex, needRefresh) {
 				console.log(volume)
-				if(volume.isDel){
+				if(volume && volume.isDel){
 					this.$Message.warning('该册别已被创建者移除!')
 					this.treeOrigin = []
 					this.curNode = {
@@ -511,6 +529,7 @@
 				this.activeVolumeIndex = volumeIndex
 				this.activeTab === 'fromCreate' ? this.getTreeByVolumeId(volume) : this.getShareTree(volume)
 				this.hasModify = false
+				this.modifyIdArr = []
 			},
 			/* 添加册别 */
 			doAddVolume() {
@@ -522,10 +541,6 @@
 				this.isEditVolume = false
 				this.isAddVolumeModal = true
 			},
-			/* 复制副本 */
-			doCopyVolume(){
-				console.log('xxx')
-			},
 			/* 搜索册别 */
 			doSearchVolume() {
 				this.isSearchVolume = true
@@ -555,32 +570,107 @@
 			/* 删除当前册别 */
 			doDeleteVolume() {
 				let curVolume = this.curVolume
+				let links = this.getVolumeRnodeLinks()
 				this.$Modal.confirm({
 					title: "删除册别",
 					content: "<p>确认移除该册别?</p>",
 					onOk: () => {
 						this.isLoading = true;
-						this.$api.syllabus.DeleteVolume({
-							id: curVolume.id,
-							code: curVolume.code.replace('Volume-', ''),
-							scope: curVolume.scope
-						}).then((res) => {
-							if (res) {
-								this.volumeList.splice(this.activeVolumeIndex, 1);
-								this.treeOrigin = []
-								this.curNode.rnodes = []
-								this.curNode.id = ''
-								this.$Message.success("删除成功");
-								this.onVolumeClick(this.volumeList.length ? this.volumeList[this
-									.activeVolumeIndex] : null, this.activeVolumeIndex)
-								this.isLoading = false;
-							} else {
-								this.$Message.error("删除失败");
-							}
-						});
+						this.doDeleteBlobResource(links).then(result => {
+							this.$api.syllabus.DeleteVolume({
+								id: curVolume.id,
+								code: curVolume.code.replace('Volume-', ''),
+								scope: curVolume.scope
+							}).then((res) => {
+								if (res) {
+									this.volumeList.splice(this.activeVolumeIndex, 1);
+									this.treeOrigin = []
+									this.curNode.rnodes = []
+									this.curNode.id = ''
+									this.$Message.success("删除成功");
+									console.log(this.activeVolumeIndex);
+									this.onVolumeClick(this.volumeList.length ? this.volumeList[0] : null, 0,true)
+									this.isLoading = false;
+								} else {
+									this.$Message.error("删除失败");
+								}
+							});
+						}).catch(err => {
+							this.$Message.error("删除失败," + err);
+						})
 					},
 				});
 			},
+			/* 删除对应关联的资源 */
+			doDeleteBlobResource(links){
+				return new Promise((r,j) => {
+					if(!links.length) r(200)
+					let syllabusLinks = links.filter(i => i.includes('/syllabus/'))
+					if(syllabusLinks.length){
+						this.$api.syllabus.CheckLink({
+							"links": syllabusLinks,
+							"code": this.curCode,
+							"scope": this.curScope
+						}).then(res => {
+							console.log(res)
+							let needDeleteLink = []
+							let curVolumeId = this.curVolume.id
+							syllabusLinks.forEach(i => {
+								if(!res.links.filter(j => j.link === i && j.volumeId !== curVolumeId).length){
+									needDeleteLink.push(i)
+								}
+							})
+							if(needDeleteLink.length){
+								let promiseArr = []
+								needDeleteLink.forEach(i => {
+									promiseArr.push(this.deleteBlobPrefix({
+										cntr:this.curCode,
+										title:i.replace('/syllabus/','')
+									}))
+								})
+								Promise.all(promiseArr).then(result => {
+									r(result)
+								}).catch(err => {
+									j(err)
+								})
+							}else{
+								r(200)
+							}
+						}).catch(e => {
+							j(e)
+						})
+					}else{
+						r(200)
+					}
+				})
+			},
+			/* 获取当前册别课纲下所有的资源link */
+			getVolumeRnodeLinks(){
+				let volumeRnodeLinks = []
+				if(this.treeOrigin.length){
+					this.treeOrigin.forEach(i => {
+						volumeRnodeLinks.push(...this.getAllRNodes(i.trees[0]).map(j => j.link))
+					})
+					return volumeRnodeLinks
+				}else{
+					return []
+				}
+			},
+			/* 获取章节下所有的资源节点 */
+			getAllRNodes(chapterNode){
+				let result = []
+				const fn = (source)=>{
+					result.push(...source.rnodes)
+					if(source.children.length){
+						console.log(JSON.stringify(source.children[0].rnodes));
+						source.children.forEach(i => {
+							fn(i)
+						})
+					}
+				}
+				fn(chapterNode)
+				return result
+			},
 			/* 根据册别查询对应课纲树形结构 */
 			getTreeByVolumeId(volume) {
 				this.curNode.rnodes = []
@@ -675,9 +765,10 @@
 				let modifyChapters = modifyIdArr.length ? modifyIdArr.map(id => {
 					return {
 						id: id,
+						codeval: this.curCode,
 						volumeId: this.curVolume.id,
 						scope: this.curVolume.scope,
-						trees: [allChapter.find(i => i.id === id)]
+						trees: allChapter.find(i => i.id === id) ? [allChapter.find(i => i.id === id)] : []
 					}
 				}) : [];
 				this.allChapterIds = allChapter.map(i => i.id)
@@ -698,7 +789,7 @@
 			onNodeClick(data) {
 				this.curChapter = this.getChapterByNode(data.node)
 				// 如果当前节点有关联试题资源 则需要去拿到试题完整信息 来给title赋值 保证为最新数据
-				if(data.data.rnodes.length){
+				if(data.data.rnodes && data.data.rnodes.length){
 					let itemNodeArr = data.data.rnodes.filter(i => i.type === 'item')
 					if(itemNodeArr.length){
 						itemNodeArr.forEach(async item => {
@@ -1234,7 +1325,7 @@
 						}else{
 							sas = sasObj.sas
 						}
-						item.link = item.link + sas
+						item.link = this.$evTools.getBlobHost() + '/' + item.cntr + item.link + sas
 						this.previewFile = item
 						this.previewStatus = true
 						break;
@@ -1324,7 +1415,9 @@
 						addVolumeParams.creatorId = this.curVolume.creatorId
 					}
 					if(this.isSaveSyllabus){
+						addVolumeParams.id = this.curVolume.id
 						addVolumeParams.name = this.curVolume.name
+						addVolumeParams.syllabusIds = this.allChapterIds || []
 						this.isSaveSyllabus = false
 					}
 					// 发送新增或者编辑册别请求
@@ -1332,7 +1425,7 @@
 						if (!res.error) {
 							this.isAddVolumeModal = false
 							this.$Message.success("操作成功");
-							this.getVolumeList()
+							this.getVolumeList(true)
 							r(200)
 						} else {
 							this.$Message.warning(res.error === 4 ? '已存在相同册别!' : res.error);