Commit 4ae825c7 authored by Yuan Zhixiang's avatar Yuan Zhixiang
Browse files

添加从OJ通过url的solution进行跳转

parent 0ce197fb
......@@ -10,7 +10,9 @@
"dependencies": {
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/view": "^6.26.3",
"@types/crypto-js": "^4.2.2",
"axios": "^1.6.8",
"crypto-js": "^4.2.0",
"vue": "^3.4.21",
"vue-codemirror": "^6.1.1"
},
......@@ -717,6 +719,11 @@
"win32"
]
},
"node_modules/@types/crypto-js": {
"version": "4.2.2",
"resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz",
"integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ=="
},
"node_modules/@types/estree": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz",
......@@ -873,6 +880,11 @@
"integrity": "sha512-VQ2MBenTq1fWZUH9DJNGti7kKv6EeAuYr3cLwxUWhIu1baTaXh4Ib5W2CqHVqib4/MqbYGJqiL3Zb8GJZr3l4g==",
"peer": true
},
"node_modules/crypto-js": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz",
"integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q=="
},
"node_modules/csstype": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz",
......
......@@ -9,6 +9,7 @@ import ControlPanel from './components/ControlPanel.vue';
import CodeViewer from './components/CodeViewer.vue';
import InfoView from './components/InfoView.vue';
import StackView from './components/StackView.vue';
import CryptoJS from 'crypto-js';
const code_input = ref('') // 用户输入的代码
const stdin_input = ref('') // 用户输入的测试用例
......@@ -167,6 +168,61 @@ function click_line(clicked) { // 点击某一行
const edit_mode = ref(true) // 编辑模式,对应的是播放模式
const loading = ref(false) // 发送请求等待后端返回的状态
function getMD5(string){ // not provide
return CryptoJS.MD5(string).toString(CryptoJS.enc.Hex)
}
function generate_random_string(length = 32) { // not provide
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
}
return result;
}
function query_oj_solution(solution_id){
const key = 'cd57c770-5384-493e-e231-51e74438287a'
const nonce = generate_random_string()
const appID = 'ProgrammingLearningJudgingPlatform'
const timestamp = Math.floor(Date.now() / 1000)
const join = 'solutionID=' + solution_id + '&key=' + key + '&nonce=' + nonce + '&appID=' + appID + '&timestamp=' + timestamp
const signature = getMD5(join)
axios.get(oj_base_url,{
params: {
solutionID: solution_id
},
headers: {
'pljp-appID': appID,
'pljp-timestamp': timestamp,
'pljp-nonce': nonce,
'pljp-signature': signature
}
})
.then(response => {
const resp = response.data
if(resp.code == 10000){
code_input.value = resp.data.code
stdin_input.value = resp.data.input
loading.value = true
try_failed.value = false
send_request()
}else{
console.log(resp)
}
})
.catch(error => {
console.error(error);
});
}
function get_oj_solution_id(){
const currentUrl = window.location.href;
const queryObject = new URLSearchParams(window.location.search);
const solution_id = queryObject.get('solution');
if(solution_id != null){
query_oj_solution(solution_id)
}
}
get_oj_solution_id()
provide('app', {
loading,
code_input,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment