index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <template>
  2. <div class="course-detail-page">
  3. <!-- 顶部课程信息卡片 -->
  4. <a-card class="course-info-card" bordered>
  5. <div class="course-info-main">
  6. <div class="cover-box">
  7. <a-image shape="square" :size="120" :src="sysConfig.FILE_URL + course.coverImagePath" />
  8. </div>
  9. <div class="info-box">
  10. <div class="title">{{ course.courseName }}</div>
  11. <div class="meta">
  12. <p><EyeOutlined class="mr-0" /> {{ course.viewCount }}</p>
  13. <p><ClockCircleOutlined class="mr-0" /> {{ course.publishTime }}</p>
  14. </div>
  15. </div>
  16. <div class="action-box">
  17. <div class="btn-group">
  18. <a-button @click="handleEdit(course)"> <EditOutlined /> 编辑课程</a-button>
  19. <a-button v-if="course.putawayStatus == '1'" @click="handleTakeOffCourse(0)">
  20. <DownOutlined /> 下架课程
  21. </a-button>
  22. <a-button v-else @click="handleTakeOffCourse(1)"> <UpOutlined /> 上架课程 </a-button>
  23. <a-button @click="handleDeleteCourse"> <DeleteOutlined /> 删除课程</a-button>
  24. </div>
  25. <div class="extra-box">
  26. <div class="row">
  27. <span>当前状态</span><span class="status-normal">● {{ course.putawayStatusName }}</span>
  28. </div>
  29. <div class="row">
  30. <span>授课教师</span><span>{{ course.teacherIdName }}</span>
  31. </div>
  32. <div class="row">
  33. <span>课程分类</span><span>{{ course.courseTypeName }}</span>
  34. </div>
  35. <div class="row">
  36. <span>课时数量</span
  37. ><span>{{
  38. course.timeLimitType === '0' ? '无限课时' : getTimeLimit(course.startTime, course.endTime)
  39. }}</span>
  40. </div>
  41. </div>
  42. </div>
  43. </div>
  44. </a-card>
  45. <!-- tab 导航 -->
  46. <a-tabs v-model:activeKey="activeTab" class="course-tabs">
  47. <a-tab-pane key="detail" tab="课程详情" />
  48. <a-tab-pane key="statice" tab="学习统计" />
  49. <!-- <a-tab-pane key="homework" tab="批改作业" />-->
  50. <!-- <a-tab-pane key="test" tab="批改测试" />-->
  51. <!-- <a-tab-pane key="student" tab="学员详情" />-->
  52. <!-- <a-tab-pane key="stat" tab="学习统计" />-->
  53. </a-tabs>
  54. <LessonDetails
  55. v-if="activeTab === 'detail'"
  56. :pagedSections="pagedSections"
  57. :currentPage="currentPage"
  58. :pageSize="pageSize"
  59. :sectionsLength="course.sections?.length || 0"
  60. @edit-lesson="onEditLesson"
  61. @delete-lesson="onDeleteLesson"
  62. @page-change="onPageChange"
  63. @page-size-change="onPageSizeChange"
  64. @urge-submit="onUrgeSubmit"
  65. />
  66. <StudentDetails :courseInfoId="courseId" v-if="activeTab === 'student'" />
  67. <LearningStatistics v-if="activeTab === 'stat'" />
  68. <KnowledgePointAnalysis v-if="activeTab === 'statice'" :courseId="courseId" />
  69. <!-- 编辑课程弹窗 -->
  70. <a-modal v-model:visible="editVisible" title="新建工单" :footer="null" width="700px" @cancel="editVisible = false">
  71. <CourseAdd />
  72. </a-modal>
  73. <!-- 编辑课时弹窗 -->
  74. <AddClassHours v-model:visible="addClassHoursVisible" @ok="onAddClassHoursOk" />
  75. </div>
  76. </template>
  77. <script setup>
  78. import { ref, computed, onMounted, watch } from 'vue'
  79. import { EyeOutlined, ClockCircleOutlined, EditOutlined, DeleteOutlined, DownOutlined } from '@ant-design/icons-vue'
  80. import { message, Modal } from 'ant-design-vue'
  81. import AddClassHours from './components/AddClassHours.vue'
  82. import LessonDetails from './components/tab/LessonDetails.vue'
  83. import KnowledgePointAnalysis from './components/tab/knowledgePointAnalysis.vue'
  84. // import Statice from './components/tab/statice.vue'
  85. // import StudentDetails from './components/tab/StudentDetails.vue'
  86. import StudentDetails from '@/views/courseAdd/components/StudentDetails.vue'
  87. import LearningStatistics from './components/tab/LearningStatistics.vue'
  88. import CourseAdd from '../courseAdd/index.vue'
  89. import {
  90. getCourseDetail,
  91. getChapterAllList,
  92. updateCourseStatus,
  93. deleteCourse,
  94. urgeSubmit
  95. } from '@/api/course/courseDetail.js'
  96. import sysConfig from '@/config/index'
  97. import EventBus from '@/utils/EventBus'
  98. const props = defineProps({
  99. courseId: {
  100. type: String,
  101. default: ''
  102. }
  103. })
  104. const course = ref({
  105. courseId: '',
  106. courseName: '',
  107. courseType: '',
  108. courseTypeName: '',
  109. courseDesc: '',
  110. teacherId: '',
  111. teacherIdName: '',
  112. collegeId: '',
  113. collegeIdName: '',
  114. majorId: '',
  115. majorIdName: '',
  116. publishTime: '',
  117. timeLimitType: 0,
  118. startTime: '',
  119. endTime: '',
  120. coverImageId: '',
  121. coverImagePath: '',
  122. collegeTwoId: '',
  123. collegeTwoIdName: '',
  124. collegeThreeId: '',
  125. collegeThreeIdName: '',
  126. collegeAllId: '',
  127. collegeAllIdName: '',
  128. putawayStatus: '',
  129. putawayStatusName: '',
  130. sections: []
  131. })
  132. const activeTab = ref('detail')
  133. const currentPage = ref(1)
  134. const courseInfoId = ref(props.courseId)
  135. const pageSize = ref(10)
  136. const editVisible = ref(false)
  137. const addClassHoursVisible = ref(false)
  138. const editingLesson = ref(null)
  139. const pagedSections = computed(() => {
  140. if (!course.value.sections) return []
  141. const start = (currentPage.value - 1) * pageSize.value
  142. return course.value.sections.slice(start, start + pageSize.value)
  143. })
  144. // onMounted(() => {
  145. // const params = {
  146. // courseId: props.courseId
  147. // }
  148. // // 获取课程基本信息
  149. // getCourseDetail(params).then((res) => {
  150. // course.value = {
  151. // ...course.value,
  152. // ...res.data
  153. // }
  154. // // 获取章节和课时信息
  155. // getChapterAllList(params).then((chapterRes) => {
  156. // if (chapterRes.data && Array.isArray(chapterRes.data)) {
  157. // course.value.sections = chapterRes.data
  158. // }
  159. // })
  160. // })
  161. // })
  162. const initDetail = () => {
  163. const params = {
  164. courseId: props.courseId
  165. }
  166. // 获取课程基本信息
  167. getCourseDetail(params).then((res) => {
  168. course.value = {
  169. ...course.value,
  170. ...res.data
  171. }
  172. // 获取章节和课时信息
  173. getChapterAllList(params).then((chapterRes) => {
  174. if (chapterRes.data && Array.isArray(chapterRes.data)) {
  175. course.value.sections = chapterRes.data
  176. }
  177. })
  178. })
  179. }
  180. const handleEdit = (item) => {
  181. // router.push({
  182. // path: '/portal/courseAdd',
  183. // query: {
  184. // id: item.courseId
  185. // }
  186. // })
  187. EventBus.emit('handleEdit', item)
  188. }
  189. function onPageChange(page) {
  190. currentPage.value = page
  191. }
  192. function onPageSizeChange(size) {
  193. pageSize.value = size
  194. currentPage.value = 1
  195. }
  196. function onEditLesson(lesson) {
  197. editingLesson.value = lesson
  198. addClassHoursVisible.value = true
  199. }
  200. function onDeleteLesson(lesson) {
  201. // 这里只做mock删除
  202. course.value.sections.forEach((section) => {
  203. section.lessons = section.lessons.filter((l) => l.id !== lesson.id)
  204. })
  205. }
  206. function onAddClassHoursOk(data) {
  207. // 这里只做mock保存
  208. if (editingLesson.value) {
  209. Object.assign(editingLesson.value, data)
  210. }
  211. addClassHoursVisible.value = false
  212. }
  213. function getTimeLimit(startTime, endTime) {
  214. const start = new Date(startTime)
  215. const end = new Date(endTime)
  216. const diff = end - start
  217. const days = Math.floor(diff / (1000 * 60 * 60 * 24))
  218. const hours = Math.floor((diff / (1000 * 60 * 60)) % 24)
  219. const minutes = Math.floor((diff / (1000 * 60)) % 60)
  220. return `${days * 24 + hours}小时${minutes}分钟`
  221. }
  222. // 处理下架课程
  223. function handleTakeOffCourse(type) {
  224. Modal.confirm({
  225. title: type === 0 ? '确认下架课程' : '确认上架课程',
  226. content: `确定要${type === 0 ? '下架' : '上架'}课程"${course.value.courseName}"吗?`,
  227. okText: '确认',
  228. cancelText: '取消',
  229. onOk: async () => {
  230. try {
  231. const params = {
  232. courseId: course.value.courseId,
  233. putawayStatus: type
  234. }
  235. const res = await updateCourseStatus(params)
  236. if (res.code === 200) {
  237. message.success(`${type === 0 ? '下架' : '上架'}成功`)
  238. // 更新课程状态
  239. course.value.putawayStatus = type
  240. course.value.putawayStatusName = `${type === 0 ? '已下架' : '已上架'}`
  241. } else {
  242. message.error(res.msg || '操作失败')
  243. }
  244. } catch (error) {
  245. console.error(`${type === 0 ? '下架' : '上架'}课程失败:`, error)
  246. message.error(`${type === 0 ? '下架' : '上架'}课程失败,请稍后重试`)
  247. }
  248. }
  249. })
  250. }
  251. // 处理删除课程
  252. function handleDeleteCourse() {
  253. Modal.confirm({
  254. title: '确认删除课程',
  255. content: `确定要删除课程"${course.value.courseName}"吗?删除后将无法恢复。`,
  256. okText: '确认删除',
  257. okType: 'danger',
  258. cancelText: '取消',
  259. onOk: async () => {
  260. try {
  261. const params = [
  262. {
  263. courseId: course.value.courseId
  264. }
  265. ]
  266. const res = await deleteCourse(params)
  267. if (res.code === 200) {
  268. message.success('课程删除成功')
  269. // 删除成功后返回课程列表页
  270. window.history.back()
  271. } else {
  272. message.error(res.msg || '删除失败')
  273. }
  274. } catch (error) {
  275. console.error('删除课程失败:', error)
  276. message.error('删除课程失败,请稍后重试')
  277. }
  278. }
  279. })
  280. }
  281. // 处理一键催缴
  282. function onUrgeSubmit(lesson) {
  283. Modal.confirm({
  284. title: '确认催缴',
  285. content: `确定要对课时"${lesson.name}"进行催缴吗?`,
  286. okText: '确认',
  287. cancelText: '取消',
  288. onOk: async () => {
  289. try {
  290. const params = {
  291. hourId: lesson.id
  292. }
  293. const res = await urgeSubmit(params)
  294. if (res.code === 200) {
  295. message.success('催缴成功')
  296. } else {
  297. message.error(res.msg || '催缴失败')
  298. }
  299. } catch (error) {
  300. console.error('催缴失败:', error)
  301. message.error('催缴失败,请稍后重试')
  302. }
  303. }
  304. })
  305. }
  306. watch(
  307. () => props.courseId,
  308. (newVal, oldVal) => {
  309. if (newVal !== oldVal) {
  310. initDetail()
  311. }
  312. },
  313. { immediate: true }
  314. )
  315. </script>
  316. <style lang="less" scoped>
  317. .course-detail-page {
  318. background: #f7f8fa;
  319. // min-height: 100vh;
  320. width: 100%;
  321. padding: 32px 0 0 0;
  322. .course-info-card {
  323. margin: 0 auto 24px auto;
  324. border-radius: 12px;
  325. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.04);
  326. border: none;
  327. .course-info-main {
  328. display: flex;
  329. align-items: flex-start;
  330. padding: 32px 32px 24px 32px;
  331. .cover-box {
  332. width: 160px;
  333. height: 120px;
  334. background: #f2f3f5;
  335. border-radius: 8px;
  336. display: flex;
  337. align-items: center;
  338. justify-content: center;
  339. margin-right: 32px;
  340. .ant-avatar {
  341. background: #e6e9ef;
  342. font-size: 48px;
  343. }
  344. :deep(.ant-image),
  345. :deep(.ant-image-img) {
  346. width: 100%;
  347. height: 100%;
  348. }
  349. }
  350. .info-box {
  351. flex: 1;
  352. .title {
  353. font-size: 22px;
  354. font-weight: 600;
  355. color: #222;
  356. margin-bottom: 12px;
  357. }
  358. .meta {
  359. color: #999;
  360. font-size: 14px;
  361. span {
  362. margin-right: 24px;
  363. display: inline-flex;
  364. align-items: center;
  365. .anticon {
  366. margin-right: 4px;
  367. }
  368. }
  369. }
  370. }
  371. .action-box {
  372. flex: 1;
  373. color: #999;
  374. .extra-box {
  375. min-width: 180px;
  376. margin-left: 32px;
  377. display: flex;
  378. justify-content: space-evenly;
  379. .row {
  380. display: flex;
  381. flex-direction: column;
  382. justify-content: space-between;
  383. font-size: 14px;
  384. margin-bottom: 8px;
  385. span:last-child {
  386. font-weight: 500;
  387. }
  388. .status-normal {
  389. margin-top: 10px;
  390. color: #52c41a;
  391. font-weight: 600;
  392. margin-left: 8px;
  393. }
  394. }
  395. }
  396. .btn-group {
  397. display: flex;
  398. flex-direction: row;
  399. margin-left: 40px;
  400. gap: 10px;
  401. justify-content: flex-end;
  402. .ant-btn {
  403. margin-bottom: 12px;
  404. width: 120px;
  405. font-size: 14px;
  406. border-radius: 6px;
  407. }
  408. .ant-btn-primary {
  409. background: #347aff;
  410. border-color: #347aff;
  411. }
  412. }
  413. }
  414. }
  415. }
  416. .course-tabs {
  417. margin: 0 auto 0 auto;
  418. background: #fff;
  419. border-radius: 12px 12px 0 0;
  420. padding-left: 20px;
  421. .ant-tabs-bar {
  422. border-bottom: 1px solid #f0f0f0;
  423. margin-bottom: 0;
  424. }
  425. .ant-tabs-nav {
  426. font-size: 16px;
  427. .ant-tabs-tab {
  428. padding: 18px 32px 14px 32px;
  429. font-weight: 500;
  430. color: #666;
  431. &.ant-tabs-tab-active {
  432. color: #347aff;
  433. font-weight: 600;
  434. }
  435. }
  436. .ant-tabs-ink-bar {
  437. background: #347aff;
  438. height: 3px;
  439. border-radius: 2px 2px 0 0;
  440. }
  441. }
  442. }
  443. .mr-0 {
  444. margin-right: 5px !important;
  445. }
  446. }
  447. </style>