|
@@ -1,7 +1,7 @@
|
|
|
<template>
|
|
|
<div class="import-create-wrap">
|
|
|
<BaseImport @importFinish="onImportFinish"></BaseImport>
|
|
|
- <Modal v-model="importStatus" title="导入试卷" width="1200" @on-ok="saveTestPaper">
|
|
|
+ <Modal v-model="importStatus" title="导入试卷" width="1200" :loading="modalLoading" @on-ok="saveTestPaper" :mask-closable="false">
|
|
|
<TestPaper ref="testPaper" :paper="evaluationInfo"></TestPaper>
|
|
|
</Modal>
|
|
|
</div>
|
|
@@ -16,6 +16,7 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ modalLoading: true,
|
|
|
routerScope: '',
|
|
|
importStatus: false,
|
|
|
errorList: [],
|
|
@@ -96,6 +97,7 @@ export default {
|
|
|
},
|
|
|
/** 保存当前试卷数据 */
|
|
|
async saveTestPaper() {
|
|
|
+ this.importStatus = true
|
|
|
let exListVm = this.$refs.testPaper.$refs.exList
|
|
|
let hasSurplus = exListVm.surPlusScore // 判断是否有剩余分数未分配
|
|
|
let noScoreList = exListVm.exerciseList.filter(item => item.score === 0) // 判断是否有未配分的题目
|
|
@@ -164,8 +166,15 @@ export default {
|
|
|
this.isLoading = false
|
|
|
}
|
|
|
} else {
|
|
|
- this.$Message.warning(`保存前请确认试卷配分是否与试卷总分一致!`)
|
|
|
+ this.$Message.warning({
|
|
|
+ content: `题目配分与试卷总分不一致!`,
|
|
|
+ duration: 2.5
|
|
|
+ })
|
|
|
this.isLoading = false
|
|
|
+ this.modalLoading = false
|
|
|
+ setTimeout(() => {
|
|
|
+ this.modalLoading = true
|
|
|
+ }, 100)
|
|
|
}
|
|
|
} else {
|
|
|
this.$Message.warning(`存在异常试题,请修改或者重新导入!`)
|
|
@@ -252,111 +261,274 @@ export default {
|
|
|
// 将传进来的试题 如果是导入的试题 则需要补充年级学段等信息
|
|
|
let refreshList = await this.refreshImportItems(list)
|
|
|
// 保存导入的试题到BLOB以及COSMOS
|
|
|
- this.savePaperItems(refreshList, modifyItems, this.isEditPaper).then(async res => {
|
|
|
- let guid = this.$tools.guid()
|
|
|
- let paperItem = {
|
|
|
- id: this.evaluationInfo.id || guid,
|
|
|
- code: this.editPaper ? this.editPaper.code : (this.isSchool ? this.$store.state.userInfo.schoolCode : this.$store
|
|
|
- .state.userInfo.TEAMModelId),
|
|
|
- scope: this.isSchool ? 'school' : 'private',
|
|
|
- gradeIds: this.isSchool ? (this.evaluationInfo.paperGrade.length ? this.evaluationInfo.paperGrade : this.gradeList
|
|
|
- .map(i => i.id)) : [],
|
|
|
- subjectId: this.isSchool ? this.subjectList[this.evaluationInfo.paperSubject].id : null,
|
|
|
- subjectName: this.isSchool ? this.subjectList[this.evaluationInfo.paperSubject].name : '',
|
|
|
- periodId: this.isSchool ? this.schoolInfo.period[this.evaluationInfo.paperPeriod].id : null,
|
|
|
- name: this.evaluationInfo.name,
|
|
|
- points: this.getPaperPoints(this.evaluationInfo.item),
|
|
|
- scoring: this.getAnswers(list),
|
|
|
- score: this.evaluationInfo.score,
|
|
|
- multipleRule: multipleRule || 1
|
|
|
- }
|
|
|
- let blobPaper = await this.$evTools.createBlobPaper(paperItem, res.slides)
|
|
|
- // 首先保存新题目的JSON文件到Blob 然后返回URL链接
|
|
|
- let paperFile = new File([JSON.stringify(blobPaper)], "index.json");
|
|
|
- // 获取初始化Blob需要的数据
|
|
|
- let sasData = this.evaluationInfo.type === 'private' ? await this.$tools.getPrivateSas() : await this.$tools.getSchoolSas()
|
|
|
- //初始化Blob
|
|
|
- let containerClient = new blobTool(sasData.url, sasData.name, sasData.sas, this.evaluationInfo.type)
|
|
|
- try {
|
|
|
- let promiseArr = []
|
|
|
- let blobFile = null
|
|
|
+ this.savePaperItems(refreshList, modifyItems, this.isEditPaper).then(
|
|
|
+ async res => {
|
|
|
+ console.log('savePaperItems成功')
|
|
|
+ let guid = this.$tools.guid()
|
|
|
+ let paperItem = {
|
|
|
+ id: this.evaluationInfo.id || guid,
|
|
|
+ code: this.editPaper ? this.editPaper.code : (this.isSchool ? this.$store.state.userInfo.schoolCode : this.$store
|
|
|
+ .state.userInfo.TEAMModelId),
|
|
|
+ scope: this.isSchool ? 'school' : 'private',
|
|
|
+ gradeIds: this.isSchool ? (this.evaluationInfo.paperGrade.length ? this.evaluationInfo.paperGrade : this.gradeList
|
|
|
+ .map(i => i.id)) : [],
|
|
|
+ subjectId: this.isSchool ? this.subjectList[this.evaluationInfo.paperSubject].id : null,
|
|
|
+ subjectName: this.isSchool ? this.subjectList[this.evaluationInfo.paperSubject].name : '',
|
|
|
+ periodId: this.isSchool ? this.schoolInfo.period[this.evaluationInfo.paperPeriod].id : null,
|
|
|
+ name: this.evaluationInfo.name,
|
|
|
+ points: this.getPaperPoints(this.evaluationInfo.item),
|
|
|
+ scoring: this.getAnswers(list),
|
|
|
+ score: this.evaluationInfo.score,
|
|
|
+ multipleRule: multipleRule || 1
|
|
|
+ }
|
|
|
+ let blobPaper = await this.$evTools.createBlobPaper(paperItem, res.slides)
|
|
|
+ // 首先保存新题目的JSON文件到Blob 然后返回URL链接
|
|
|
+ let paperFile = new File([JSON.stringify(blobPaper)], "index.json");
|
|
|
+ // 获取初始化Blob需要的数据
|
|
|
+ let sasData = this.evaluationInfo.type === 'private' ? await this.$tools.getPrivateSas() : await this.$tools.getSchoolSas()
|
|
|
+ //初始化Blob
|
|
|
+ let containerClient = new blobTool(sasData.url, sasData.name, sasData.sas, this.evaluationInfo.type)
|
|
|
+ try {
|
|
|
+ let promiseArr = []
|
|
|
+ let blobFile = null
|
|
|
|
|
|
- console.log('试卷题目的ID集合', res.files)
|
|
|
- console.log('试卷ITEM', paperItem)
|
|
|
- // return
|
|
|
- let privateSas = await this.$tools.getPrivateSas()
|
|
|
- let privateBlob = new blobTool(privateSas.url, privateSas.name, privateSas.sas, 'private')
|
|
|
- let schoolSas = await this.$tools.getSchoolSas()
|
|
|
- let schoolBlob = new blobTool(schoolSas.url, schoolSas.name, schoolSas.sas, 'school')
|
|
|
+ console.log('试卷题目的ID集合', res.files)
|
|
|
+ console.log('试卷ITEM', paperItem)
|
|
|
+ // return
|
|
|
+ let privateSas = await this.$tools.getPrivateSas()
|
|
|
+ let privateBlob = new blobTool(privateSas.url, privateSas.name, privateSas.sas, 'private')
|
|
|
+ let schoolSas = await this.$tools.getSchoolSas()
|
|
|
+ let schoolBlob = new blobTool(schoolSas.url, schoolSas.name, schoolSas.sas, 'school')
|
|
|
|
|
|
- // 放入试题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, undefined, false)
|
|
|
- // r(result)
|
|
|
+ // 放入试题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, undefined, false)
|
|
|
+ // r(result)
|
|
|
|
|
|
- let item = res.files[i]
|
|
|
- if (item.scope == 'school') {
|
|
|
- containerClient.copyFolder('paper/' + paperItem.name + '/', 'item/' + item.id, schoolBlob)
|
|
|
- } else {
|
|
|
- containerClient.copyFolder('paper/' + paperItem.name + '/', 'item/' + item.id, privateBlob)
|
|
|
- }
|
|
|
- r(200)
|
|
|
- }))
|
|
|
+ let item = res.files[i]
|
|
|
+ if (item.scope == 'school') {
|
|
|
+ containerClient.copyFolder('paper/' + paperItem.name + '/', 'item/' + item.id, schoolBlob)
|
|
|
+ } else {
|
|
|
+ containerClient.copyFolder('paper/' + paperItem.name + '/', 'item/' + item.id, privateBlob)
|
|
|
+ }
|
|
|
+ r(200)
|
|
|
+ }))
|
|
|
|
|
|
|
|
|
- }
|
|
|
- promiseArr.push(new Promise(async (r, j) => {
|
|
|
- try {
|
|
|
- blobFile = await containerClient.upload(paperFile, 'paper/' + paperItem.name, undefined, false)
|
|
|
- console.log('上传到试卷目录下', blobFile)
|
|
|
- r(blobFile)
|
|
|
- } catch (e) {
|
|
|
- j(e)
|
|
|
- this.$Message.error(e.spaceError)
|
|
|
- this.isLoading = false
|
|
|
}
|
|
|
-
|
|
|
- }))
|
|
|
- // 进行试卷文件上传Blob
|
|
|
- Promise.all(promiseArr).then(async result => {
|
|
|
- console.log('试卷上传文件的promise结果', result)
|
|
|
- if (blobFile.blob) {
|
|
|
- // 保存到COSMOS是不含base64图片编码的数据 避免数据量过大
|
|
|
- paperItem.blob = blobFile.blob.split('/index.json')[0]
|
|
|
- let params = {
|
|
|
- paper: await this.$evTools.createCosmosPaper(paperItem),
|
|
|
- option: this.isEditPaper ? 'update' : 'insert'
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ try {
|
|
|
+ blobFile = await containerClient.upload(paperFile, 'paper/' + paperItem.name, undefined, false)
|
|
|
+ console.log('上传到试卷目录下', blobFile)
|
|
|
+ r(blobFile)
|
|
|
+ } catch (e) {
|
|
|
+ j(e)
|
|
|
+ this.$Message.error(e.spaceError)
|
|
|
+ this.isLoading = false
|
|
|
}
|
|
|
- // 保存试卷到cosmos
|
|
|
- this.$api.learnActivity.SaveExamPaper(params).then(
|
|
|
- res => {
|
|
|
- if (res.error == null) {
|
|
|
- this.$Message.success(this.isEditPaper ? '编辑成功' : '保存成功')
|
|
|
+
|
|
|
+ }))
|
|
|
+ // 进行试卷文件上传Blob
|
|
|
+ Promise.all(promiseArr).then(async result => {
|
|
|
+ console.log('试卷上传文件的promise结果', result)
|
|
|
+ if (blobFile.blob) {
|
|
|
+ // 保存到COSMOS是不含base64图片编码的数据 避免数据量过大
|
|
|
+ paperItem.blob = blobFile.blob.split('/index.json')[0]
|
|
|
+ let params = {
|
|
|
+ paper: await this.$evTools.createCosmosPaper(paperItem),
|
|
|
+ option: this.isEditPaper ? 'update' : 'insert'
|
|
|
+ }
|
|
|
+ // 保存试卷到cosmos
|
|
|
+ this.$api.learnActivity.SaveExamPaper(params).then(
|
|
|
+ res => {
|
|
|
+ if (res.error == null) {
|
|
|
+ this.$Message.success(this.isEditPaper ? '编辑成功' : '保存成功')
|
|
|
+ this.isLoading = false
|
|
|
+ this.$router.push({
|
|
|
+ name: this.evaluationInfo.type === 'private' ? 'personalBank' : 'schoolBank',
|
|
|
+ params: {
|
|
|
+ tabName: 'paper'
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.$Message.error('保存试卷失败')
|
|
|
+ this.isLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ this.$Message.error('保存试卷失败')
|
|
|
this.isLoading = false
|
|
|
- this.$router.push({
|
|
|
- name: this.evaluationInfo.type === 'private' ? 'personalBank' : 'schoolBank',
|
|
|
- params: {
|
|
|
- tabName: 'paper'
|
|
|
- }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ this.$Message.error('上传失败!')
|
|
|
+ console.log(e)
|
|
|
+ this.isLoading = false
|
|
|
+ }
|
|
|
+ },
|
|
|
+ err => {
|
|
|
+ console.log('savePaperItems失败')
|
|
|
+ }).finally(() => {
|
|
|
+ console.log('savePaperItems结束')
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 将list中的试题 保存到Cosmos以及Blob中 */
|
|
|
+ async savePaperItems(list, modifyItems, isEdit) {
|
|
|
+ let that = this
|
|
|
+ console.log('保存的试题列表')
|
|
|
+ console.log(list)
|
|
|
+ // 获取初始化Blob需要的数据
|
|
|
+ let sasData = this.isSchool ? await this.$tools.getSchoolSas() : await this.$tools.getPrivateSas()
|
|
|
+ let itemJsonFiles = []
|
|
|
+ //初始化Blob
|
|
|
+ let containerClient = new blobTool(sasData.url, sasData.name, sasData.sas, this.evaluationInfo.type)
|
|
|
+ return new Promise(async (resolve, j) => {
|
|
|
+ let promiseArr = []
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ let exerciseItem = list[i]
|
|
|
+ console.log(exerciseItem)
|
|
|
+ // 如果是编辑试卷状态 或者 从题目是来自题库
|
|
|
+ if (isEdit || exerciseItem.blob) {
|
|
|
+ if (exerciseItem.children.length) {
|
|
|
+ // 如果是编辑状态下的综合题
|
|
|
+ let composeArr = [exerciseItem, ...exerciseItem.children]
|
|
|
+ composeArr.forEach(composeItem => {
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ if (composeItem.children.length && composeItem.children[0].id) {
|
|
|
+ composeItem.children = composeItem.children.map(i => i.id)
|
|
|
+ }
|
|
|
+ // 保存试题的blob链接
|
|
|
+ const itemJsonFile = await this.$evTools.createBlobItem(composeItem)
|
|
|
+ let file = new File([JSON.stringify(itemJsonFile)], composeItem.id + ".json");
|
|
|
+ itemJsonFiles.push(composeItem)
|
|
|
+ r(composeItem)
|
|
|
+ console.log(composeItem)
|
|
|
+ }))
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 如果已有blob字段 说明是已经保存到blob的试题 只需要将最新试题更新到paper目录下(自动手动挑题情况)
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ // 保存试题的blob链接
|
|
|
+ const itemJsonFile = await this.$evTools.createBlobItem(exerciseItem)
|
|
|
+ let file = new File([JSON.stringify(itemJsonFile)], exerciseItem.id + ".json");
|
|
|
+ itemJsonFiles.push(exerciseItem)
|
|
|
+ r(exerciseItem)
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ } else if (exerciseItem.children.length) { //如果是导入的 综合题
|
|
|
+ // 如果是综合题 则需要把题干和小题都进行保存操作
|
|
|
+ let composeArr = [exerciseItem, ...exerciseItem.children]
|
|
|
+ composeArr.forEach(composeItem => {
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ if (composeItem.children.length && composeItem.children[0].id) {
|
|
|
+ composeItem.children = composeItem.children.map(i => i.id)
|
|
|
+ }
|
|
|
+ // 将当前的试题数据转化为BLOB内部的试题JSON格式
|
|
|
+ const itemJsonFile = await this.$evTools.createBlobItem(composeItem)
|
|
|
+ const cosmosItem = await this.$evTools.createCosmosItem(composeItem)
|
|
|
+ // 首先保存新题目的JSON文件到Blob 然后返回URL链接
|
|
|
+ let file = new File([JSON.stringify(itemJsonFile)], composeItem.id + ".json");
|
|
|
+ try {
|
|
|
+ // 等待上传blob的返回结果
|
|
|
+ let blobFile = await containerClient.upload(file, 'item/' + composeItem.id, undefined, false)
|
|
|
+ if (blobFile.blob) {
|
|
|
+ // 保存试题JSON文件到试卷文件夹需要
|
|
|
+ itemJsonFiles.push(composeItem)
|
|
|
+ // 保存到COSMOS是不含base64图片编码的数据 避免数据量过大
|
|
|
+ cosmosItem.blob = blobFile.blob
|
|
|
+ // 保存当前试题到数据库
|
|
|
+ that.saveExercise(cosmosItem).then(res => {
|
|
|
+ r(composeItem)
|
|
|
})
|
|
|
} else {
|
|
|
- this.$Message.error('保存试卷失败')
|
|
|
- this.isLoading = false
|
|
|
+ j(500)
|
|
|
}
|
|
|
- },
|
|
|
- err => {
|
|
|
- this.$Message.error('保存试卷失败')
|
|
|
+ } catch (e) {
|
|
|
+ console.log('------', e)
|
|
|
+ this.$Message.error(e.spaceError)
|
|
|
this.isLoading = false
|
|
|
}
|
|
|
- )
|
|
|
+ }))
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ // 如果没有blob字段 说明试题还没有保存到item目录下 则需要进行保存item文件夹后再保存到paper文件夹(导入试题情况)
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ // 将当前的试题数据转化为BLOB内部的试题JSON格式
|
|
|
+ const itemJsonFile = await this.$evTools.createBlobItem(exerciseItem)
|
|
|
+ const cosmosItem = await this.$evTools.createCosmosItem(exerciseItem)
|
|
|
+ // 首先保存新题目的JSON文件到Blob 然后返回URL链接
|
|
|
+ let file = new File([JSON.stringify(itemJsonFile)], exerciseItem.id + ".json");
|
|
|
+ try {
|
|
|
+ // 等待上传blob的返回结果
|
|
|
+ let blobFile = await containerClient.upload(file, 'item/' + exerciseItem.id, undefined, false)
|
|
|
+ if (blobFile.blob) {
|
|
|
+ // 保存试题JSON文件到试卷文件夹需要
|
|
|
+ itemJsonFiles.push(exerciseItem)
|
|
|
+ // 保存到COSMOS是不含base64图片编码的数据 避免数据量过大
|
|
|
+ cosmosItem.blob = blobFile.blob
|
|
|
+ // 保存当前试题到数据库
|
|
|
+ that.saveExercise(cosmosItem).then(res => {
|
|
|
+ r(exerciseItem)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ j(500)
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ this.$Message.error(e.spaceError)
|
|
|
+ this.isLoading = false
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Promise.all(promiseArr).then(result => {
|
|
|
+ console.log(result)
|
|
|
+ let slides = []
|
|
|
+ // 主观题的answer为空数组
|
|
|
+ let nullType = ['complete', 'subjective', 'compose']
|
|
|
+ result.forEach(item => {
|
|
|
+ let o = {
|
|
|
+ url: item.id + '.json',
|
|
|
+ type: item.type,
|
|
|
+ scoring: {
|
|
|
+ score: item.score,
|
|
|
+ knowledge: item.points || [],
|
|
|
+ field: item.field || 1,
|
|
|
+ ans: nullType.includes(item.type) ? [] : item.answer
|
|
|
+ }
|
|
|
}
|
|
|
+ item.type === 'compose' && delete o.scoring
|
|
|
+ slides.push(o)
|
|
|
})
|
|
|
- } catch (e) {
|
|
|
- this.$Message.error('上传失败!')
|
|
|
- console.log(e)
|
|
|
- this.isLoading = false
|
|
|
- }
|
|
|
+ resolve({
|
|
|
+ slides: slides,
|
|
|
+ files: itemJsonFiles
|
|
|
+ })
|
|
|
+ }).catch(err => {
|
|
|
+ console.log(err)
|
|
|
+ this.$Message.error('操作失败')
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 保存单个试题 */
|
|
|
+ saveExercise(item) {
|
|
|
+ item.code = item.scope === 'school' ? this.$store.state.userInfo.schoolCode : this.$store.state.userInfo.TEAMModelId
|
|
|
+ return new Promise((r, j) => {
|
|
|
+ this.$api.newEvaluation.SaveSingleExercise({
|
|
|
+ itemInfo: item,
|
|
|
+ // option: this.isEditPaper ? 'update' : 'insert'
|
|
|
+ option: 'insert'
|
|
|
+ }).then(res => {
|
|
|
+ if (!res.error) {
|
|
|
+ r(res)
|
|
|
+ } else {
|
|
|
+ j(res)
|
|
|
+ this.$Message.error('服务器繁忙!')
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
})
|
|
|
},
|
|
|
},
|