index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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="videoHeight"
  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, watch } 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. remoteVideo,
  243. roomLiving,
  244. videoHeight,
  245. handleStopDrawing,
  246. handlePlay,
  247. } = usePull(route.params.roomId as string);
  248. onMounted(() => {
  249. handleSlideList();
  250. getLiveRoomList();
  251. getBg();
  252. videoWrapRef.value = videoWrapTmpRef.value;
  253. });
  254. watch(
  255. () => remoteVideo.value,
  256. (newVal) => {
  257. newVal.forEach((item) => {
  258. remoteVideoRef.value?.appendChild(item);
  259. });
  260. },
  261. {
  262. deep: true,
  263. }
  264. );
  265. function handleSlideList() {
  266. const row = 2;
  267. const res: any[] = [];
  268. const count = Math.ceil(sliderList.length / row);
  269. for (let i = 0, len = sliderList.length; i < len; i += count) {
  270. const item = sliderList.slice(i, i + count);
  271. res.push([...item]);
  272. }
  273. interactionList.value = res;
  274. }
  275. async function getBg() {
  276. try {
  277. const res = await fetchFindLiveConfigByKey('frontend_live_home_bg');
  278. if (res.code === 200) {
  279. const reg = /.+\.mp4$/g;
  280. const url = res.data.value as string;
  281. if (reg.exec(url)) {
  282. configVideo.value = res.data.value;
  283. } else {
  284. configBg.value = res.data.value;
  285. }
  286. }
  287. } catch (error) {
  288. console.log(error);
  289. }
  290. }
  291. function handleRefresh() {
  292. playLive(currentLiveRoom.value!);
  293. }
  294. function playLive(item: ILive) {
  295. handleStopDrawing();
  296. currentLiveRoom.value = item;
  297. canvasRef.value?.childNodes?.forEach((item) => {
  298. item.remove();
  299. });
  300. appStore.setLiveRoomInfo(item.live_room!);
  301. roomLiving.value = true;
  302. handlePlay(item.live_room!);
  303. }
  304. function changeLiveRoom(item: ILive) {
  305. if (item.id === currentLiveRoom.value?.id) return;
  306. if (
  307. ![
  308. LiveRoomTypeEnum.wertc_live,
  309. LiveRoomTypeEnum.wertc_meeting_one,
  310. LiveRoomTypeEnum.wertc_meeting_two,
  311. ].includes(item.live_room?.type!)
  312. ) {
  313. appStore.setLiveLine(LiveLineEnum.hls);
  314. }
  315. appStore.playing = true;
  316. playLive(item);
  317. }
  318. async function getLiveRoomList() {
  319. try {
  320. const res = await fetchLiveList({
  321. live_room_is_show: LiveRoomIsShowEnum.yes,
  322. orderName: 'created_at',
  323. orderBy: 'desc',
  324. });
  325. if (res.code === 200) {
  326. topLiveRoomList.value = res.data.rows.slice(0, topNums.value);
  327. otherLiveRoomList.value = res.data.rows.slice(topNums.value);
  328. if (res.data.total) {
  329. currentLiveRoom.value = topLiveRoomList.value[0];
  330. appStore.setLiveRoomInfo(currentLiveRoom.value.live_room!);
  331. roomLiving.value = true;
  332. }
  333. }
  334. } catch (error) {
  335. console.log(error);
  336. }
  337. }
  338. function joinRoom(data: { roomId: number }) {
  339. router.push({
  340. name: routerName.pull,
  341. params: { roomId: data.roomId },
  342. });
  343. }
  344. </script>
  345. <style lang="scss" scoped>
  346. .home-wrap {
  347. .play-container {
  348. position: relative;
  349. z-index: 1;
  350. padding-bottom: 50px;
  351. .bg-img {
  352. position: absolute;
  353. top: 0;
  354. right: 0;
  355. left: 0;
  356. z-index: -1;
  357. width: 100%;
  358. height: 100%;
  359. background-position: center;
  360. background-size: cover;
  361. background-repeat: no-repeat;
  362. }
  363. .bg-video {
  364. position: absolute;
  365. top: 0;
  366. right: 0;
  367. left: 0;
  368. z-index: -1;
  369. width: 100%;
  370. height: 100%;
  371. // object-fit: fill;
  372. }
  373. .slider-wrap {
  374. padding: 4px 0;
  375. }
  376. .container {
  377. display: flex;
  378. justify-content: center;
  379. box-sizing: border-box;
  380. margin: 0 auto;
  381. height: calc($w-1100 / $video-ratio);
  382. .left {
  383. position: relative;
  384. display: inline-block;
  385. overflow: hidden;
  386. flex-shrink: 0;
  387. box-sizing: border-box;
  388. margin-right: 20px;
  389. width: $w-1100;
  390. height: 100%;
  391. border-radius: 4px;
  392. background-color: rgba($color: #000000, $alpha: 0.3);
  393. @extend %coverBg;
  394. .cdn-ico {
  395. position: absolute;
  396. top: -9px;
  397. right: -10px;
  398. z-index: 2;
  399. width: 70px;
  400. height: 32px;
  401. background-color: #f87c48;
  402. color: white;
  403. transform: rotate(45deg);
  404. transform-origin: bottom;
  405. .txt {
  406. margin-top: 11px;
  407. margin-left: 20px;
  408. background-image: initial !important;
  409. font-size: 14px;
  410. }
  411. }
  412. .cover {
  413. position: absolute;
  414. background-position: center center;
  415. background-size: cover;
  416. filter: blur(10px);
  417. inset: 0;
  418. }
  419. :deep(canvas) {
  420. position: absolute;
  421. top: 50%;
  422. left: 50%;
  423. // min-width: 100%;
  424. // min-height: 100%;
  425. max-width: $w-1100;
  426. max-height: calc($w-1100 / $video-ratio);
  427. transform: translate(-50%, -50%);
  428. user-select: none;
  429. }
  430. :deep(video) {
  431. position: absolute;
  432. top: 50%;
  433. left: 50%;
  434. // min-width: 100%;
  435. // min-height: 100%;
  436. max-width: $w-1100;
  437. max-height: calc($w-1100 / $video-ratio);
  438. transform: translate(-50%, -50%);
  439. user-select: none;
  440. }
  441. &:hover {
  442. .join-btn {
  443. display: inline-flex !important;
  444. }
  445. }
  446. .join-btn {
  447. position: absolute;
  448. top: 50%;
  449. left: 50%;
  450. z-index: 20;
  451. display: none;
  452. align-items: center;
  453. align-items: center;
  454. justify-content: center;
  455. box-sizing: border-box;
  456. // width: 80%;
  457. transform: translate(-50%, -50%);
  458. &.show {
  459. display: inline-flex !important;
  460. }
  461. .btn {
  462. padding: 14px 26px;
  463. border: 2px solid rgba($color: $theme-color-gold, $alpha: 0.5);
  464. border-radius: 6px;
  465. background-color: rgba(0, 0, 0, 0.3);
  466. color: $theme-color-gold;
  467. font-size: 16px;
  468. cursor: pointer;
  469. &:hover {
  470. background-color: $theme-color-gold;
  471. color: white;
  472. }
  473. }
  474. }
  475. }
  476. .right {
  477. display: inline-block;
  478. overflow: scroll;
  479. flex-shrink: 0;
  480. box-sizing: border-box;
  481. padding: 12px 10px;
  482. height: 100%;
  483. border-radius: 4px;
  484. background-color: rgba($color: #000000, $alpha: 0.3);
  485. @extend %hideScrollbar;
  486. .list {
  487. .item {
  488. position: relative;
  489. box-sizing: border-box;
  490. margin-bottom: 10px;
  491. width: 200px;
  492. height: 110px;
  493. border-radius: 4px;
  494. background-color: rgba($color: #000000, $alpha: 0.3);
  495. cursor: pointer;
  496. @extend %coverBg;
  497. &:last-child {
  498. margin-bottom: 0;
  499. }
  500. .hidden {
  501. position: relative;
  502. overflow: hidden;
  503. width: 200px;
  504. height: 110px;
  505. .cdn-ico {
  506. position: absolute;
  507. top: -9px;
  508. right: -9px;
  509. z-index: 2;
  510. width: 60px;
  511. height: 28px;
  512. background-color: #f87c48;
  513. color: white;
  514. transform: rotate(45deg);
  515. transform-origin: bottom;
  516. .txt {
  517. margin-left: 10px;
  518. background-image: initial !important;
  519. font-size: 12px;
  520. line-height: 0.8;
  521. }
  522. }
  523. }
  524. .border {
  525. position: absolute;
  526. top: 0;
  527. right: 0;
  528. bottom: 0;
  529. left: 0;
  530. z-index: 3;
  531. border: 2px solid $theme-color-gold;
  532. border-radius: 4px;
  533. }
  534. .triangle {
  535. position: absolute;
  536. top: 50%;
  537. left: 0;
  538. display: inline-block;
  539. border: 5px solid transparent;
  540. border-right-color: $theme-color-gold;
  541. transform: translate(-100%, -50%);
  542. }
  543. &.active {
  544. &::before {
  545. background-color: transparent;
  546. }
  547. }
  548. &:hover {
  549. &::before {
  550. background-color: transparent;
  551. }
  552. }
  553. &::before {
  554. position: absolute;
  555. display: block;
  556. width: 100%;
  557. height: 100%;
  558. border-radius: 4px;
  559. background-color: rgba(0, 0, 0, 0.4);
  560. content: '';
  561. transition: all cubic-bezier(0.22, 0.58, 0.12, 0.98) 0.4s;
  562. }
  563. .txt {
  564. position: absolute;
  565. bottom: 0;
  566. left: 0;
  567. box-sizing: border-box;
  568. padding: 4px 8px;
  569. width: 100%;
  570. border-radius: 0 0 4px 4px;
  571. background-image: linear-gradient(
  572. -180deg,
  573. rgba(0, 0, 0, 0),
  574. rgba(0, 0, 0, 0.6)
  575. );
  576. color: white;
  577. text-align: initial;
  578. font-size: 13px;
  579. @extend %singleEllipsis;
  580. }
  581. }
  582. }
  583. .none {
  584. width: 200px;
  585. color: white;
  586. text-align: center;
  587. font-size: 14px;
  588. }
  589. }
  590. }
  591. }
  592. .area-container {
  593. box-sizing: border-box;
  594. margin: 10px auto;
  595. width: $w-1350;
  596. .area-item {
  597. .title {
  598. padding: 10px 0;
  599. font-size: 26px;
  600. }
  601. .live-room {
  602. display: inline-block;
  603. margin-right: 32px;
  604. margin-bottom: 10px;
  605. width: 300px;
  606. cursor: pointer;
  607. .cover {
  608. position: relative;
  609. overflow: hidden;
  610. width: 100%;
  611. height: 150px;
  612. border-radius: 8px;
  613. background-position: center center;
  614. background-size: cover;
  615. .cdn-ico {
  616. position: absolute;
  617. top: -10px;
  618. right: -10px;
  619. z-index: 2;
  620. width: 70px;
  621. height: 28px;
  622. background-color: #f87c48;
  623. color: white;
  624. transform: rotate(45deg);
  625. transform-origin: bottom;
  626. .txt {
  627. margin-left: 18px;
  628. background-image: initial !important;
  629. font-size: 13px;
  630. }
  631. }
  632. .txt {
  633. position: absolute;
  634. bottom: 0;
  635. left: 0;
  636. box-sizing: border-box;
  637. padding: 4px 8px;
  638. width: 100%;
  639. border-radius: 0 0 4px 4px;
  640. background-image: linear-gradient(
  641. -180deg,
  642. rgba(0, 0, 0, 0),
  643. rgba(0, 0, 0, 0.6)
  644. );
  645. color: white;
  646. text-align: initial;
  647. font-size: 13px;
  648. @extend %singleEllipsis;
  649. }
  650. }
  651. .desc {
  652. margin-top: 4px;
  653. font-size: 14px;
  654. @extend %singleEllipsis;
  655. }
  656. }
  657. }
  658. }
  659. .foot {
  660. margin-top: 10px;
  661. text-align: center;
  662. }
  663. }
  664. // 屏幕宽度小于1330的时候
  665. @media screen and (max-width: 1330px) {
  666. .home-wrap {
  667. .play-container {
  668. .container {
  669. height: calc($w-900 / $video-ratio);
  670. .left {
  671. width: $w-900;
  672. :deep(canvas) {
  673. max-width: $w-900;
  674. max-height: calc($w-900 / $video-ratio);
  675. }
  676. :deep(video) {
  677. max-width: $w-900;
  678. max-height: calc($w-900 / $video-ratio);
  679. }
  680. }
  681. .right {
  682. }
  683. }
  684. }
  685. .area-container {
  686. width: $w-1150;
  687. }
  688. }
  689. }
  690. </style>