123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <template>
- <view
- class="question-item"
- :class="{
- 'question-item-selected':
- question.checked && !props.showResult && styleCount !== 6,
- 'question-item-correct':
- question.checked && props.showResult && question.isRight && styleCount !== 6,
- 'question-item-wrong':
- question.checked && props.showResult && !question.isRight && styleCount !== 6,
- }"
- :style="{
- border: styleCount !== 6 ? '1px solid #ccc' : 0,
- padding: styleCount !== 6 ? '28rpx;' : 0,
- }"
- @tap="handleClick"
- >
- <view
- class="option-label"
- :class="{
- 'option-label-selected': question.checked && !props.showResult,
- 'option-label-correct':
- question.checked && props.showResult && question.isRight,
- 'option-label-wrong':
- question.checked && props.showResult && !question.isRight,
- }"
- >
- {{ question.value }}
- </view>
- <uvParse
- :content="replaceImageDimensions(question.label)"
- class="option-text"
- ></uvParse>
- <view
- class="option-icon"
- v-if="
- question.checked && props.showResult && !question.isRight && styleCount !== 6
- "
- >
- <uni-icons type="closeempty" color="#f00"></uni-icons>
- </view>
- <view
- class="option-icon"
- v-if="
- question.checked && props.showResult && question.isRight && styleCount !== 6
- "
- >
- <uni-icons type="checkmarkempty" color="#00be00"></uni-icons>
- </view>
- </view>
- </template>
- <script setup>
- import { computed } from "vue";
- import uvParse from "../../uni_modules/uv-parse/components/uv-parse/uv-parse.vue";
- // Props 定义
- const props = defineProps({
- answerList: {
- type: Array,
- default: () => [],
- },
- selectCount: {
- type: Array,
- default: () => [],
- },
- question: {
- type: Object,
- required: true,
- default: () => ({
- label: "",
- value: 0,
- checked: false,
- }),
- },
- parindex: {
- type: Number,
- required: true,
- },
- showResult: {
- type: Boolean,
- default: false,
- },
- styleCount: Number,
- });
- // Emits 定义
- const emit = defineEmits(["select"]);
- const replaceImageDimensions = (str) =>
- str
- .replace(
- /<img([^>]*?)style="([^"]*?)width:\s*[^;]+;\s*height:\s*[^;]+;([^"]*?)"([^>]*?)\/?>/g,
- '<img$1style="$2width:100%;height:100%;$3"$4/>'
- )
- .replace(
- /<img([^>]*?)width="[^"]*"([^>]*?)height="[^"]*"([^>]*?)\/?>/g,
- '<img$1width="100%"$2height="100%"$3/>'
- );
- // 方法
- const handleClick = () => {
- if (props.showResult) return;
- emit("select", {
- ...props.question,
- pid: props.parindex,
- style: props.styleCount,
- });
- };
- </script>
- <style lang="scss" scoped>
- @import "@/uni.scss";
- .question-item {
- display: flex;
- border-radius: 8px;
- background-color: #fafbfd;
- gap: 12px;
- align-items: center;
- color: #333;
- }
- .question-item-correct {
- border-color: $success;
- background-color: #e8f5e9;
- }
- .question-item-wrong {
- border-color: $error;
- background-color: #ffebee;
- }
- .question-item-selected {
- border-color: $uni-primary;
- background-color: #e3f2fd;
- }
- .option-label {
- border: 1px solid #ccc;
- border-radius: 50%;
- padding: 0 5px;
- }
- .option-label-correct {
- border-color: $success;
- background-color: $success;
- color: #fff;
- }
- .option-label-wrong {
- border-color: $error;
- background-color: $error;
- color: #fff;
- }
- .option-label-selected {
- border-color: $uni-primary;
- background-color: $uni-primary;
- color: #fff;
- }
- .option-text {
- flex: 1;
- white-space: normal;
- }
- </style>
|