完善提交列表细节,完成提交详情的逻辑部分

This commit is contained in:
zemal 2017-07-06 16:07:53 +08:00
parent 6a8d2fb285
commit f3f94bdb75
5 changed files with 118 additions and 26 deletions

View File

@ -204,7 +204,7 @@ export default {
})
},
submitCode(problemId, language, code) {
return ajax('submissions', 'post', {
return ajax('submission', 'post', {
body: {
problem_id: problemId,
language,

View File

@ -3,6 +3,16 @@ import moment from 'moment'
export default {
backendDatetimeFormat(dt) {
return moment(dt).format('YYYY-M-D HH:mm:ss')
},
backendMemoryFormat(memory) {
if (memory === undefined) return '--'
// 1048576 = 1024 * 1024
let t = parseInt(memory) / 1048576
return String(t.toFixed(0)) + 'MB'
},
backendTimeFormat(time) {
if (time === undefined) return '--'
return time + 'MS'
}
}

View File

@ -45,9 +45,9 @@
<Col :span="10">
<div id="status" v-if="statusVisible">
<span>Status:</span>
<router-link :to="{name: 'problem-submission-list', params: {id: problem._id}}">
<a @click.prevent="handleRoute('/status/'+submissionId)">
<Tag type="dot" :color="submissionStatus.color">{{submissionStatus.text}}</Tag>
</router-link>
</a>
</div>
</Col>
<Col :span="10">
@ -191,7 +191,7 @@
let id = this.submissionId
api.getSubmission(id).then(res => {
this.result = res.data.data
if (Object.keys(res.data.data.info).length !== 0) {
if (Object.keys(res.data.data.statistic_info).length !== 0) {
this.submitting = false
clearInterval(this.refreshStatus)
}

View File

@ -1,35 +1,120 @@
<template>
<!--<Table stripe :disabled-hover="true" :columns="columns" :data="info"></Table>-->
<div>
<Alert
</div>
<Row type="flex" justify="space-around">
<Col :span="20" id="status">
<Alert :type="type" showIcon>
<span class="title">{{statusName}}</span>
<div slot="desc" class="content">
<template v-if="data.result == -2">
{{data.statistic_info.err_info}}
</template>
<template v-else>
<span>Time: {{data.statistic_info.time_cost}}MS</span>
<span>Memory: {{parseMemory(data.statistic_info.memory_cost)}}MB</span>
<span>Lang: {{data.language}}</span>
</template>
</div>
</Alert>
</Col>
<!-- OI模式后台会返info -->
<Col v-if="data.info && data.result != -2" :span="20">
<Table stripe :disabled-hover="true" :columns="columns" :data="data.info.data"></Table>
</Col>
<Col :span="20">
<pre>{{data.code}}</pre>
</Col>
</Row>
</template>
<script>
import api from '@/api'
import {STATUS} from '@/utils/consts'
import utils from '@/utils/utils'
export default {
name: 'submissionDetails',
data() {
return {
columns: [
{
title: 'TestCase',
type: 'index',
align: 'center'
// width: 60
title: 'ID',
align: 'center',
type: 'index'
},
{
title: 'Status',
align: 'center',
render: (h, params) => {
return h('Tag', {
props: {
color: STATUS[params.row.result].color
}
}, STATUS[params.row.result].name)
}
},
{
title: 'Time',
align: 'center',
render: (h, params) => {
return h('span', params.row.cpu_time + 'MS')
}
},
{
title: 'Memory',
align: 'center',
render: (h, params) => {
return h('span', utils.backendMemoryFormat(params.row.memory) + 'MB')
}
}
],
info: []
data: {
result: '0',
info: {
data: []
},
statistic_info: {
time_cost: '',
memory_cost: ''
}
}
}
},
mounted() {
api.getSubmission(this.$route.params.id).then((res) => {
beforeRouteEnter(to, from, next) {
api.getSubmission(to.params.id).then((res) => {
console.log(res.data.data)
this.info = res.data.data.info.data
})
next((vm) => {
vm.data = res.data.data
})
}, (res) => { next() })
},
methods: {}
methods: {
parseMemory(memory) {
return utils.backendMemoryFormat(memory)
}
},
computed: {
type() {
return STATUS[this.data.result].type
},
statusName() {
return STATUS[this.data.result].name
}
}
}
</script>
<style scoped lang="less">
#status {
.title {
font-size: 20px;
}
.content {
margin-top: 10px;
font-size: 14px;
span {
margin-right: 10px;
}
}
}
</style>

View File

@ -49,6 +49,7 @@
{
title: 'Status',
align: 'center',
width: 180,
render: (h, params) => {
return h('Tag', {
props: {
@ -82,14 +83,14 @@
title: 'Time',
align: 'center',
render: (h, params) => {
return h('span', params.row.statistic_info.time_cost + 'MS')
return h('span', utils.backendTimeFormat(params.row.statistic_info.time_cost))
}
},
{
title: 'Memory',
align: 'center',
render: (h, params) => {
return h('span', this.parseMemory(params.row.statistic_info.memory_cost))
return h('span', utils.backendMemoryFormat(params.row.statistic_info.memory_cost))
}
},
{
@ -111,11 +112,6 @@
this.getProblemName()
},
methods: {
parseMemory(memory) {
// 1048576 = 1024 * 1024
let t = parseInt(memory) / 1048576
return String(t.toFixed(0)) + 'MB'
},
getProblemName() {
let _id = this.$route.params.id
if (_id !== undefined) {
@ -124,9 +120,10 @@
})
}
},
// TODO myself
getSubmissions() {
let params = {
myself: true,
myself: 1,
problem_id: this.$route.params.id
}
api.getSubmissionList(params).then((res) => {