index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <div class="course-chapter">
  3. <!-- 添加章节按钮 -->
  4. <a-button type="primary" class="add-chapter-btn" @click="showModal">添加章节</a-button>
  5. <!-- 章节列表 -->
  6. <div v-for="(chapter, chapterIndex) in chapters" :key="chapterIndex" class="chapter">
  7. <!-- 章节标题 -->
  8. <div class="chapter-title">
  9. <span>{{ chapter.title }}</span>
  10. <a-icon type="edit" @click="editChapter(chapterIndex)" />
  11. </div>
  12. <!-- 添加课时按钮 -->
  13. <a-button class="add-chapter-btn1" type="primary" size="small" @click="showAddLessonModal(chapterIndex)">
  14. <PlusOutlined /> 添加课时</a-button
  15. >
  16. <!-- 课时列表 -->
  17. <div v-for="(lesson, lessonIndex) in chapter.lessons" :key="lessonIndex" class="lesson">
  18. <a-row :gutter="48">
  19. <a-col :span="4">
  20. <!-- 视频封面 -->
  21. <img src="@/assets/images/fileImg/gif.png" alt="Video Cover" class="video-cover" />
  22. </a-col>
  23. <a-col :span="16">
  24. <!-- 课时信息 -->
  25. <div class="lesson-info">
  26. <div class="lesson-title">{{ lesson.title }}</div>
  27. <div class="lesson-details">
  28. <span>视频大小:{{ lesson.size }}MB</span>
  29. <span>发布时间:{{ lesson.publishTime }}</span>
  30. <span>发布人:{{ lesson.publisher }}</span>
  31. </div>
  32. </div>
  33. </a-col>
  34. <a-col :span="4">
  35. <!-- 编辑和删除按钮 -->
  36. <div class="lesson-actions">
  37. <EditOutlined class="action-icon" @click="$emit('edit-lesson', lesson)" />
  38. <DeleteOutlined class="action-icon" @click="$emit('delete-lesson', lesson)" />
  39. </div>
  40. </a-col>
  41. </a-row>
  42. </div>
  43. </div>
  44. <!-- 添加章节模态框 -->
  45. <a-modal v-model:visible="modalVisible" title="添加章节" @ok="handleOk" @cancel="handleCancel">
  46. <a-form :model="formState">
  47. <a-form-item label="章节名称">
  48. <a-input v-model:value="formState.chapterName" placeholder="请输入章节名称" />
  49. </a-form-item>
  50. </a-form>
  51. </a-modal>
  52. <!-- 添加课时模态框 -->
  53. <addClassHours v-model:visible="addLessonModalVisible" @ok="onAddClassHoursOk" />
  54. </div>
  55. </template>
  56. <script setup>
  57. import { ref } from 'vue'
  58. import addClassHours from './addClassHours.vue'
  59. const addLessonModalVisible = ref(false)
  60. // 章节数据
  61. const chapters = ref([
  62. {
  63. title: '第一章 课程导学',
  64. lessons: [
  65. {
  66. title: '1-1 课程简介',
  67. size: 300,
  68. publishTime: '2025-07-01 10:23:59',
  69. publisher: '张三'
  70. },
  71. {
  72. title: '1-2 课程前瞻',
  73. size: 300,
  74. publishTime: '2025-07-01 10:23:59',
  75. publisher: '张三'
  76. }
  77. ]
  78. },
  79. {
  80. title: '第二章 课程XX',
  81. lessons: [
  82. {
  83. title: '2-1 课时标题',
  84. size: 300,
  85. publishTime: '2025-07-01 10:23:59',
  86. publisher: '张三'
  87. },
  88. {
  89. title: '2-2 课时标题',
  90. size: 300,
  91. publishTime: '2025-07-01 10:23:59',
  92. publisher: '张三'
  93. },
  94. {
  95. title: '2-3 课时标题',
  96. size: 300,
  97. publishTime: '2025-07-01 10:23:59',
  98. publisher: '张三'
  99. }
  100. ]
  101. }
  102. ])
  103. // 模态框显示状态
  104. const modalVisible = ref(false)
  105. const currentChapterIndex = ref(null)
  106. // 表单状态
  107. const formState = ref({
  108. chapterName: ''
  109. })
  110. // 显示模态框
  111. const showModal = () => {
  112. modalVisible.value = true
  113. }
  114. // 确认按钮点击事件
  115. const handleOk = () => {
  116. if (formState.value.chapterName) {
  117. chapters.value.push({
  118. title: formState.value.chapterName,
  119. lessons: []
  120. })
  121. formState.value.chapterName = '' // 清空表单
  122. modalVisible.value = false // 关闭模态框
  123. }
  124. }
  125. // 取消按钮点击事件
  126. const handleCancel = () => {
  127. formState.value.chapterName = '' // 清空表单
  128. modalVisible.value = false // 关闭模态框
  129. }
  130. // 编辑章节
  131. const editChapter = (chapterIndex) => {
  132. // 实现编辑逻辑
  133. }
  134. // 编辑课时
  135. const editLesson = (chapterIndex, lessonIndex) => {
  136. // 实现编辑逻辑
  137. }
  138. // 删除课时
  139. const deleteLesson = (chapterIndex, lessonIndex) => {
  140. chapters.value[chapterIndex].lessons.splice(lessonIndex, 1)
  141. }
  142. // 显示课时模态框
  143. const showAddLessonModal = (chapterIndex) => {
  144. currentChapterIndex.value = chapterIndex
  145. addLessonModalVisible.value = true
  146. }
  147. // 显示课时模态框
  148. const onAddClassHoursOk = (data) => {
  149. console.log(data, 'onAddClassHoursOk')
  150. // addLessonModalVisible.value = true
  151. }
  152. </script>
  153. <style scoped>
  154. .chapter {
  155. width: 80%;
  156. }
  157. .course-chapter {
  158. padding: 20px;
  159. }
  160. .chapter-title {
  161. background: #f0f0f0;
  162. padding: 10px;
  163. margin-bottom: 10px;
  164. display: flex;
  165. justify-content: space-between;
  166. align-items: center;
  167. }
  168. .lesson {
  169. width: 100%;
  170. height: 120px;
  171. display: flex;
  172. align-items: center;
  173. background: #f7f8fa;
  174. border-radius: 8px;
  175. margin-bottom: 16px;
  176. padding: 16px 4px;
  177. box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.03);
  178. transition: box-shadow 0.2s;
  179. }
  180. .video-cover {
  181. width: 100%;
  182. height: 100%;
  183. object-fit: cover;
  184. border-radius: 4px;
  185. }
  186. .lesson-info {
  187. margin-left: 10px;
  188. }
  189. .lesson-title {
  190. font-weight: bold;
  191. margin-bottom: 30px;
  192. }
  193. .lesson-details {
  194. display: flex;
  195. flex-wrap: wrap;
  196. }
  197. .lesson-details span {
  198. margin-right: 10px;
  199. }
  200. /* 模态框内样式 */
  201. .ant-modal-content {
  202. width: 400px;
  203. }
  204. .ant-modal-body {
  205. padding: 20px;
  206. }
  207. .ant-form-item-label > label {
  208. font-weight: normal;
  209. }
  210. .lesson-actions {
  211. display: flex;
  212. align-items: center;
  213. }
  214. .action-icon {
  215. font-size: 18px;
  216. color: #347aff;
  217. margin-left: 18px;
  218. cursor: pointer;
  219. transition: color 0.2s;
  220. }
  221. .action-icon:hover {
  222. color: #1d5fd6;
  223. }
  224. .add-chapter-btn {
  225. background: #ffff;
  226. border: 1px solid #347aff;
  227. color: #347aff;
  228. border-radius: 3px;
  229. margin-bottom: 10px;
  230. }
  231. .add-chapter-btn1 {
  232. color: #ffff;
  233. border: 1px solid #347aff;
  234. background: #347aff;
  235. border-radius: 3px;
  236. margin-bottom: 10px;
  237. }
  238. </style>