123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- // 题目混入
- import QuestionBase from './QuestionBase.vue';
- import RichText from '@/components/common/RichText.vue';
- import AudioPlay from '@/views/exercise_questions/create/components/common/AudioPlay.vue';
- import { GetQuestionInfo, SaveQuestion } from '@/api/exercise';
- import {
- stemTypeList,
- scoreTypeList,
- switchOption,
- isEnable,
- questionNumberTypeList,
- computedQuestionNumber,
- fontSizeList,
- } from '@/views/exercise_questions/data/common';
- const mixin = {
- data() {
- return {
- fontSizeList,
- stemTypeList,
- scoreTypeList,
- switchOption,
- isEnable,
- questionNumberTypeList,
- computedQuestionNumber,
- };
- },
- provide: ['refreshPreviewData'],
- props: {
- questionId: {
- type: String,
- default: '',
- },
- isChild: {
- type: Boolean,
- default: false,
- },
- isChange: {
- type: Boolean,
- default: false,
- },
- },
- components: {
- QuestionBase,
- RichText,
- AudioPlay,
- },
- created() {
- // 题目的子题目保存
- if (this.isChild) {
- if (this.isChange) return;
- GetQuestionInfo({ question_id: this.questionId })
- .then(({ question }) => {
- if (!question.content) return;
- this.data = JSON.parse(question.content);
- this.refreshPreviewData();
- })
- .catch(() => {});
- }
- },
- watch: {
- 'data.property.score'(val) {
- if (val === undefined) return;
- this.data.answer.score = val;
- },
- 'data.property.score_type'(val) {
- if (val === undefined) return;
- this.data.answer.score_type = val;
- },
- data: {
- handler() {
- if (!this.isChild) return;
- this.$emit('updatePreviewData', this.data);
- },
- deep: true,
- immediate: true,
- },
- },
- methods: {
- saveChildQuestion() {
- SaveQuestion({
- question_id: this.questionId,
- type: this.data.type,
- additional_type: this.data.property.select_type || '',
- content: JSON.stringify(this.data),
- }).catch(() => {});
- },
- upload(file_id) {
- this.data.file_id_list.push(file_id);
- },
- deleteFile(file_id) {
- let index = this.data.file_id_list.indexOf(file_id);
- if (index !== -1) {
- this.data.file_id_list.splice(index, 1);
- }
- },
- /**
- * 设置题目内容
- * @param {object} content 题目内容
- */
- setQuestion(content) {
- this.data = content;
- },
- /**
- * 单独设置题号
- * @param {string} question_number 题号
- */
- setQuestionNumber(question_number) {
- this.data.property.question_number = question_number;
- },
- /**
- * 删除选项
- * @param {Number} i 索引
- */
- deleteOption(i) {
- this.data.option_list.splice(i, 1);
- },
- },
- };
- export default mixin;
|