fix: 修复问卷索引错误的问题
- 更改索引计算方法
This commit is contained in:
@@ -127,3 +127,18 @@ export function compareArrayByField(arr1, arr2, field) {
|
||||
|
||||
return arr1Fields.every((i) => arr2Fields.includes(i));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取题目索引
|
||||
* @param questions {question.list}
|
||||
* @param question {questionsList}
|
||||
* @return {number}
|
||||
*/
|
||||
export function getQuestionIndex(questions, question) {
|
||||
if (!question) {
|
||||
return -1;
|
||||
}
|
||||
const result = questions.indexOf(question);
|
||||
console.log(`get question index`, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
<preview-choice
|
||||
v-if="question.question_type === 1"
|
||||
v-model:answer="question.answer"
|
||||
v-model:answerIndex="question.answerIndex"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:config="question.config"
|
||||
:hideOptions="question.hideOptions"
|
||||
@@ -113,7 +113,7 @@
|
||||
<preview-checkbox
|
||||
v-else-if="question.question_type === 2"
|
||||
v-model:answer="question.answer"
|
||||
v-model:answerIndex="question.answerIndex"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:config="question.config"
|
||||
:hideOptions="question.hideOptions"
|
||||
@@ -139,6 +139,7 @@
|
||||
v-else-if="question.question_type === 4"
|
||||
:config="question.config"
|
||||
:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:stem="question.stem"
|
||||
:answerSn="questionsData.answer.sn"
|
||||
:answerSurveySn="questionsData.answer.survey_sn"
|
||||
@@ -151,6 +152,7 @@
|
||||
<preview-rate
|
||||
v-else-if="question.question_type === 5"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:config="question.config"
|
||||
:question="question"
|
||||
@@ -182,6 +184,7 @@
|
||||
<preview-matrix-text
|
||||
v-else-if="question.question_type === 8"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:questionIndex="question.question_index"
|
||||
:config="question.config"
|
||||
@@ -195,6 +198,7 @@
|
||||
<preview-matrix-radio
|
||||
v-else-if="question.question_type === 9"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:questionIndex="question.question_index"
|
||||
:config="question.config"
|
||||
@@ -210,6 +214,7 @@
|
||||
<preview-matrix-checkbox
|
||||
v-else-if="question.question_type === 10"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:list="question.list"
|
||||
:config="question.config"
|
||||
:question="question"
|
||||
@@ -286,6 +291,7 @@
|
||||
<preview-file-upload
|
||||
v-else-if="question.question_type === 18"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:config="question.config"
|
||||
:question="question"
|
||||
isMobile
|
||||
@@ -453,6 +459,7 @@
|
||||
<preview-n-p-s
|
||||
v-else-if="question.question_type === 106"
|
||||
v-model:answer="question.answer"
|
||||
:answerIndex="getQuestionIndex(questionsData.questions, question)"
|
||||
:isPreview="isPreview"
|
||||
:title="question.title"
|
||||
:stem="question.stem"
|
||||
@@ -513,19 +520,14 @@
|
||||
|
||||
<script setup>
|
||||
import { useTemplateRef } from 'vue';
|
||||
// import LangTranslate from './components/LangTranslate.vue';
|
||||
import QLast from '@/views/Survey/views/Preview/components/questions/QLast.vue';
|
||||
// import Question from '@/views/Survey/views/Preview/components/questions/Question.vue';
|
||||
// import QFirst from '@/views/Survey/views/Preview/components/questions/QFirst.vue';
|
||||
import PfePagination from './components/PfePagination/Index.vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { useQuestionStore } from '@/stores/Questions/useQuestionStore';
|
||||
// import ProgressBar from './components/ProcessBar/Index.vue';
|
||||
import { AnswerApi } from './js/api';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getLanguage } from '@/views/Survey/views/Preview/js/language';
|
||||
import PreviewChoice from './components/questions/PreviewChoice.vue';
|
||||
// import QRadio from '@/views/Survey/views/Preview/components/questions/QRadio.vue';
|
||||
import PreviewCompletion from '@/views/Survey/views/Preview/components/questions/PreviewCompletion.vue';
|
||||
import PreviewFileUpload from '@/views/Survey/views/Preview/components/questions/PreviewFileUpload.vue';
|
||||
import PreviewMatrixRadio from '@/views/Survey/views/Preview/components/questions/PreviewMatrixRadio.vue';
|
||||
@@ -534,6 +536,7 @@ import PreviewMatrixText from '@/views/Survey/views/Preview/components/questions
|
||||
import PreviewNPS from '@/views/Survey/views/Preview/components/questions/PreviewNPS.vue';
|
||||
import msg from './js/message';
|
||||
import answerMock from '@/views/Survey/views/Preview/js/mock.js';
|
||||
import { getQuestionIndex } from '@/utils/utils.js';
|
||||
|
||||
// hooks file
|
||||
import icon from '@/assets/img/create-right-back.png';
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import FileUpload from '@/views/Design/components/Questions/FileUpload.vue';
|
||||
const questionIndex = defineModel<number>('questionIndex', { default: NaN });
|
||||
const answerIndex = defineModel<number>('answerIndex', { default: NaN });
|
||||
const question = defineModel<question>('question', {});
|
||||
// 接口还未稳定
|
||||
// 需要的数据暂时先放在这里
|
||||
@@ -14,7 +15,7 @@ const question = defineModel<question>('question', {});
|
||||
</script>
|
||||
<template>
|
||||
<!-- 文件上传题 -->
|
||||
<file-upload :element="question" :index="questionIndex" :active="false" />
|
||||
<file-upload :element="question" :index="answerIndex ?? questionIndex" :active="false" />
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
||||
@@ -26,7 +26,7 @@ type answerType = {
|
||||
// const list = defineModel<questionsList[]>('list', { required: false });
|
||||
// const config = defineModel<OptionConfigType>('config', { required: false });
|
||||
const question = defineModel<question>('question');
|
||||
const questionIndex = defineModel<number>('questionIndex', { required: false, default: 0 });
|
||||
const questionIndex = defineModel<number>('answerIndex', { required: false, default: 0 });
|
||||
// console.log(question.value);
|
||||
const emit = defineEmits(['changeAnswer', 'previous', 'next']);
|
||||
// 示例
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import MartrixQuestion from '@/views/Design/components/Questions/MartrixQuestion.vue';
|
||||
// const questionType = defineModel<number>('questionType', { required: false });
|
||||
const questionIndex = defineModel<number>('questionIndex', { required: false, default: 0 });
|
||||
const questionIndex = defineModel<number>('answerIndex', { required: false, default: 0 });
|
||||
|
||||
// 矩阵多选的答案类型
|
||||
type answerType = {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<template>
|
||||
<n-p-s v-model:element="question" v-model:value="value" :active="false" :isPreview="true" />
|
||||
<n-p-s
|
||||
v-model:element="question"
|
||||
v-model:value="value"
|
||||
:active="false"
|
||||
:isPreview="true"
|
||||
:index="answerIndex"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -17,6 +23,7 @@ const question = defineModel<question>('question', { default: { config: { is_req
|
||||
* }
|
||||
*/
|
||||
const answer = defineModel<NPSAnswerType>('answer', { default: undefined });
|
||||
const answerIndex = defineModel<number>('answerIndex', { default: undefined });
|
||||
|
||||
// 解析答案
|
||||
// function parseAnswer() {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<template>
|
||||
<rate v-model:element="question" v-model:value="value" :active="false" :isPreview="true" />
|
||||
<rate
|
||||
v-model:element="question"
|
||||
v-model:value="value"
|
||||
:active="false"
|
||||
:isPreview="true"
|
||||
:index="answerIndex"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -26,6 +32,7 @@ function initData() {
|
||||
* }
|
||||
*/
|
||||
const answer = defineModel<NPSAnswerType>('answer', { default: undefined });
|
||||
const answerIndex = defineModel<number>('answerIndex', { default: undefined });
|
||||
|
||||
// 解析答案
|
||||
// function parseAnswer() {
|
||||
|
||||
Reference in New Issue
Block a user