index.vue 10 KB

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