|
|
|
@ -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, // 如果传进来了判分点id,说明本地有缓存,则直接取本地缓存的判分点id,否则,取第一个项目的第一个判分点id |
|
|
|
|
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 |
|
|
|
|
// 如果是本地缓存里有项目id和判分点id,则要再次获取项目详情,取判分列表再次赋值;本地没有缓存则取只恢复第一个判分点的代码 |
|
|
|
|
// 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 => {}) |
|
|
|
|