|
|
@@ -1,17 +1,14 @@
|
|
|
<template>
|
|
|
<div>
|
|
|
-
|
|
|
- <section>
|
|
|
- <h3>题干:</h3>
|
|
|
+ <editor-section title="题干">
|
|
|
<editor
|
|
|
:init-content="initValue.stem"
|
|
|
- @update-markdown="updateStem"
|
|
|
+ @update-markdown="value.stem = $event"
|
|
|
/>
|
|
|
- </section>
|
|
|
- <section>
|
|
|
- <h3>选项:</h3>
|
|
|
+ </editor-section>
|
|
|
+ <editor-section title="选项">
|
|
|
<section
|
|
|
- v-for="(item, index) in initValue.options"
|
|
|
+ v-for="(item, index) in value.options"
|
|
|
:key="index"
|
|
|
class="choice"
|
|
|
>
|
|
|
@@ -21,61 +18,61 @@
|
|
|
:init-content="item"
|
|
|
@update-markdown="updateOptions(index, $event)"
|
|
|
/>
|
|
|
- <c-button
|
|
|
- class="icon"
|
|
|
+ <button
|
|
|
@click="removeOption(index)"
|
|
|
>
|
|
|
<eva-icon-trash2-outline />
|
|
|
- </c-button>
|
|
|
+ </button>
|
|
|
+ <button
|
|
|
+ :style="{ background: index === value.answer? 'green': 'inherit' }"
|
|
|
+ @click="index === value.answer? value.answer = '': value.answer = index"
|
|
|
+ >
|
|
|
+ <eva-icon-checkmark />
|
|
|
+ </button>
|
|
|
</section>
|
|
|
- <c-button class="icon blue-icon" @click="addNewOption">
|
|
|
- <eva-icon-plus />
|
|
|
- </c-button>
|
|
|
- </section>
|
|
|
- <section>
|
|
|
- <h3>答案:</h3>
|
|
|
<section>
|
|
|
- <editor
|
|
|
- :init-content="value.answer"
|
|
|
- @update-markdown="updateAnswer"
|
|
|
- />
|
|
|
+ <button class="icon blue-icon" @click="addNewOption">
|
|
|
+ <eva-icon-plus />
|
|
|
+ </button>
|
|
|
</section>
|
|
|
- </section>
|
|
|
- <section>
|
|
|
- <h3>解析:</h3>
|
|
|
- <section>
|
|
|
- <editor
|
|
|
- :init-content="value.analysis"
|
|
|
- @update-markdown="updateAnalysis"
|
|
|
- />
|
|
|
- </section>
|
|
|
- </section>
|
|
|
+ </editor-section>
|
|
|
+ <editor-section title="答案">
|
|
|
+ {{ value.answer || '请选择答案' }}
|
|
|
+ </editor-section>
|
|
|
+ <editor-section title="解析">
|
|
|
+ <editor
|
|
|
+ :init-content="value.analysis"
|
|
|
+ @update-markdown="value.analysis = $event"
|
|
|
+ />
|
|
|
+ </editor-section>
|
|
|
+ <button @click="handleSubmit">{{ submitText }}</button>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import Editor from '@/components/Editor'
|
|
|
-import CButton from '@/components/CButton'
|
|
|
import EvaIconTrash2Outline from '@/components/EvaIcon/EvaIconTrash2Outline'
|
|
|
import EvaIconPlus from '@/components/EvaIcon/EvaIconPlus'
|
|
|
-
|
|
|
-const createDefaultChoiceQuestion = () => ({
|
|
|
- stem: '',
|
|
|
- options: {},
|
|
|
- answer: '',
|
|
|
- analysis: ''
|
|
|
-})
|
|
|
-
|
|
|
-const getCharFromIndex = (index = 0) =>
|
|
|
- String.fromCharCode('A'.charCodeAt(0) + index)
|
|
|
+import EvaIconCheckmark from '@/components/EvaIcon/EvaIconCheckmark'
|
|
|
+import EditorSection from '@/views/quiz/components/EditorSection'
|
|
|
+import getCharFromIndex from '@/views/quiz/utils/getCharFromIndex'
|
|
|
+import { createDefaultChoiceQuestion } from '@/views/quiz/utils/default'
|
|
|
|
|
|
export default {
|
|
|
name: 'ChoiceQuestionEditor',
|
|
|
- components: { EvaIconPlus, EvaIconTrash2Outline, CButton, Editor },
|
|
|
+ components: { EditorSection, EvaIconCheckmark, EvaIconPlus, EvaIconTrash2Outline, Editor },
|
|
|
props: {
|
|
|
initValue: {
|
|
|
type: Object,
|
|
|
default: createDefaultChoiceQuestion
|
|
|
+ },
|
|
|
+ readonly: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ submitText: {
|
|
|
+ type: String,
|
|
|
+ default: '提交'
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
@@ -83,17 +80,26 @@ export default {
|
|
|
value: createDefaultChoiceQuestion()
|
|
|
}
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ value: {
|
|
|
+ deep: true,
|
|
|
+ handler: nextValue => this.$emit('input', nextValue)
|
|
|
+ }
|
|
|
+ },
|
|
|
methods: {
|
|
|
|
|
|
- updateAnswer(text) {
|
|
|
- this.value.answer = text
|
|
|
- this.handleInput()
|
|
|
+ handleSubmit() {
|
|
|
+ const { stem, options, answer, analysis } = this.value
|
|
|
+ if (!stem) this.$setErrorMessage('请输入题干')
|
|
|
+ else if (!options?.A) this.$setErrorMessage('请输入选项')
|
|
|
+ else if (!answer) this.$setErrorMessage('请选择答案')
|
|
|
+ else if (!analysis) this.$setErrorMessage('请输入解析')
|
|
|
+ else this.$emit('submit', this.value)
|
|
|
},
|
|
|
|
|
|
updateOptions(index, text) {
|
|
|
if (this.value.options) {
|
|
|
this.value.options[index] = text
|
|
|
- this.handleInput()
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -107,6 +113,9 @@ export default {
|
|
|
},
|
|
|
|
|
|
removeOption(index) {
|
|
|
+ // 同时删除答案
|
|
|
+ this.value.answer = ''
|
|
|
+
|
|
|
const options = this.value.options || {}
|
|
|
delete options[index]
|
|
|
this.value.options = Object.values(options).reduce((acc, curr, index) => {
|
|
|
@@ -116,25 +125,13 @@ export default {
|
|
|
[choice]: curr
|
|
|
}
|
|
|
}, {})
|
|
|
- },
|
|
|
-
|
|
|
- updateStem(text) {
|
|
|
- this.value.stem = text
|
|
|
- this.handleInput()
|
|
|
- },
|
|
|
-
|
|
|
- updateAnalysis(text) {
|
|
|
- this.value.analysis = text
|
|
|
- this.handleInput()
|
|
|
- },
|
|
|
-
|
|
|
- handleInput() {
|
|
|
- this.$nextTick(() => this.$emit('input', this.value))
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
-<style scoped>
|
|
|
-
|
|
|
+<style lang="scss" scoped>
|
|
|
+.choice {
|
|
|
+ display: flex;
|
|
|
+}
|
|
|
</style>
|