voluntary-result-score.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view class="p-28 bg-white rounded-xl">
  3. <voluntary-result-title title="学生分数"/>
  4. <view class="p-28 gap-28 flex flex-col">
  5. <voluntary-result-progress v-for="i in progressList" :key="i.label" v-bind="i"/>
  6. </view>
  7. <voluntary-result-card tag="分析">
  8. <view class="flex-1 text-23 leading-38 text-fore-title">
  9. 该专业考试总分为
  10. <text class="text-primary">{{ sum }}</text>
  11. 分, 您当前成绩为
  12. <text class="text-primary">{{ score }}</text>
  13. 分。 参考
  14. <text>{{ recentHistory.year }}</text>
  15. 年录取分数线, {{ tip.prefix }}
  16. <text v-if="tip.middle" :class="tip.middleClass">{{ tip.middle }}</text>
  17. {{ tip.suffix }}
  18. </view>
  19. </voluntary-result-card>
  20. </view>
  21. </template>
  22. <script setup lang="ts" name="VoluntaryResultScore">
  23. import VoluntaryResultTitle from "@/pagesOther/pages/voluntary/result/components/plus/voluntary-result-title.vue";
  24. import VoluntaryResultProgress from "@/pagesOther/pages/voluntary/result/components/plus/voluntary-result-progress.vue";
  25. import VoluntaryResultCard from "@/pagesOther/pages/voluntary/result/components/plus/voluntary-result-card.vue";
  26. import {VOLUNTARY_FORM, VOLUNTARY_MODEL, VOLUNTARY_RESULT} from "@/types/injectionSymbols";
  27. import {VoluntaryResultHistory, VoluntaryScoreItem} from "@/types/voluntary";
  28. import _ from "lodash";
  29. const model = inject(VOLUNTARY_MODEL)
  30. const data = inject(VOLUNTARY_FORM)
  31. const result = inject(VOLUNTARY_RESULT)
  32. interface RichText {
  33. prefix: string;
  34. middle: string;
  35. middleClass: string;
  36. suffix: string;
  37. }
  38. const emptyRichText: RichText = {prefix: '', middle: '', middleClass: '', suffix: ''}
  39. const progressList = computed(() => {
  40. const scores = model?.value
  41. const form = data?.value
  42. if (!scores || !form) return []
  43. const results: VoluntaryScoreItem[] = []
  44. form.rules?.forEach(i => {
  45. i.details?.forEach(r => {
  46. results.push({
  47. label: r.label,
  48. score: Number(scores[r.fieldName]),
  49. total: Number(scores[r.fieldName + 'Total']),
  50. labelWidth: '',
  51. scoreWidth: ''
  52. })
  53. })
  54. })
  55. // 因为label score需要全局对齐,所以拼装的逻辑在progress外层
  56. const maxLabel = _.chain(results).map(i => i.label.length).max().value()
  57. const maxScore = _.chain(results).map(i => (i.score + '/' + i.total).length).max().value()
  58. const labelWidth = maxLabel * 29
  59. const scoreWidth = maxScore * 18
  60. results.forEach(i => {
  61. i.labelWidth = labelWidth + 'rpx'
  62. i.scoreWidth = scoreWidth + 'rpx'
  63. })
  64. return results
  65. })
  66. const sum = computed(() => _.sumBy(progressList.value, 'total'))
  67. const score = computed(() => _.sumBy(progressList.value, 'score'))
  68. const recentHistory = computed(() => _.first(result?.value.histories) || {} as VoluntaryResultHistory)
  69. const tip = computed(() => {
  70. const diff = recentHistory.value.diff
  71. if (diff === undefined || diff === null) return emptyRichText
  72. if (diff < 0) return {
  73. prefix: '预估还需再提升',
  74. middle: Math.abs(diff) + '',
  75. middleClass: 'text-danger',
  76. suffix: '分即可达标!'
  77. }
  78. if (diff > 0) return {
  79. prefix: '预估已经超过',
  80. middle: Math.abs(diff) + '',
  81. middleClass: 'text-success',
  82. suffix: '分,已达标!'
  83. }
  84. if (diff === 0) return {
  85. prefix: '预估已经与之',
  86. middle: '持平',
  87. middleClass: 'text-primary',
  88. suffix: ',继续努力!'
  89. }
  90. return emptyRichText
  91. })
  92. </script>
  93. <style scoped>
  94. </style>