video.vue 15 KB

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