Skip to content

Commit

Permalink
[Add] Global programming language Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry-zklcdc committed Jul 11, 2021
1 parent 02c6706 commit 2bd250e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/pages/oj/views/ide/ide.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,17 @@
},
mounted () {
let Code = storage.get(buildProblemCodeKey(-1))
let OverallCode = storage.get(buildProblemCodeKey('Overall'))
let exited = false
if (Code) {
this.language = Code.language
this.code = Code.code
this.theme = Code.theme
exited = true
} else if (OverallCode) {
this.language = OverallCode.language
this.theme = OverallCode.theme
exited = true
}
api.getLanguages().then(res => {
for (var i = 0; i < res.data.data.languages.length; i++) {
Expand Down Expand Up @@ -161,6 +166,10 @@
})
},
beforeunloadFn (e) {
storage.set(buildProblemCodeKey('Overall'), {
language: this.language,
theme: this.theme
})
storage.set(buildProblemCodeKey(-1), {
code: this.code,
language: this.language,
Expand Down Expand Up @@ -197,6 +206,10 @@
language: this.language,
theme: this.theme
})
storage.set(buildProblemCodeKey('Overall'), {
language: this.language,
theme: this.theme
})
next()
},
watch: {
Expand Down
29 changes: 25 additions & 4 deletions src/pages/oj/views/problem/Problem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@
theme: 'solarized',
submissionId: '',
submitted: false,
exited: false,
result: {
result: 9
},
Expand Down Expand Up @@ -261,11 +262,24 @@
},
beforeRouteEnter (to, from, next) {
let problemCode = storage.get(buildProblemCodeKey(to.params.problemID, to.params.contestID))
let OverallCode = storage.get(buildProblemCodeKey('Overall'))
if (problemCode) {
if (problemCode.code !== '') {
next(vm => {
vm.language = problemCode.language
vm.code = problemCode.code
vm.theme = problemCode.theme
})
} else if (OverallCode) {
next(vm => {
vm.language = OverallCode.language
vm.theme = OverallCode.theme
})
}
} else if (OverallCode && problemCode === null) {
next(vm => {
vm.language = problemCode.language
vm.code = problemCode.code
vm.theme = problemCode.theme
vm.language = OverallCode.language
vm.theme = OverallCode.theme
})
} else {
next()
Expand Down Expand Up @@ -297,6 +311,9 @@
if (this.code !== '') {
return
}
if (this.language !== 'C' && this.problem.languages.includes(this.language)) {
return
}
// try to load problem template
this.language = this.problem.languages[0]
let template = this.problem.template
Expand Down Expand Up @@ -478,7 +495,7 @@
submissionStatus () {
return {
text: JUDGE_STATUS[this.result.result]['name'],
color: JUDGE_STATUS[this.result.result]['color']
color: JUDGE_STATUS[this.result.result]['type']
}
},
submissionRoute () {
Expand All @@ -499,6 +516,10 @@
language: this.language,
theme: this.theme
})
storage.set(buildProblemCodeKey('Overall'), {
language: this.language,
theme: this.theme
})
next()
},
watch: {
Expand Down

0 comments on commit 2bd250e

Please sign in to comment.