index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <template>
  2. <view class="live-container">
  3. <!-- 状态栏占位 -->
  4. <view class="status_bar" :style="{ height: statusBarHeight + 'px' }"></view>
  5. <!-- 顶部导航栏 -->
  6. <view class="nav-bar">
  7. <text class="nav-title">讲堂</text>
  8. <view class="search-box" @click="toSearch">
  9. <image class="search-icon" src="/static/search_gray.png" mode="aspectFit"></image>
  10. <text class="placeholder">搜索课程</text>
  11. </view>
  12. <!-- 右侧留出微信胶囊位 -->
  13. <view class="capsule-placeholder"></view>
  14. </view>
  15. <!-- 分类切换栏 -->
  16. <view class="category-wrapper">
  17. <scroll-view class="category-scroll" scroll-x :show-scrollbar="false">
  18. <view class="category-list">
  19. <view
  20. v-for="(item, index) in categories"
  21. :key="index"
  22. class="category-item"
  23. :class="{ active: currentCateIndex === index }"
  24. @click="changeCate(index)"
  25. >
  26. <text class="cate-name">{{ item }}</text>
  27. <view class="active-line" v-if="currentCateIndex === index"></view>
  28. </view>
  29. </view>
  30. </scroll-view>
  31. <view class="expand-btn">
  32. <image class="arrow-icon" src="/static/icon_arrow_down.png" mode="aspectFit"></image>
  33. </view>
  34. </view>
  35. <!-- 课程列表 -->
  36. <scroll-view class="course-scroll" scroll-y @scrolltolower="loadMore">
  37. <view class="course-list">
  38. <view
  39. class="course-item"
  40. v-for="(item, index) in courseList"
  41. :key="index"
  42. @click="goDetail(item)"
  43. >
  44. <image class="course-thumb" :src="item.image || '/static/course_img.png'" mode="aspectFill"></image>
  45. <view class="course-content">
  46. <view class="course-title-wrap">
  47. <text class="course-title ellipsis-2">{{ item.title }}</text>
  48. </view>
  49. <view class="course-footer">
  50. <text class="play-count">{{ item.playCount }}次播放</text>
  51. <view class="study-btn">去学习</view>
  52. </view>
  53. </view>
  54. </view>
  55. </view>
  56. <!-- 底部占位,防止被系统tabbar遮挡 -->
  57. <view class="bottom-placeholder"></view>
  58. </scroll-view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  66. currentCateIndex: 0,
  67. categories: ['热门好课', '养生', '健康饮食', '乐器', '慢性病', '心理健康', '运动健身', '家庭教育'],
  68. courseList: [
  69. {
  70. id: 1,
  71. title: "脑梗塞是帕金森病的发病因素吗?",
  72. image: "/static/famous_doctor_img.png",
  73. playCount: "25862"
  74. },
  75. {
  76. id: 2,
  77. title: "合理的运动与健康",
  78. image: "/static/famous_doctor_img2.png",
  79. playCount: "25862"
  80. },
  81. {
  82. id: 3,
  83. title: "合理的运动与健康",
  84. image: "/static/course_img.png",
  85. playCount: "25862"
  86. },
  87. {
  88. id: 4,
  89. title: "合理的运动与健康",
  90. image: "/static/famous_doctor_img.png",
  91. playCount: "25862"
  92. },
  93. {
  94. id: 5,
  95. title: "合理的运动与健康",
  96. image: "/static/famous_doctor_img2.png",
  97. playCount: "25862"
  98. },
  99. {
  100. id: 6,
  101. title: "合理的运动与健康",
  102. image: "/static/course_img.png",
  103. playCount: "25862"
  104. }
  105. ]
  106. };
  107. },
  108. methods: {
  109. changeCate(index) {
  110. this.currentCateIndex = index;
  111. // 这里通常会重新请求对应分类的课程数据
  112. },
  113. toSearch() {
  114. uni.navigateTo({
  115. url: '/pages/home/productSearch'
  116. });
  117. },
  118. goDetail(item) {
  119. uni.navigateTo({
  120. url: `/pages_course/learn?courseId=${item.id}&type=1`
  121. });
  122. },
  123. loadMore() {
  124. console.log('加载更多...');
  125. }
  126. }
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. .live-container {
  131. width: 100%;
  132. height: 100vh;
  133. display: flex;
  134. flex-direction: column;
  135. background-color: #ffffff;
  136. }
  137. .status_bar {
  138. width: 100%;
  139. background-color: #ffffff;
  140. }
  141. .nav-bar {
  142. height: 44px;
  143. display: flex;
  144. align-items: center;
  145. padding: 0 30rpx;
  146. background-color: #ffffff;
  147. .nav-title {
  148. font-size: 44rpx;
  149. font-weight: bold;
  150. color: #1A1A1A;
  151. margin-right: 30rpx;
  152. }
  153. .search-box {
  154. flex: 1;
  155. height: 72rpx;
  156. background: #F5F6F8;
  157. border-radius: 36rpx;
  158. display: flex;
  159. align-items: center;
  160. padding: 0 24rpx;
  161. margin-right: 20rpx;
  162. .search-icon {
  163. width: 32rpx;
  164. height: 32rpx;
  165. margin-right: 12rpx;
  166. }
  167. .placeholder {
  168. font-size: 28rpx;
  169. color: #999999;
  170. }
  171. }
  172. .capsule-placeholder {
  173. width: 180rpx; // 模拟微信胶囊宽度
  174. }
  175. }
  176. .category-wrapper {
  177. display: flex;
  178. align-items: center;
  179. padding: 20rpx 0 10rpx;
  180. background-color: #ffffff;
  181. .category-scroll {
  182. flex: 1;
  183. white-space: nowrap;
  184. padding-left: 30rpx;
  185. .category-list {
  186. display: inline-flex;
  187. align-items: center;
  188. .category-item {
  189. margin-right: 50rpx;
  190. position: relative;
  191. display: flex;
  192. flex-direction: column;
  193. align-items: center;
  194. padding-bottom: 15rpx;
  195. .cate-name {
  196. font-size: 32rpx;
  197. color: #666666;
  198. transition: all 0.3s;
  199. }
  200. .active-line {
  201. position: absolute;
  202. bottom: 0;
  203. left: 50%;
  204. transform: translateX(-50%);
  205. width: 60rpx;
  206. height: 6rpx;
  207. background: #5B37FD;
  208. border-radius: 3rpx;
  209. }
  210. &.active {
  211. .cate-name {
  212. color: #1A1A1A;
  213. font-weight: bold;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. .expand-btn {
  220. width: 80rpx;
  221. height: 60rpx;
  222. display: flex;
  223. align-items: center;
  224. justify-content: center;
  225. background: linear-gradient(to right, rgba(255,255,255,0), #fff 20%);
  226. .arrow-icon {
  227. width: 32rpx;
  228. height: 32rpx;
  229. opacity: 0.4;
  230. }
  231. }
  232. }
  233. .course-scroll {
  234. flex: 1;
  235. overflow: hidden;
  236. }
  237. .course-list {
  238. padding: 20rpx 30rpx;
  239. .course-item {
  240. display: flex;
  241. padding: 24rpx 0;
  242. &:last-child {
  243. border-bottom: none;
  244. }
  245. .course-thumb {
  246. width: 240rpx;
  247. height: 150rpx;
  248. border-radius: 12rpx;
  249. margin-right: 24rpx;
  250. flex-shrink: 0;
  251. }
  252. .course-content {
  253. flex: 1;
  254. display: flex;
  255. flex-direction: column;
  256. justify-content: space-between;
  257. .course-title-wrap {
  258. .course-title {
  259. font-size: 32rpx;
  260. color: #1A1A1A;
  261. font-weight: 500;
  262. line-height: 1.4;
  263. }
  264. }
  265. .course-footer {
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. .play-count {
  270. font-size: 24rpx;
  271. color: #CCCCCC;
  272. }
  273. .study-btn {
  274. padding: 10rpx 36rpx;
  275. background: #5B37FD;
  276. color: #FFFFFF;
  277. font-size: 26rpx;
  278. border-radius: 32rpx;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. .bottom-placeholder {
  285. height: 40rpx;
  286. }
  287. .ellipsis-2 {
  288. display: -webkit-box;
  289. -webkit-box-orient: vertical;
  290. -webkit-line-clamp: 2;
  291. overflow: hidden;
  292. }
  293. </style>