course.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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 class="textTwo">{{ 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">{{ $formattedViewCount(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 class="courseMetaIcon" src="@/static/images/new/renshu.png"></image>
  100. <text class="meta-count">{{ $formattedViewCount(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: 6,
  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({courseType:0},
  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. return;
  215. if (this.recommendPage.total <= this.recommendList.length) {
  216. return;
  217. }
  218. this.recommendPage.pageNum++;
  219. this.getRecommendData();
  220. },
  221. // 为您精选课程列表重置方法
  222. resetRecommendDataList() {
  223. this.recommendPage.pageNum = 1;
  224. this.recommendPage.total = 0;
  225. this.recommendList = [];
  226. this.getRecommendData();
  227. },
  228. // 点击分类标签
  229. handleCategoryIdClick(id) {
  230. this.categoryIndex = id;
  231. this.resetJpDataList();
  232. },
  233. // 获取精品课程-类型
  234. async getJpCourseTypeData() {
  235. const params = {
  236. pageNum: 1,
  237. pageSize: 20,
  238. isShow: 1,
  239. cateType: 1,
  240. yxxTag: 0
  241. };
  242. const res = await courseTypeDataApi(params);
  243. if (res.code === 200) {
  244. this.categories = [...this.categories, ...res.data.list];
  245. }
  246. },
  247. // 获取精品课程-列表
  248. async getJpCourseList() {
  249. let params = {
  250. pageNum: this.jpPage.pageNum,
  251. pageSize: this.jpPage.pageSize,
  252. subCateId: this.categoryIndex,
  253. yxxTag: 0,
  254. };
  255. if (params.subCateId === 0) {
  256. delete params.subCateId;
  257. }
  258. uni.showLoading({
  259. title: "加载中...",
  260. mask: true,
  261. })
  262. const res = await courseListDataApi(params);
  263. uni.hideLoading()
  264. if (res.code === 200 && res.data.list.length > 0) {
  265. this.jpPage.total = res.data.total;
  266. this.courseList = [...this.courseList, ...res.data.list];
  267. }
  268. },
  269. // 分页获取精品课程列表
  270. getPageJpCoursesData() {
  271. if (this.jpPage.total <= this.courseList.length) {
  272. return;
  273. }
  274. this.jpPage.pageNum++;
  275. this.getJpCourseList();
  276. },
  277. // 精品课程列表重置方法
  278. resetJpDataList() {
  279. this.jpPage.pageNum = 1;
  280. this.jpPage.total = 0;
  281. this.courseList = [];
  282. this.getJpCourseList();
  283. },
  284. }
  285. }
  286. </script>
  287. <style scoped lang="scss">
  288. /* 图片箭头旋转类(展开时向上) */
  289. .rotate-arrow {
  290. transform: rotate(180deg);
  291. }
  292. .container {
  293. min-height: 100vh;
  294. background: #F5F5F5;
  295. display: flex;
  296. flex-direction: column;
  297. }
  298. /* 顶部 Tab */
  299. .top-nav {
  300. display: flex;
  301. flex-direction: column;
  302. background: #fff;
  303. /* border-bottom: 1rpx solid #f0f0f0; */
  304. }
  305. .nav-tabs {
  306. display: flex;
  307. align-items: center;
  308. justify-content: center;
  309. }
  310. .nav-item {
  311. flex: 1;
  312. display: flex;
  313. align-items: center;
  314. justify-content: center;
  315. position: relative;
  316. padding: 24rpx 0;
  317. }
  318. .nav-item text {
  319. font-family: PingFangSC, PingFang SC;
  320. font-weight: 400;
  321. font-size: 36rpx;
  322. color: #030303;
  323. }
  324. .nav-item.active text {
  325. font-weight: 600;
  326. font-size: 40rpx;
  327. }
  328. .nav-indicator {
  329. position: absolute;
  330. left: 50%;
  331. bottom: 0;
  332. transform: translateX(-50%);
  333. width: 100rpx;
  334. height: 10rpx;
  335. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  336. border-radius: 6rpx;
  337. }
  338. .nav-actions {
  339. display: flex;
  340. align-items: center;
  341. gap: 24rpx;
  342. }
  343. .action-icon {
  344. font-size: 36rpx;
  345. color: #666;
  346. }
  347. /* 滚动区 */
  348. .scroll-wrap {
  349. flex: 1;
  350. height: 0;
  351. }
  352. /* 分类标签 */
  353. .category-wrap {
  354. padding: 24rpx 0;
  355. border-radius: 0rpx 0rpx 20rpx 20rpx;
  356. background: #fff;
  357. display: flex;
  358. align-items: center;
  359. flex-direction: column;
  360. }
  361. .category-tags {
  362. width: 100%;
  363. box-sizing: border-box;
  364. padding: 0 24rpx;
  365. display: flex;
  366. flex-wrap: wrap;
  367. flex-direction: row;
  368. }
  369. .category-tags.collapsed {
  370. max-height: 340rpx;
  371. overflow: hidden;
  372. }
  373. .tag-item {
  374. width: 31%;
  375. height: 96rpx;
  376. box-sizing: border-box;
  377. padding: 20rpx 0;
  378. text-align: center;
  379. border-radius: 20rpx;
  380. background: #f0f0f0;
  381. margin-right: 3%;
  382. margin-bottom: 24rpx;
  383. display: flex;
  384. align-items: center;
  385. justify-content: center;
  386. }
  387. .tag-item:nth-last-child(-n+3) {
  388. margin-bottom: 0;
  389. }
  390. .tag-item:nth-child(3n) {
  391. margin-right: 0;
  392. }
  393. .tag-item text {
  394. font-family: PingFangSC, PingFang SC;
  395. font-weight: 400;
  396. font-size: 40rpx;
  397. color: rgba(0, 0, 0, 0.85);
  398. }
  399. .tag-item.active {
  400. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  401. }
  402. .tag-item.active text {
  403. color: #fff;
  404. }
  405. .expand-btn {
  406. display: flex;
  407. align-items: center;
  408. justify-content: center;
  409. margin-top: 20rpx;
  410. width: 166rpx;
  411. height: 64rpx;
  412. border-radius: 32rpx;
  413. border: 2rpx solid #FF233C;
  414. }
  415. .expand-btn text {
  416. font-family: PingFangSC, PingFang SC;
  417. font-weight: 400;
  418. font-size: 32rpx;
  419. color: #FF233C;
  420. }
  421. .expand-btn .arrow {
  422. margin-left: 6rpx;
  423. font-size: 22rpx;
  424. }
  425. .expand-btn image {
  426. margin-left: 10rpx;
  427. width: 32rpx;
  428. height: 32rpx;
  429. }
  430. /* 课程网格 */
  431. .course-grid {
  432. display: flex;
  433. flex-wrap: wrap;
  434. padding: 24rpx;
  435. gap: 24rpx 20rpx;
  436. flex-direction: column;
  437. }
  438. .course-card {
  439. display: flex;
  440. background: #fff;
  441. border-radius: 20rpx;
  442. overflow: hidden;
  443. padding: 20rpx;
  444. }
  445. .course-tag {
  446. position: absolute;
  447. left: 0;
  448. bottom: 0;
  449. right: 0;
  450. padding: 8rpx 12rpx;
  451. background: linear-gradient(transparent, rgba(0, 0, 0, 0.6));
  452. font-size: 22rpx;
  453. color: #fff;
  454. }
  455. .course-info {
  456. flex: 1;
  457. padding-left: 24rpx;
  458. /* padding: 20rpx 24rpx; */
  459. display: flex;
  460. flex-direction: column;
  461. justify-content: space-between;
  462. min-width: 0;
  463. }
  464. .course-meta {
  465. display: flex;
  466. align-items: center;
  467. .courseMetaIcon {
  468. width: 30rpx;
  469. height: 30rpx;
  470. }
  471. }
  472. .meta-icon {
  473. font-size: 24rpx;
  474. margin-right: 6rpx;
  475. color: #999;
  476. }
  477. .meta-count {
  478. margin-left: 10rpx;
  479. font-family: PingFangSC, PingFang SC;
  480. font-weight: 400;
  481. font-size: 32rpx;
  482. color: #666666;
  483. }
  484. .card-cover {
  485. position: relative;
  486. width: 296rpx;
  487. height: 222rpx;
  488. border-radius: 20rpx;
  489. overflow: hidden;
  490. flex-shrink: 0;
  491. }
  492. .cover-img {
  493. width: 100%;
  494. height: 100%;
  495. background: #BB6D6D;
  496. }
  497. .card-title {
  498. font-family: PingFangSC, PingFang SC;
  499. font-weight: 600;
  500. font-size: 36rpx;
  501. color: #222222;
  502. line-height: 50rpx;
  503. text-align: justify;
  504. overflow: hidden;
  505. text-overflow: ellipsis;
  506. display: -webkit-box;
  507. -webkit-line-clamp: 2;
  508. -webkit-box-orient: vertical;
  509. }
  510. .card-footer {
  511. flex: 1;
  512. padding-left: 24rpx;
  513. /* padding: 20rpx 24rpx; */
  514. display: flex;
  515. flex-direction: column;
  516. justify-content: space-between;
  517. min-width: 0;
  518. }
  519. .card-views {
  520. font-family: PingFangSC, PingFang SC;
  521. font-weight: 400;
  522. font-size: 32rpx;
  523. color: #666666;
  524. line-height: 44rpx;
  525. }
  526. .btn-watch {
  527. width: 168rpx;
  528. height: 64rpx;
  529. line-height: 64rpx;
  530. text-align: center;
  531. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  532. border-radius: 32rpx;
  533. font-family: PingFangSC, PingFang SC;
  534. font-weight: 600;
  535. font-size: 32rpx;
  536. color: #FFFFFF;
  537. }
  538. /* 最近学习 - 按日期分组 */
  539. .recent-group {
  540. padding: 24rpx 24rpx 0;
  541. }
  542. .group-date {
  543. display: flex;
  544. align-items: center;
  545. margin-bottom: 24rpx;
  546. }
  547. .date-icon {
  548. width: 32rpx;
  549. height: 32rpx;
  550. margin-right: 8rpx;
  551. }
  552. .date-text {
  553. font-family: PingFangSC, PingFang SC;
  554. font-weight: 600;
  555. font-size: 40rpx;
  556. line-height: 56rpx;
  557. color: #222222;
  558. }
  559. .recent-card {
  560. display: flex;
  561. background: #fff;
  562. border-radius: 20rpx;
  563. overflow: hidden;
  564. padding: 20rpx;
  565. margin-bottom: 24rpx;
  566. }
  567. .recent-card:last-child {
  568. margin-bottom: 0;
  569. }
  570. .recent-thumb {
  571. position: relative;
  572. width: 296rpx;
  573. height: 222rpx;
  574. border-radius: 20rpx;
  575. overflow: hidden;
  576. flex-shrink: 0;
  577. }
  578. .thumb-img {
  579. width: 100%;
  580. height: 100%;
  581. background: #BB6D6D;
  582. }
  583. .recent-info {
  584. flex: 1;
  585. padding-left: 24rpx;
  586. /* padding: 20rpx 24rpx; */
  587. display: flex;
  588. flex-direction: column;
  589. justify-content: space-between;
  590. min-width: 0;
  591. }
  592. .recent-title {
  593. font-family: PingFangSC, PingFang SC;
  594. font-weight: 600;
  595. font-size: 36rpx;
  596. color: #222222;
  597. line-height: 50rpx;
  598. text-align: justify;
  599. overflow: hidden;
  600. text-overflow: ellipsis;
  601. display: -webkit-box;
  602. -webkit-line-clamp: 2;
  603. -webkit-box-orient: vertical;
  604. }
  605. .recent-progress {
  606. font-family: PingFangSC, PingFang SC;
  607. font-weight: 400;
  608. font-size: 32rpx;
  609. color: rgba(0, 0, 0, 0.65);
  610. line-height: 44rpx;
  611. }
  612. /* 空态 */
  613. .empty-state {
  614. display: flex;
  615. flex-direction: column;
  616. align-items: center;
  617. justify-content: center;
  618. padding: 80rpx 0 48rpx;
  619. /* background: linear-gradient(180deg, #fff5f5 0%, #fff 100%); */
  620. }
  621. .empty-icon {
  622. width: 310rpx;
  623. height: 260rpx;
  624. margin-bottom: 30rpx;
  625. }
  626. .empty-text {
  627. font-family: PingFangSC, PingFang SC;
  628. font-weight: 400;
  629. font-size: 36rpx;
  630. color: rgba(0, 0, 0, 0.25);
  631. line-height: 50rpx;
  632. }
  633. /* 为您精选 */
  634. .recommend-section {
  635. padding: 0 24rpx 32rpx;
  636. }
  637. .recommend-title {
  638. display: block;
  639. font-family: PingFangSC, PingFang SC;
  640. font-weight: 600;
  641. font-size: 40rpx;
  642. color: #222222;
  643. line-height: 56rpx;
  644. padding-bottom: 24rpx;
  645. }
  646. .bottom-placeholder {
  647. height: 120rpx;
  648. }
  649. </style>