缓存每个判分规则的代码

dev_2022-03-03
jialong.yu 3 years ago
parent f6b96bacf3
commit 2798eecf45
  1. 122
      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
this.$post(this.api.getLastCache, { let points = []
assessmentId: assessmentId ? Number(assessmentId) : '', if (pId) {
bcId: judgmentId, // ididid cache.judgmentIdList.map(e => {
projectId, // id points.push({
cid // id judgmentId: e
}).then(res => { })
this.closeLoad() })
const code = res.getLastCache } else {
// //
if (code) { points = JSON.parse(JSON.stringify(this.points))
this.$confirm('是否要继续上次的实验?', '提示', { }
confirmButtonText: '是', let newJudgmentId = '' // id
cancelButtonText: '否', const promiseList = [] // promise
type: 'success' let hasCache = 0 //
}).then(() => { points.map((e, i) => {
localStorage.removeItem('codeCache') // const judgmentId = e.judgmentId
this.projectId = projectId promiseList.push(new Promise((resolve,reject) => {
this.judgmentId = judgmentId this.$post(this.api.getLastCache, {
// idid assessmentId: assessmentId ? Number(assessmentId) : '',
if (pId) { bcId: judgmentId,
this.getProDetail().then(() => { projectId, // id
const points = this.points cid // id
const item = points.find(e => e.judgmentId === judgmentId) }).then(res => {
if (item) item.code = code this.closeLoad()
this.$emit('tell', projectId, points) const code = res.getLastCache
this.$emit('recoveryCode', points.findIndex(e => e.judgmentId === judgmentId) + '') // tab //
}).catch(res => {}) if (code) {
} else { hasCache = 1
const item = this.points.find(e => e.judgmentId === judgmentId) if (!newJudgmentId) newJudgmentId = i
if (item) item.code = code e.code = code
this.$emit('tell', projectId, this.points)
this.$emit('recoveryCode')
} }
}).catch(() => { resolve()
localStorage.removeItem('codeCache') }).catch(res => {
this.$post(`${this.api.delCache}`, { reject()
this.closeLoad()
})
}))
})
//
Promise.all(promiseList).then(_ => {
hasCache && this.$confirm('是否要继续上次的实验?', '提示', {
confirmButtonText: '是',
cancelButtonText: '否',
type: 'success'
}).then(() => {
localStorage.removeItem('codeCache') //
this.projectId = projectId
// this.judgmentId = newJudgmentId
// id
if (pId) {
this.getProDetail().then(() => {
this.points.map(e => {
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('recoveryCode', newJudgmentId + '') // tab
}).catch(res => {})
} else {
this.points.map(e => {
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('recoveryCode')
}
}).catch(() => {
//
localStorage.removeItem('codeCache')
//
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