You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
3.4 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <div class="container">
  3. <div class="course-grid">
  4. <div v-for="course in courses" :key="course.id" class="course-card">
  5. <div class="course-image">
  6. <img :src="course.cover" alt="课程图片">
  7. <div class="live-badge">即将开播</div>
  8. <div class="live-time">{{ course.startTime }}</div>
  9. </div>
  10. <div class="course-info">
  11. <div class="course-title">{{ course.title }}</div>
  12. <div class="course-footer">
  13. <div class="course-tag">
  14. <img :src="course.cover" alt="讲师头像">
  15. <!-- <img src="../pic/images/1.png" alt="讲师头像"> -->
  16. {{ course.publisherName }}
  17. </div>
  18. <button class="book-btn" :class="{ active: course.booked }" @click="toggleBook(course.id)">预约</button>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import zhiboApi from '@/api/zhiboApi';
  27. import { ref } from 'vue';
  28. const courses = ref([]);
  29. function formatTime(queryType) {
  30. zhiboApi.selectZhibo(queryType).then(resp => {
  31. if(resp.data){
  32. courses.value = resp.data.list;
  33. console.log(courses.value);
  34. }
  35. })
  36. }
  37. formatTime();
  38. </script>
  39. <style scoped>
  40. .container {
  41. max-width: 1200px;
  42. margin: 0 auto;
  43. padding: 20px;
  44. }
  45. .course-grid {
  46. display: grid;
  47. grid-template-columns: repeat(4, 1fr);
  48. gap: 15px;
  49. }
  50. .course-card {
  51. background-color: #fff;
  52. border-radius: 8px;
  53. overflow: hidden;
  54. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  55. transition: transform 0.3s, box-shadow 0.3s;
  56. min-width: 250px;
  57. height: 230px;
  58. }
  59. .course-card:hover {
  60. transform: translateY(-5px);
  61. box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
  62. }
  63. .course-image {
  64. position: relative;
  65. height: 150px;
  66. background-color: #333;
  67. overflow: hidden;
  68. display: flex;
  69. align-items: center;
  70. justify-content: center;
  71. }
  72. .course-image img {
  73. width: 100%;
  74. height: 100%;
  75. object-fit: cover;
  76. }
  77. .live-badge {
  78. position: absolute;
  79. top: 50%;
  80. left: 50%;
  81. transform: translate(-50%, -50%);
  82. background-color: rgba(0, 0, 0, 0.6);
  83. color: #fff;
  84. padding: 8px 16px;
  85. border-radius: 4px;
  86. font-size: 16px;
  87. font-weight: bold;
  88. z-index: 2;
  89. }
  90. .live-time {
  91. position: absolute;
  92. top: calc(50% + 30px);
  93. left: 50%;
  94. transform: translateX(-50%);
  95. background-color: rgba(0, 0, 0, 0.6);
  96. color: #fff;
  97. padding: 3px 8px;
  98. border-radius: 4px;
  99. font-size: 12px;
  100. }
  101. .course-info {
  102. padding: 5px; /* 减少内边距 */
  103. }
  104. .course-title {
  105. font-size: 14px;
  106. font-weight: bold;
  107. margin-bottom: 5px; /* 减少底部边距 */
  108. white-space: nowrap;
  109. overflow: hidden;
  110. text-overflow: ellipsis;
  111. height: 28px;
  112. text-align: left;
  113. }
  114. .course-footer {
  115. display: flex;
  116. align-items: center;
  117. justify-content: space-between;
  118. margin-top: 5px; /* 减少顶部边距 */
  119. }
  120. .course-tag {
  121. display: flex;
  122. align-items: center;
  123. font-size: 12px;
  124. color: #666;
  125. }
  126. .course-tag img {
  127. width: 16px;
  128. height: 16px;
  129. border-radius: 50%;
  130. margin-right: 5px;
  131. }
  132. .book-btn {
  133. background-color: #ff6b00;
  134. color: white;
  135. border: none;
  136. border-radius: 20px;
  137. padding: 4px 15px;
  138. font-size: 12px;
  139. cursor: pointer;
  140. transition: background-color 0.3s, transform 0.2s; /* 添加动态效果 */
  141. }
  142. .book-btn:hover {
  143. background-color: #ff8c33;
  144. transform: scale(1.05); /* 悬停时放大按钮 */
  145. }
  146. .book-btn.active {
  147. background-color: #ff8c33;
  148. transform: scale(1.05); /* 预约成功后保持放大效果 */
  149. }
  150. </style>