| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871 |
- <template>
- <div class="pull-wrap">
- <div class="bg-img-wrap">
- <div
- v-if="configBg !== ''"
- class="bg-img"
- :style="{ backgroundImage: `url(${configBg})` }"
- ></div>
- <video
- v-if="configVideo !== ''"
- class="bg-video"
- :src="configVideo"
- muted
- autoplay
- loop
- ></video>
- <div
- v-else
- class="bg-img"
- ></div>
- </div>
- <div class="left">
- <div
- ref="topRef"
- class="head"
- >
- <div class="info">
- <div
- class="avatar"
- :style="{
- backgroundImage: `url(${anchorInfo?.avatar})`,
- }"
- @click="
- router.push({
- name: routerName.profile,
- params: { userId: anchorInfo?.id },
- })
- "
- ></div>
- <div class="detail">
- <div class="top">{{ anchorInfo?.username }}</div>
- <div class="bottom">
- <span>{{ appStore.liveRoomInfo?.desc }}</span>
- <span v-if="NODE_ENV === 'development'">
- socketId:{{ mySocketId }}
- </span>
- <span
- class="area"
- @click="
- router.push({
- name: routerName.area,
- query: { id: appStore.liveRoomInfo?.areas?.[0].id },
- })
- "
- >{{ appStore.liveRoomInfo?.areas?.[0].name }}</span
- >
- </div>
- </div>
- </div>
- <div class="other">在线人数:{{ liveUserList.length }}</div>
- </div>
- <div
- ref="containerRef"
- class="container"
- >
- <div
- class="no-live"
- v-if="!roomLiving"
- >
- 主播还没开播~
- </div>
- <div
- v-else
- v-loading="videoLoading"
- class="video-wrap"
- >
- <div
- class="cover"
- :style="{
- backgroundImage: `url(${
- appStore.liveRoomInfo?.cover_img || anchorInfo?.avatar
- })`,
- }"
- ></div>
- <div
- ref="remoteVideoRef"
- class="media-list"
- :class="{ item: appStore.allTrack.length > 1 }"
- ></div>
- <VideoControls
- :resolution="videoHeight"
- @refresh="handleRefresh"
- ></VideoControls>
- </div>
- </div>
- <div
- ref="bottomRef"
- v-loading="giftLoading"
- class="gift-list"
- >
- <div
- v-for="(item, index) in giftGoodsList"
- :key="index"
- class="item"
- @click="handlePay()"
- >
- <div
- class="ico"
- :style="{ backgroundImage: `url(${item.cover})` }"
- >
- <div
- v-if="item.badge"
- class="badge"
- :style="{ backgroundColor: item.badge_bg }"
- >
- <span class="txt">{{ item.badge }}</span>
- </div>
- </div>
- <div class="name">{{ item.name }}</div>
- <div class="price">¥{{ item.price }}</div>
- </div>
- <div
- class="item"
- @click="handleRecharge"
- >
- <div class="ico wallet"></div>
- <div class="name">余额:{{ userStore.userInfo?.wallet?.balance }}</div>
- <div class="price">立即充值</div>
- </div>
- </div>
- </div>
- <div class="right">
- <div class="tab">
- <span>在线用户</span>
- <span> | </span>
- <span>排行榜</span>
- </div>
- <div class="user-list">
- <div
- v-for="(item, index) in liveUserList.filter(
- (item) => item.id !== mySocketId
- )"
- :key="index"
- class="item"
- >
- <div class="info">
- <div
- class="avatar"
- :style="{ backgroundImage: `url(${item.userInfo?.avatar})` }"
- ></div>
- <div class="username">
- {{ item.userInfo?.username || item.id }}
- </div>
- </div>
- </div>
- <div
- v-if="userStore.userInfo"
- class="item"
- >
- <div class="info">
- <img
- :src="userStore.userInfo.avatar"
- class="avatar"
- alt=""
- />
- <div class="username">{{ userStore.userInfo.username }}</div>
- </div>
- </div>
- </div>
- <div
- ref="danmuListRef"
- class="danmu-list"
- >
- <div
- v-for="(item, index) in damuList"
- :key="index"
- class="item"
- >
- <template v-if="item.msgType === DanmuMsgTypeEnum.danmu">
- <span class="name">
- <span v-if="item.userInfo">
- {{ item.userInfo.username }}[{{
- item.userInfo.roles?.map((v) => v.role_name).join()
- }}]
- </span>
- <span v-else>{{ item.socket_id }}[游客]</span>
- </span>
- <span>:</span>
- <span
- class="msg"
- v-if="!item.msgIsFile"
- >
- {{ item.msg }}
- </span>
- <div
- class="msg img"
- v-else
- >
- <img
- :src="item.msg"
- alt=""
- @load="handleScrollTop"
- />
- </div>
- </template>
- <template v-else-if="item.msgType === DanmuMsgTypeEnum.otherJoin">
- <span class="name system">系统通知:</span>
- <span class="msg">
- {{ item.userInfo?.username || item.socket_id }}进入直播!
- </span>
- </template>
- <template v-else-if="item.msgType === DanmuMsgTypeEnum.userLeaved">
- <span class="name system">系统通知:</span>
- <span class="msg">
- {{ item.userInfo?.username || item.socket_id }}离开直播!
- </span>
- </template>
- </div>
- </div>
- <div
- class="send-msg"
- v-loading="msgLoading"
- >
- <div class="control">
- <div
- class="ico face"
- title="表情"
- @click="handleWait"
- ></div>
- <div
- class="ico img"
- title="图片"
- @click="mockClick"
- >
- <input
- placeholder="发个弹幕吧~"
- ref="uploadRef"
- type="file"
- class="input-upload"
- accept=".webp,.png,.jpg,.jpeg,.gif"
- @change="uploadChange"
- />
- </div>
- </div>
- <textarea
- v-model="danmuStr"
- class="ipt"
- @keydown="keydownDanmu"
- ></textarea>
- <div
- class="btn"
- @click="sendDanmu"
- >
- 发送
- </div>
- </div>
- </div>
- <RechargeCpt
- :show="showRecharge"
- @close="(v) => (showRecharge = v)"
- ></RechargeCpt>
- </div>
- </template>
- <script lang="ts" setup>
- import { onMounted, onUnmounted, ref, watch } from 'vue';
- import { fetchGoodsList } from '@/api/goods';
- import { MODULE_CONFIG_SWITCH, QINIU_LIVE } from '@/constant';
- import { loginTip } from '@/hooks/use-login';
- import { usePull } from '@/hooks/use-pull';
- import { useUpload } from '@/hooks/use-upload';
- import { DanmuMsgTypeEnum, GoodsTypeEnum, IGoods } from '@/interface';
- import router, { routerName } from '@/router';
- import { useAppStore } from '@/store/app';
- import { useUserStore } from '@/store/user';
- import { NODE_ENV } from 'script/constant';
- import RechargeCpt from './recharge/index.vue';
- const userStore = useUserStore();
- const appStore = useAppStore();
- const configBg = ref();
- const configVideo = ref();
- const giftGoodsList = ref<IGoods[]>([]);
- const height = ref(0);
- const giftLoading = ref(false);
- const showRecharge = ref(false);
- const msgLoading = ref(false);
- const topRef = ref<HTMLDivElement>();
- const bottomRef = ref<HTMLDivElement>();
- const danmuListRef = ref<HTMLDivElement>();
- const remoteVideoRef = ref<HTMLDivElement>();
- const containerRef = ref<HTMLDivElement>();
- const uploadRef = ref<HTMLInputElement>();
- const {
- initPull,
- closeWs,
- closeRtc,
- keydownDanmu,
- sendDanmu,
- handlePlay,
- msgIsFile,
- mySocketId,
- videoHeight,
- videoLoading,
- remoteVideo,
- roomLiving,
- damuList,
- liveUserList,
- danmuStr,
- anchorInfo,
- } = usePull();
- onMounted(() => {
- setTimeout(() => {
- scrollTo(0, 0);
- }, 100);
- appStore.setPlay(true);
- getGoodsList();
- if (topRef.value && bottomRef.value && containerRef.value) {
- const res =
- bottomRef.value.getBoundingClientRect().top -
- (topRef.value.getBoundingClientRect().top +
- topRef.value.getBoundingClientRect().height);
- height.value = res;
- }
- getBg();
- initPull();
- });
- onUnmounted(() => {
- closeWs();
- closeRtc();
- });
- watch(
- () => remoteVideo.value,
- (newVal) => {
- newVal.forEach((item) => {
- remoteVideoRef.value?.appendChild(item);
- });
- },
- {
- deep: true,
- immediate: true,
- }
- );
- watch(
- () => damuList.value.length,
- () => {
- setTimeout(() => {
- handleScrollTop();
- }, 0);
- }
- );
- watch(
- () => appStore.liveRoomInfo,
- () => {
- getBg();
- },
- {
- deep: true,
- }
- );
- function getBg() {
- try {
- const reg = /.+\.mp4$/g;
- const url = appStore.liveRoomInfo?.bg_img;
- if (url) {
- if (reg.exec(url)) {
- configVideo.value = url;
- } else {
- configBg.value = url;
- }
- }
- } catch (error) {
- console.log(error);
- }
- }
- function handleWait() {
- window.$message.warning('敬请期待!');
- }
- function mockClick() {
- uploadRef.value?.click();
- }
- async function uploadChange() {
- const fileList = uploadRef.value?.files;
- if (fileList?.length) {
- try {
- msgLoading.value = true;
- msgIsFile.value = true;
- const res = await useUpload({
- prefix: QINIU_LIVE.prefix['billd-live/msg-image/'],
- file: fileList[0],
- });
- if (res?.resultUrl) {
- danmuStr.value = res.resultUrl || '错误图片';
- sendDanmu();
- }
- } catch (error) {
- console.log(error);
- } finally {
- msgIsFile.value = false;
- msgLoading.value = false;
- if (uploadRef.value) {
- uploadRef.value.value = '';
- }
- }
- }
- }
- function handlePay() {
- if (!MODULE_CONFIG_SWITCH.pay) {
- window.$message.info('敬请期待!');
- return;
- }
- window.$message.info('敬请期待!');
- }
- function handleRefresh() {
- if (appStore.liveRoomInfo) {
- handlePlay(appStore.liveRoomInfo);
- }
- }
- async function getGoodsList() {
- try {
- giftLoading.value = true;
- const res = await fetchGoodsList({
- type: GoodsTypeEnum.gift,
- orderName: 'created_at',
- orderBy: 'desc',
- });
- if (res.code === 200) {
- giftGoodsList.value = res.data.rows;
- }
- } catch (error) {
- console.log(error);
- } finally {
- giftLoading.value = false;
- }
- }
- function handleRecharge() {
- if (!MODULE_CONFIG_SWITCH.pay) {
- window.$message.info('敬请期待!');
- return;
- }
- if (!loginTip()) return;
- showRecharge.value = true;
- }
- function handleScrollTop() {
- if (danmuListRef.value) {
- danmuListRef.value.scrollTop = danmuListRef.value.scrollHeight + 10000;
- }
- }
- </script>
- <style lang="scss" scoped>
- .pull-wrap {
- display: flex;
- justify-content: space-around;
- margin: 15px auto 0;
- width: $w-1275;
- .bg-img-wrap {
- position: absolute;
- top: $layout-head-h;
- left: 50%;
- max-width: 1920px;
- max-height: 890px;
- width: 100%;
- height: 100%;
- background-position: center center;
- background-size: cover;
- background-repeat: no-repeat;
- transform: translateX(-50%);
- .bg-img {
- position: absolute;
- top: 0;
- right: 0;
- left: 0;
- z-index: -1;
- width: 100%;
- height: 100%;
- background-position: center;
- background-size: cover;
- background-repeat: no-repeat;
- }
- .bg-video {
- position: absolute;
- top: 0;
- right: 0;
- left: 0;
- z-index: -1;
- width: 100%;
- height: 100%;
- }
- }
- .left {
- position: relative;
- display: inline-block;
- overflow: hidden;
- box-sizing: border-box;
- width: $w-1000;
- height: 100%;
- border-radius: 6px;
- background-color: papayawhip;
- color: #61666d;
- vertical-align: top;
- .head {
- display: flex;
- justify-content: space-between;
- padding: 10px 20px;
- .info {
- display: flex;
- align-items: center;
- text-align: initial;
- .avatar {
- margin-right: 20px;
- width: 50px;
- height: 50px;
- border-radius: 50%;
- cursor: pointer;
- @extend %containBg;
- }
- .detail {
- .top {
- margin-bottom: 10px;
- color: #18191c;
- }
- .bottom {
- font-size: 14px;
- .area {
- margin-left: 10px;
- color: #9499a0;
- cursor: pointer;
- }
- }
- }
- }
- .other {
- display: flex;
- flex-direction: column;
- justify-content: center;
- font-size: 14px;
- }
- }
- .container {
- display: flex;
- align-items: center;
- justify-content: space-between;
- height: 562px;
- background-color: rgba($color: #000000, $alpha: 0.5);
- .no-live {
- position: absolute;
- top: 50%;
- left: 50%;
- z-index: 20;
- color: white;
- font-size: 28px;
- transform: translate(-50%, -50%);
- }
- .video-wrap {
- position: relative;
- overflow: hidden;
- flex: 1;
- height: 100%;
- .cover {
- position: absolute;
- background-position: center center;
- background-size: cover;
- filter: blur(10px);
- inset: 0;
- }
- .videoControls {
- position: relative;
- z-index: 20;
- }
- .media-list {
- position: relative;
- height: 562px;
- :deep(video) {
- position: absolute;
- top: 50%;
- left: 50%;
- display: block;
- margin: 0 auto;
- // min-width: 100%;
- // min-height: 100%;
- max-width: $w-1000;
- max-height: 562px;
- transform: translate(-50%, -50%);
- }
- :deep(canvas) {
- position: absolute;
- top: 50%;
- left: 50%;
- display: block;
- margin: 0 auto;
- // min-width: 100%;
- // min-height: 100%;
- max-width: $w-1000;
- max-height: 562px;
- transform: translate(-50%, -50%);
- }
- // &.item {
- // :deep(video) {
- // width: 50%;
- // height: initial !important;
- // }
- // :deep(canvas) {
- // width: 50%;
- // height: initial !important;
- // }
- // }
- }
- .controls {
- display: none;
- }
- .tip-btn {
- position: absolute;
- top: 50%;
- left: 50%;
- z-index: 1;
- align-items: center;
- padding: 12px 26px;
- border: 2px solid rgba($color: $theme-color-gold, $alpha: 0.5);
- border-radius: 6px;
- background-color: rgba(0, 0, 0, 0.3);
- color: $theme-color-gold;
- cursor: pointer;
- transform: translate(-50%, -50%);
- &:hover {
- background-color: rgba($color: $theme-color-gold, $alpha: 0.5);
- color: white;
- }
- }
- }
- }
- .gift-list {
- position: relative;
- display: flex;
- align-items: center;
- justify-content: space-around;
- box-sizing: border-box;
- margin: 5px 0;
- height: 100px;
- > :last-child {
- position: absolute;
- }
- .item {
- display: flex;
- align-items: center;
- flex-direction: column;
- justify-content: center;
- box-sizing: border-box;
- width: 100px;
- height: 100px;
- text-align: center;
- cursor: pointer;
- &:hover {
- background-color: #ebe0ce;
- }
- .ico {
- position: relative;
- width: 45px;
- height: 45px;
- background-position: center center;
- background-size: cover;
- background-repeat: no-repeat;
- &.wallet {
- background-image: url('@/assets/img/wallet.webp');
- }
- .badge {
- position: absolute;
- top: -8px;
- right: -10px;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 2px;
- border-radius: 2px;
- color: white;
- .txt {
- display: inline-block;
- line-height: 1;
- transform-origin: center !important;
- @include minFont(10);
- }
- }
- }
- .name {
- color: #18191c;
- font-size: 12px;
- }
- .price {
- color: #9499a0;
- font-size: 12px;
- }
- }
- }
- }
- .right {
- position: relative;
- display: inline-block;
- box-sizing: border-box;
- width: $w-250;
- border-radius: 6px;
- background-color: papayawhip;
- color: #9499a0;
- .tab {
- display: flex;
- align-items: center;
- justify-content: space-evenly;
- padding: 5px 0;
- font-size: 12px;
- }
- .user-list {
- overflow-y: scroll;
- padding: 0 15px;
- height: 100px;
- background-color: papayawhip;
- @extend %customScrollbar;
- .item {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 10px;
- font-size: 12px;
- .info {
- display: flex;
- align-items: center;
- cursor: pointer;
- .avatar {
- margin-right: 5px;
- width: 25px;
- height: 25px;
- border-radius: 50%;
- @extend %containBg;
- }
- .username {
- color: black;
- }
- }
- }
- }
- .danmu-list {
- overflow-y: scroll;
- box-sizing: border-box;
- padding-top: 4px;
- height: 480px;
- background-color: #f6f7f8;
- text-align: initial;
- @extend %customScrollbar;
- .item {
- box-sizing: border-box;
- margin-bottom: 4px;
- padding: 2px 10px;
- white-space: normal;
- word-wrap: break-word;
- font-size: 13px;
- .name {
- color: #9499a0;
- cursor: pointer;
- &.system {
- color: red;
- }
- }
- .msg {
- margin-top: 4px;
- color: #61666d;
- &.img {
- img {
- width: 80%;
- }
- }
- }
- }
- }
- .send-msg {
- position: relative;
- box-sizing: border-box;
- padding: 4px 10px;
- width: 100%;
- .control {
- display: flex;
- margin: 4px 0;
- .ico {
- margin-right: 6px;
- width: 24px;
- height: 24px;
- cursor: pointer;
- .input-upload {
- width: 0;
- height: 0;
- opacity: 0;
- }
- &.face {
- @include setBackground('@/assets/img/msg-face.webp');
- }
- &.img {
- @include setBackground('@/assets/img/msg-img.webp');
- }
- }
- }
- .ipt {
- display: block;
- box-sizing: border-box;
- margin: 0 auto;
- padding: 10px;
- width: 100%;
- height: 60px;
- outline: none;
- border: 1px solid hsla(0, 0%, 60%, 0.2);
- border-radius: 4px;
- background-color: #f1f2f3;
- font-size: 14px;
- }
- .btn {
- box-sizing: border-box;
- margin-top: 10px;
- margin-left: auto;
- padding: 4px;
- width: 70px;
- border-radius: 4px;
- background-color: $theme-color-gold;
- color: white;
- text-align: center;
- font-size: 12px;
- cursor: pointer;
- }
- }
- }
- }
- // 屏幕宽度大于1500的时候
- @media screen and (min-width: $w-1500) {
- .pull-wrap {
- width: $w-1350;
- .left {
- width: $w-1000;
- }
- .right {
- width: $w-300;
- }
- }
- }
- </style>
|