From 2bd250eb5e7378c55c2bf20d847bcb9126842a8d Mon Sep 17 00:00:00 2001 From: Harry-zklcdc <1269158832@qq.com> Date: Sun, 11 Jul 2021 20:40:17 +0800 Subject: [PATCH] [Add] Global programming language Cache --- src/pages/oj/views/ide/ide.vue | 13 ++++++++++++ src/pages/oj/views/problem/Problem.vue | 29 ++++++++++++++++++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/pages/oj/views/ide/ide.vue b/src/pages/oj/views/ide/ide.vue index 9ab2d5e..be7c0c4 100644 --- a/src/pages/oj/views/ide/ide.vue +++ b/src/pages/oj/views/ide/ide.vue @@ -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++) { @@ -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, @@ -197,6 +206,10 @@ language: this.language, theme: this.theme }) + storage.set(buildProblemCodeKey('Overall'), { + language: this.language, + theme: this.theme + }) next() }, watch: { diff --git a/src/pages/oj/views/problem/Problem.vue b/src/pages/oj/views/problem/Problem.vue index 8a01d33..b2ae329 100644 --- a/src/pages/oj/views/problem/Problem.vue +++ b/src/pages/oj/views/problem/Problem.vue @@ -234,6 +234,7 @@ theme: 'solarized', submissionId: '', submitted: false, + exited: false, result: { result: 9 }, @@ -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() @@ -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 @@ -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 () { @@ -499,6 +516,10 @@ language: this.language, theme: this.theme }) + storage.set(buildProblemCodeKey('Overall'), { + language: this.language, + theme: this.theme + }) next() }, watch: {