SafetyPropaganda.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="safety-propaganda-container">
  3. <div class="title">
  4. <span class="line"></span>
  5. <span class="text">安全宣传栏</span>
  6. </div>
  7. <div class="safety-propaganda">
  8. <div
  9. class="item"
  10. v-for="item in data"
  11. :key="item.id"
  12. @click="
  13. router.push({
  14. name: 'safetyPublicityBoardManagementItem',
  15. query: { id: item.id, operate: 'safety-publicity-board-view' },
  16. })
  17. "
  18. >
  19. <img v-if="item.imageUrls[0]?.url" class="propaganda-img" :src="item.imageUrls[0].url" alt="" />
  20. <img v-else class="propaganda-img" src="@/assets/images/institute-safety/default-propaganda.jpeg" alt="" />
  21. <div class="category-name">{{ item.materialName }}</div>
  22. <div class="propaganda-time">{{ item.createdAt }}</div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script setup lang="ts">
  28. import { ref, onMounted } from 'vue';
  29. import { useRouter } from 'vue-router';
  30. import { getPaprogandaData } from '../safety-company-home/apis';
  31. const router = useRouter();
  32. const data = ref();
  33. onMounted(() => {
  34. getPaprogandaData().then((res) => {
  35. data.value = res || [];
  36. data.value.forEach((item) => {
  37. item.imageUrls = JSON.parse(item.imageUrls || '[]');
  38. });
  39. });
  40. });
  41. </script>
  42. <style scoped>
  43. .safety-propaganda-container {
  44. font-family: PingFangSC, PingFang SC;
  45. margin-top: 20px;
  46. }
  47. .safety-propaganda {
  48. display: grid;
  49. grid-template-columns: repeat(5, 1fr);
  50. gap: 12px;
  51. }
  52. .item {
  53. /* width: 228px; */
  54. height: 224px;
  55. background: #f0f2f6;
  56. border-radius: 8px;
  57. cursor: pointer;
  58. }
  59. .propaganda-img {
  60. width: 100%;
  61. height: 140px;
  62. object-fit: cover;
  63. border-radius: 8px 8px 0 0;
  64. }
  65. .category-name {
  66. margin-left: 12px;
  67. margin-top: 10px;
  68. font-weight: 500;
  69. font-size: 14px;
  70. color: #333333;
  71. /* 设置最大宽度(你可以随意改) */
  72. max-width: 204px;
  73. height: 40px;
  74. /* 核心:多行文本溢出省略 */
  75. display: -webkit-box;
  76. -webkit-line-clamp: 2; /* 最多显示 2 行 */
  77. -webkit-box-orient: vertical;
  78. overflow: hidden;
  79. text-overflow: ellipsis;
  80. /* 可选:文字换行 */
  81. word-break: break-all;
  82. }
  83. .propaganda-time {
  84. margin-left: 12px;
  85. margin-top: 5px;
  86. font-weight: 400;
  87. font-size: 12px;
  88. color: #999999;
  89. }
  90. .title {
  91. display: flex;
  92. align-items: center;
  93. gap: 10px;
  94. margin-bottom: 16px;
  95. }
  96. .line {
  97. width: 3px;
  98. height: 16px;
  99. background: #1777ff;
  100. }
  101. .text {
  102. font-weight: 500;
  103. font-size: 16px;
  104. color: #000000;
  105. line-height: 22px;
  106. }
  107. </style>