index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. <template>
  2. <div class="home-wrap">
  3. <div class="play-container">
  4. <div
  5. v-if="configBg && configBg !== ''"
  6. class="bg-img"
  7. :style="{ backgroundImage: `url(${configBg})` }"
  8. ></div>
  9. <video
  10. v-if="configVideo && configVideo !== ''"
  11. class="bg-video"
  12. :src="configVideo"
  13. muted
  14. autoplay
  15. loop
  16. ></video>
  17. <div class="slider-wrap">
  18. <div
  19. v-for="(item, index) in interactionList"
  20. :key="index"
  21. >
  22. <Slider
  23. v-if="item.length"
  24. :list="item"
  25. :width="docW"
  26. :speed="60"
  27. :direction="index % 2 === 0 ? 'l-r' : 'r-l'"
  28. :customStyle="{ margin: '0 auto' }"
  29. ></Slider>
  30. </div>
  31. </div>
  32. <div class="container">
  33. <div
  34. v-loading="videoLoading"
  35. class="left"
  36. ref="videoWrapTmpRef"
  37. @click="showJoinBtn = !showJoinBtn"
  38. >
  39. <div
  40. v-if="
  41. currentLiveRoom?.live_room?.cdn === LiveRoomUseCDNEnum.yes ||
  42. [
  43. LiveRoomTypeEnum.tencent_css,
  44. LiveRoomTypeEnum.tencent_css_pk,
  45. ].includes(currentLiveRoom?.live_room?.type!)
  46. "
  47. class="cdn-ico"
  48. >
  49. <div class="txt">CDN</div>
  50. </div>
  51. <div
  52. class="cover"
  53. :style="{
  54. backgroundImage: `url(${
  55. currentLiveRoom?.live_room?.cover_img ||
  56. currentLiveRoom?.user?.avatar
  57. })`,
  58. }"
  59. ></div>
  60. <div
  61. v-if="currentLiveRoom?.live_room?.flv_url"
  62. ref="remoteVideoRef"
  63. ></div>
  64. <template v-if="currentLiveRoom">
  65. <VideoControls
  66. @click.stop
  67. :resolution="videoResolution"
  68. @refresh="handleRefresh"
  69. ></VideoControls>
  70. <div
  71. class="join-btn"
  72. :class="{
  73. show: showJoinBtn,
  74. }"
  75. >
  76. <div
  77. class="btn"
  78. @click="joinRoom({ roomId: currentLiveRoom.live_room?.id! })"
  79. >
  80. 进入直播
  81. </div>
  82. </div>
  83. </template>
  84. </div>
  85. <div class="right">
  86. <div
  87. v-if="topLiveRoomList.length"
  88. class="list"
  89. >
  90. <div
  91. v-for="(item, index) in topLiveRoomList"
  92. :key="index"
  93. :class="{
  94. item: 1,
  95. active: item.live_room_id === currentLiveRoom?.live_room_id,
  96. }"
  97. :style="{
  98. backgroundImage: `url(${
  99. item.live_room?.cover_img || item?.user?.avatar
  100. })`,
  101. }"
  102. @click="changeLiveRoom(item)"
  103. >
  104. <PullAuthTip
  105. v-if="
  106. item.live_room?.pull_is_should_auth ===
  107. LiveRoomPullIsShouldAuthEnum.yes
  108. "
  109. ></PullAuthTip>
  110. <div class="hidden">
  111. <div
  112. class="cdn-ico"
  113. v-if="
  114. item?.live_room?.cdn === LiveRoomUseCDNEnum.yes ||
  115. [
  116. LiveRoomTypeEnum.tencent_css,
  117. LiveRoomTypeEnum.tencent_css_pk,
  118. ].includes(item.live_room?.type!)
  119. "
  120. >
  121. <div class="txt">CDN</div>
  122. </div>
  123. </div>
  124. <div
  125. class="border"
  126. :style="{
  127. opacity:
  128. item.live_room_id === currentLiveRoom?.live_room_id ? 1 : 0,
  129. }"
  130. ></div>
  131. <div
  132. v-if="item.live_room_id === currentLiveRoom?.live_room_id"
  133. class="triangle"
  134. ></div>
  135. <div class="txt">{{ item.live_room?.name }}</div>
  136. </div>
  137. </div>
  138. <div
  139. v-else
  140. class="none"
  141. >
  142. {{ t('home.noliveRoomTip') }}
  143. </div>
  144. </div>
  145. </div>
  146. </div>
  147. <div class="area-container">
  148. <div class="area-item">
  149. <div class="title">{{ t('home.recommendLive') }}</div>
  150. <div class="live-room-list">
  151. <div
  152. v-for="(iten, indey) in otherLiveRoomList"
  153. :key="indey"
  154. class="live-room"
  155. @click="
  156. joinRoom({
  157. roomId: iten.live_room?.id!,
  158. })
  159. "
  160. >
  161. <div
  162. class="cover"
  163. :style="{
  164. backgroundImage: `url('${
  165. iten?.live_room?.cover_img || iten?.user?.avatar
  166. }')`,
  167. }"
  168. >
  169. <PullAuthTip
  170. v-if="
  171. iten.live_room?.pull_is_should_auth ===
  172. LiveRoomPullIsShouldAuthEnum.yes
  173. "
  174. ></PullAuthTip>
  175. <div
  176. v-if="
  177. iten?.live_room?.cdn === LiveRoomUseCDNEnum.yes ||
  178. [
  179. LiveRoomTypeEnum.tencent_css,
  180. LiveRoomTypeEnum.tencent_css_pk,
  181. ].includes(iten.live_room?.type!)
  182. "
  183. class="cdn-ico"
  184. >
  185. <div class="txt">CDN</div>
  186. </div>
  187. <div class="txt">{{ iten?.user?.username }}</div>
  188. </div>
  189. <div class="desc">{{ iten?.live_room?.name }}</div>
  190. </div>
  191. <div
  192. v-if="!otherLiveRoomList.length"
  193. class="null"
  194. >
  195. {{ t('common.nonedata') }}
  196. </div>
  197. </div>
  198. </div>
  199. </div>
  200. <div class="foot">*{{ t('home.copyrightTip') }}~</div>
  201. </div>
  202. </template>
  203. <script lang="ts" setup>
  204. import { onMounted, ref } from 'vue';
  205. import { useI18n } from 'vue-i18n';
  206. import { useRoute, useRouter } from 'vue-router';
  207. import { fetchLiveList } from '@/api/live';
  208. import { fetchFindLiveConfigByKey } from '@/api/liveConfig';
  209. import { sliderList } from '@/constant';
  210. import { usePull } from '@/hooks/use-pull';
  211. import { ILive, LiveLineEnum } from '@/interface';
  212. import { routerName } from '@/router';
  213. import { useAppStore } from '@/store/app';
  214. import {
  215. LiveRoomIsShowEnum,
  216. LiveRoomPullIsShouldAuthEnum,
  217. LiveRoomTypeEnum,
  218. LiveRoomUseCDNEnum,
  219. } from '@/types/ILiveRoom';
  220. const route = useRoute();
  221. const router = useRouter();
  222. const appStore = useAppStore();
  223. const canvasRef = ref<Element>();
  224. const showJoinBtn = ref(false);
  225. const topNums = ref(6);
  226. const configBg = ref('');
  227. const configVideo = ref();
  228. // const configVideo = ref(
  229. // 'https://www.xdyun.com/resldmnqcom/ldq_website/all_ldy/cloudphone_xdyun_ldy_mobile/mobile/assets/xd-video-6c9bcd.mp4'
  230. // );
  231. const topLiveRoomList = ref<ILive[]>([]);
  232. const otherLiveRoomList = ref<ILive[]>([]);
  233. const currentLiveRoom = ref<ILive>();
  234. const interactionList = ref<any[]>([]);
  235. const videoWrapTmpRef = ref<HTMLDivElement>();
  236. const remoteVideoRef = ref<HTMLDivElement>();
  237. const docW = document.documentElement.clientWidth;
  238. const { t } = useI18n();
  239. const {
  240. videoWrapRef,
  241. videoLoading,
  242. roomLiving,
  243. videoResolution,
  244. handleStopDrawing,
  245. handlePlay,
  246. } = usePull(route.params.roomId as string);
  247. onMounted(() => {
  248. handleSlideList();
  249. getLiveRoomList();
  250. getBg();
  251. videoWrapRef.value = videoWrapTmpRef.value;
  252. });
  253. function handleSlideList() {
  254. const row = 2;
  255. const res: any[] = [];
  256. const count = Math.ceil(sliderList.length / row);
  257. for (let i = 0, len = sliderList.length; i < len; i += count) {
  258. const item = sliderList.slice(i, i + count);
  259. res.push([...item]);
  260. }
  261. interactionList.value = res;
  262. }
  263. async function getBg() {
  264. try {
  265. const res = await fetchFindLiveConfigByKey('frontend_live_home_bg');
  266. if (res.code === 200) {
  267. const reg = /.+\.mp4$/g;
  268. const url = res.data.value as string;
  269. if (reg.exec(url)) {
  270. configVideo.value = res.data.value;
  271. } else {
  272. configBg.value = res.data.value;
  273. }
  274. }
  275. } catch (error) {
  276. console.log(error);
  277. }
  278. }
  279. function handleRefresh() {
  280. playLive(currentLiveRoom.value!);
  281. }
  282. function playLive(item: ILive) {
  283. handleStopDrawing();
  284. currentLiveRoom.value = item;
  285. canvasRef.value?.childNodes?.forEach((item) => {
  286. item.remove();
  287. });
  288. appStore.setLiveRoomInfo(item.live_room!);
  289. roomLiving.value = true;
  290. handlePlay(item.live_room!);
  291. }
  292. function changeLiveRoom(item: ILive) {
  293. if (item.id === currentLiveRoom.value?.id) return;
  294. if (
  295. ![
  296. LiveRoomTypeEnum.wertc_live,
  297. LiveRoomTypeEnum.wertc_meeting_one,
  298. LiveRoomTypeEnum.wertc_meeting_two,
  299. ].includes(item.live_room?.type!)
  300. ) {
  301. appStore.setLiveLine(LiveLineEnum.hls);
  302. }
  303. appStore.playing = true;
  304. playLive(item);
  305. }
  306. async function getLiveRoomList() {
  307. try {
  308. const res = await fetchLiveList({
  309. live_room_is_show: LiveRoomIsShowEnum.yes,
  310. orderName: 'created_at',
  311. orderBy: 'desc',
  312. });
  313. if (res.code === 200) {
  314. topLiveRoomList.value = res.data.rows.slice(0, topNums.value);
  315. otherLiveRoomList.value = res.data.rows.slice(topNums.value);
  316. if (res.data.total) {
  317. currentLiveRoom.value = topLiveRoomList.value[0];
  318. appStore.setLiveRoomInfo(currentLiveRoom.value.live_room!);
  319. roomLiving.value = true;
  320. }
  321. }
  322. } catch (error) {
  323. console.log(error);
  324. }
  325. }
  326. function joinRoom(data: { roomId: number }) {
  327. router.push({
  328. name: routerName.pull,
  329. params: { roomId: data.roomId },
  330. });
  331. }
  332. </script>
  333. <style lang="scss" scoped>
  334. .home-wrap {
  335. .play-container {
  336. position: relative;
  337. z-index: 1;
  338. padding-bottom: 50px;
  339. .bg-img {
  340. position: absolute;
  341. top: 0;
  342. right: 0;
  343. left: 0;
  344. z-index: -1;
  345. width: 100%;
  346. height: 100%;
  347. background-position: center;
  348. background-size: cover;
  349. background-repeat: no-repeat;
  350. }
  351. .bg-video {
  352. position: absolute;
  353. top: 0;
  354. right: 0;
  355. left: 0;
  356. z-index: -1;
  357. width: 100%;
  358. height: 100%;
  359. // object-fit: fill;
  360. }
  361. .slider-wrap {
  362. padding: 4px 0;
  363. }
  364. .container {
  365. display: flex;
  366. justify-content: center;
  367. box-sizing: border-box;
  368. margin: 0 auto;
  369. height: calc($w-1100 / $video-ratio);
  370. .left {
  371. position: relative;
  372. display: inline-block;
  373. overflow: hidden;
  374. flex-shrink: 0;
  375. box-sizing: border-box;
  376. margin-right: 20px;
  377. width: $w-1100;
  378. height: 100%;
  379. border-radius: 4px;
  380. background-color: rgba($color: #000000, $alpha: 0.3);
  381. @extend %coverBg;
  382. .cdn-ico {
  383. position: absolute;
  384. top: -9px;
  385. right: -10px;
  386. z-index: 2;
  387. width: 70px;
  388. height: 32px;
  389. background-color: #f87c48;
  390. color: white;
  391. transform: rotate(45deg);
  392. transform-origin: bottom;
  393. .txt {
  394. margin-top: 11px;
  395. margin-left: 20px;
  396. background-image: initial !important;
  397. font-size: 14px;
  398. }
  399. }
  400. .cover {
  401. position: absolute;
  402. background-position: center center;
  403. background-size: cover;
  404. filter: blur(10px);
  405. inset: 0;
  406. }
  407. :deep(canvas) {
  408. position: absolute;
  409. top: 50%;
  410. left: 50%;
  411. // min-width: 100%;
  412. // min-height: 100%;
  413. max-width: $w-1100;
  414. max-height: calc($w-1100 / $video-ratio);
  415. transform: translate(-50%, -50%);
  416. user-select: none;
  417. }
  418. :deep(video) {
  419. position: absolute;
  420. top: 50%;
  421. left: 50%;
  422. // min-width: 100%;
  423. // min-height: 100%;
  424. max-width: $w-1100;
  425. max-height: calc($w-1100 / $video-ratio);
  426. transform: translate(-50%, -50%);
  427. user-select: none;
  428. }
  429. &:hover {
  430. .join-btn {
  431. display: inline-flex !important;
  432. }
  433. }
  434. .join-btn {
  435. position: absolute;
  436. top: 50%;
  437. left: 50%;
  438. z-index: 20;
  439. display: none;
  440. align-items: center;
  441. align-items: center;
  442. justify-content: center;
  443. box-sizing: border-box;
  444. // width: 80%;
  445. transform: translate(-50%, -50%);
  446. &.show {
  447. display: inline-flex !important;
  448. }
  449. .btn {
  450. padding: 14px 26px;
  451. border: 2px solid rgba($color: $theme-color-gold, $alpha: 0.5);
  452. border-radius: 6px;
  453. background-color: rgba(0, 0, 0, 0.3);
  454. color: $theme-color-gold;
  455. font-size: 16px;
  456. cursor: pointer;
  457. &:hover {
  458. background-color: $theme-color-gold;
  459. color: white;
  460. }
  461. }
  462. }
  463. }
  464. .right {
  465. display: inline-block;
  466. overflow: scroll;
  467. flex-shrink: 0;
  468. box-sizing: border-box;
  469. padding: 12px 10px;
  470. height: 100%;
  471. border-radius: 4px;
  472. background-color: rgba($color: #000000, $alpha: 0.3);
  473. @extend %hideScrollbar;
  474. .list {
  475. .item {
  476. position: relative;
  477. box-sizing: border-box;
  478. margin-bottom: 10px;
  479. width: 200px;
  480. height: 110px;
  481. border-radius: 4px;
  482. background-color: rgba($color: #000000, $alpha: 0.3);
  483. cursor: pointer;
  484. @extend %coverBg;
  485. &:last-child {
  486. margin-bottom: 0;
  487. }
  488. .hidden {
  489. position: relative;
  490. overflow: hidden;
  491. width: 200px;
  492. height: 110px;
  493. .cdn-ico {
  494. position: absolute;
  495. top: -9px;
  496. right: -9px;
  497. z-index: 2;
  498. width: 60px;
  499. height: 28px;
  500. background-color: #f87c48;
  501. color: white;
  502. transform: rotate(45deg);
  503. transform-origin: bottom;
  504. .txt {
  505. margin-left: 10px;
  506. background-image: initial !important;
  507. font-size: 12px;
  508. line-height: 0.8;
  509. }
  510. }
  511. }
  512. .border {
  513. position: absolute;
  514. top: 0;
  515. right: 0;
  516. bottom: 0;
  517. left: 0;
  518. z-index: 3;
  519. border: 2px solid $theme-color-gold;
  520. border-radius: 4px;
  521. }
  522. .triangle {
  523. position: absolute;
  524. top: 50%;
  525. left: 0;
  526. display: inline-block;
  527. border: 5px solid transparent;
  528. border-right-color: $theme-color-gold;
  529. transform: translate(-100%, -50%);
  530. }
  531. &.active {
  532. &::before {
  533. background-color: transparent;
  534. }
  535. }
  536. &:hover {
  537. &::before {
  538. background-color: transparent;
  539. }
  540. }
  541. &::before {
  542. position: absolute;
  543. display: block;
  544. width: 100%;
  545. height: 100%;
  546. border-radius: 4px;
  547. background-color: rgba(0, 0, 0, 0.4);
  548. content: '';
  549. transition: all cubic-bezier(0.22, 0.58, 0.12, 0.98) 0.4s;
  550. }
  551. .txt {
  552. position: absolute;
  553. bottom: 0;
  554. left: 0;
  555. box-sizing: border-box;
  556. padding: 4px 8px;
  557. width: 100%;
  558. border-radius: 0 0 4px 4px;
  559. background-image: linear-gradient(
  560. -180deg,
  561. rgba(0, 0, 0, 0),
  562. rgba(0, 0, 0, 0.6)
  563. );
  564. color: white;
  565. text-align: initial;
  566. font-size: 13px;
  567. @extend %singleEllipsis;
  568. }
  569. }
  570. }
  571. .none {
  572. width: 200px;
  573. color: white;
  574. text-align: center;
  575. font-size: 14px;
  576. }
  577. }
  578. }
  579. }
  580. .area-container {
  581. box-sizing: border-box;
  582. margin: 10px auto;
  583. width: $w-1350;
  584. .area-item {
  585. .title {
  586. padding: 10px 0;
  587. font-size: 26px;
  588. }
  589. .live-room {
  590. display: inline-block;
  591. margin-right: 32px;
  592. margin-bottom: 10px;
  593. width: 300px;
  594. cursor: pointer;
  595. .cover {
  596. position: relative;
  597. overflow: hidden;
  598. width: 100%;
  599. height: 150px;
  600. border-radius: 8px;
  601. background-position: center center;
  602. background-size: cover;
  603. .cdn-ico {
  604. position: absolute;
  605. top: -10px;
  606. right: -10px;
  607. z-index: 2;
  608. width: 70px;
  609. height: 28px;
  610. background-color: #f87c48;
  611. color: white;
  612. transform: rotate(45deg);
  613. transform-origin: bottom;
  614. .txt {
  615. margin-left: 18px;
  616. background-image: initial !important;
  617. font-size: 13px;
  618. }
  619. }
  620. .txt {
  621. position: absolute;
  622. bottom: 0;
  623. left: 0;
  624. box-sizing: border-box;
  625. padding: 4px 8px;
  626. width: 100%;
  627. border-radius: 0 0 4px 4px;
  628. background-image: linear-gradient(
  629. -180deg,
  630. rgba(0, 0, 0, 0),
  631. rgba(0, 0, 0, 0.6)
  632. );
  633. color: white;
  634. text-align: initial;
  635. font-size: 13px;
  636. @extend %singleEllipsis;
  637. }
  638. }
  639. .desc {
  640. margin-top: 4px;
  641. font-size: 14px;
  642. @extend %singleEllipsis;
  643. }
  644. }
  645. }
  646. }
  647. .foot {
  648. margin-top: 10px;
  649. text-align: center;
  650. }
  651. }
  652. // 屏幕宽度小于1330的时候
  653. @media screen and (max-width: 1330px) {
  654. .home-wrap {
  655. .play-container {
  656. .container {
  657. height: calc($w-900 / $video-ratio);
  658. .left {
  659. width: $w-900;
  660. :deep(canvas) {
  661. max-width: $w-900;
  662. max-height: calc($w-900 / $video-ratio);
  663. }
  664. :deep(video) {
  665. max-width: $w-900;
  666. max-height: calc($w-900 / $video-ratio);
  667. }
  668. }
  669. .right {
  670. }
  671. }
  672. }
  673. .area-container {
  674. width: $w-1150;
  675. }
  676. }
  677. }
  678. </style>