|
22 | 22 |
|
23 | 23 | <!-- Answer tab connent -->
|
24 | 24 | <section v-show="currentTab === 'answer'">
|
25 |
| - <!-- Answer block --> |
| 25 | + <!-- Short answer input --> |
26 | 26 | <v-textarea
|
| 27 | + v-if="props.questionType === 'short' || props.questionType === ''" |
27 | 28 | v-model="currentData.answer"
|
28 | 29 | variant="solo"
|
29 | 30 | auto-grow
|
|
37 | 38 | @keyup="handleKeyup"
|
38 | 39 | />
|
39 | 40 |
|
| 41 | + <!-- Single choice --> |
| 42 | + <v-card |
| 43 | + class="pt-5 pb-0 px-4 mb-5" |
| 44 | + :elevation="0" |
| 45 | + :color="defaultBgColor" |
| 46 | + > |
| 47 | + <v-radio-group v-model="currentData.answer" :disabled="isShowExamine"> |
| 48 | + <v-radio |
| 49 | + v-for="item in options" |
| 50 | + :key="item" |
| 51 | + :label="item" |
| 52 | + :value="item" |
| 53 | + /> |
| 54 | + </v-radio-group> |
| 55 | + </v-card> |
| 56 | + |
40 | 57 | <!-- Examine block -->
|
41 | 58 | <Transition name="scroll-x-reverse-transition">
|
42 | 59 | <v-card
|
@@ -115,7 +132,11 @@ import { ErrorResponse } from '@/constant'
|
115 | 132 |
|
116 | 133 | const { locale, t } = useI18n()
|
117 | 134 | const PROFILE_STORE = useProfileStore()
|
118 |
| -const props = defineProps(['id']) |
| 135 | +const props = defineProps<{ |
| 136 | + id: string |
| 137 | + questionContent: string |
| 138 | + questionType: 'short' | 'choice' | 'blank' | '' |
| 139 | +}>() |
119 | 140 | const currentTab = ref<'answer' | 'lastAnswer' | 'document'>('answer')
|
120 | 141 |
|
121 | 142 | // Get data cache
|
@@ -214,13 +235,34 @@ const handleGetDocument = async () => {
|
214 | 235 | document_content.value = data
|
215 | 236 | }
|
216 | 237 |
|
| 238 | +const options = ref<string[]>([]) |
| 239 | +const splitQuestionToOptions = () => { |
| 240 | + if (props.questionType !== 'choice') return |
| 241 | + const questionLines = props.questionContent.trim().split('\n') |
| 242 | +
|
| 243 | + for (let i = 1; i < questionLines.length; i++) { |
| 244 | + const optionLine = questionLines[i].trim() |
| 245 | + if ( |
| 246 | + optionLine.startsWith('A.') || |
| 247 | + optionLine.startsWith('B.') || |
| 248 | + optionLine.startsWith('C.') || |
| 249 | + optionLine.startsWith('D.') |
| 250 | + ) { |
| 251 | + options.value.push(optionLine) |
| 252 | + } |
| 253 | + } |
| 254 | + console.log(options.value) |
| 255 | +} |
| 256 | +
|
217 | 257 | // Watching if current question id is changed
|
218 | 258 | watch(
|
219 | 259 | () => props.id,
|
220 | 260 | async () => {
|
221 | 261 | await handleGetLastAnswer()
|
222 | 262 | await handleGetDocument()
|
223 | 263 |
|
| 264 | + if (props.questionType === 'choice') splitQuestionToOptions() |
| 265 | +
|
224 | 266 | if (currentData.value.examine) {
|
225 | 267 | isShowExamine.value = true
|
226 | 268 | isFinishExaming.value = true
|
|
0 commit comments