fix: 修复矩阵填空内容选择一个就可以跳过的问题
- 添加行记录和对比选项,如果不一致则不传递答案 - 修正错误泛型 - 行和列数据获取调整
This commit is contained in:
4
src/types/question.d.ts
vendored
4
src/types/question.d.ts
vendored
@@ -81,7 +81,7 @@ export declare interface IQuestionConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 答案 question
|
// 答案 question
|
||||||
export declare interface IQuestion<QuestionConfig> {
|
export declare interface IQuestion<QuestionConfig = IBaseConfig> {
|
||||||
error: string;
|
error: string;
|
||||||
answer?: unknown;
|
answer?: unknown;
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -93,7 +93,7 @@ export declare interface IQuestion<QuestionConfig> {
|
|||||||
question_index?: number;
|
question_index?: number;
|
||||||
question_type?: number;
|
question_type?: number;
|
||||||
// 如果没有自定义类型,那么就直接用基础 config 类型
|
// 如果没有自定义类型,那么就直接用基础 config 类型
|
||||||
config?: QuestionConfig extends undefined ? IBaseConfig : QuestionConfig;
|
config?: QuestionConfig;
|
||||||
created_at?: string;
|
created_at?: string;
|
||||||
created_user_id?: number;
|
created_user_id?: number;
|
||||||
updated_user_id?: number | null;
|
updated_user_id?: number | null;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<template>
|
<template>
|
||||||
<MatrixQuestion
|
<MatrixQuestion
|
||||||
v-model:rowRecord="rowRecord"
|
v-model:rowRecord="rowRecord"
|
||||||
:rows="rows"
|
:rows="rows.options"
|
||||||
:cols="cols"
|
:cols="cols.options"
|
||||||
:index="answerIndex"
|
:index="answerIndex"
|
||||||
:element="question"
|
:element="question"
|
||||||
:is-preview="true"
|
:is-preview="true"
|
||||||
@@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
import MatrixQuestion from '@/views/Design/components/Questions/MatrixQuestion.vue';
|
import MatrixQuestion from '@/views/Design/components/Questions/MatrixQuestion.vue';
|
||||||
|
import type { IQuestion } from '@/types/question';
|
||||||
// const questionType = defineModel<number>('questionType', { required: false });
|
// const questionType = defineModel<number>('questionType', { required: false });
|
||||||
|
|
||||||
// 矩阵单选的答案类型
|
// 矩阵单选的答案类型
|
||||||
@@ -26,7 +26,10 @@ type answerType = {
|
|||||||
// const stem = defineModel('stem');
|
// const stem = defineModel('stem');
|
||||||
// const list = defineModel<questionsList[]>('list', { required: false });
|
// const list = defineModel<questionsList[]>('list', { required: false });
|
||||||
// const config = defineModel<OptionConfigType>('config', { required: false });
|
// const config = defineModel<OptionConfigType>('config', { required: false });
|
||||||
const question = defineModel<question>('question', { default: () => {} });
|
const question = defineModel<IQuestion>('question', { default: () => {} });
|
||||||
|
|
||||||
|
// console.log(`question`, question.value);
|
||||||
|
|
||||||
const answerIndex = computed(() => question.value?.title ?? 0);
|
const answerIndex = computed(() => question.value?.title ?? 0);
|
||||||
// console.log(question.value);
|
// console.log(question.value);
|
||||||
const emit = defineEmits(['changeAnswer', 'previous', 'next']);
|
const emit = defineEmits(['changeAnswer', 'previous', 'next']);
|
||||||
@@ -70,8 +73,7 @@ function parseAnswer(answer: answerType) {
|
|||||||
* 行的内容在 question.list[0].options
|
* 行的内容在 question.list[0].options
|
||||||
* 列的内容在 question.list[1].options
|
* 列的内容在 question.list[1].options
|
||||||
*/
|
*/
|
||||||
const rows = computed(() => question.value?.list[0]?.options ?? []);
|
const [rows, cols] = question.value?.list;
|
||||||
const cols = computed(() => question.value?.list[1]?.options ?? []);
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
rowRecord,
|
rowRecord,
|
||||||
@@ -82,6 +84,10 @@ watch(
|
|||||||
rowRecord.value.forEach((row, col) => {
|
rowRecord.value.forEach((row, col) => {
|
||||||
newAnswer[`${col + 1}_${row + 1}`] = 1;
|
newAnswer[`${col + 1}_${row + 1}`] = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 如果行记录答案不够,那么就不进行传递答案
|
||||||
|
if (rowRecord.value.length !== rows.options.length) return;
|
||||||
|
|
||||||
answer.value = newAnswer;
|
answer.value = newAnswer;
|
||||||
emit('changeAnswer', newAnswer);
|
emit('changeAnswer', newAnswer);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user