question-title.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="question-title">
  3. <view v-if="question.typeId && !isSubQuestion" class="question-type">
  4. <text>{{ question.typeTitle || questionTypeDesc[question.typeId as EnumQuestionType] }}</text>
  5. <!-- 考试模式下显示分数 -->
  6. <text v-if="showScore">({{ getScore }}分)</text>
  7. </view>
  8. <text v-if="isSubQuestion" class="text-nowrap text-30">
  9. <text>{{ getQuestionTitle() }}</text>
  10. <text v-if="isExam">({{ getScore }}分)</text>
  11. <text v-else>&nbsp;</text>
  12. </text>
  13. <mp-html :content="question.title" />
  14. <!-- <uv-parse :content="question.title" containerStyle="display:inline"
  15. contentStyle="word-break:break-word;"></uv-parse> -->
  16. </view>
  17. </template>
  18. <script lang="ts" setup>
  19. import { EnumPaperType, EnumQuestionType } from '@/common/enum';
  20. import { useExam } from '@/composables/useExam';
  21. import { Study, Transfer } from '@/types';
  22. import { EXAM_DATA, EXAM_PAGE_OPTIONS } from '@/types/injectionSymbols';
  23. const examPageOptions = inject(EXAM_PAGE_OPTIONS) || {} as Transfer.ExamAnalysisPageOptions;
  24. const examData = inject(EXAM_DATA) || {} as ReturnType<typeof useExam>;
  25. const { questionTypeDesc } = examData;
  26. const props = defineProps<{
  27. question: Study.Question;
  28. }>();
  29. const isExam = computed(() => {
  30. const { paperType } = examPageOptions;
  31. return paperType === EnumPaperType.SIMULATED || paperType === EnumPaperType.TEST;
  32. });
  33. const isSubQuestion = computed(() => {
  34. return props.question.isSubQuestion;
  35. });
  36. const showScore = computed(() => {
  37. return isExam.value;
  38. });
  39. const getScore = computed(() => {
  40. if (props.question.subQuestions && props.question.subQuestions.length > 0) {
  41. return props.question.subQuestions.reduce((acc: number, curr: Study.Question) => {
  42. return acc + curr.totalScore;
  43. }, 0);
  44. }
  45. return props.question.totalScore;
  46. });
  47. const getQuestionTitle = () => {
  48. if (isSubQuestion.value) {
  49. const prefix = questionTypeDesc[props.question.typeId as EnumQuestionType].slice(0, 3);
  50. return `[${props.question.typeTitle || prefix}]`;
  51. }
  52. return '';
  53. };
  54. </script>
  55. <style lang="scss" scoped>
  56. .question-title {
  57. @apply text-32 text-fore-title break-words;
  58. }
  59. .question-type {
  60. @apply mb-20 text-32 text-fore-subtitle font-bold;
  61. }
  62. </style>