缓存每个判分规则的代码

dev_2022-03-03
jialong.yu 3 years ago
parent f6b96bacf3
commit 2798eecf45
  1. 78
      src/components/TestPanel.vue
  2. 15
      src/views/Home.vue

@ -173,8 +173,7 @@ export default {
let cache = localStorage.getItem('codeCache') // let cache = localStorage.getItem('codeCache') //
// //
if (cache) { if (cache) {
cache = JSON.parse(cache) this.getCache(JSON.parse(cache))
this.getCache(cache.projectId, cache.judgmentId)
} else { } else {
this.getCache() this.getCache()
} }
@ -278,56 +277,90 @@ export default {
}).catch(res => {}) }).catch(res => {})
}, },
// //
getCache(pId, jId) { getCache(cache) {
const projectId = pId || this.projectId const pId = cache ? cache.projectId : ''
const judgmentId = jId || this.judgmentId const projectId = Number(pId || this.projectId)
const cid = this.courseId const cid = this.courseId
const assessmentId = this.assessmentId const assessmentId = this.assessmentId
let points = []
if (pId) {
cache.judgmentIdList.map(e => {
points.push({
judgmentId: e
})
})
} else {
//
points = JSON.parse(JSON.stringify(this.points))
}
let newJudgmentId = '' // id
const promiseList = [] // promise
let hasCache = 0 //
points.map((e, i) => {
const judgmentId = e.judgmentId
promiseList.push(new Promise((resolve,reject) => {
this.$post(this.api.getLastCache, { this.$post(this.api.getLastCache, {
assessmentId: assessmentId ? Number(assessmentId) : '', assessmentId: assessmentId ? Number(assessmentId) : '',
bcId: judgmentId, // ididid bcId: judgmentId,
projectId, // id projectId, // id
cid // id cid // id
}).then(res => { }).then(res => {
this.closeLoad() this.closeLoad()
const code = res.getLastCache const code = res.getLastCache
// //
if (code) { if (code) {
this.$confirm('是否要继续上次的实验?', '提示', { hasCache = 1
if (!newJudgmentId) newJudgmentId = i
e.code = code
}
resolve()
}).catch(res => {
reject()
this.closeLoad()
})
}))
})
//
Promise.all(promiseList).then(_ => {
hasCache && this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是', confirmButtonText: '是',
cancelButtonText: '否', cancelButtonText: '否',
type: 'success' type: 'success'
}).then(() => { }).then(() => {
localStorage.removeItem('codeCache') // localStorage.removeItem('codeCache') //
this.projectId = projectId this.projectId = projectId
this.judgmentId = judgmentId // this.judgmentId = newJudgmentId
// idid // id
if (pId) { if (pId) {
this.getProDetail().then(() => { this.getProDetail().then(() => {
const points = this.points this.points.map(e => {
const item = points.find(e => e.judgmentId === judgmentId) const item = points.find(n => n.judgmentId === e.judgmentId)
if (item) item.code = code if (item && item.code) this.$set(e, 'code', item.code)
this.$emit('tell', projectId, points) })
this.$emit('recoveryCode', points.findIndex(e => e.judgmentId === judgmentId) + '') // tab this.$emit('tell', projectId, this.points)
this.$emit('recoveryCode', newJudgmentId + '') // tab
}).catch(res => {}) }).catch(res => {})
} else { } else {
const item = this.points.find(e => e.judgmentId === judgmentId) this.points.map(e => {
if (item) item.code = code const item = points.find(n => n.judgmentId === e.judgmentId)
if (item && item.code) this.$set(e, 'code', item.code)
})
this.$emit('tell', projectId, this.points) this.$emit('tell', projectId, this.points)
this.$emit('recoveryCode') this.$emit('recoveryCode')
} }
}).catch(() => { }).catch(() => {
//
localStorage.removeItem('codeCache') localStorage.removeItem('codeCache')
this.$post(`${this.api.delCache}`, { //
points.map(e => {
e.code && this.$post(`${this.api.delCache}`, {
assessmentId, assessmentId,
bcId: judgmentId, bcId: e.judgmentId,
projectId, projectId,
cid cid
}).then(res => {}).catch(() => {}) }).then(res => {}).catch(() => {})
}) })
} })
}).catch(res => {
this.closeLoad()
}) })
}, },
// //
@ -340,6 +373,7 @@ export default {
// //
if (done) { if (done) {
clearInterval(this.statusTimer) clearInterval(this.statusTimer)
this.$message.success('考核时间已到,系统已自动交卷')
this.submit() this.submit()
} }
}).catch(res => {}) }).catch(res => {})

@ -13,14 +13,15 @@
</div> </div>
<div class="tab"> <div class="tab">
<el-tabs v-model="curTab" type="card"> <el-tabs v-model="curTab" type="card" @tab-click="judChange">
<el-tab-pane <el-tab-pane
v-for="item in workbench" v-for="(item, i) in workbench"
:key="item.judgmentId" :key="item.judgmentId"
:label="item.name" :label="item.name"
:value="item.judgmentId" :value="item.judgmentId"
> >
<codemirror <codemirror
:ref="'code' + i"
:key="codeKey" :key="codeKey"
:projectId.sync="projectId" :projectId.sync="projectId"
:code.sync="item.code" :code.sync="item.code"
@ -84,8 +85,8 @@ export default {
const list = this.workbench const list = this.workbench
if(!this.$refs.mainindex.isSubmit && list.length && list.some(e => e.code)){ if(!this.$refs.mainindex.isSubmit && list.length && list.some(e => e.code)){
const cache = { const cache = {
projectId: this.projectId, projectId: Number(this.projectId),
judgmentId: list[Number(this.curTab)].judgmentId judgmentIdList: this.workbench.map(e => e.judgmentId)
} }
localStorage.setItem('codeCache', JSON.stringify(cache)) // ididid localStorage.setItem('codeCache', JSON.stringify(cache)) // ididid
list.map(e => { list.map(e => {
@ -119,6 +120,12 @@ export default {
} }
},1000) },1000)
}, },
//
judChange() {
const code = this.$refs['code' + this.curTab][0].$refs.codemirror.codemirror
code.focus()
code.setCursor(code.lineCount(), 0)
},
// //
recoveryCode(curTab = '0'){ recoveryCode(curTab = '0'){
this.curTab = curTab this.curTab = curTab

Loading…
Cancel
Save