|
|
|
@ -506,42 +506,49 @@ export default { |
|
|
|
|
projectId, |
|
|
|
|
type: 0 |
|
|
|
|
}).then(res => { |
|
|
|
|
const data = res.code |
|
|
|
|
const photo = data.photoUrl |
|
|
|
|
const result = data.runResult || '' |
|
|
|
|
this.$emit('cache') // 每次运行代码都要把代码传给后端做缓存 |
|
|
|
|
this.loadIns.close() |
|
|
|
|
this.picSrcList = [] |
|
|
|
|
if (photo) this.picSrcList = photo.split(',') |
|
|
|
|
this.$emit('update:codeId', res.codeId) // 更新coddeId |
|
|
|
|
this.$emit('update:answer', result) // 更新运行结果 |
|
|
|
|
this.$emit('update:retResult', data.retResult) // 更新返回结果 |
|
|
|
|
let imgList = '' |
|
|
|
|
let firtImg = '' |
|
|
|
|
try { |
|
|
|
|
imgList = eval(result) |
|
|
|
|
} catch (error) { } |
|
|
|
|
if (imgList && imgList.length) firtImg = imgList[0] |
|
|
|
|
// 如果是下载图片的代码,则要显示图片和运行结果,不用显示对错,换成显示下载图片 |
|
|
|
|
if (photo) { |
|
|
|
|
this.isError = data.retResult // 对错隐藏 |
|
|
|
|
const text = result.replace(photo, '') // 结果里包含了图片路径,所以要把图片路径给去掉 |
|
|
|
|
this.runResult = text |
|
|
|
|
this.picSrcList = photo.split(',') |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) |
|
|
|
|
} else if (imgList instanceof Array && imgList.length && typeof firtImg === 'string' && (firtImg.includes('.jpg') || firtImg.includes('.png') || firtImg.includes('img'))) { |
|
|
|
|
/** |
|
|
|
|
* 这段是为要下载图片的项目案例写的,后端会返回图片名称的数组,前端负责循环这个数组,然后下载下来 |
|
|
|
|
*/ |
|
|
|
|
imgList.map((n, i) => { |
|
|
|
|
util.downloadFile(`${i + 1}.jpg`, n) |
|
|
|
|
}) |
|
|
|
|
this.isError = 0 |
|
|
|
|
this.runResult = '下载完成' |
|
|
|
|
} else { |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
this.runResult = result |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) |
|
|
|
|
// 正常返回结果 |
|
|
|
|
if (res.code) { |
|
|
|
|
const data = res.code |
|
|
|
|
const photo = data.photoUrl |
|
|
|
|
const result = data.runResult || '' |
|
|
|
|
this.$emit('cache') // 每次运行代码都要把代码传给后端做缓存 |
|
|
|
|
this.loadIns.close() |
|
|
|
|
this.picSrcList = [] |
|
|
|
|
if (photo) this.picSrcList = photo.split(',') |
|
|
|
|
this.$emit('update:codeId', res.codeId) // 更新coddeId |
|
|
|
|
this.$emit('update:answer', result) // 更新运行结果 |
|
|
|
|
this.$emit('update:retResult', data.retResult) // 更新返回结果 |
|
|
|
|
let imgList = '' |
|
|
|
|
let firtImg = '' |
|
|
|
|
try { |
|
|
|
|
imgList = eval(result) |
|
|
|
|
} catch (error) { } |
|
|
|
|
if (imgList && imgList.length) firtImg = imgList[0] |
|
|
|
|
// 如果是下载图片的代码,则要显示图片和运行结果,不用显示对错,换成显示下载图片 |
|
|
|
|
if (photo) { |
|
|
|
|
this.isError = data.retResult // 对错隐藏 |
|
|
|
|
const text = result.replace(photo, '') // 结果里包含了图片路径,所以要把图片路径给去掉 |
|
|
|
|
this.runResult = text |
|
|
|
|
this.picSrcList = photo.split(',') |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) |
|
|
|
|
} else if (imgList instanceof Array && imgList.length && typeof firtImg === 'string' && (firtImg.includes('.jpg') || firtImg.includes('.png') || firtImg.includes('img'))) { |
|
|
|
|
/** |
|
|
|
|
* 这段是为要下载图片的项目案例写的,后端会返回图片名称的数组,前端负责循环这个数组,然后下载下来 |
|
|
|
|
*/ |
|
|
|
|
imgList.map((n, i) => { |
|
|
|
|
util.downloadFile(`${i + 1}.jpg`, n) |
|
|
|
|
}) |
|
|
|
|
this.isError = 0 |
|
|
|
|
this.runResult = '下载完成' |
|
|
|
|
} else { |
|
|
|
|
this.isError = data.retResult |
|
|
|
|
this.runResult = result |
|
|
|
|
this.errLine = parseInt(result.substring(result.indexOf("line") + 4, result.length)) |
|
|
|
|
} |
|
|
|
|
} else if (res.data && res.data.current) { |
|
|
|
|
// 进入运行队列 |
|
|
|
|
this.$message.success(`当前队列有${res.data.current - 1}人在排队,请稍等!`) |
|
|
|
|
this.loadIns.close() |
|
|
|
|
} |
|
|
|
|
}).catch(res => { |
|
|
|
|
this.isError = false |
|
|
|
|