index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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.name }}</span>
  10. <!-- <a-icon type="edit" @click="editChapter(chapterIndex)" />-->
  11. <div>
  12. <EditOutlined style="margin-right: 20px" @click="editChapter(chapterIndex)"/>
  13. <a-popover v-model:visible="popoverVisible[chapterIndex]" title="提示" trigger="click">
  14. <template #content>
  15. <a-button style="margin-right: 10px" type="primary" @click="delChapter(chapterIndex)">删除
  16. </a-button>
  17. <a-button @click="()=>{ popoverVisible[chapterIndex] = false}">取消</a-button>
  18. </template>
  19. <DeleteOutlined/>
  20. </a-popover>
  21. </div>
  22. </div>
  23. <!-- 添加课时按钮 -->
  24. <a-button class="add-chapter-btn1" type="primary" size="small" @click="showAddLessonModal(chapterIndex)">
  25. <PlusOutlined/>
  26. 添加课时
  27. </a-button>
  28. <!-- 课时列表 -->
  29. <div v-for="(lesson, lessonIndex) in chapter.classHours" :key="lessonIndex" class="lesson">
  30. <!-- 视频封面 -->
  31. <img src="@/assets/images/fileImg/gif.png" alt="Video Cover" class="video-cover" style="width: 140px; height: 90px"/>
  32. <!-- 课时信息 -->
  33. <div style="display: flex; flex-direction: column; justify-content: space-between; height: 100% ">
  34. <div>{{ lesson.name }}</div>
  35. <div>
  36. <!-- <span>视频大小:{{ lesson.size }}MB</span>-->
  37. <span>发布时间:{{ lesson.createTime }}</span>
  38. <span>发布人:{{ lesson.createUserName }}</span>
  39. </div>
  40. </div>
  41. <div style="display: flex; height: 100%; position: absolute; right: 15px; top: 15px">
  42. <div>
  43. <EditOutlined class="action-icon" @click="handleEdit(lesson)"/>
  44. <DeleteOutlined class="action-icon" @click="handleDel(lesson)"/>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <!-- 添加章节模态框 -->
  50. <a-modal v-model:visible="modalVisible" :title="dialogTitle" @ok="handleOk" @cancel="handleCancel">
  51. <a-form :model="formState">
  52. <a-form-item label="章节名称">
  53. <a-input v-model:value="formState.chapterName" placeholder="请输入章节名称"/>
  54. </a-form-item>
  55. </a-form>
  56. </a-modal>
  57. <!-- 添加课时模态框 -->
  58. <addDialog ref="addDialogRef" @ok="onAddClassHoursOk" @onAddChapter="onAddChapter"/>
  59. </div>
  60. </template>
  61. <script setup>
  62. import {ref, reactive, onMounted} from 'vue'
  63. import addDialog from './addDialog.vue'
  64. import courseProductionApi from '@/api/courseCenter/courseProduction.js'
  65. import {useRoute, useRouter} from 'vue-router'
  66. import { del , edit as editApi } from '@/api/hour/index'
  67. const router = useRouter()
  68. const route = useRoute()
  69. const popoverVisible = ref({})
  70. const modeTag = ref('add')
  71. const dialogTitle = ref('添加章节')
  72. const props = defineProps({
  73. //课程id
  74. courseInfoId: {
  75. type: Number,
  76. required: true,
  77. default: null
  78. }
  79. })
  80. // 章节数据
  81. const chapters = ref([])
  82. const closePopover = () => {
  83. popoverVisible.value = false
  84. }
  85. const handleEdit = (item) => {
  86. addDialogRef.value.edit(item)
  87. }
  88. const handleDel = (item) => {
  89. console.log('删除',item)
  90. del([{id : item.id}]).then(()=>{
  91. getList()
  92. })
  93. }
  94. // 模态框显示状态
  95. const modalVisible = ref(false)
  96. const currentChapterIndex = ref(null)
  97. const addDialogRef = ref(null)
  98. // 表单状态
  99. const formState = reactive({
  100. id: '',
  101. chapterName: ''
  102. })
  103. const pagination = reactive({
  104. pageSize: 10,
  105. pageNum: 1,
  106. total: 50,
  107. showTotal: (total) => `共${total}条`
  108. })
  109. // 显示模态框
  110. const showModal = () => {
  111. dialogTitle.value = '添加章节'
  112. modeTag.value = 'add'
  113. modalVisible.value = true
  114. formState.chapterName = ''
  115. }
  116. // 确认按钮点击事件
  117. const handleOk = () => {
  118. let courseInfoId = props.courseInfoId
  119. if (formState.chapterName && modeTag.value == 'add') {
  120. courseProductionApi
  121. .add({
  122. courseId: courseInfoId,
  123. name: formState.chapterName
  124. })
  125. .then((res) => {
  126. console.log(res, '章节添加')
  127. getList()
  128. })
  129. .catch((err) => {
  130. console.log(err)
  131. })
  132. formState.chapterName = '' // 清空表单
  133. modalVisible.value = false // 关闭模态框
  134. }
  135. if (formState.chapterName && modeTag.value == 'edit') {
  136. courseProductionApi
  137. .edit({
  138. id: formState.id,
  139. courseId: courseInfoId,
  140. name: formState.chapterName
  141. })
  142. .then((res) => {
  143. console.log(res, '章节添加')
  144. getList()
  145. })
  146. .catch((err) => {
  147. console.log(err)
  148. })
  149. formState.chapterName = '' // 清空表单
  150. modalVisible.value = false // 关闭模态框
  151. }
  152. }
  153. // 取消按钮点击事件
  154. const handleCancel = () => {
  155. formState.chapterName = '' // 清空表单
  156. modalVisible.value = false // 关闭模态框
  157. }
  158. // 编辑章节
  159. const editChapter = (chapterIndex) => {
  160. // 实现编辑逻辑
  161. let item = chapters.value[chapterIndex]
  162. modalVisible.value = true
  163. dialogTitle.value = '修改章节'
  164. modeTag.value = 'edit'
  165. formState.id = item.id
  166. formState.chapterName = item.name
  167. }
  168. // 编辑课时
  169. const editLesson = (chapterIndex, lessonIndex) => {
  170. // 实现编辑逻辑
  171. }
  172. const delChapter = (chapterIndex) => {
  173. console.log('删除', chapterIndex)
  174. // 实现编辑逻辑
  175. let item = chapters.value[chapterIndex]
  176. popoverVisible.value[chapterIndex] = false
  177. courseProductionApi.delete([{id: item.id}]).then((res) => {
  178. console.log('章节列表', res)
  179. getList()
  180. })
  181. .catch((err) => {
  182. console.log(err)
  183. })
  184. }
  185. // 获取章节列表
  186. const getList = () => {
  187. courseProductionApi
  188. .allList({courseId: props.courseInfoId})
  189. .then((res) => {
  190. console.log('章节列表', res)
  191. chapters.value = res.data
  192. })
  193. .catch((err) => {
  194. console.log(err)
  195. })
  196. }
  197. // 删除课时
  198. const deleteLesson = (chapterIndex, lessonIndex) => {
  199. chapters.value[chapterIndex].lessons.splice(lessonIndex, 1)
  200. }
  201. // 显示课时模态框
  202. const showAddLessonModal = (chapterIndex) => {
  203. currentChapterIndex.value = chapterIndex
  204. addDialogRef.value.open()
  205. addDialogRef.value.setData(chapters.value[chapterIndex])
  206. modeTag.value = 'add'
  207. }
  208. // 显示课时模态框
  209. const onAddClassHoursOk = (data) => {
  210. console.log(data, 'onAddClassHoursOk')
  211. // addLessonModalVisible.value = true
  212. }
  213. const onAddChapter = () => {
  214. getList()
  215. }
  216. onMounted(() => {
  217. console.log('有没有id呢', props.courseInfoId)
  218. getList()
  219. })
  220. </script>
  221. <style scoped>
  222. .chapter {
  223. width: 80%;
  224. }
  225. .course-chapter {
  226. padding: 20px;
  227. }
  228. .chapter-title {
  229. background: #f0f0f0;
  230. padding: 10px;
  231. margin-bottom: 10px;
  232. display: flex;
  233. justify-content: space-between;
  234. align-items: center;
  235. }
  236. .lesson {
  237. width: 100%;
  238. height: 120px;
  239. display: flex;
  240. align-items: center;
  241. background: #f7f8fa;
  242. border-radius: 8px;
  243. margin-bottom: 16px;
  244. padding: 16px 4px;
  245. box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.03);
  246. transition: box-shadow 0.2s;
  247. position: relative;
  248. }
  249. .video-cover {
  250. width: 100%;
  251. height: 100%;
  252. object-fit: cover;
  253. border-radius: 4px;
  254. }
  255. .lesson-info {
  256. margin-left: 10px;
  257. }
  258. .lesson-title {
  259. font-weight: bold;
  260. margin-bottom: 30px;
  261. }
  262. .lesson-details {
  263. display: flex;
  264. flex-wrap: wrap;
  265. }
  266. .lesson-details span {
  267. margin-right: 10px;
  268. }
  269. /* 模态框内样式 */
  270. .ant-modal-content {
  271. width: 400px;
  272. }
  273. .ant-modal-body {
  274. padding: 20px;
  275. }
  276. .ant-form-item-label > label {
  277. font-weight: normal;
  278. }
  279. .lesson-actions {
  280. display: flex;
  281. align-items: center;
  282. }
  283. .action-icon {
  284. font-size: 18px;
  285. color: #347aff;
  286. margin-left: 18px;
  287. cursor: pointer;
  288. transition: color 0.2s;
  289. }
  290. .action-icon:hover {
  291. color: #1d5fd6;
  292. }
  293. .add-chapter-btn {
  294. background: #ffff;
  295. border: 1px solid #347aff;
  296. color: #347aff;
  297. border-radius: 3px;
  298. margin-bottom: 10px;
  299. }
  300. .add-chapter-btn1 {
  301. color: #ffff;
  302. border: 1px solid #347aff;
  303. background: #347aff;
  304. border-radius: 3px;
  305. margin-bottom: 10px;
  306. }
  307. </style>