index.vue 9.0 KB

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