|
@@ -47,7 +47,16 @@
|
|
|
@deleteQuestion="deleteQuestion(i)"
|
|
|
@recognition="recognition(i, $event)"
|
|
|
/>
|
|
|
- <component :is="exerciseComponents[item.type]" ref="exercise" :external-data="item" />
|
|
|
+ <KeepAlive>
|
|
|
+ <component
|
|
|
+ :is="exerciseComponents[item.type]"
|
|
|
+ ref="exercise"
|
|
|
+ :is-change="change"
|
|
|
+ :is-child="true"
|
|
|
+ :question-id="item.id"
|
|
|
+ @updatePreviewData="updatePreviewData(i, $event)"
|
|
|
+ />
|
|
|
+ </KeepAlive>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -106,11 +115,7 @@
|
|
|
|
|
|
<script>
|
|
|
import { readData, questionTypeOption, exerciseTypeList } from '@/views/exercise_questions/data/read';
|
|
|
-import { getSelectData } from '@/views/exercise_questions/data/select';
|
|
|
-import { getJudgeData } from '@/views/exercise_questions/data/judge';
|
|
|
-import { getMatchingDataTemplate } from '@/views/exercise_questions/data/matching';
|
|
|
-import { fillData } from '@/views/exercise_questions/data/fill';
|
|
|
-import { curry } from '@/utils';
|
|
|
+import { AddQuestionToExercise, DeleteQuestion } from '@/api/exercise';
|
|
|
|
|
|
import QuestionMixin from '../common/QuestionMixin.js';
|
|
|
import SelectQuestionType from '@/views/exercise_questions/create/components/common/SelectQuestionType.vue';
|
|
@@ -129,11 +134,13 @@ export default {
|
|
|
FillQuestion,
|
|
|
},
|
|
|
mixins: [QuestionMixin],
|
|
|
+ inject: ['exercise_id'],
|
|
|
data() {
|
|
|
return {
|
|
|
- curry,
|
|
|
+ change: false, // 是否改变题目类型
|
|
|
questionTypeOption,
|
|
|
exerciseTypeList,
|
|
|
+ childPreviewData: [],
|
|
|
data: JSON.parse(JSON.stringify(readData)),
|
|
|
exerciseComponents: {
|
|
|
select: SelectQuestion,
|
|
@@ -141,21 +148,32 @@ export default {
|
|
|
matching: MatchingQuestion,
|
|
|
fill: FillQuestion,
|
|
|
},
|
|
|
- exerciseData: {
|
|
|
- select: getSelectData(),
|
|
|
- judge: getJudgeData(),
|
|
|
- matching: getMatchingDataTemplate(),
|
|
|
- fill: fillData,
|
|
|
- },
|
|
|
};
|
|
|
},
|
|
|
methods: {
|
|
|
addQuestion() {
|
|
|
- this.data.question_list.push(JSON.parse(JSON.stringify(this.exerciseData['select'])));
|
|
|
+ AddQuestionToExercise({
|
|
|
+ exercise_id: this.exercise_id,
|
|
|
+ is_child_question: 'true',
|
|
|
+ parent_question_id: this.questionId,
|
|
|
+ type: 'select',
|
|
|
+ additional_type: 'single',
|
|
|
+ content: '',
|
|
|
+ }).then(({ status, question_id }) => {
|
|
|
+ if (status !== 1) return;
|
|
|
+ this.data.question_list.push({ id: question_id, type: 'select', additional_type: 'single' });
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 删除题目
|
|
|
+ * @param {Number} i 题目索引
|
|
|
+ */
|
|
|
deleteQuestion(i) {
|
|
|
- this.data.question_list.splice(i, 1);
|
|
|
+ DeleteQuestion({ question_id: this.data.question_list[i].id }).then(({ status }) => {
|
|
|
+ if (status !== 1) return;
|
|
|
+ this.data.question_list.splice(i, 1);
|
|
|
+ });
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -167,9 +185,20 @@ export default {
|
|
|
this.$refs.exercise[i]?.recognition(text);
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新当前题目类型
|
|
|
+ * @param {Number} i 题目索引
|
|
|
+ * @param {Array} arr 选中的题目类型
|
|
|
+ */
|
|
|
updateCurQuestionType(i, arr) {
|
|
|
let type = arr[arr.length - 1];
|
|
|
- this.$set(this.data.question_list, i, JSON.parse(JSON.stringify(this.exerciseData[type])));
|
|
|
+ this.data.question_list[i].type = type;
|
|
|
+ this.change = true;
|
|
|
+ this.data.question_list[i].additional_type = type === 'select' ? 'single' : '';
|
|
|
+ },
|
|
|
+
|
|
|
+ updatePreviewData(i, data) {
|
|
|
+ this.$set(this.childPreviewData, i, data);
|
|
|
},
|
|
|
},
|
|
|
};
|