index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. <template>
  2. <view class="home-container">
  3. <!-- 顶部背景装饰 -->
  4. <view class="top-bg-decoration"></view>
  5. <!-- 自定义导航栏 -->
  6. <view class="nav-bar-fixed" :style="{ paddingTop: statusBarHeight + 'px' }">
  7. <view class="nav-content">
  8. <view class="product-name">产品名称</view>
  9. <view class="search-input-box" @click="toSearch">
  10. <image class="search-icon" src="/static/search_gray.png" mode="aspectFit"></image>
  11. <text class="placeholder">搜索课程</text>
  12. </view>
  13. </view>
  14. </view>
  15. <!-- 内容区域 -->
  16. <scroll-view class="main-content-scroll" scroll-y :style="{ paddingTop: (statusBarHeight + 44) + 'px' }">
  17. <!-- Banner 轮播图 -->
  18. <view class="banner-section">
  19. <swiper class="banner-swiper" :indicator-dots="true" circular autoplay interval="3000" duration="500"
  20. indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff">
  21. <swiper-item v-for="(item, index) in advList" :key="index" @click="handleAdvClick(item)">
  22. <view class="banner-card">
  23. <image v-if="item.imageUrl" class="banner-image" :src="item.imageUrl" mode="aspectFill"></image>
  24. </view>
  25. </swiper-item>
  26. </swiper>
  27. </view>
  28. <!-- 导航网格 -->
  29. <view class="nav-grid">
  30. <view class="nav-item" v-for="(item, index) in navMenus" :key="index" @click="menuClick(item)">
  31. <view class="nav-icon-wrap">
  32. <image class="nav-icon" :src="item.icon" mode="aspectFit"></image>
  33. </view>
  34. <text class="nav-title">{{ item.title }}</text>
  35. </view>
  36. </view>
  37. <!-- 热门好课 -->
  38. <view class="section-container">
  39. <view class="section-header">
  40. <text class="section-title">热门好课</text>
  41. <view class="more-link" @click="goClassList(1)">
  42. <text>更多</text>
  43. <image class="arrow-icon" src="/static/right_arrow_right.png" mode="aspectFit"></image>
  44. </view>
  45. </view>
  46. <!-- 特色大课 -->
  47. <view class="featured-course-card" v-if="featuredCourse" @click="goClass(featuredCourse.courseId, 1)">
  48. <view class="cover-wrap">
  49. <image class="course-cover" :src="featuredCourse.imgUrl || '/static/bg_video.png'" mode="aspectFill"></image>
  50. <view class="tag-yangsheng">养生</view>
  51. <view class="lesson-badge">
  52. <view class="left">
  53. <image class="left-icon" src="/static/course_number_bg.png" mode="aspectFit"></image>
  54. <image class="play-icon-small" src="/static/course_number.png" mode="aspectFit"></image>
  55. <text>第1讲</text>
  56. </view>
  57. <text>共{{ featuredCourse.lessonCount }}节课</text>
  58. <image class="arrow-right-small" src="/static/right_arrow_white.png" mode="aspectFit"></image>
  59. </view>
  60. </view>
  61. <view class="course-info">
  62. <view class="course-title">{{ featuredCourse.courseName }}</view>
  63. <view class="course-footer">
  64. <view class="author-info">
  65. <image class="author-avatar" :src="featuredCourse.authorAvatar || '/static/avatar.png'" mode="aspectFill"></image>
  66. <text class="author-name">{{ featuredCourse.authorName }}</text>
  67. </view>
  68. <view class="playback-count">{{ featuredCourse.playCount }}次播放</view>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 课程列表 -->
  73. <view class="course-list">
  74. <view class="course-item" v-for="(item, index) in otherCourses" :key="index" @click="goClass(item.courseId, 1)">
  75. <image class="item-thumb" :src="item.imgUrl || '/static/course_img.png'" mode="aspectFill"></image>
  76. <view class="item-content">
  77. <view class="item-title ellipsis-2">{{ item.courseName }}</view>
  78. <view class="item-footer">
  79. <text class="item-playback">{{ item.playCount }}次播放</text>
  80. <view class="study-btn">去学习</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. <!-- 底部间距 -->
  87. <view class="bottom-safe-area"></view>
  88. </scroll-view>
  89. <!-- 原有的弹窗组件保留 -->
  90. <view class="popup-box" v-if="activityShow">
  91. <view class="info-mask" @tap="closeActivity()"></view>
  92. <view class="info-form">
  93. <image :src="activity.logoUrl" @tap="showActivity()" />
  94. </view>
  95. </view>
  96. <z-modal :show="tuiModalControl" placeholderText="请输入邀请码" :btnGroup="btnGroup" :contentType="2"
  97. titleText="填写邀请码" @cancle="cancleTui" @sure="submitTui"></z-modal>
  98. </view>
  99. </template>
  100. <script>
  101. import { courseList } from '@/api/class.js'
  102. import zModal from '@/components/z-modal/z-modal.vue'
  103. import { getStoreActivity } from '@/api/activity.js'
  104. import { getIndexData, bindPromoter } from '@/api/index'
  105. import { getUserInfo } from '@/api/user'
  106. export default {
  107. components: {
  108. zModal
  109. },
  110. data() {
  111. return {
  112. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  113. advList: [
  114. { imageUrl: '', advUrl: '', showType: 1 },
  115. { imageUrl: '', advUrl: '', showType: 1 }
  116. ],
  117. navMenus: [
  118. { title: '药品商城', icon: '/static/menu1.png', linkUrl: '/pages/shopping/index', linkType: 1 },
  119. { title: '热门好课', icon: '/static/menu2.png',linkUrl: '/pages_course/teacherClassroom?type=1', linkType: 1 },
  120. { title: '我的课程', icon: '/static/menu3.png', linkUrl: '/pages_course/teacherClassroom?type=2', linkType: 1 },
  121. { title: '专业客服', icon: '/static/menu4.png', linkUrl: '/pages/message/index', linkType: 1 }
  122. ],
  123. featuredCourse: {
  124. courseId: 4,
  125. courseName: '你和合理膳食还有多少距离?',
  126. imgUrl: '/static/bg_video.png',
  127. lessonCount: 30,
  128. authorName: '健康大讲堂',
  129. authorAvatar: '/static/avatar.png',
  130. playCount: '8.1万'
  131. },
  132. otherCourses: [
  133. { courseId: 5, courseName: '脑梗塞是帕金森病的发病因素吗?', imgUrl: '/static/famous_doctor_img.png', playCount: '25862' },
  134. { courseId: 6, courseName: '合理的运动与健康', imgUrl: '/static/famous_doctor_img2.png', playCount: '25862' },
  135. { courseId: 7, courseName: '合理的运动与健康', imgUrl: '/static/course_img.png', playCount: '25862' },
  136. { courseId: 8, courseName: '合理的运动与健康', imgUrl: '/static/famous_doctor_img.png', playCount: '25862' }
  137. ],
  138. activityShow: false,
  139. activity: null,
  140. tuiModalControl: false,
  141. btnGroup: [
  142. { text: '取消', color: '#FFFFFF', bgColor: '#999999', width: '150rpx', height: '80rpx', shape: 'fillet', eventName: 'cancle' },
  143. { text: '确定', color: '#FFFFFF', bgColor: '#5B37FD', width: '150rpx', height: '80rpx', shape: 'fillet', eventName: 'sure' }
  144. ]
  145. }
  146. },
  147. onLoad() {
  148. this.getIndexData();
  149. this.getCourseList();
  150. },
  151. methods: {
  152. getCourseList() {
  153. courseList().then(res => {
  154. if (res.code == 200 && res.data && res.data.length > 0) {
  155. // 实际数据更新
  156. }
  157. });
  158. },
  159. getIndexData() {
  160. getIndexData().then(res => {
  161. if (res.code == 200 && res.data.advList && res.data.advList.length > 0) {
  162. this.advList = res.data.advList;
  163. }
  164. });
  165. },
  166. handleAdvClick(item) {
  167. if (item.advUrl) {
  168. uni.navigateTo({ url: item.advUrl });
  169. }
  170. },
  171. menuClick(item) {
  172. if (item.linkType == 1) {
  173. uni.navigateTo({ url: item.linkUrl });
  174. }
  175. },
  176. goClass(id, type) {
  177. uni.navigateTo({
  178. url: '/pages_course/learn?courseId=' + id + '&type=' + type
  179. });
  180. },
  181. goClassList(type) {
  182. uni.navigateTo({
  183. url: '/pages_course/teacherClassroom?type=' + type
  184. });
  185. },
  186. toSearch() {
  187. uni.navigateTo({ url: './productSearch' });
  188. },
  189. closeActivity() { this.activityShow = false; },
  190. showActivity() {
  191. this.activityShow = false;
  192. uni.navigateTo({ url: '/pages_shopping/shopping/activityDetails?activityId=' + this.activity.activityId });
  193. },
  194. cancleTui() { this.tuiModalControl = false; },
  195. submitTui(e) {
  196. if (!e.inputText) {
  197. uni.showToast({ icon: 'none', title: "请输入邀请码" });
  198. return;
  199. }
  200. bindPromoter({ userCode: e.inputText }).then(res => {
  201. if (res.code == 200) {
  202. uni.showToast({ icon: 'none', title: res.msg });
  203. this.tuiModalControl = false;
  204. }
  205. });
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .home-container {
  212. min-height: 100vh;
  213. background-color: #FFFFFF;
  214. position: relative;
  215. }
  216. .top-bg-decoration {
  217. position: absolute;
  218. top: 0;
  219. left: 0;
  220. width: 100%;
  221. height: 450rpx;
  222. background: linear-gradient(180deg, #F0F2FF 0%, rgba(255, 255, 255, 0) 100%);
  223. z-index: 0;
  224. }
  225. /* 导航栏 */
  226. .nav-bar-fixed {
  227. position: fixed;
  228. top: 0;
  229. left: 0;
  230. width: 100%;
  231. z-index: 100;
  232. background-color: transparent;
  233. .nav-content {
  234. height: 44px;
  235. display: flex;
  236. align-items: center;
  237. padding: 0 30rpx;
  238. .product-name {
  239. font-size: 42rpx;
  240. font-weight: bold;
  241. color: #1A1A1A;
  242. margin-right: 24rpx;
  243. flex-shrink: 0;
  244. }
  245. .search-input-box {
  246. width: 302rpx;
  247. height: 68rpx;
  248. background: #FFFFFF;
  249. border-radius: 34rpx;
  250. display: flex;
  251. align-items: center;
  252. padding: 0 28rpx;
  253. margin-right: 24rpx;
  254. box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  255. .search-icon {
  256. width: 30rpx;
  257. height: 30rpx;
  258. margin-right: 14rpx;
  259. }
  260. .placeholder {
  261. font-size: 28rpx;
  262. color: #BBBBBB;
  263. }
  264. }
  265. }
  266. }
  267. .main-content-scroll {
  268. height: 100vh;
  269. position: relative;
  270. z-index: 1;
  271. }
  272. /* Banner */
  273. .banner-section {
  274. padding: 20rpx 30rpx;
  275. .banner-swiper {
  276. height: 233rpx;
  277. border-radius: 28rpx;
  278. overflow: hidden;
  279. }
  280. .banner-card {
  281. width: 100%;
  282. height: 100%;
  283. background: linear-gradient(135deg, #FF4D4D 0%, #FF8533 100%);
  284. position: relative;
  285. }
  286. .banner-image {
  287. position: absolute;
  288. width: 100%;
  289. height: 100%;
  290. z-index: 1;
  291. }
  292. }
  293. /* 导航网格 */
  294. .nav-grid {
  295. display: flex;
  296. justify-content: space-between;
  297. padding: 40rpx 50rpx;
  298. .nav-item {
  299. display: flex;
  300. flex-direction: column;
  301. align-items: center;
  302. .nav-icon-wrap {
  303. width: 104rpx;
  304. height: 104rpx;
  305. display: flex;
  306. align-items: center;
  307. justify-content: center;
  308. margin-bottom: 20rpx;
  309. .nav-icon {
  310. width:100%;
  311. height: 100%;
  312. }
  313. }
  314. .nav-title {
  315. font-size: 28rpx;
  316. color: #333333;
  317. font-weight: 500;
  318. }
  319. }
  320. }
  321. /* 章节容器 */
  322. .section-container {
  323. padding: 20rpx 30rpx;
  324. .section-header {
  325. display: flex;
  326. justify-content: space-between;
  327. align-items: center;
  328. margin-bottom: 30rpx;
  329. .section-title {
  330. font-size: 38rpx;
  331. font-weight: bold;
  332. color: #1A1A1A;
  333. }
  334. .more-link {
  335. display: flex;
  336. align-items: center;
  337. font-size: 28rpx;
  338. color: #BBBBBB;
  339. .arrow-icon {
  340. width: 28rpx;
  341. height: 28rpx;
  342. margin-left: 4rpx;
  343. }
  344. }
  345. }
  346. }
  347. /* 特色大课卡片 */
  348. .featured-course-card {
  349. background: #FFFFFF;
  350. border-radius: 28rpx;
  351. overflow: hidden;
  352. box-shadow: 0 6rpx 30rpx rgba(0, 0, 0, 0.06);
  353. margin-bottom: 40rpx;
  354. .cover-wrap {
  355. position: relative;
  356. width: 100%;
  357. height: 420rpx;
  358. .course-cover {
  359. width: 100%;
  360. height: 100%;
  361. }
  362. .tag-yangsheng {
  363. position: absolute;
  364. top: 0;
  365. left: 0;
  366. padding: 10rpx 28rpx;
  367. background: #5B37FD;
  368. color: #FFFFFF;
  369. font-size: 26rpx;
  370. border-bottom-right-radius: 24rpx;
  371. }
  372. .lesson-badge {
  373. padding-right: 16rpx;
  374. position: absolute;
  375. bottom: 24rpx;
  376. right: 24rpx;
  377. background: rgba(0,0,0,0.5);
  378. backdrop-filter: blur(6px);
  379. border-radius: 24rpx;
  380. display: flex;
  381. height: 48rpx;
  382. align-items: center;
  383. color: #FFFFFF;
  384. font-size: 26rpx;
  385. .left{
  386. display: flex;
  387. align-items: center;
  388. padding-left: 16rpx;
  389. width: 144rpx;
  390. height: 48rpx;
  391. position: relative;
  392. .left-icon{
  393. position: absolute;
  394. left: 0;
  395. top: 0;
  396. width: 144rpx;
  397. height: 48rpx;
  398. z-index: -1;
  399. }
  400. .play-icon-small {
  401. width: 30rpx;
  402. height: 30rpx;
  403. margin-right: 4rpx;
  404. }
  405. }
  406. .arrow-right-small {
  407. width: 20rpx;
  408. height: 20rpx;
  409. }
  410. }
  411. }
  412. .course-info {
  413. padding: 30rpx;
  414. background: #68686A;
  415. color: #fff;
  416. .course-title {
  417. font-size: 36rpx;
  418. font-weight: bold;
  419. margin-bottom: 28rpx;
  420. }
  421. .course-footer {
  422. display: flex;
  423. justify-content: space-between;
  424. align-items: center;
  425. .author-info {
  426. display: flex;
  427. align-items: center;
  428. .author-avatar {
  429. width: 52rpx;
  430. height: 52rpx;
  431. border-radius: 50%;
  432. margin-right: 16rpx;
  433. }
  434. .author-name {
  435. font-size: 28rpx;
  436. }
  437. }
  438. .playback-count {
  439. font-size: 28rpx;
  440. }
  441. }
  442. }
  443. }
  444. /* 课程列表 */
  445. .course-list {
  446. .course-item {
  447. display: flex;
  448. padding: 30rpx 0;
  449. &:last-child {
  450. border-bottom: none;
  451. }
  452. .item-thumb {
  453. width: 260rpx;
  454. height: 160rpx;
  455. border-radius: 20rpx;
  456. margin-right: 30rpx;
  457. }
  458. .item-content {
  459. flex: 1;
  460. display: flex;
  461. flex-direction: column;
  462. justify-content: space-between;
  463. .item-title {
  464. font-size: 32rpx;
  465. color: #1A1A1A;
  466. font-weight: bold;
  467. line-height: 1.4;
  468. }
  469. .item-footer {
  470. display: flex;
  471. justify-content: space-between;
  472. align-items: center;
  473. .item-playback {
  474. font-size: 26rpx;
  475. color: #CCCCCC;
  476. }
  477. .study-btn {
  478. padding: 12rpx 40rpx;
  479. background: #5B37FD;
  480. color: #FFFFFF;
  481. font-size: 28rpx;
  482. border-radius: 36rpx;
  483. font-weight: 500;
  484. }
  485. }
  486. }
  487. }
  488. }
  489. .ellipsis-2 {
  490. display: -webkit-box;
  491. -webkit-box-orient: vertical;
  492. -webkit-line-clamp: 2;
  493. overflow: hidden;
  494. }
  495. .bottom-safe-area {
  496. height: 160rpx;
  497. }
  498. </style>