12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <template>
- <view v-if="question" class="ezy-yingyu-danxuan-box">
- <!-- 标题区域 -->
- <view class="yingyu-danxuan-title"></view>
- <!-- 题干区域 -->
- <textReplaceIconVue :code="code" :question="question" :text="question.name" :placeholders="placeholders" class="ezy-shiti-question">
- </textReplaceIconVue>
- <!-- 选项区域 -->
- <view v-for="(item,index) in data.contents" class="yingyu-danxuan-option-box" :class="formatClass(index)" :key="index" @click="onSelect(index)">
- <text class="option-change">{{item.number}}</text>
- <textReplaceIconVue :code="code" :question="question" :text="item.label" :placeholders="placeholders" @itemclick="onSelect(index)" class="option-question">
- </textReplaceIconVue>
- </view>
- </view>
- </template>
- <script setup>
- import {
- ref,
- reactive,
- watch
- } from 'vue';
- import {
- useQuestionTools
- } from "../useQuestionTools"
- import textReplaceIconVue from './textReplaceIcon.vue'
-
- const {
- getLetterByIndex
- } = useQuestionTools();
-
- const props = defineProps({
- question: {
- type: Object,
- },
- showError: {
- type: Boolean,
- default: false
- },
- placeholders: { // 占位符
- type: Array,
- required: true
- },
- code: {
- type: String,
- }
- })
- const data = reactive({
- name: '', //题干数据
- contents: [], // 选项数据
- })
- watch(() => props.question, (val) => formatData(val), {
- immediate: true
- })
-
- function formatClass(index) {
- if (props.showError) {
- return {
- active_right: props.question.result == index,
- showError: props.question.reply == index && props.question.result != index
- }
- } else {
- return {
- active: props.question.reply == index
- }
- }
- }
-
- function formatData(val) {
- console.log('val',val);
- if (val) {
- data.name = val.name;
- data.contents = val.optList.map((item, index) => {
- return {
- label: item,
- number: getLetterByIndex(index)
- }
- })
- }
- }
-
- function onSelect(index) {
- if (props.showError) {
- return;
- }
- props.question.reply = index;
- }
- </script>
|