college-item.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <template>
  2. <view class="p-20 bg-white flex justify-between items-start gap-20" @click="emits('click')">
  3. <ie-image v-if="!hiddenLogo&&!reverse" :src="item.logo" mode="aspectFit" custom-class="w-128 h-128"/>
  4. <view class="flex-1 flex flex-col gap-10">
  5. <view v-if="showName||showStar" class="flex justify-between items-center gap-20">
  6. <uv-text v-if="showName" type="main" bold :text="item.name"/>
  7. <uv-tags v-if="showStar" v-bind="starBinding" :text="item.star"/>
  8. </view>
  9. <view v-if="bxTags.length" class="flex flex-wrap gap-8">
  10. <uv-tags v-for="t in bxTags" :text="t" v-bind="getHighlightBindings(t)" @click="handleTagClick(t)"/>
  11. </view>
  12. <slot v-if="!hiddenAddress" name="address">
  13. <uv-text type="tips" prefix-icon="empty-address" :lines="addressLines" :icon-style="{color: '#999999'}"
  14. size="12" :text="item.address"/>
  15. </slot>
  16. </view>
  17. <uv-image v-if="!hiddenLogo&&reverse" :src="item.logo" width="64" height="64" mode="aspectFit"/>
  18. <slot name="right"/>
  19. </view>
  20. </template>
  21. <script setup lang="ts">
  22. import _ from 'lodash';
  23. import {University} from "@/types/university";
  24. const props = withDefaults(defineProps<{
  25. item: University;
  26. hiddenLogo?: boolean;
  27. hiddenName?: boolean;
  28. hiddenStar?: boolean;
  29. hiddenAddress?: boolean;
  30. addressLines?: number;
  31. reverse?: boolean;
  32. }>(), {
  33. item: () => ({} as University),
  34. addressLines: 2
  35. })
  36. const emits = defineEmits(['tag', 'click'])
  37. const isCultural = ref(false) //useUserStore() // 这是早先兼容河南文化类填报时的字段
  38. const showName = computed(() => !props.hiddenName)
  39. const showStar = computed(() => !props.hiddenStar && props.item.star)
  40. const tagAttrs = {
  41. type: 'info',
  42. plain: true,
  43. size: 'tiny',
  44. 'class': 'pointer-events-none'
  45. }
  46. const highlights = ['双高']
  47. const starBinding = {
  48. ...tagAttrs,
  49. type: 'warning'
  50. }
  51. const tagHighlight = {
  52. ...tagAttrs,
  53. type: 'primary',
  54. plainFill: true
  55. }
  56. const bxTags = computed(() => {
  57. const {bxLevel, bxType} = props.item
  58. const tags = bxLevel ? bxLevel.split(',') : []
  59. if (bxType) {
  60. _.pull(tags, '双高')
  61. tags.push(bxType)
  62. }
  63. return tags
  64. })
  65. const isSpecialTag = (tag: string) => {
  66. return !isCultural.value && tag == props.item.bxType
  67. }
  68. const isHighlight = (tag: string) => {
  69. return highlights.includes(tag) || isSpecialTag(tag)
  70. }
  71. const getHighlightBindings = (tag: string) => {
  72. const attrs = isHighlight(tag) ? tagHighlight : tagAttrs
  73. return isSpecialTag(tag) ? {...attrs, icon: 'question-circle', reverse: true, 'class': ''} : attrs
  74. }
  75. const handleTagClick = (tag: string) => {
  76. if (isSpecialTag(tag)) emits('tag')
  77. }
  78. </script>
  79. <style scoped>
  80. </style>