question-title.vue 2.1 KB

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