video.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  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="ellipsis2">{{ cat.cateName }}</text>
  20. </view>
  21. </view>
  22. <view v-if="categories.length>9" 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="getPageYxxeCoursesData">
  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="course-meta">
  41. {{ course.courseDesc }}
  42. </view>
  43. <view class="y-end">
  44. <view class="btn-watch" @click.stop="onCourseClick(course)">立即观看</view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. <view v-else class="empty-state">
  50. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  51. <text class="empty-text">暂无课程</text>
  52. </view>
  53. <view class="bottom-placeholder"></view>
  54. </scroll-view>
  55. <!-- 最近学习 内容 -->
  56. <scroll-view v-show="tabIndex === 1" scroll-y class="scroll-wrap" :show-scrollbar="false"
  57. @scrolltolower="recentList.length > 0 ? getPageCourseStudyData() : getPageRecommendCoursesData()">
  58. <!-- 有学习记录:按日期分组列表 -->
  59. <template v-if="recentList.length > 0">
  60. <view v-for="(group, gIdx) in recentList" :key="gIdx" class="recent-group">
  61. <view class="group-date">
  62. <image class="date-icon" src="@/static/images/new/time.png"></image>
  63. <text class="date-text">{{ group.date }}</text>
  64. </view>
  65. <view v-for="(item, i) in group.courses" :key="i" class="recent-card" @click="onCourseClick(item)">
  66. <view class="recent-thumb">
  67. <image :src="item.imgUrl || '/static/logo.jpg'" mode="aspectFill" class="thumb-img"></image>
  68. </view>
  69. <view class="recent-info">
  70. <text class="recent-title">{{ item.courseName }}</text>
  71. <!-- <text class="recent-meta">{{ item.courseDesc }}</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="course-meta">
  98. {{ course.courseDesc }}
  99. </view>
  100. <view class="y-end">
  101. <view class="btn-watch" @click.stop="onCourseClick(course)">回看</view>
  102. </view>
  103. </view>
  104. </view>
  105. </view>
  106. <view v-else class="empty-state">
  107. <image class="empty-icon" src="@/static/images/new/nodata.png"></image>
  108. <text class="empty-text">暂无课程</text>
  109. </view>
  110. </view>
  111. </template>
  112. <view class="bottom-placeholder"></view>
  113. </scroll-view>
  114. </view>
  115. </template>
  116. <script>
  117. import {
  118. courseTypeDataApi, courseListDataApi
  119. } from '@/api/home'
  120. import { getCourseStudyList } from '@/api/course'
  121. export default {
  122. data() {
  123. return {
  124. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  125. tabIndex: 0,
  126. categoryExpand: false,
  127. categoryIndex: 0,
  128. categories: [{ cateId: 0, cateName: '全部' }],
  129. courseList: [],
  130. yxxPage: {
  131. pageNum: 1,
  132. pageSize: 10,
  133. total: 0,
  134. },
  135. recentList: [],
  136. recentPage: {
  137. pageNum: 1,
  138. pageSize: 10,
  139. total: 0,
  140. },
  141. recommendList: [],
  142. recommendPage: {
  143. pageNum: 1,
  144. pageSize: 6,
  145. total: 0,
  146. },
  147. }
  148. },
  149. onLoad() {
  150. this.getOneCourseTypeData();
  151. this.getYxxCourseList();
  152. },
  153. methods: {
  154. onCourseClick(e) {
  155. let newUrl = `/pages/course/info?courseId=${e.courseId}`
  156. if (e.videoId) {
  157. newUrl = `${newUrl}&videoId=${e.videoId}`
  158. }
  159. uni.navigateTo({
  160. url: newUrl
  161. })
  162. },
  163. // 切换顶部 Tab
  164. handleChangeTopTab(index) {
  165. this.tabIndex = index;
  166. if (index == 1) {
  167. this.resetCourseStudyDataList()
  168. }
  169. },
  170. // 获取学习记录课程列表
  171. async getCourseStudyListMethos() {
  172. const res = await getCourseStudyList({courseType:1},
  173. this.recentPage.pageNum,
  174. this.recentPage.pageSize,
  175. );
  176. if (res.code === 200 && res.data.list.length > 0) {
  177. this.recentPage.total = res.data.total;
  178. this.recentList = [...this.recentList, ...res.data.list];
  179. } else {
  180. this.recentList = [];
  181. this.resetRecommendDataList();
  182. }
  183. },
  184. // 分页获取学习记录课程列表
  185. getPageCourseStudyData() {
  186. if (this.recentPage.total <= this.recentList.length) {
  187. return;
  188. }
  189. this.recentPage.pageNum++;
  190. this.getCourseStudyListMethos();
  191. },
  192. // 学习记录课程列表重置方法
  193. resetCourseStudyDataList() {
  194. this.recentPage.pageNum = 1;
  195. this.recentPage.total = 0;
  196. this.recentList = [];
  197. this.getCourseStudyListMethos();
  198. },
  199. // 获取精彩推荐课程列表
  200. async getRecommendData() {
  201. let params = {
  202. pageNum: this.recommendPage.pageNum,
  203. pageSize: this.recommendPage.pageSize,
  204. };
  205. const res = await courseListDataApi(params);
  206. if (res.code === 200 && res.data.list.length > 0) {
  207. this.recommendPage.total = res.data.total;
  208. this.recommendList = [...this.recommendList, ...res.data.list];
  209. }
  210. },
  211. // 分页获取精彩推荐课程列表
  212. getPageRecommendCoursesData() {
  213. return;
  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.resetYxxDataList();
  231. },
  232. // 获取央广原乡行-类型
  233. async getOneCourseTypeData() {
  234. const params = {
  235. pageNum: 1,
  236. pageSize: 50,
  237. isShow: 1,
  238. cateType: 1,
  239. yxxTag: 1
  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 getYxxCourseList() {
  248. let params = {
  249. pageNum: this.yxxPage.pageNum,
  250. pageSize: this.yxxPage.pageSize,
  251. subCateId: this.categoryIndex,
  252. yxxTag: 1,
  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.yxxPage.total = res.data.total;
  265. this.courseList = [...this.courseList, ...res.data.list];
  266. }
  267. },
  268. // 分页获取原乡行课程列表
  269. getPageYxxeCoursesData() {
  270. if (this.yxxPage.total <= this.courseList.length) {
  271. return;
  272. }
  273. this.yxxPage.pageNum++;
  274. this.getYxxCourseList();
  275. },
  276. // 原乡行课程列表重置方法
  277. resetYxxDataList() {
  278. this.yxxPage.pageNum = 1;
  279. this.yxxPage.total = 0;
  280. this.courseList = [];
  281. this.getYxxCourseList();
  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: 340rpx;
  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. font-family: PingFangSC, PingFang SC;
  465. font-weight: 400;
  466. font-size: 32rpx;
  467. color: rgba(0, 0, 0, 0.65);
  468. line-height: 44rpx;
  469. text-align: justify;
  470. overflow: hidden;
  471. text-overflow: ellipsis;
  472. display: -webkit-box;
  473. -webkit-line-clamp: 2;
  474. -webkit-box-orient: vertical;
  475. }
  476. .meta-icon {
  477. font-size: 24rpx;
  478. margin-right: 6rpx;
  479. color: #999;
  480. }
  481. .meta-count {
  482. margin-left: 10rpx;
  483. font-family: PingFangSC, PingFang SC;
  484. font-weight: 400;
  485. font-size: 32rpx;
  486. color: #666666;
  487. }
  488. .card-cover {
  489. position: relative;
  490. width: 296rpx;
  491. height: 222rpx;
  492. border-radius: 20rpx;
  493. overflow: hidden;
  494. flex-shrink: 0;
  495. }
  496. .cover-img {
  497. width: 100%;
  498. height: 100%;
  499. background: #BB6D6D;
  500. }
  501. .card-title {
  502. font-family: PingFangSC, PingFang SC;
  503. font-weight: 600;
  504. font-size: 36rpx;
  505. color: #222222;
  506. line-height: 50rpx;
  507. text-align: justify;
  508. overflow: hidden;
  509. text-overflow: ellipsis;
  510. display: -webkit-box;
  511. -webkit-line-clamp: 1;
  512. -webkit-box-orient: vertical;
  513. }
  514. .card-footer {
  515. flex: 1;
  516. padding-left: 24rpx;
  517. /* padding: 20rpx 24rpx; */
  518. display: flex;
  519. flex-direction: column;
  520. justify-content: space-between;
  521. min-width: 0;
  522. }
  523. .card-views {
  524. font-family: PingFangSC, PingFang SC;
  525. font-weight: 400;
  526. font-size: 32rpx;
  527. color: #666666;
  528. line-height: 44rpx;
  529. }
  530. .btn-watch {
  531. width: 168rpx;
  532. height: 64rpx;
  533. line-height: 60rpx;
  534. text-align: center;
  535. background: linear-gradient(135deg, #FF5267 0%, #FF233C 100%);
  536. border-radius: 32rpx;
  537. font-family: PingFangSC, PingFang SC;
  538. font-weight: 600;
  539. font-size: 32rpx;
  540. color: #FFFFFF;
  541. }
  542. /* 最近学习 - 按日期分组 */
  543. .recent-group {
  544. padding: 24rpx 24rpx 0;
  545. }
  546. .group-date {
  547. display: flex;
  548. align-items: center;
  549. margin-bottom: 24rpx;
  550. }
  551. .date-icon {
  552. width: 32rpx;
  553. height: 32rpx;
  554. margin-right: 8rpx;
  555. }
  556. .date-text {
  557. font-family: PingFangSC, PingFang SC;
  558. font-weight: 600;
  559. font-size: 40rpx;
  560. line-height: 56rpx;
  561. color: #222222;
  562. }
  563. .recent-card {
  564. display: flex;
  565. background: #fff;
  566. border-radius: 20rpx;
  567. overflow: hidden;
  568. padding: 20rpx;
  569. margin-bottom: 24rpx;
  570. }
  571. .recent-card:last-child {
  572. margin-bottom: 0;
  573. }
  574. .recent-thumb {
  575. position: relative;
  576. width: 296rpx;
  577. height: 222rpx;
  578. border-radius: 20rpx;
  579. overflow: hidden;
  580. flex-shrink: 0;
  581. }
  582. .thumb-img {
  583. width: 100%;
  584. height: 100%;
  585. background: #BB6D6D;
  586. }
  587. .recent-info {
  588. flex: 1;
  589. padding-left: 24rpx;
  590. /* padding: 20rpx 24rpx; */
  591. display: flex;
  592. flex-direction: column;
  593. justify-content: space-between;
  594. min-width: 0;
  595. }
  596. .recent-title {
  597. font-family: PingFangSC, PingFang SC;
  598. font-weight: 600;
  599. font-size: 36rpx;
  600. color: #222222;
  601. line-height: 50rpx;
  602. text-align: justify;
  603. overflow: hidden;
  604. text-overflow: ellipsis;
  605. display: -webkit-box;
  606. -webkit-line-clamp: 2;
  607. -webkit-box-orient: vertical;
  608. }
  609. .recent-progress {
  610. font-family: PingFangSC, PingFang SC;
  611. font-weight: 400;
  612. font-size: 32rpx;
  613. color: rgba(0, 0, 0, 0.65);
  614. line-height: 44rpx;
  615. }
  616. /* 空态 */
  617. .empty-state {
  618. display: flex;
  619. flex-direction: column;
  620. align-items: center;
  621. justify-content: center;
  622. padding: 80rpx 0 48rpx;
  623. /* background: linear-gradient(180deg, #fff5f5 0%, #fff 100%); */
  624. }
  625. .empty-icon {
  626. width: 310rpx;
  627. height: 260rpx;
  628. margin-bottom: 30rpx;
  629. }
  630. .empty-text {
  631. font-family: PingFangSC, PingFang SC;
  632. font-weight: 400;
  633. font-size: 36rpx;
  634. color: rgba(0, 0, 0, 0.25);
  635. line-height: 50rpx;
  636. }
  637. /* 为您精选 */
  638. .recommend-section {
  639. padding: 0 24rpx 32rpx;
  640. }
  641. .recommend-title {
  642. display: block;
  643. font-family: PingFangSC, PingFang SC;
  644. font-weight: 600;
  645. font-size: 40rpx;
  646. color: #222222;
  647. line-height: 56rpx;
  648. padding-bottom: 24rpx;
  649. }
  650. .bottom-placeholder {
  651. height: 120rpx;
  652. }
  653. </style>