index.vue 9.1 KB

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