course.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <template>
  2. <view class="container">
  3. <!-- 顶部导航 Tab -->
  4. <view class="top-nav" :style="{ marginTop: statusBarHeight }">
  5. <view class="nav-tabs">
  6. <view class="nav-item" :class="{ active: tabIndex === 0 }" @click="handleChangeTopTab(0)">
  7. <text>精品课程</text>
  8. <view v-if="tabIndex === 0" class="nav-indicator"></view>
  9. </view>
  10. <view class="nav-item" :class="{ active: tabIndex === 1 }" @click="handleChangeTopTab(1)">
  11. <text>最近学习</text>
  12. <view v-if="tabIndex === 1" class="nav-indicator"></view>
  13. </view>
  14. </view>
  15. <view v-if="tabIndex === 0" class="category-wrap">
  16. <view class="category-tags" :class="{ collapsed: !categoryExpand }">
  17. <view v-for="(cat, idx) in categories" :key="idx" class="tag-item"
  18. :class="{ active: categoryIndex === cat.cateId }" @click="handleCategoryIdClick(cat.cateId)">
  19. <text>{{ cat.cateName }}</text>
  20. </view>
  21. </view>
  22. <view class="expand-btn" @click="categoryExpand = !categoryExpand">
  23. <text>{{ categoryExpand ? '收起' : '展开' }}</text>
  24. <image :class="{ 'rotate-arrow': !categoryExpand }" src="@/static/images/new/expand.png"></image>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- 精品课程 内容 -->
  29. <scroll-view v-show="tabIndex === 0" scroll-y class="scroll-wrap" :show-scrollbar="false"
  30. @scrolltolower="getPageJpCoursesData">
  31. <!-- 分类标签区 -->
  32. <!-- 课程网格 -->
  33. <view v-if="courseList.length > 0" class="course-grid">
  34. <view v-for="(course, idx) in courseList" :key="idx" class="course-card" @click="onCourseClick(course)">
  35. <view class="card-cover">
  36. <image :src="course.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="cover-img"></image>
  37. </view>
  38. <view class="course-info">
  39. <text class="card-title">{{ course.courseName }}</text>
  40. <view class="x-end" style="justify-content: space-between;">
  41. <view class="course-meta">
  42. <image class="courseMetaIcon" src="@/static/images/new/renshu.png"></image>
  43. <text class="meta-count">{{ course.watchUserCount }}</text>
  44. </view>
  45. <view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <view v-else class="empty-state">
  51. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  52. <text class="empty-text">暂无课程</text>
  53. </view>
  54. <view class="bottom-placeholder"></view>
  55. </scroll-view>
  56. <!-- 最近学习 内容 -->
  57. <scroll-view v-show="tabIndex === 1" scroll-y class="scroll-wrap" :show-scrollbar="false"
  58. @scrolltolower="recentList.length > 0 ? getPageCourseStudyData() : getPageRecommendCoursesData()">
  59. <!-- 有学习记录:按日期分组列表 -->
  60. <template v-if="recentList.length > 0">
  61. <view v-for="(group, gIdx) in recentList" :key="gIdx" class="recent-group">
  62. <view class="group-date">
  63. <image class="date-icon" src="@/static/images/new/time.png"></image>
  64. <text class="date-text">{{ group.date }}</text>
  65. </view>
  66. <view v-for="(item, i) in group.courses" :key="i" class="recent-card" @click="onCourseClick(item)">
  67. <view class="recent-thumb">
  68. <image :src="item.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="thumb-img"></image>
  69. </view>
  70. <view class="recent-info">
  71. <text class="recent-title">{{ item.courseName }}</text>
  72. <text class="recent-progress">已学: {{ item.progress }}%</text>
  73. <view class="y-end">
  74. <view class="btn-watch" @click.stop="onCourseClick(item)">立即观看</view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </template>
  80. <!-- 无学习记录:空态 + 为您精选 -->
  81. <template v-else>
  82. <view class="empty-state">
  83. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  84. <text class="empty-text">暂无学习内容</text>
  85. </view>
  86. <view class="recommend-section">
  87. <text class="recommend-title">为您精选</text>
  88. <view v-if="recommendList.length > 0" class="course-grid" style="padding: 0;">
  89. <view v-for="(course, idx) in recommendList" :key="idx" class="course-card"
  90. @click="onCourseClick(course)">
  91. <view class="card-cover">
  92. <image :src="course.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="cover-img">
  93. </image>
  94. </view>
  95. <view class="card-footer">
  96. <text class="card-title">{{ course.courseName }}</text>
  97. <view class="x-end" style="justify-content: space-between;">
  98. <view class="course-meta">
  99. <image src="@/static/images/new/renshu.png"></image>
  100. <text class="meta-count">{{ course.watchUserCount }}</text>
  101. </view>
  102. <view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
  103. </view>
  104. </view>
  105. </view>
  106. </view>
  107. <view v-else class="empty-state">
  108. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  109. <text class="empty-text">暂无课程</text>
  110. </view>
  111. </view>
  112. </template>
  113. <view class="bottom-placeholder"></view>
  114. </scroll-view>
  115. </view>
  116. </template>
  117. <script>
  118. import {
  119. courseTypeDataApi, courseListDataApi
  120. } from '@/api/home'
  121. import { getCourseStudyList } from '@/api/course'
  122. export default {
  123. data() {
  124. return {
  125. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  126. tabIndex: 0,
  127. categoryExpand: false,
  128. categoryIndex: 0,
  129. categories: [{ cateId: 0, cateName: '全部' }],
  130. courseList: [],
  131. jpPage: {
  132. pageNum: 1,
  133. pageSize: 10,
  134. total: 0,
  135. },
  136. recentList: [],
  137. recentPage: {
  138. pageNum: 1,
  139. pageSize: 10,
  140. total: 0,
  141. },
  142. recommendList: [],
  143. recommendPage: {
  144. pageNum: 1,
  145. pageSize: 10,
  146. total: 0,
  147. },
  148. }
  149. },
  150. onLoad() {
  151. this.getJpCourseTypeData();
  152. this.getJpCourseList();
  153. },
  154. methods: {
  155. onCourseClick(e) {
  156. let newUrl = `/pages/course/info?courseId=${e.courseId}`
  157. if (e.videoId) {
  158. newUrl = `${newUrl}&videoId=${e.videoId}`
  159. }
  160. uni.navigateTo({
  161. url: newUrl
  162. })
  163. },
  164. // 切换顶部 Tab
  165. handleChangeTopTab(index) {
  166. this.tabIndex = index;
  167. if (index == 1) {
  168. this.resetCourseStudyDataList()
  169. }
  170. },
  171. // 获取学习记录课程列表
  172. async getCourseStudyListMethos() {
  173. const res = await getCourseStudyList({},
  174. this.recentPage.pageNum,
  175. this.recentPage.pageSize,
  176. );
  177. if (res.code === 200 && res.data.list.length > 0) {
  178. this.recentPage.total = res.data.total;
  179. this.recentList = [...this.recentList, ...res.data.list];
  180. } else {
  181. this.recentList = [];
  182. this.resetRecommendDataList();
  183. }
  184. },
  185. // 分页获取学习记录课程列表
  186. getPageCourseStudyData() {
  187. if (this.recentPage.total <= this.recentList.length) {
  188. return;
  189. }
  190. this.recentPage.pageNum++;
  191. this.getCourseStudyListMethos();
  192. },
  193. // 学习记录课程列表重置方法
  194. resetCourseStudyDataList() {
  195. this.recentPage.pageNum = 1;
  196. this.recentPage.total = 0;
  197. this.recentList = [];
  198. this.getCourseStudyListMethos();
  199. },
  200. // 获取为您精选课程列表
  201. async getRecommendData() {
  202. let params = {
  203. pageNum: this.recommendPage.pageNum,
  204. pageSize: this.recommendPage.pageSize,
  205. };
  206. const res = await courseListDataApi(params);
  207. if (res.code === 200 && res.data.list.length > 0) {
  208. this.recommendPage.total = res.data.total;
  209. this.recommendList = [...this.recommendList, ...res.data.list];
  210. }
  211. },
  212. // 分页获取为您精选课程列表
  213. getPageRecommendCoursesData() {
  214. if (this.recommendPage.total <= this.recommendList.length) {
  215. return;
  216. }
  217. this.recommendPage.pageNum++;
  218. this.getRecommendData();
  219. },
  220. // 为您精选课程列表重置方法
  221. resetRecommendDataList() {
  222. this.recommendPage.pageNum = 1;
  223. this.recommendPage.total = 0;
  224. this.recommendList = [];
  225. this.getRecommendData();
  226. },
  227. // 点击分类标签
  228. handleCategoryIdClick(id) {
  229. this.categoryIndex = id;
  230. this.resetJpDataList();
  231. },
  232. // 获取精品课程-类型
  233. async getJpCourseTypeData() {
  234. const params = {
  235. pageNum: 1,
  236. pageSize: 20,
  237. isShow: 1,
  238. cateType: 1,
  239. yxxTag: 0
  240. };
  241. const res = await courseTypeDataApi(params);
  242. if (res.code === 200) {
  243. this.categories = [...this.categories, ...res.data.list];
  244. }
  245. },
  246. // 获取精品课程-列表
  247. async getJpCourseList() {
  248. let params = {
  249. pageNum: this.jpPage.pageNum,
  250. pageSize: this.jpPage.pageSize,
  251. subCateId: this.categoryIndex,
  252. yxxTag: 0,
  253. };
  254. if (params.subCateId === 0) {
  255. delete params.subCateId;
  256. }
  257. uni.showLoading({
  258. title: "加载中...",
  259. mask: true,
  260. })
  261. const res = await courseListDataApi(params);
  262. uni.hideLoading()
  263. if (res.code === 200 && res.data.list.length > 0) {
  264. this.jpPage.total = res.data.total;
  265. this.courseList = [...this.courseList, ...res.data.list];
  266. }
  267. },
  268. // 分页获取精品课程列表
  269. getPageJpCoursesData() {
  270. if (this.jpPage.total <= this.courseList.length) {
  271. return;
  272. }
  273. this.jpPage.pageNum++;
  274. this.getJpCourseList();
  275. },
  276. // 精品课程列表重置方法
  277. resetJpDataList() {
  278. this.jpPage.pageNum = 1;
  279. this.jpPage.total = 0;
  280. this.courseList = [];
  281. this.getJpCourseList();
  282. },
  283. }
  284. }
  285. </script>
  286. <style scoped lang="scss">
  287. /* 图片箭头旋转类(展开时向上) */
  288. .rotate-arrow {
  289. transform: rotate(180deg);
  290. }
  291. .container {
  292. min-height: 100vh;
  293. background: #F5F5F5;
  294. display: flex;
  295. flex-direction: column;
  296. }
  297. /* 顶部 Tab */
  298. .top-nav {
  299. display: flex;
  300. flex-direction: column;
  301. background: #fff;
  302. /* border-bottom: 1rpx solid #f0f0f0; */
  303. }
  304. .nav-tabs {
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. }
  309. .nav-item {
  310. flex: 1;
  311. display: flex;
  312. align-items: center;
  313. justify-content: center;
  314. position: relative;
  315. padding: 24rpx 0;
  316. }
  317. .nav-item text {
  318. font-family: PingFangSC, PingFang SC;
  319. font-weight: 400;
  320. font-size: 36rpx;
  321. color: #030303;
  322. }
  323. .nav-item.active text {
  324. font-weight: 600;
  325. font-size: 40rpx;
  326. }
  327. .nav-indicator {
  328. position: absolute;
  329. left: 50%;
  330. bottom: 0;
  331. transform: translateX(-50%);
  332. width: 100rpx;
  333. height: 10rpx;
  334. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  335. border-radius: 6rpx;
  336. }
  337. .nav-actions {
  338. display: flex;
  339. align-items: center;
  340. gap: 24rpx;
  341. }
  342. .action-icon {
  343. font-size: 36rpx;
  344. color: #666;
  345. }
  346. /* 滚动区 */
  347. .scroll-wrap {
  348. flex: 1;
  349. height: 0;
  350. }
  351. /* 分类标签 */
  352. .category-wrap {
  353. padding: 24rpx 0;
  354. border-radius: 0rpx 0rpx 20rpx 20rpx;
  355. background: #fff;
  356. display: flex;
  357. align-items: center;
  358. flex-direction: column;
  359. }
  360. .category-tags {
  361. width: 100%;
  362. box-sizing: border-box;
  363. padding: 0 24rpx;
  364. display: flex;
  365. flex-wrap: wrap;
  366. flex-direction: row;
  367. }
  368. .category-tags.collapsed {
  369. max-height: 100rpx;
  370. overflow: hidden;
  371. }
  372. .tag-item {
  373. width: 31%;
  374. height: 96rpx;
  375. box-sizing: border-box;
  376. padding: 20rpx 0;
  377. text-align: center;
  378. border-radius: 20rpx;
  379. background: #f0f0f0;
  380. margin-right: 3%;
  381. margin-bottom: 24rpx;
  382. display: flex;
  383. align-items: center;
  384. justify-content: center;
  385. }
  386. .tag-item:nth-last-child(-n+3) {
  387. margin-bottom: 0;
  388. }
  389. .tag-item:nth-child(3n) {
  390. margin-right: 0;
  391. }
  392. .tag-item text {
  393. font-family: PingFangSC, PingFang SC;
  394. font-weight: 400;
  395. font-size: 40rpx;
  396. color: rgba(0, 0, 0, 0.85);
  397. }
  398. .tag-item.active {
  399. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  400. }
  401. .tag-item.active text {
  402. color: #fff;
  403. }
  404. .expand-btn {
  405. display: flex;
  406. align-items: center;
  407. justify-content: center;
  408. margin-top: 20rpx;
  409. width: 166rpx;
  410. height: 64rpx;
  411. border-radius: 32rpx;
  412. border: 2rpx solid #FF233C;
  413. }
  414. .expand-btn text {
  415. font-family: PingFangSC, PingFang SC;
  416. font-weight: 400;
  417. font-size: 32rpx;
  418. color: #FF233C;
  419. }
  420. .expand-btn .arrow {
  421. margin-left: 6rpx;
  422. font-size: 22rpx;
  423. }
  424. .expand-btn image {
  425. margin-left: 10rpx;
  426. width: 32rpx;
  427. height: 32rpx;
  428. }
  429. /* 课程网格 */
  430. .course-grid {
  431. display: flex;
  432. flex-wrap: wrap;
  433. padding: 24rpx;
  434. gap: 24rpx 20rpx;
  435. flex-direction: column;
  436. }
  437. .course-card {
  438. display: flex;
  439. background: #fff;
  440. border-radius: 20rpx;
  441. overflow: hidden;
  442. padding: 20rpx;
  443. }
  444. .course-tag {
  445. position: absolute;
  446. left: 0;
  447. bottom: 0;
  448. right: 0;
  449. padding: 8rpx 12rpx;
  450. background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  451. font-size: 22rpx;
  452. color: #fff;
  453. }
  454. .course-info {
  455. flex: 1;
  456. padding-left: 24rpx;
  457. /* padding: 20rpx 24rpx; */
  458. display: flex;
  459. flex-direction: column;
  460. justify-content: space-between;
  461. min-width: 0;
  462. }
  463. .course-meta {
  464. display: flex;
  465. align-items: center;
  466. .courseMetaIcon {
  467. width: 30rpx;
  468. height: 30rpx;
  469. }
  470. }
  471. .meta-icon {
  472. font-size: 24rpx;
  473. margin-right: 6rpx;
  474. color: #999;
  475. }
  476. .meta-count {
  477. margin-left: 10rpx;
  478. font-family: PingFangSC, PingFang SC;
  479. font-weight: 400;
  480. font-size: 32rpx;
  481. color: #666666;
  482. }
  483. .card-cover {
  484. position: relative;
  485. width: 296rpx;
  486. height: 222rpx;
  487. border-radius: 20rpx;
  488. overflow: hidden;
  489. flex-shrink: 0;
  490. }
  491. .cover-img {
  492. width: 100%;
  493. height: 100%;
  494. background: #BB6D6D;
  495. }
  496. .card-title {
  497. font-family: PingFangSC, PingFang SC;
  498. font-weight: 600;
  499. font-size: 36rpx;
  500. color: #222222;
  501. line-height: 50rpx;
  502. text-align: justify;
  503. overflow: hidden;
  504. text-overflow: ellipsis;
  505. display: -webkit-box;
  506. -webkit-line-clamp: 2;
  507. -webkit-box-orient: vertical;
  508. }
  509. .card-footer {
  510. flex: 1;
  511. padding-left: 24rpx;
  512. /* padding: 20rpx 24rpx; */
  513. display: flex;
  514. flex-direction: column;
  515. justify-content: space-between;
  516. min-width: 0;
  517. }
  518. .card-views {
  519. font-family: PingFangSC, PingFang SC;
  520. font-weight: 400;
  521. font-size: 32rpx;
  522. color: #666666;
  523. line-height: 44rpx;
  524. }
  525. .btn-watch {
  526. width: 168rpx;
  527. height: 64rpx;
  528. line-height: 64rpx;
  529. text-align: center;
  530. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  531. border-radius: 32rpx;
  532. font-family: PingFangSC, PingFang SC;
  533. font-weight: 600;
  534. font-size: 32rpx;
  535. color: #FFFFFF;
  536. }
  537. /* 最近学习 - 按日期分组 */
  538. .recent-group {
  539. padding: 24rpx 24rpx 0;
  540. }
  541. .group-date {
  542. display: flex;
  543. align-items: center;
  544. margin-bottom: 24rpx;
  545. }
  546. .date-icon {
  547. width: 32rpx;
  548. height: 32rpx;
  549. margin-right: 8rpx;
  550. }
  551. .date-text {
  552. font-family: PingFangSC, PingFang SC;
  553. font-weight: 600;
  554. font-size: 40rpx;
  555. line-height: 56rpx;
  556. color: #222222;
  557. }
  558. .recent-card {
  559. display: flex;
  560. background: #fff;
  561. border-radius: 20rpx;
  562. overflow: hidden;
  563. padding: 20rpx;
  564. margin-bottom: 24rpx;
  565. }
  566. .recent-card:last-child {
  567. margin-bottom: 0;
  568. }
  569. .recent-thumb {
  570. position: relative;
  571. width: 296rpx;
  572. height: 222rpx;
  573. border-radius: 20rpx;
  574. overflow: hidden;
  575. flex-shrink: 0;
  576. }
  577. .thumb-img {
  578. width: 100%;
  579. height: 100%;
  580. background: #BB6D6D;
  581. }
  582. .recent-info {
  583. flex: 1;
  584. padding-left: 24rpx;
  585. /* padding: 20rpx 24rpx; */
  586. display: flex;
  587. flex-direction: column;
  588. justify-content: space-between;
  589. min-width: 0;
  590. }
  591. .recent-title {
  592. font-family: PingFangSC, PingFang SC;
  593. font-weight: 600;
  594. font-size: 36rpx;
  595. color: #222222;
  596. line-height: 50rpx;
  597. text-align: justify;
  598. overflow: hidden;
  599. text-overflow: ellipsis;
  600. display: -webkit-box;
  601. -webkit-line-clamp: 2;
  602. -webkit-box-orient: vertical;
  603. }
  604. .recent-progress {
  605. font-family: PingFangSC, PingFang SC;
  606. font-weight: 400;
  607. font-size: 32rpx;
  608. color: rgba(0, 0, 0, 0.65);
  609. line-height: 44rpx;
  610. }
  611. /* 空态 */
  612. .empty-state {
  613. display: flex;
  614. flex-direction: column;
  615. align-items: center;
  616. justify-content: center;
  617. padding: 80rpx 0 48rpx;
  618. /* background: linear-gradient(180deg, #fff5f5 0%, #fff 100%); */
  619. }
  620. .empty-icon {
  621. width: 310rpx;
  622. height: 260rpx;
  623. margin-bottom: 30rpx;
  624. }
  625. .empty-text {
  626. font-family: PingFangSC, PingFang SC;
  627. font-weight: 400;
  628. font-size: 36rpx;
  629. color: rgba(0, 0, 0, 0.25);
  630. line-height: 50rpx;
  631. }
  632. /* 为您精选 */
  633. .recommend-section {
  634. padding: 0 24rpx 32rpx;
  635. }
  636. .recommend-title {
  637. display: block;
  638. font-family: PingFangSC, PingFang SC;
  639. font-weight: 600;
  640. font-size: 40rpx;
  641. color: #222222;
  642. line-height: 56rpx;
  643. padding-bottom: 24rpx;
  644. }
  645. .bottom-placeholder {
  646. height: 120rpx;
  647. }
  648. </style>