缓存每个判分规则的代码

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') //
//
if (cache) {
cache = JSON.parse(cache)
this.getCache(cache.projectId, cache.judgmentId)
this.getCache(JSON.parse(cache))
} else {
this.getCache()
}
@ -278,56 +277,90 @@ export default {
}).catch(res => {})
},
//
getCache(pId, jId) {
const projectId = pId || this.projectId
const judgmentId = jId || this.judgmentId
getCache(cache) {
const pId = cache ? cache.projectId : ''
const projectId = Number(pId || this.projectId)
const cid = this.courseId
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, {
assessmentId: assessmentId ? Number(assessmentId) : '',
bcId: judgmentId, // ididid
bcId: judgmentId,
projectId, // id
cid // id
}).then(res => {
this.closeLoad()
const code = res.getLastCache
//
//
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: '是',
cancelButtonText: '否',
type: 'success'
}).then(() => {
localStorage.removeItem('codeCache') //
this.projectId = projectId
this.judgmentId = judgmentId
// idid
// this.judgmentId = newJudgmentId
// id
if (pId) {
this.getProDetail().then(() => {
const points = this.points
const item = points.find(e => e.judgmentId === judgmentId)
if (item) item.code = code
this.$emit('tell', projectId, points)
this.$emit('recoveryCode', points.findIndex(e => e.judgmentId === judgmentId) + '') // tab
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 {
const item = this.points.find(e => e.judgmentId === judgmentId)
if (item) item.code = code
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')
this.$post(`${this.api.delCache}`, {
//
points.map(e => {
e.code && this.$post(`${this.api.delCache}`, {
assessmentId,
bcId: judgmentId,
bcId: e.judgmentId,
projectId,
cid
}).then(res => {}).catch(() => {})
})
}
}).catch(res => {
this.closeLoad()
})
})
},
//
@ -340,6 +373,7 @@ export default {
//
if (done) {
clearInterval(this.statusTimer)
this.$message.success('考核时间已到,系统已自动交卷')
this.submit()
}
}).catch(res => {})

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

Loading…
Cancel
Save