| | |
| | | <ExamInfo class="mb-5" :questionIndex="currentIndex" :activeQuestion="activeQuestion"></ExamInfo> |
| | | |
| | | <div class="answer-content"> |
| | | <div class="answer-item flex" v-for="item, index in activeQuestion.questionItemList" |
| | | :class="answerState(item)"> |
| | | <div class="answer-item flex" v-for="item, index in activeQuestion.questionItemList" :class="answerState(item,index)"> |
| | | <div class="answer-icon flex flex-col justify-center items-center flex-shrink-0">{{ item.prefix }}</div> |
| | | <div class="answer-text text-gray-700"> |
| | | <el-input v-model="answerList[`answer${index}`]" @focus="answerClick(item)" maxlength="30" placeholder="请输入内容"></el-input> |
| | | <div class="answer-text text-gray-700 grow"> |
| | | <el-input v-model="answerList[index]" |
| | | maxlength="30" |
| | | placeholder="请输入内容" |
| | | class="answer-input" |
| | | @focus="answerFocus(item)" |
| | | @blur="answerBlur(item)" |
| | | @change="answerChange(index)"></el-input> |
| | | </div> |
| | | </div> |
| | | </div> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref,watchEffect } from 'vue'; |
| | | import { ref, watchEffect } from 'vue'; |
| | | import { storeToRefs } from 'pinia'; |
| | | import ExamInfo from '@/components/ExamInfo/index.vue'; |
| | | import { useExamStore } from '@/store/index.js'; |
| | | const examStore = useExamStore(); |
| | | |
| | | const answerList = ref({}); |
| | | const answerList = ref([]); |
| | | |
| | | |
| | | const { currentType, currentIndex } = storeToRefs(examStore); |
| | | |
| | | const activeQuestion = ref(examStore.getActiveQuestion); |
| | | |
| | | const answerClick = (item) => { |
| | | return; |
| | | if (item) { |
| | | if (item.isActive) { |
| | | item.isActive = !item.isActive; |
| | | } else { |
| | | resetAnswer(); |
| | | item.isActive = true; |
| | | } |
| | | const answerList = filterAnswer(); |
| | | let temp = ''; |
| | | if(answerList) { |
| | | temp = answerList.prefix; |
| | | } |
| | | examStore.setQuestionAnswer(currentType.value, currentIndex.value, temp); |
| | | } |
| | | const answerFocus = (item) => { |
| | | item.isActive = true; |
| | | }; |
| | | |
| | | const answerState = (item) => { |
| | | const answerBlur = (item) => { |
| | | item.isActive = false; |
| | | } |
| | | |
| | | const answerState = (item,index) => { |
| | | if(Array.isArray(activeQuestion.value.answerList) && activeQuestion.value.answerList[index]) { |
| | | item.isActive = true; |
| | | } |
| | | return { |
| | | active: item.isActive |
| | | }; |
| | | }; |
| | | |
| | | const resetAnswer = () => { |
| | | activeQuestion.value.questionItemList.forEach(item => item.isActive = false); |
| | | }; |
| | | |
| | | const filterAnswer = () => { |
| | | return activeQuestion.value.questionItemList.find(item => item.isActive); |
| | | const answerChange = (index) => { |
| | | examStore.setQuestionAnswerList(currentType.value, currentIndex.value, answerList.value); |
| | | } |
| | | |
| | | |
| | | watchEffect(() => { |
| | | activeQuestion.value.questionItemList.forEach((item,index) => { |
| | | answerList[`answer${index}`] = ''; |
| | | }) |
| | | activeQuestion.value.questionItemList.forEach((item, index) => { |
| | | if(Array.isArray(activeQuestion.value.answerList)) { |
| | | answerList[index] = activeQuestion.value.answerList[index]; |
| | | } else { |
| | | answerList[index] = ''; |
| | | } |
| | | }); |
| | | }) |
| | | |
| | | |
| | |
| | | background-color: #409EFF !important; |
| | | } |
| | | } |
| | | |
| | | .answer-input { |
| | | width: 100%; |
| | | border: 0; |
| | | |
| | | .el-input__wrapper, |
| | | .is-focus { |
| | | box-shadow: none !important; |
| | | } |
| | | |
| | | .el-input__wrapper:hover { |
| | | box-shadow: none !important; |
| | | } |
| | | |
| | | } |
| | | </style> |