onlineLecture.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. <template>
  2. <view class="container">
  3. <!-- 搜索栏 -->
  4. <view class="search-bar">
  5. <view class="search-input-wrapper">
  6. <text class="search-icon">🔍</text>
  7. <input
  8. class="search-input"
  9. v-model="keyword"
  10. placeholder="请输入关键字"
  11. @confirm="doSearch"
  12. />
  13. </view>
  14. </view>
  15. <!-- 标签栏 -->
  16. <view class="tabs-bar">
  17. <view class="tab-item"
  18. :class="{ active: currentTab === 'incomplete' }"
  19. @click="switchTab('incomplete')">
  20. 未完成
  21. </view>
  22. <view class="tab-item"
  23. :class="{ active: currentTab === 'completed' }"
  24. @click="switchTab('completed')">
  25. 已完成
  26. </view>
  27. </view>
  28. <!-- 讲座列表 -->
  29. <scroll-view class="content" scroll-y>
  30. <view class="lecture-card" v-for="(item, index) in lectureList" :key="index">
  31. <view class="card-thumbnail">
  32. <image class="thumbnail-img" :src="item.thumbnail" mode="aspectFill"></image>
  33. <view class="thumbnail-status" v-if="item.status === 'inProgress'">
  34. <text class="status-text">进行中</text>
  35. </view>
  36. <view class="thumbnail-date" v-else-if="item.scheduledTime">
  37. <text class="date-icon">🕐</text>
  38. <text class="date-text">{{ item.scheduledTime }}</text>
  39. </view>
  40. </view>
  41. <view class="card-content">
  42. <view class="card-title">{{ item.title }}</view>
  43. <view class="card-tags">
  44. <view class="tag-item">{{ item.category }}</view>
  45. <view class="tag-item">{{ item.type }}</view>
  46. </view>
  47. <view class="card-points">{{ item.points }} 积分</view>
  48. <view class="card-views" v-if="currentTab === 'completed'">
  49. <text class="eye-icon">👁</text>
  50. <text>{{ item.viewCount }}</text>
  51. </view>
  52. <view class="card-action">
  53. <view class="action-btn"
  54. v-if="item.status === 'inProgress' || item.status === 'scheduled'"
  55. @click.stop="openChannelPicker(item)">
  56. {{ item.status === 'inProgress' ? '继续开播' : '去开播' }}
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <view class="no-more">没有更多了~</view>
  62. </scroll-view>
  63. <!-- 选择开播渠道弹窗 -->
  64. <view class="channel-picker-popup" v-if="showChannelPicker" @click="showChannelPicker = false">
  65. <view class="channel-picker-content" @click.stop>
  66. <view class="picker-header">
  67. <view class="picker-title">选择开播渠道</view>
  68. <view class="picker-close" @click="showChannelPicker = false">×</view>
  69. </view>
  70. <!-- 电脑浏览器开播 -->
  71. <view class="channel-option">
  72. <view class="option-icon">💻</view>
  73. <view class="option-content">
  74. <view class="option-title">电脑浏览器开播</view>
  75. <view class="option-url-wrapper">
  76. <text class="option-url">{{ broadcastUrl }}</text>
  77. <view class="copy-btn" @click="copyUrl">复制链接</view>
  78. </view>
  79. <view class="option-tips">复制至谷歌浏览器,登录账号即可开播</view>
  80. </view>
  81. </view>
  82. <!-- 微信小程序开播 -->
  83. <view class="channel-option">
  84. <view class="option-icon wechat">💬</view>
  85. <view class="option-content">
  86. <view class="option-title">微信小程序开播</view>
  87. <view class="option-action">
  88. <view class="enter-btn" @click="enterMiniProgram">立即进入</view>
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </view>
  94. </view>
  95. </template>
  96. <script>
  97. import { getOnlineLectureList, getBroadcastUrl, enterMiniProgram } from '@/api-js/onlineLecture'
  98. export default {
  99. data() {
  100. return {
  101. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  102. keyword: '',
  103. currentTab: 'incomplete',
  104. showChannelPicker: false,
  105. broadcastUrl: 'https://www.test.coe.huahua...',
  106. currentLecture: null,
  107. lectureList: []
  108. }
  109. },
  110. onLoad() {
  111. this.loadData()
  112. },
  113. onReachBottom() {
  114. this.loadMore()
  115. },
  116. methods: {
  117. goBack() {
  118. uni.navigateBack()
  119. },
  120. doSearch() {
  121. this.loadData()
  122. },
  123. switchTab(tab) {
  124. this.currentTab = tab
  125. this.loadData()
  126. },
  127. async openChannelPicker(item) {
  128. this.currentLecture = item
  129. // try {
  130. // const res = await getBroadcastUrl({ lectureId: item.id })
  131. // if (res.code === 200 && res.data) {
  132. // this.broadcastUrl = res.data.url
  133. // }
  134. // } catch (e) {
  135. // console.error('获取开播链接失败', e)
  136. // }
  137. this.showChannelPicker = true
  138. },
  139. copyUrl() {
  140. uni.setClipboardData({
  141. data: this.broadcastUrl,
  142. success: () => {
  143. uni.showToast({
  144. icon: 'success',
  145. title: '链接已复制'
  146. })
  147. }
  148. })
  149. },
  150. async enterMiniProgram() {
  151. try {
  152. const res = await enterMiniProgram({ lectureId: this.currentLecture.id })
  153. if (res.code === 200 && res.data) {
  154. // 跳转到微信小程序
  155. uni.navigateToMiniProgram({
  156. appId: res.data.appId,
  157. path: res.data.path,
  158. success: () => {
  159. this.showChannelPicker = false
  160. }
  161. })
  162. }
  163. } catch (e) {
  164. uni.showToast({
  165. icon: 'none',
  166. title: '进入失败'
  167. })
  168. }
  169. },
  170. async loadData() {
  171. try {
  172. uni.showLoading({ title: '加载中...' })
  173. const res = await getOnlineLectureList({
  174. keyword: this.keyword,
  175. status: this.currentTab,
  176. page: 1,
  177. pageSize: 20
  178. })
  179. uni.hideLoading()
  180. if (res.code === 200 && res.data) {
  181. this.lectureList = res.data.list || this.getDefaultData()
  182. } else {
  183. this.lectureList = this.getDefaultData()
  184. }
  185. } catch (e) {
  186. uni.hideLoading()
  187. console.error('加载数据失败', e)
  188. this.lectureList = this.getDefaultData()
  189. }
  190. },
  191. async loadMore() {
  192. // 加载更多数据
  193. },
  194. getDefaultData() {
  195. if (this.currentTab === 'incomplete') {
  196. return [
  197. {
  198. id: 1,
  199. title: '康复医学概论',
  200. thumbnail: '/static/image/lecture1.png',
  201. category: '学术讲座',
  202. type: '单人讲座',
  203. points: '32.50',
  204. status: 'inProgress',
  205. scheduledTime: ''
  206. },
  207. {
  208. id: 2,
  209. title: '中医养生至冬病夏天治...',
  210. thumbnail: '/static/image/lecture2.png',
  211. category: '学术讲座',
  212. type: '单人讲座',
  213. points: '32.50',
  214. status: 'scheduled',
  215. scheduledTime: '05-12 12:00'
  216. },
  217. {
  218. id: 3,
  219. title: '康复医学概论',
  220. thumbnail: '/static/image/lecture3.png',
  221. category: '学术讲座',
  222. type: '单人讲座',
  223. points: '32.50',
  224. status: 'scheduled',
  225. scheduledTime: '05-24 16:00'
  226. }
  227. ]
  228. } else {
  229. return [
  230. {
  231. id: 4,
  232. title: '康复医学概论',
  233. thumbnail: '/static/image/lecture1.png',
  234. category: '学术讲座',
  235. type: '单人讲座',
  236. points: '32.50',
  237. viewCount: '123',
  238. scheduledTime: '05-12 12:00'
  239. },
  240. {
  241. id: 5,
  242. title: '康复医学概论',
  243. thumbnail: '/static/image/lecture2.png',
  244. category: '学术讲座',
  245. type: '单人讲座',
  246. points: '32.50',
  247. viewCount: '123',
  248. scheduledTime: '05-12 12:00'
  249. },
  250. {
  251. id: 6,
  252. title: '康复医学概论',
  253. thumbnail: '/static/image/lecture3.png',
  254. category: '学术讲座',
  255. type: '单人讲座',
  256. points: '32.50',
  257. viewCount: '123',
  258. scheduledTime: '05-12 12:00'
  259. }
  260. ]
  261. }
  262. }
  263. }
  264. }
  265. </script>
  266. <style lang="scss" scoped>
  267. .container {
  268. min-height: 100vh;
  269. background: #f5f5f5;
  270. display: flex;
  271. flex-direction: column;
  272. }
  273. .status-bar {
  274. width: 100%;
  275. background: #fff;
  276. }
  277. .header {
  278. position: relative;
  279. height: 88rpx;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. background: #fff;
  284. border-bottom: 1rpx solid #f0f0f0;
  285. .back-btn {
  286. position: absolute;
  287. left: 24rpx;
  288. width: 40rpx;
  289. height: 40rpx;
  290. image {
  291. width: 100%;
  292. height: 100%;
  293. }
  294. }
  295. .title {
  296. font-size: 36rpx;
  297. font-weight: bold;
  298. color: #333;
  299. }
  300. .header-right {
  301. position: absolute;
  302. right: 24rpx;
  303. display: flex;
  304. align-items: center;
  305. gap: 16rpx;
  306. .more-icon {
  307. font-size: 32rpx;
  308. color: #333;
  309. }
  310. }
  311. }
  312. .search-bar {
  313. padding: 24rpx;
  314. background: #fff;
  315. border-bottom: 1rpx solid #f0f0f0;
  316. .search-input-wrapper {
  317. display: flex;
  318. align-items: center;
  319. height: 72rpx;
  320. background: #f5f5f5;
  321. border-radius: 36rpx;
  322. padding: 0 24rpx;
  323. .search-icon {
  324. font-size: 32rpx;
  325. margin-right: 16rpx;
  326. color: #999;
  327. }
  328. .search-input {
  329. flex: 1;
  330. font-size: 28rpx;
  331. color: #333;
  332. }
  333. }
  334. }
  335. .tabs-bar {
  336. display: flex;
  337. background: #fff;
  338. border-bottom: 1rpx solid #f0f0f0;
  339. .tab-item {
  340. flex: 1;
  341. height: 88rpx;
  342. line-height: 88rpx;
  343. text-align: center;
  344. font-size: 28rpx;
  345. color: #666;
  346. position: relative;
  347. &.active {
  348. color: #388BFF;
  349. font-weight: bold;
  350. &::after {
  351. content: '';
  352. position: absolute;
  353. bottom: 0;
  354. left: 0;
  355. right: 0;
  356. height: 4rpx;
  357. background: #388BFF;
  358. }
  359. }
  360. }
  361. }
  362. .content {
  363. flex: 1;
  364. padding: 24rpx;
  365. }
  366. .lecture-card {
  367. display: flex;
  368. background: #fff;
  369. border-radius: 16rpx;
  370. padding: 24rpx;
  371. margin-bottom: 24rpx;
  372. .card-thumbnail {
  373. position: relative;
  374. width: 240rpx;
  375. height: 180rpx;
  376. border-radius: 12rpx;
  377. overflow: hidden;
  378. margin-right: 24rpx;
  379. flex-shrink: 0;
  380. .thumbnail-img {
  381. width: 100%;
  382. height: 100%;
  383. }
  384. .thumbnail-status {
  385. position: absolute;
  386. top: 8rpx;
  387. left: 8rpx;
  388. padding: 4rpx 12rpx;
  389. background: #FF9800;
  390. border-radius: 4rpx;
  391. .status-text {
  392. font-size: 20rpx;
  393. color: #fff;
  394. }
  395. }
  396. .thumbnail-date {
  397. position: absolute;
  398. top: 8rpx;
  399. left: 8rpx;
  400. display: flex;
  401. align-items: center;
  402. gap: 4rpx;
  403. padding: 4rpx 12rpx;
  404. background: rgba(0, 0, 0, 0.5);
  405. border-radius: 4rpx;
  406. .date-icon {
  407. font-size: 20rpx;
  408. }
  409. .date-text {
  410. font-size: 20rpx;
  411. color: #fff;
  412. }
  413. }
  414. }
  415. .card-content {
  416. flex: 1;
  417. display: flex;
  418. flex-direction: column;
  419. justify-content: space-between;
  420. .card-title {
  421. font-size: 30rpx;
  422. font-weight: bold;
  423. color: #333;
  424. margin-bottom: 12rpx;
  425. overflow: hidden;
  426. text-overflow: ellipsis;
  427. white-space: nowrap;
  428. }
  429. .card-tags {
  430. display: flex;
  431. align-items: center;
  432. gap: 12rpx;
  433. margin-bottom: 12rpx;
  434. .tag-item {
  435. padding: 4rpx 12rpx;
  436. background: #f5f5f5;
  437. border-radius: 4rpx;
  438. font-size: 22rpx;
  439. color: #666;
  440. }
  441. }
  442. .card-points {
  443. font-size: 26rpx;
  444. color: #333;
  445. margin-bottom: 12rpx;
  446. }
  447. .card-views {
  448. display: flex;
  449. align-items: center;
  450. gap: 4rpx;
  451. font-size: 24rpx;
  452. color: #999;
  453. margin-bottom: 12rpx;
  454. .eye-icon {
  455. font-size: 24rpx;
  456. }
  457. }
  458. .card-action {
  459. display: flex;
  460. justify-content: flex-end;
  461. .action-btn {
  462. padding: 12rpx 32rpx;
  463. background: #388BFF;
  464. border-radius: 8rpx;
  465. font-size: 26rpx;
  466. color: #fff;
  467. }
  468. }
  469. }
  470. }
  471. .no-more {
  472. text-align: center;
  473. padding: 48rpx 0;
  474. font-size: 24rpx;
  475. color: #999;
  476. }
  477. .channel-picker-popup {
  478. position: fixed;
  479. top: 0;
  480. left: 0;
  481. right: 0;
  482. bottom: 0;
  483. background: rgba(0, 0, 0, 0.5);
  484. z-index: 999;
  485. display: flex;
  486. align-items: center;
  487. justify-content: center;
  488. }
  489. .channel-picker-content {
  490. width: 90%;
  491. max-width: 600rpx;
  492. background: #fff;
  493. border-radius: 24rpx;
  494. padding: 24rpx;
  495. .picker-header {
  496. display: flex;
  497. align-items: center;
  498. justify-content: space-between;
  499. margin-bottom: 32rpx;
  500. .picker-title {
  501. font-size: 32rpx;
  502. font-weight: bold;
  503. color: #333;
  504. }
  505. .picker-close {
  506. width: 48rpx;
  507. height: 48rpx;
  508. display: flex;
  509. align-items: center;
  510. justify-content: center;
  511. font-size: 40rpx;
  512. color: #999;
  513. }
  514. }
  515. .channel-option {
  516. display: flex;
  517. align-items: flex-start;
  518. margin-bottom: 32rpx;
  519. &:last-child {
  520. margin-bottom: 0;
  521. }
  522. .option-icon {
  523. width: 64rpx;
  524. height: 64rpx;
  525. display: flex;
  526. align-items: center;
  527. justify-content: center;
  528. font-size: 48rpx;
  529. margin-right: 24rpx;
  530. flex-shrink: 0;
  531. &.wechat {
  532. background: #07C160;
  533. border-radius: 8rpx;
  534. }
  535. }
  536. .option-content {
  537. flex: 1;
  538. .option-title {
  539. font-size: 30rpx;
  540. font-weight: bold;
  541. color: #333;
  542. margin-bottom: 16rpx;
  543. }
  544. .option-url-wrapper {
  545. display: flex;
  546. align-items: center;
  547. gap: 16rpx;
  548. margin-bottom: 12rpx;
  549. .option-url {
  550. flex: 1;
  551. padding: 12rpx 16rpx;
  552. background: #f5f5f5;
  553. border-radius: 8rpx;
  554. font-size: 24rpx;
  555. color: #666;
  556. overflow: hidden;
  557. text-overflow: ellipsis;
  558. white-space: nowrap;
  559. }
  560. .copy-btn {
  561. padding: 12rpx 24rpx;
  562. background: #388BFF;
  563. border-radius: 8rpx;
  564. font-size: 24rpx;
  565. color: #fff;
  566. white-space: nowrap;
  567. }
  568. }
  569. .option-tips {
  570. font-size: 22rpx;
  571. color: #999;
  572. }
  573. .option-action {
  574. display: flex;
  575. justify-content: flex-end;
  576. .enter-btn {
  577. padding: 12rpx 32rpx;
  578. background: #388BFF;
  579. border-radius: 8rpx;
  580. font-size: 28rpx;
  581. color: #fff;
  582. }
  583. }
  584. }
  585. }
  586. }
  587. </style>