detail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view class="course-detail-page">
  3. <!-- 加载骨架 -->
  4. <LoadingSkeleton v-if="loading" :rows="4" />
  5. <!-- 错误态 -->
  6. <ErrorState v-else-if="error" message="课程详情加载失败" @retry="loadAll" />
  7. <!-- 空态 -->
  8. <EmptyState
  9. v-else-if="!course.id"
  10. icon="🔍"
  11. title="课程不存在或已下架"
  12. desc="请返回课程列表重新选择"
  13. action-text="返回课程列表"
  14. @action="goBackCourse"
  15. />
  16. <!-- 正常态:课程内容 -->
  17. <template v-else>
  18. <!-- 课程介绍 -->
  19. <view class="course-head">
  20. <text class="course-level">{{ course.level || 'L' }}</text>
  21. <text class="course-name">{{ course.name }}</text>
  22. <text class="course-status" :class="'st-' + course.effectiveStatus">{{ statusLabel(course.effectiveStatus) }}</text>
  23. <text class="course-desc" v-if="course.description">{{ course.description }}</text>
  24. <text class="course-time" v-if="course.startTime || course.endTime">
  25. 开课 {{ fmtDate(course.startTime) }} · 结课 {{ fmtDate(course.endTime) }}
  26. </text>
  27. <text class="course-class" v-if="className">我的班次:{{ className }}</text>
  28. </view>
  29. <!-- 未报名:先报名 -->
  30. <view class="action-card" v-if="enrollmentStatus === 'none'">
  31. <text class="action-title">报名参加本课程</text>
  32. <text class="action-desc">填写报名信息并完成支付后,即可申请进班学习</text>
  33. <button class="action-btn" @click="goTo('/pages/enroll/list')">去报名</button>
  34. </view>
  35. <!-- 已报名未进班 -->
  36. <view class="action-card" v-else-if="enrollmentStatus === 'pending'">
  37. <text class="action-title">报名待支付</text>
  38. <text class="action-desc">完成支付后即可申请进班</text>
  39. <button class="action-btn" @click="goTo('/pages/enroll/list')">去支付</button>
  40. </view>
  41. <view class="action-card" v-else-if="enrollmentStatus === 'paid'">
  42. <text class="action-title">已报名,待进班</text>
  43. <text class="action-desc">提交进班申请后由班主任审核,审核通过即可开始学习</text>
  44. <button class="action-btn" :disabled="enterLoading" @click="applyEnter">申请进班</button>
  45. </view>
  46. <view class="action-card" v-else-if="enrollmentStatus === 'reviewing'">
  47. <text class="action-title">进班审核中</text>
  48. <text class="action-desc">班主任正在审核你的进班申请,请耐心等待</text>
  49. <button class="action-btn disabled" disabled>审核中</button>
  50. </view>
  51. <view class="action-card" v-else-if="enrollmentStatus === 'rejected'">
  52. <text class="action-title">进班申请被驳回</text>
  53. <text class="action-desc">可重新提交进班申请,或联系班主任了解原因</text>
  54. <button class="action-btn" :disabled="enterLoading" @click="applyEnter">重新申请进班</button>
  55. </view>
  56. <!-- 已进班:课程学习安排(班次=上课期次,负责上课时间地点) -->
  57. <template v-if="enrollmentStatus === 'confirmed'">
  58. <view class="class-info-card" v-if="className">
  59. <text class="class-info-title">上课班次</text>
  60. <text class="class-info-name">{{ className }}</text>
  61. <text class="class-info-time" v-if="classTime">上课时间:{{ classTime }}</text>
  62. <text class="class-info-place" v-if="classPlace">上课地点:{{ classPlace }}</text>
  63. </view>
  64. <!-- 模块列表 -->
  65. <view class="module-section" v-if="modules && modules.length > 0">
  66. <view class="section-title-block">课程模块</view>
  67. <view class="module-list">
  68. <view class="module-item" v-for="(mod, idx) in modules" :key="idx">
  69. <view class="module-main">
  70. <text class="module-key">{{ mod.moduleKey }}</text>
  71. <text class="module-title">{{ mod.name }}</text>
  72. <text class="module-version" v-if="mod.version">v{{ mod.version }}</text>
  73. </view>
  74. <text class="module-output" v-if="mod.outputDesc">{{ mod.outputDesc }}</text>
  75. <text class="module-output" v-if="mod.description && !mod.outputDesc">{{ mod.description }}</text>
  76. <view class="module-footer">
  77. <text class="module-duration" v-if="mod.duration">时长:{{ mod.duration }}</text>
  78. <text class="module-duration" v-if="mod.price > 0">模块价 ¥{{ fenToYuan(mod.price) }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <!-- 课程前:课前准备 -->
  84. <view class="stage-card" v-if="stage === 'upcoming'">
  85. <text class="stage-icon">📅</text>
  86. <view class="stage-text">
  87. <text class="stage-title">课程即将开课</text>
  88. <text class="stage-sub">先完成课前准备,做好学习规划</text>
  89. </view>
  90. </view>
  91. <!-- 课程中:学习进度 -->
  92. <view class="section-card" v-if="stage === 'active'">
  93. <view class="section-head">
  94. <text class="section-title">学习进度</text>
  95. <text class="progress-count">{{ progress.done }}/{{ progress.total }} 项完成</text>
  96. </view>
  97. <view class="progress-bar">
  98. <view class="progress-fill" :style="{ width: progressPercent }"></view>
  99. </view>
  100. <view class="progress-list">
  101. <view class="progress-item" v-for="(it, idx) in progress.items" :key="idx">
  102. <text class="progress-icon" :class="{ done: it.ok }">{{ it.ok ? '✅' : '⬜' }}</text>
  103. <text class="progress-label">{{ it.label }}</text>
  104. </view>
  105. </view>
  106. </view>
  107. <!-- 课程后:结业事项 -->
  108. <view class="stage-card" v-if="stage === 'finished'">
  109. <text class="stage-icon">🎉</text>
  110. <view class="stage-text">
  111. <text class="stage-title">课程已结束</text>
  112. <text class="stage-sub">完成结业事项,收获学习成果</text>
  113. </view>
  114. </view>
  115. <!-- 本阶段要做的事 -->
  116. <view class="stage-title-block">本阶段要做的事</view>
  117. <view class="nav-grid">
  118. <view class="nav-item" v-for="(g, idx) in stageMenus" :key="idx" @click="onMenu(g)">
  119. <text class="nav-icon">{{ g.icon }}</text>
  120. <text class="nav-text">{{ g.text }}</text>
  121. </view>
  122. </view>
  123. </template>
  124. <!-- 分享入口:小程序端转发卡片(带 inviteCode),H5 端复制带邀请码链接 -->
  125. <view class="share-bar">
  126. <!-- #ifdef MP-WEIXIN -->
  127. <button class="share-bar-btn" open-type="share">分享给好友</button>
  128. <!-- #endif -->
  129. <!-- #ifndef MP-WEIXIN -->
  130. <button class="share-bar-btn" @click="copyShareLink">复制分享链接</button>
  131. <!-- #endif -->
  132. </view>
  133. </template>
  134. </view>
  135. </template>
  136. <script>
  137. import { getMyCourse, getCourseProgress, enterCourse, getCourseModules } from '@/utils/api.js'
  138. import { formatDateTime } from '@/utils/format.js'
  139. import { requireLogin } from '@/utils/guard.js'
  140. import { loadInviteCode, getInviteCode, buildSharePath } from '@/utils/share.js'
  141. import { captureInviteCode } from '@/utils/invite.js'
  142. import LoadingSkeleton from '@/components/loading-skeleton.vue'
  143. import ErrorState from '@/components/error-state.vue'
  144. import EmptyState from '@/components/empty-state.vue'
  145. export default {
  146. components: { LoadingSkeleton, ErrorState, EmptyState },
  147. data() {
  148. return {
  149. course: {},
  150. className: '',
  151. classTime: '',
  152. classPlace: '',
  153. enrollment: null,
  154. progress: { done: 0, total: 0, items: [] },
  155. modules: [],
  156. enterLoading: false,
  157. loading: true,
  158. error: false
  159. }
  160. },
  161. computed: {
  162. isLoggedIn() {
  163. return this.$store.getters.isLoggedIn
  164. },
  165. progressPercent() {
  166. var total = this.progress.total || 0
  167. if (!total) return '0%'
  168. var pct = Math.round((this.progress.done || 0) * 100 / total)
  169. return pct + '%'
  170. },
  171. // 课程所处阶段:upcoming(前) / active(中) / finished(后) / draft
  172. stage() {
  173. return this.course.effectiveStatus || 'active'
  174. },
  175. enrollmentStatus() {
  176. if (!this.enrollment || !this.enrollment.status) return 'none'
  177. return this.enrollment.status
  178. },
  179. stageMenus() {
  180. // 课程配置了"需要完成调研":进班后按课程绑定调研,三个阶段都展示入口
  181. var surveyMenu = null
  182. if (this.course.needsSurvey === 1 && this.course.id) {
  183. surveyMenu = { icon: '📝', text: '课程调研', url: '/pages/survey/index?courseId=' + this.course.id }
  184. }
  185. if (this.stage === 'upcoming') {
  186. // 课程前:课前准备
  187. var upcoming = [
  188. { icon: '📄', text: '课前资料', url: '/pages/material/index' },
  189. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  190. { icon: '👥', text: '我的小组', url: '/pages/group/index' }
  191. ]
  192. if (surveyMenu) upcoming.push(surveyMenu)
  193. return upcoming
  194. }
  195. if (this.stage === 'finished') {
  196. // 课程后:结业事项
  197. var finished = [
  198. { icon: '📋', text: '三本账', url: '/pages/assignment/index' },
  199. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  200. { icon: '🏆', text: '积分榜', url: '/pages/scoreboard/index' },
  201. { icon: '🗳️', text: '路演投票', url: '/pages/vote/index' }
  202. ]
  203. if (surveyMenu) finished.push(surveyMenu)
  204. return finished
  205. }
  206. // 课程中:学习内容
  207. var active = [
  208. { icon: '📄', text: '课前资料', url: '/pages/material/index' },
  209. { icon: '👥', text: '我的小组', url: '/pages/group/index' },
  210. { icon: '✅', text: '装机打卡', url: '/pages/checkin/index', tab: true },
  211. { icon: '📤', text: '成果上传', url: '/pages/upload/index' },
  212. { icon: '📝', text: '教学卡', url: '/pages/teaching/index' },
  213. { icon: '🎤', text: '路演材料', url: '/pages/roadmap/index' },
  214. { icon: '🗳️', text: '路演投票', url: '/pages/vote/index' },
  215. { icon: '🏆', text: '积分榜', url: '/pages/scoreboard/index' },
  216. { icon: '📅', text: '行动计划', url: '/pages/plan/index' },
  217. { icon: '📋', text: '三本账', url: '/pages/assignment/index' }
  218. ]
  219. if (surveyMenu) active.push(surveyMenu)
  220. return active
  221. }
  222. },
  223. onLoad(options) {
  224. this.courseId = (options && options.courseId) || ''
  225. captureInviteCode(options)
  226. loadInviteCode()
  227. this.loadAll()
  228. },
  229. // 分享给好友:带 courseId 回跳课程主页
  230. onShareAppMessage() {
  231. return {
  232. title: this.shareTitle(),
  233. path: buildSharePath('/pages/course/detail' + (this.courseId ? '?courseId=' + this.courseId : ''))
  234. }
  235. },
  236. // 分享到朋友圈
  237. onShareTimeline() {
  238. var query = this.courseId ? 'courseId=' + this.courseId : ''
  239. var code = getInviteCode()
  240. if (code) query += (query ? '&' : '') + 'inviteCode=' + code
  241. return {
  242. title: this.shareTitle(),
  243. query: query
  244. }
  245. },
  246. methods: {
  247. shareTitle() {
  248. var c = this.course || {}
  249. if (c.name) return (c.level || '') + ' · ' + c.name
  250. return '爱伴-健康之旅|课程详情'
  251. },
  252. /** H5 端复制带邀请码的分享链接(小程序端用 open-type="share" 走 onShareAppMessage) */
  253. copyShareLink() {
  254. var code = getInviteCode()
  255. var link = ''
  256. // #ifdef H5
  257. if (typeof window !== 'undefined' && window.location) {
  258. link = window.location.href
  259. }
  260. // #endif
  261. if (!link) {
  262. link = '/pages/course/detail' + (this.courseId ? '?courseId=' + this.courseId : '')
  263. }
  264. if (code) {
  265. link += (link.indexOf('?') > -1 ? '&' : '?') + 'inviteCode=' + code
  266. }
  267. uni.setClipboardData({
  268. data: link,
  269. success: function() {
  270. uni.showToast({ title: '分享链接已复制', icon: 'success' })
  271. }
  272. })
  273. },
  274. loadAll() {
  275. var self = this
  276. self.loading = true
  277. self.error = false
  278. getMyCourse(self.courseId).then(function(resp) {
  279. var d = resp.data || {}
  280. var c = d.course || {}
  281. self.course = c
  282. self.className = d.className || ''
  283. self.classTime = d.classTime || ''
  284. self.classPlace = d.classPlace || ''
  285. self.enrollment = d.enrollment || null
  286. }).catch(function() {
  287. self.error = true
  288. }).finally(function() {
  289. self.loading = false
  290. })
  291. // 获取模块列表
  292. if (self.courseId) {
  293. getCourseModules(self.courseId).then(function(resp) {
  294. self.modules = resp.data || []
  295. }).catch(function() {})
  296. }
  297. // 学习进度需登录后请求,未登录浏览时不调用(避免 401 误触发登录过期弹窗)
  298. if (self.isLoggedIn) {
  299. getCourseProgress().then(function(resp) {
  300. var d = resp.data || {}
  301. self.progress = {
  302. done: d.done || 0,
  303. total: d.total || 0,
  304. items: d.items || []
  305. }
  306. }).catch(function() {})
  307. }
  308. },
  309. onMenu(g) {
  310. if (!g) return
  311. if (g.tab) {
  312. uni.switchTab({ url: g.url })
  313. } else {
  314. uni.navigateTo({ url: g.url })
  315. }
  316. },
  317. goBackCourse() {
  318. var pages = getCurrentPages()
  319. if (pages.length > 1) {
  320. uni.navigateBack()
  321. } else {
  322. uni.redirectTo({ url: '/pages/course/index' })
  323. }
  324. },
  325. applyEnter() {
  326. var self = this
  327. if (!requireLogin()) return
  328. if (!self.course.id) return
  329. uni.showModal({
  330. title: '申请进班',
  331. content: '确认提交进班申请?提交后由班主任审核。',
  332. success: function(res) {
  333. if (!res.confirm) return
  334. self.enterLoading = true
  335. enterCourse(self.course.id).then(function(resp) {
  336. uni.showToast({ title: '已提交申请', icon: 'success' })
  337. self.loadAll()
  338. }).catch(function(err) {
  339. var msg = (err && err.message) || '提交失败'
  340. if (msg.indexOf('报名') >= 0 || msg.indexOf('支付') >= 0) {
  341. uni.showModal({
  342. title: '提示',
  343. content: msg,
  344. confirmText: '去报名',
  345. success: function(r) {
  346. if (r.confirm) {
  347. uni.navigateTo({ url: '/pages/enroll/list' })
  348. }
  349. }
  350. })
  351. } else {
  352. uni.showToast({ title: msg, icon: 'none' })
  353. }
  354. }).finally(function() {
  355. self.enterLoading = false
  356. })
  357. }
  358. })
  359. },
  360. statusLabel(st) {
  361. var map = { upcoming: '未开始', active: '进行中', finished: '已结束', draft: '未发布' }
  362. return map[st] || st || '-'
  363. },
  364. fmtDate(v) {
  365. if (!v) return '-'
  366. return formatDateTime(v)
  367. },
  368. fenToYuan(fen) {
  369. return ((fen || 0) / 100).toFixed(2)
  370. },
  371. goTo(url) {
  372. // 去报名/去支付为实际操作,未登录先引导登录(课程信息浏览已放行)
  373. if (!requireLogin()) return
  374. uni.navigateTo({ url: url })
  375. }
  376. }
  377. }
  378. </script>
  379. <style scoped>
  380. .course-detail-page { min-height: 100vh; background: #F5FAFE; padding: 24rpx 32rpx; }
  381. .course-head { background: #FFF; border-radius: 20rpx; padding: 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; }
  382. .action-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; align-items: center; }
  383. .action-title { font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 12rpx; }
  384. .action-desc { font-size: 26rpx; color: #3B5A78; text-align: center; line-height: 1.6; margin-bottom: 28rpx; }
  385. .action-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; }
  386. .action-btn.disabled { background: #E3ECF4; color: #6B7B8C; }
  387. .action-btn:active { opacity: 0.88; }
  388. .course-level { align-self: flex-start; font-size: 22rpx; font-weight: 600; color: #2E6FA8; background: #E8F3FC; border-radius: 8rpx; padding: 4rpx 14rpx; margin-bottom: 12rpx; }
  389. .course-name { font-size: 36rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; }
  390. .course-status { align-self: flex-start; font-size: 22rpx; border-radius: 6rpx; padding: 4rpx 16rpx; margin-bottom: 12rpx; }
  391. .course-status.st-upcoming { color: #2E6FA8; background: #E8F3FC; }
  392. .course-status.st-active { color: #0E8A4F; background: #E6F6EE; }
  393. .course-status.st-finished { color: #6B7B8C; background: #E3ECF4; }
  394. .course-desc { font-size: 26rpx; color: #3B5A78; line-height: 1.6; margin-bottom: 8rpx; }
  395. .course-time { font-size: 24rpx; color: #6B7B8C; margin-bottom: 8rpx; }
  396. .course-class { font-size: 24rpx; color: #1E3A5F; background: #E3ECF4; border-radius: 8rpx; padding: 8rpx 16rpx; align-self: flex-start; }
  397. .module-section { margin-bottom: 24rpx; }
  398. .module-list { display: flex; flex-direction: column; gap: 20rpx; }
  399. .module-item { background: #FFF; border-radius: 16rpx; padding: 24rpx; border: 1px solid #E3ECF4; }
  400. .module-main { display: flex; align-items: center; margin-bottom: 12rpx; }
  401. .module-key { font-size: 20rpx; color: #2E6FA8; background: #E8F3FC; padding: 2rpx 8rpx; border-radius: 4rpx; margin-right: 12rpx; font-weight: 600; }
  402. .module-title { font-size: 28rpx; font-weight: 700; color: #1E3A5F; flex: 1; }
  403. .module-version { font-size: 22rpx; color: #6B7B8C; }
  404. .module-output { font-size: 24rpx; color: #3B5A78; line-height: 1.5; margin-bottom: 16rpx; }
  405. .module-footer { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid #E3ECF4; padding-top: 16rpx; }
  406. .module-duration { font-size: 22rpx; color: #6B7B8C; }
  407. .module-status { font-size: 22rpx; font-weight: 600; color: #6B7B8C; }
  408. .module-status.done { color: #0E8A4F; }
  409. .class-info-card { background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; display: flex; flex-direction: column; }
  410. .class-info-title { font-size: 24rpx; color: #6B7B8C; margin-bottom: 8rpx; }
  411. .class-info-name { font-size: 30rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 8rpx; }
  412. .class-info-time { font-size: 26rpx; color: #3B5A78; margin-bottom: 4rpx; }
  413. .class-info-place { font-size: 26rpx; color: #3B5A78; }
  414. .stage-card { display: flex; align-items: center; background: #FFF; border-radius: 16rpx; padding: 28rpx 32rpx; margin-bottom: 24rpx; }
  415. .stage-icon { font-size: 48rpx; margin-right: 20rpx; }
  416. .stage-text { display: flex; flex-direction: column; }
  417. .stage-title { font-size: 30rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 6rpx; }
  418. .stage-sub { font-size: 24rpx; color: #3B5A78; }
  419. .stage-title-block { font-size: 30rpx; font-weight: 600; color: #1E3A5F; margin-bottom: 16rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  420. .section-card { background: #FFF; border-radius: 16rpx; padding: 28rpx; margin-bottom: 24rpx; }
  421. .section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16rpx; }
  422. .section-title { font-size: 30rpx; font-weight: 600; color: #1E3A5F; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  423. .progress-count { font-size: 24rpx; color: #3B5A78; }
  424. .progress-bar { height: 16rpx; background: #E3ECF4; border-radius: 8rpx; overflow: hidden; margin-bottom: 20rpx; }
  425. .progress-fill { height: 100%; background: #2E6FA8; border-radius: 8rpx; }
  426. .progress-list { display: flex; flex-direction: column; }
  427. .progress-item { display: flex; align-items: center; padding: 10rpx 0; }
  428. .progress-icon { font-size: 28rpx; margin-right: 12rpx; }
  429. .progress-label { font-size: 26rpx; color: #1E3A5F; }
  430. .nav-grid { display: flex; flex-wrap: wrap; gap: 0; background: #FFF; border-radius: 16rpx; overflow: hidden; }
  431. .nav-item { width: 25%; display: flex; flex-direction: column; align-items: center; padding: 28rpx 0; }
  432. .nav-item:active { background: #F5FAFE; }
  433. .nav-icon { font-size: 44rpx; margin-bottom: 8rpx; }
  434. .nav-text { font-size: 24rpx; color: #1E3A5F; text-align: center; }
  435. .share-bar { margin: 8rpx 0 32rpx; }
  436. .share-bar-btn { width: 100%; height: 84rpx; line-height: 84rpx; background: #FFF; color: #2E6FA8; font-size: 28rpx; font-weight: 600; border-radius: 42rpx; border: 2rpx solid #C3D2DF; }
  437. .share-bar-btn:active { opacity: 0.85; }
  438. </style>