|
|
@@ -9,8 +9,11 @@
|
|
|
</v-tabs>
|
|
|
<v-tabs-items v-model="tab">
|
|
|
<v-tab-item>
|
|
|
- <div class="overflow-y-auto" style="height: 80vh">
|
|
|
- <markdown-text :raw="stem" style="height: 100%"></markdown-text>
|
|
|
+ <div class="overflow-y-auto" style="height: 80vh;max-width: 30vw">
|
|
|
+ <markdown-text
|
|
|
+ :raw="question.stem"
|
|
|
+ style="height: 100%"
|
|
|
+ ></markdown-text>
|
|
|
</div>
|
|
|
</v-tab-item>
|
|
|
<v-tab-item class="pa-2">
|
|
|
@@ -79,9 +82,9 @@
|
|
|
</div>
|
|
|
|
|
|
<div style="height: 32px" class="d-flex justify-space-between">
|
|
|
- <v-btn color="info" small>上一题</v-btn>
|
|
|
- <span> 代码题 1/4</span>
|
|
|
- <v-btn color="info" small>下一题</v-btn>
|
|
|
+ <v-btn color="info" small @click="prevQuestion">上一题</v-btn>
|
|
|
+ <span> 代码题 {{ question.id }} / {{ totalQuestionNum }}</span>
|
|
|
+ <v-btn color="info" small @click="nextQuestion">下一题</v-btn>
|
|
|
</div>
|
|
|
</div>
|
|
|
<v-divider vertical class="mx-1"></v-divider>
|
|
|
@@ -141,54 +144,51 @@
|
|
|
>保存测试</v-btn
|
|
|
>
|
|
|
</div>
|
|
|
- <code-editor
|
|
|
- :language="currentLang"
|
|
|
- v-model="currentCode"
|
|
|
- ></code-editor>
|
|
|
+ <code-editor :language="currentLang" v-model="curCode"></code-editor>
|
|
|
</div>
|
|
|
</div>
|
|
|
</v-card>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts">
|
|
|
-import Vue from 'vue'
|
|
|
+import Vue, { PropType } from 'vue'
|
|
|
import CodeEditor from '@/views/exam/components/CodeEditor.vue'
|
|
|
import MarkdownText from '@/views/exam/components/MarkdownText.vue'
|
|
|
import { clone } from 'ramda'
|
|
|
+import { CodeQuestionSerializer, CodeTuple } from '@/api/types'
|
|
|
|
|
|
interface CommitInfo {
|
|
|
id?: string
|
|
|
submitTime?: string
|
|
|
status?: string
|
|
|
score?: number
|
|
|
- codes?: CodeQuestionPair[]
|
|
|
+ codes?: CodeTuple[]
|
|
|
msg?: string
|
|
|
}
|
|
|
|
|
|
-interface CodeQuestionPair {
|
|
|
- id?: string
|
|
|
- stem?: string
|
|
|
- originalCode?: LanguageCode[]
|
|
|
- currentCode?: LanguageCode[]
|
|
|
-}
|
|
|
-
|
|
|
-interface LanguageCode {
|
|
|
- type?: string
|
|
|
- code?: string
|
|
|
-}
|
|
|
-
|
|
|
export default Vue.extend({
|
|
|
components: {
|
|
|
CodeEditor,
|
|
|
MarkdownText
|
|
|
},
|
|
|
+ props: {
|
|
|
+ question: {
|
|
|
+ required: true,
|
|
|
+ type: Object as PropType<CodeQuestionSerializer>
|
|
|
+ },
|
|
|
+ totalQuestionNum: {
|
|
|
+ required: true,
|
|
|
+ type: Number
|
|
|
+ }
|
|
|
+ },
|
|
|
data() {
|
|
|
return {
|
|
|
- content: '213123123',
|
|
|
tab: null,
|
|
|
commits: [] as CommitInfo[],
|
|
|
languages: ['cpp', 'java', 'python'],
|
|
|
- currentLang: 'java',
|
|
|
+ currentLang: '',
|
|
|
+ curCode: '',
|
|
|
+ codeAnswer: {} as CodeQuestionSerializer,
|
|
|
currentCommit: (null as unknown) as CommitInfo,
|
|
|
statusTags: [
|
|
|
'所有用例通过',
|
|
|
@@ -197,11 +197,7 @@ export default Vue.extend({
|
|
|
'运行超时',
|
|
|
'等待运行'
|
|
|
],
|
|
|
- statusColors: ['success', 'warning', 'error', 'accent', 'info'],
|
|
|
- stem: '',
|
|
|
- codeQuestions: [] as CodeQuestionPair[],
|
|
|
- currentQuestion: {} as CodeQuestionPair,
|
|
|
- currentCode: [] as CodeQuestionPair[]
|
|
|
+ statusColors: ['success', 'warning', 'error', 'accent', 'info']
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -219,11 +215,33 @@ export default Vue.extend({
|
|
|
// }
|
|
|
},
|
|
|
watch: {
|
|
|
- // currentLang() {
|
|
|
- // this.currentCode = this.codeByLanguage
|
|
|
- // }
|
|
|
+ currentLang(val, oldVal) {
|
|
|
+ if (oldVal !== '' && val !== oldVal) {
|
|
|
+ const newCode = this.codeAnswer.codeTuples?.find((value) => {
|
|
|
+ return value.lang === val
|
|
|
+ }).code
|
|
|
+
|
|
|
+ const oldCodeIndex = this.codeAnswer.codeTuples.findIndex((value) => {
|
|
|
+ return value.lang === oldVal
|
|
|
+ })
|
|
|
+ this.codeAnswer.codeTuples[oldCodeIndex].code = this.curCode
|
|
|
+
|
|
|
+ this.curCode = newCode
|
|
|
+ }
|
|
|
+ }
|
|
|
},
|
|
|
- beforeMount() {
|
|
|
+ created() {
|
|
|
+ console.log(this.question)
|
|
|
+
|
|
|
+ this.languages = this.question.codeTuples?.map((value) => {
|
|
|
+ return value.lang
|
|
|
+ })
|
|
|
+ this.currentLang = this.languages[0]
|
|
|
+
|
|
|
+ this.curCode = this.question.codeTuples[0].code
|
|
|
+
|
|
|
+ this.codeAnswer = clone(this.question)
|
|
|
+
|
|
|
for (let i = 0; i < 10; i++) {
|
|
|
const r = Math.floor(Math.random() * 4 + 1)
|
|
|
this.commits.push({
|
|
|
@@ -234,25 +252,11 @@ export default Vue.extend({
|
|
|
})
|
|
|
}
|
|
|
this.currentCommit = this.getCurrentCommit()
|
|
|
-
|
|
|
- this.fetchData()
|
|
|
},
|
|
|
methods: {
|
|
|
submitCode(): void {
|
|
|
- const r = Math.floor(Math.random() * 5)
|
|
|
- const id = Math.floor(Math.random() * 1000).toString()
|
|
|
- this.commits = [
|
|
|
- {
|
|
|
- id: id,
|
|
|
- submitTime: '2020-12-11 20:03',
|
|
|
- status: this.statusTags[r],
|
|
|
- score: 100
|
|
|
- },
|
|
|
- ...this.commits
|
|
|
- ]
|
|
|
- this.currentCommit = this.getCurrentCommit()
|
|
|
-
|
|
|
console.log(this.currentCode)
|
|
|
+ this.$emit('submitCode')
|
|
|
},
|
|
|
getCurrentCommit(): CommitInfo {
|
|
|
return this.commits[0]
|
|
|
@@ -260,28 +264,7 @@ export default Vue.extend({
|
|
|
statusToColor(status: string): string {
|
|
|
return this.statusColors[this.statusTags.indexOf(status)]
|
|
|
},
|
|
|
- fetchData() {
|
|
|
- const cpp = { type: 'cpp', code: 'int main(){}' } as LanguageCode
|
|
|
- const java = { type: 'java', code: 'int a=0;' } as LanguageCode
|
|
|
- const python = { type: 'python', code: 'print a' } as LanguageCode
|
|
|
-
|
|
|
- this.currentQuestion = {
|
|
|
- id: '123',
|
|
|
- stem: 'description',
|
|
|
- originalCode: [cpp, java, python],
|
|
|
- currentCode: [cpp, java, python]
|
|
|
- }
|
|
|
- this.codeQuestions.push(this.currentQuestion)
|
|
|
- this.codeQuestions.push({
|
|
|
- id: '234',
|
|
|
- stem: 'description',
|
|
|
- originalCode: [cpp, java, python],
|
|
|
- currentCode: [cpp, java, python]
|
|
|
- })
|
|
|
-
|
|
|
- // this.currentCode = this.codeByLanguage
|
|
|
- console.log(this.currentCode)
|
|
|
- },
|
|
|
+ fetchData() {},
|
|
|
resetCode() {
|
|
|
for (const codeQuestion of this.codeQuestions) {
|
|
|
if (codeQuestion.id === this.currentQuestion.id) {
|
|
|
@@ -289,7 +272,14 @@ export default Vue.extend({
|
|
|
}
|
|
|
// 添加完成后的提示
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ prevQuestion() {
|
|
|
+ this.$emit('prevQuestion')
|
|
|
+ },
|
|
|
+ nextQuestion() {
|
|
|
+ this.$emit('nextQuestion')
|
|
|
+ },
|
|
|
+ onLanguageChange() {}
|
|
|
}
|
|
|
})
|
|
|
</script>
|