mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
css-loader 0.28->3.5 del 4.1->5.1 eslint 5.18->6.8 eslint-config-airbnb 17.1->18.1 eslint-loader 2.1->4.0 file-loader 2.0->6.0 fs.extra 8.0->9.0 gulp 2.0->3.0 gulp-nunjucks 4.0->5.0 json-loader 0.5->Removed style-loader 0.23->1.1 uglifyjs-webpack-plugin 1.3->2.2 yargs 13.2->15.3 katex 0.10->0.11 react-monaco-editor 0.35->0.36 timeage-react 1.2->3.0 timeago.js 3.0->4.0 uuid 3.3->7.0
120 lines
3.1 KiB
JavaScript
120 lines
3.1 KiB
JavaScript
import { NamedPage } from 'vj/misc/PageLoader';
|
|
|
|
import * as recordEnum from 'vj/constant/record';
|
|
|
|
const page = new NamedPage('judge_playground', async () => {
|
|
const { default: SockJs } = await import('sockjs-client');
|
|
|
|
const sock = new SockJs('/judge/consume-conn');
|
|
|
|
sock.onopen = () => {
|
|
const div = $('<div class="section visible">').appendTo('#messages');
|
|
$('<div class="section__header"><h1 class="section__title">Connection opened.</h1></div>')
|
|
.appendTo(div);
|
|
};
|
|
|
|
sock.onmessage = (message) => {
|
|
const msg = JSON.parse(message.data);
|
|
const div = $('<div class="section visible">').appendTo('#messages');
|
|
$('<div class="section__header"><h1 class="section__title">Record</h1></div>')
|
|
.appendTo(div);
|
|
const body = $('<div class="section__body">').text(message.data).appendTo(div);
|
|
|
|
const send = (key, packet) => {
|
|
const data = {
|
|
...packet,
|
|
key,
|
|
tag: msg.tag,
|
|
};
|
|
sock.send(JSON.stringify(data));
|
|
};
|
|
|
|
$('<button class="button rounded primary">').text('Compile')
|
|
.on('click', () => {
|
|
send('next', { status: 20 });
|
|
})
|
|
.appendTo(body);
|
|
|
|
$('<button class="button rounded primary">').text('Point0')
|
|
.on('click', () => {
|
|
send('next', {
|
|
case: {
|
|
status: recordEnum.STATUS_WRONG_ANSWER,
|
|
score: 0,
|
|
time_ms: 1,
|
|
memory_kb: 777,
|
|
judge_text: 'from playground',
|
|
},
|
|
progress: 51.123,
|
|
});
|
|
})
|
|
.appendTo(body);
|
|
|
|
$('<button class="button rounded primary">').text('Point10')
|
|
.on('click', () => {
|
|
send('next', {
|
|
case: {
|
|
status: recordEnum.STATUS_ACCEPTED,
|
|
score: 10,
|
|
time_ms: 1,
|
|
memory_kb: 233,
|
|
judge_text: 'from playground',
|
|
},
|
|
progress: 90.0,
|
|
});
|
|
})
|
|
.appendTo(body);
|
|
|
|
$('<button class="button rounded primary">').text('Accept')
|
|
.on('click', () => {
|
|
send('end', {
|
|
status: recordEnum.STATUS_ACCEPTED,
|
|
score: 100,
|
|
time_ms: 1,
|
|
memory_kb: 1,
|
|
});
|
|
$('button', div).detach();
|
|
})
|
|
.appendTo(body);
|
|
|
|
$('<button class="button rounded primary">').text('WA')
|
|
.on('click', () => {
|
|
send('end', {
|
|
status: recordEnum.STATUS_WRONG_ANSWER,
|
|
score: 88,
|
|
time_ms: 88,
|
|
memory_kb: 88,
|
|
});
|
|
$('button', div).detach();
|
|
})
|
|
.appendTo(body);
|
|
|
|
$('<button class="button rounded primary">').text('TLE')
|
|
.on('click', () => {
|
|
send('end', {
|
|
status: recordEnum.STATUS_TIME_LIMIT_EXCEEDED,
|
|
score: 10,
|
|
time_ms: 9999,
|
|
memory_kb: 88,
|
|
});
|
|
$('button', div).detach();
|
|
})
|
|
.appendTo(body);
|
|
};
|
|
|
|
sock.onclose = (message) => {
|
|
const div = $('<div class="section visible">').appendTo('#messages');
|
|
$(`
|
|
<div class="section__header">
|
|
<h1 class="section__title">
|
|
Connection closed,
|
|
reason=${JSON.stringify(message.reason)}
|
|
</h1>
|
|
</div>
|
|
`)
|
|
.appendTo(div);
|
|
};
|
|
});
|
|
|
|
export default page;
|