|
@@ -10,13 +10,11 @@ import { app } from '@/boot-app.js'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
-
|
|
|
|
/* 根据登录后的用户信息获取blobHOST域名 */
|
|
/* 根据登录后的用户信息获取blobHOST域名 */
|
|
getBlobHost(){
|
|
getBlobHost(){
|
|
let s = store.state.user.userProfile.blob_uri || store.state.user.studentProfile.blob_uri || 'https://teammodelstorage.blob.core.chinacloudapi.cn/hbcn'
|
|
let s = store.state.user.userProfile.blob_uri || store.state.user.studentProfile.blob_uri || 'https://teammodelstorage.blob.core.chinacloudapi.cn/hbcn'
|
|
return s.split(s.substring(s.lastIndexOf('/')))[0]
|
|
return s.split(s.substring(s.lastIndexOf('/')))[0]
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 获取试题保存在Blob的JSON文件 */
|
|
/* 获取试题保存在Blob的JSON文件 */
|
|
createBlobItem(item){
|
|
createBlobItem(item){
|
|
return new Promise((r,j) => {
|
|
return new Promise((r,j) => {
|
|
@@ -53,7 +51,6 @@ export default {
|
|
r(itemJson)
|
|
r(itemJson)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 获取保存在COSMOS里面的试题格式 */
|
|
/* 获取保存在COSMOS里面的试题格式 */
|
|
createCosmosItem(item){
|
|
createCosmosItem(item){
|
|
return new Promise((r,j) => {
|
|
return new Promise((r,j) => {
|
|
@@ -81,7 +78,6 @@ export default {
|
|
r(cosmosItem)
|
|
r(cosmosItem)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 生成试卷的index.json文件格式 */
|
|
/* 生成试卷的index.json文件格式 */
|
|
createBlobPaper(paper,slides){
|
|
createBlobPaper(paper,slides){
|
|
return new Promise((r,j) => {
|
|
return new Promise((r,j) => {
|
|
@@ -102,7 +98,6 @@ export default {
|
|
r(paperItem)
|
|
r(paperItem)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 生成试卷保存在cosmos的数据结构 */
|
|
/* 生成试卷保存在cosmos的数据结构 */
|
|
createCosmosPaper(paper){
|
|
createCosmosPaper(paper){
|
|
return new Promise((r,j) => {
|
|
return new Promise((r,j) => {
|
|
@@ -124,7 +119,41 @@ export default {
|
|
r(paperItem)
|
|
r(paperItem)
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ /* 根据醍摩豆ID获取对应用户Blob内部的完整试题 */
|
|
|
|
+ getFullItemByTmdId(tmdId,blob){
|
|
|
|
+ return new Promise(async (r,j) => {
|
|
|
|
+ let privateSas = await this.getBlobPrivateSas(tmdId)
|
|
|
|
+ let fullPath = this.getBlobHost() + '/' + tmdId + blob + privateSas
|
|
|
|
+ let jsonData = JSON.parse(await $tools.getFile(fullPath))
|
|
|
|
+ // 如果是综合题 那就拿到children里面的小题id集合 去换取小题的blobJSON文件 然后替换children的内容
|
|
|
|
+ if(jsonData.exercise.children.length && jsonData.exercise.type === 'compose'){
|
|
|
|
+ let childrenUrls = jsonData.exercise.children.map(i => this.getBlobHost() + '/' + tmdId + '/item/' + i + '/' + i + '.json' + privateSas)
|
|
|
|
+ jsonData.exercise.children = await this.getFullChildren(childrenUrls,tmdId)
|
|
|
|
+ }
|
|
|
|
+ // 调整渲染试题数据结构
|
|
|
|
+ jsonData.exercise.question = jsonData.item[0].question
|
|
|
|
+ jsonData.exercise.blob = fullPath
|
|
|
|
+ jsonData.exercise.code = tmdId
|
|
|
|
+ jsonData.exercise.option = jsonData.item[0].option
|
|
|
|
+ jsonData.exercise.id = jsonData.id
|
|
|
|
+ jsonData.exercise.pid = jsonData.pid
|
|
|
|
+ jsonData.exercise = await this.doAddHost(jsonData.exercise,null,tmdId)
|
|
|
|
+ r(jsonData.exercise)
|
|
|
|
+ })
|
|
|
|
+ },
|
|
|
|
+ /* 根据醍摩豆ID获取对应BLOB个人容器授权信息 */
|
|
|
|
+ getBlobPrivateSas(tmdId){
|
|
|
|
+ return new Promise((r,j) => {
|
|
|
|
+ $api.blob.blobSasR({
|
|
|
|
+ name:tmdId,
|
|
|
|
+ role:'teacher'
|
|
|
|
+ }).then(res => {
|
|
|
|
+ if(!res.error){
|
|
|
|
+ r('?' + res.sas)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ })
|
|
|
|
+ },
|
|
/* 获取完整的试题数据 */
|
|
/* 获取完整的试题数据 */
|
|
getFullItem(list,examScope){
|
|
getFullItem(list,examScope){
|
|
console.log('接受到的examScope',examScope)
|
|
console.log('接受到的examScope',examScope)
|
|
@@ -140,24 +169,30 @@ export default {
|
|
const blobHost = curScope === 'school' ? JSON.parse(decodeURIComponent(localStorage.school_profile, "utf-8")).blob_uri : JSON.parse(decodeURIComponent(localStorage.user_profile, "utf-8")).blob_uri
|
|
const blobHost = curScope === 'school' ? JSON.parse(decodeURIComponent(localStorage.school_profile, "utf-8")).blob_uri : JSON.parse(decodeURIComponent(localStorage.user_profile, "utf-8")).blob_uri
|
|
// 根据试题的Blob地址 去读取JSON文件
|
|
// 根据试题的Blob地址 去读取JSON文件
|
|
let sasString = curScope === 'school' ? await $tools.getSchoolSas() : await $tools.getPrivateSas()
|
|
let sasString = curScope === 'school' ? await $tools.getSchoolSas() : await $tools.getPrivateSas()
|
|
- let jsonInfo = list[i].blob.includes('https://') ? await $tools.getFile(list[i].blob + sasString.sas) : await $tools.getFile(blobHost + list[i].blob + sasString.sas)
|
|
|
|
- let jsonData = JSON.parse(jsonInfo)
|
|
|
|
- // 如果是综合题 那就拿到children里面的小题id集合 去换取小题的blobJSON文件 然后替换children的内容
|
|
|
|
- if(jsonData.exercise.children.length && jsonData.exercise.type === 'compose'){
|
|
|
|
- let childrenUrls = jsonData.exercise.children.map(i => blobHost + '/item/' + i + '/' + i + '.json' + sasString.sas)
|
|
|
|
- jsonData.exercise.children = await this.getFullChildren(childrenUrls,list[i].code)
|
|
|
|
|
|
+ try{
|
|
|
|
+ let jsonInfo = list[i].blob.includes('https://') ? await $tools.getFile(list[i].blob + sasString.sas) : await $tools.getFile(blobHost + list[i].blob + sasString.sas)
|
|
|
|
+ let jsonData = JSON.parse(jsonInfo)
|
|
|
|
+ // 如果是综合题 那就拿到children里面的小题id集合 去换取小题的blobJSON文件 然后替换children的内容
|
|
|
|
+ if(jsonData.exercise.children.length && jsonData.exercise.type === 'compose'){
|
|
|
|
+ let childrenUrls = jsonData.exercise.children.map(i => blobHost + '/item/' + i + '/' + i + '.json' + sasString.sas)
|
|
|
|
+ jsonData.exercise.children = await this.getFullChildren(childrenUrls,list[i].code)
|
|
|
|
+ }
|
|
|
|
+ // 调整渲染试题数据结构
|
|
|
|
+ jsonData.id = list[i].id
|
|
|
|
+ jsonData.exercise.question = jsonData.item[0].question
|
|
|
|
+ jsonData.exercise.createTime = list[i].createTime || 0
|
|
|
|
+ jsonData.exercise.blob = list[i].blob
|
|
|
|
+ jsonData.exercise.code = list[i].code
|
|
|
|
+ jsonData.exercise.option = jsonData.item[0].option
|
|
|
|
+ jsonData.exercise.id = list[i].id
|
|
|
|
+ jsonData.exercise.pid = jsonData.pid
|
|
|
|
+ jsonData.exercise = await this.doAddHost(jsonData.exercise)
|
|
|
|
+ r(jsonData.exercise)
|
|
|
|
+ }catch(e){
|
|
|
|
+ console.log(e)
|
|
|
|
+ this.$Message.error(e)
|
|
}
|
|
}
|
|
- // 调整渲染试题数据结构
|
|
|
|
- jsonData.id = list[i].id
|
|
|
|
- jsonData.exercise.question = jsonData.item[0].question
|
|
|
|
- jsonData.exercise.createTime = list[i].createTime || 0
|
|
|
|
- jsonData.exercise.blob = list[i].blob
|
|
|
|
- jsonData.exercise.code = list[i].code
|
|
|
|
- jsonData.exercise.option = jsonData.item[0].option
|
|
|
|
- jsonData.exercise.id = list[i].id
|
|
|
|
- jsonData.exercise.pid = jsonData.pid
|
|
|
|
- jsonData.exercise = await this.doAddHost(jsonData.exercise)
|
|
|
|
- r(jsonData.exercise)
|
|
|
|
|
|
+
|
|
}else{
|
|
}else{
|
|
r(null)
|
|
r(null)
|
|
}
|
|
}
|
|
@@ -172,12 +207,11 @@ export default {
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
- /* 给富文本添加 */
|
|
|
|
- doAddHost(exerciseItem,paperItem){
|
|
|
|
|
|
+ /* 给富文本添加 cntr是防止读取的是其他用户的BLOB */
|
|
|
|
+ doAddHost(exerciseItem,paperItem,cntr){
|
|
/* 如果操作的是试卷内的试题 则需要拿试卷的code来作为containerName */
|
|
/* 如果操作的是试卷内的试题 则需要拿试卷的code来作为containerName */
|
|
let curScope = paperItem ? paperItem.scope : exerciseItem.scope
|
|
let curScope = paperItem ? paperItem.scope : exerciseItem.scope
|
|
- let container = curScope === 'school' ? store.state.userInfo.schoolCode : store.state.userInfo.TEAMModelId
|
|
|
|
|
|
+ let container = cntr || (curScope === 'school' ? store.state.userInfo.schoolCode : store.state.userInfo.TEAMModelId)
|
|
let isSubjective = exerciseItem.type === 'complete' || exerciseItem.type === 'subjective' || exerciseItem.type === 'compose'
|
|
let isSubjective = exerciseItem.type === 'complete' || exerciseItem.type === 'subjective' || exerciseItem.type === 'compose'
|
|
let richTextObj = {
|
|
let richTextObj = {
|
|
question: exerciseItem.question,
|
|
question: exerciseItem.question,
|
|
@@ -245,7 +279,6 @@ export default {
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 保存综合题小题 */
|
|
/* 保存综合题小题 */
|
|
saveChildren(children,containerClient){
|
|
saveChildren(children,containerClient){
|
|
return new Promise((resolve,reject) => {
|
|
return new Promise((resolve,reject) => {
|
|
@@ -289,7 +322,6 @@ export default {
|
|
})
|
|
})
|
|
|
|
|
|
},
|
|
},
|
|
-
|
|
|
|
/* 获取综合题子题的Blob数据 */
|
|
/* 获取综合题子题的Blob数据 */
|
|
getFullChildren(urls,code){
|
|
getFullChildren(urls,code){
|
|
return new Promise((resolve,reject) => {
|
|
return new Promise((resolve,reject) => {
|
|
@@ -317,7 +349,66 @@ export default {
|
|
})
|
|
})
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ /* 根据醍摩豆ID获取对应用户Blob内部的完整试卷 */
|
|
|
|
+ getFullPaperByTmdId(tmdId,blob){
|
|
|
|
+ return new Promise(async (r,j) => {
|
|
|
|
+ console.log('根据ID获取试题')
|
|
|
|
+ let privateSas = await this.getBlobPrivateSas(tmdId)
|
|
|
|
+ let fullPath = this.getBlobHost() + '/' + tmdId + blob + '/index.json' + privateSas
|
|
|
|
+ try{
|
|
|
|
+ let jsonInfo = await $tools.getFile(fullPath)
|
|
|
|
+ let jsonData = JSON.parse(jsonInfo)
|
|
|
|
+ // 获取试卷包含的试题数据并包装好
|
|
|
|
+ if(jsonData.slides && jsonData.slides.length){
|
|
|
|
+ let promiseArr = []
|
|
|
|
+ let allItems = []
|
|
|
|
+ jsonData.item = []
|
|
|
|
+ const path = this.getBlobHost() + '/' + tmdId + blob
|
|
|
|
+ jsonData.slides.forEach(async (item,index) => {
|
|
|
|
+ promiseArr.push(new Promise(async (resolve,reject) => {
|
|
|
|
+ try{
|
|
|
|
+ // 获取题目JSON并且包装成完整试题对象
|
|
|
|
+ let itemJson = JSON.parse(await $tools.getFile(path + '/' + item.url + privateSas))
|
|
|
|
+ itemJson.exercise.question = itemJson.item[0].question
|
|
|
|
+ itemJson.exercise.option = itemJson.item[0].option
|
|
|
|
+ itemJson.exercise.id = itemJson.id
|
|
|
|
+ itemJson.exercise.pid = itemJson.pid
|
|
|
|
+ itemJson.exercise.blob = path + '/' + item.url // 添加blob是方便在保存试卷是 refresh 与导入的试题区分开
|
|
|
|
+ itemJson.exercise.score = item.scoring ? item.scoring.score : 0
|
|
|
|
+ try{
|
|
|
|
+ itemJson.exercise = await this.doAddHost(itemJson.exercise,{ name : jsonData.name },tmdId) // 检测试题中的富文本 为有src为相对路径的音视频文件添加blob的HOST地址
|
|
|
|
+ resolve(itemJson.exercise)
|
|
|
|
+ }catch(e){
|
|
|
|
+ reject(e)
|
|
|
|
+ }
|
|
|
|
+ }catch(e){
|
|
|
|
+ reject(e)
|
|
|
|
+ }
|
|
|
|
+ }))
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ Promise.all(promiseArr).then(res => {
|
|
|
|
+ res.forEach((resItem,resIndex) => {
|
|
|
|
+ resItem.children = []
|
|
|
|
+ if(resItem.pid){
|
|
|
|
+ let pItem = res.filter(i => i.id === resItem.pid)[0]
|
|
|
|
+ pItem.children.push(resItem)
|
|
|
|
+ pItem.score = pItem.score + resItem.score
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ jsonData.item = res.filter(i => !i.pid)
|
|
|
|
+ r(jsonData)
|
|
|
|
+ }).catch(e => {
|
|
|
|
+ // Message.error('试卷文件读取失败')
|
|
|
|
+ j(e)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }catch(e){
|
|
|
|
+ console.log(e)
|
|
|
|
+ j(e)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ },
|
|
/* 获取完整的试卷数据 */
|
|
/* 获取完整的试卷数据 */
|
|
getFullPaper(paper,examScope){
|
|
getFullPaper(paper,examScope){
|
|
console.log(paper)
|
|
console.log(paper)
|
|
@@ -385,8 +476,6 @@ export default {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
-
|
|
|
|
/* 获取完整的试卷数据 */
|
|
/* 获取完整的试卷数据 */
|
|
getStuPaper(paper, examScope) {
|
|
getStuPaper(paper, examScope) {
|
|
let curScope = examScope || paper.scope
|
|
let curScope = examScope || paper.scope
|
|
@@ -458,18 +547,17 @@ export default {
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
-
|
|
|
|
- // 提取富文本内容中的文本
|
|
|
|
|
|
+ /* 提取富文本内容中的文本 */
|
|
getSimpleText(html) {
|
|
getSimpleText(html) {
|
|
var r = /<\/?(img)[^>]*>/gi;
|
|
var r = /<\/?(img)[^>]*>/gi;
|
|
return html.replace(r, "");
|
|
return html.replace(r, "");
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ /* 判断是否为客观题 */
|
|
getItemType(type){
|
|
getItemType(type){
|
|
const objective = ['single','multiple','judge']
|
|
const objective = ['single','multiple','judge']
|
|
return objective.includes(type)
|
|
return objective.includes(type)
|
|
},
|
|
},
|
|
-
|
|
|
|
|
|
+ /* 获取img标签内的src */
|
|
getImgSrc(richtext) {
|
|
getImgSrc(richtext) {
|
|
let imgList = [];
|
|
let imgList = [];
|
|
richtext.replace(/<video [^>]*src=['"]([^'"]+)[^>]*>/g, (match, capture) => {
|
|
richtext.replace(/<video [^>]*src=['"]([^'"]+)[^>]*>/g, (match, capture) => {
|