Bladeren bron

fix: 优化

shuisheng 1 jaar geleden
bovenliggende
commit
593f06b699

+ 2 - 2
src/api/wallet.ts

@@ -7,6 +7,6 @@ export function fetchWalletList(params) {
   });
 }
 
-export function fetchMyWallet() {
-  return request.get<IWallet>('/wallet/my_wallet');
+export function fetchMyWallet(params) {
+  return request.get<IWallet>('/wallet/my_wallet', { params });
 }

+ 13 - 22
src/hooks/use-push.ts

@@ -1,11 +1,7 @@
 import { getRandomString, windowReload } from 'billd-utils';
 import { onMounted, onUnmounted, ref, watch } from 'vue';
-import { useRoute, useRouter } from 'vue-router';
 
-import {
-  fetchCreateUserLiveRoom,
-  fetchUserHasLiveRoom,
-} from '@/api/userLiveRoom';
+import { fetchCreateUserLiveRoom } from '@/api/userLiveRoom';
 import {
   DanmuMsgTypeEnum,
   WsMessageContentTypeEnum,
@@ -29,8 +25,6 @@ import { useTip } from './use-tip';
 import { useWebsocket } from './use-websocket';
 
 export function usePush() {
-  const route = useRoute();
-  const router = useRouter();
   const appStore = useAppStore();
   const userStore = useUserStore();
   const networkStore = useNetworkStore();
@@ -157,7 +151,7 @@ export function usePush() {
     () => userStore.userInfo,
     async (newVal) => {
       if (newVal) {
-        const res = await handleUserHasLiveRoom();
+        const res = handleUserHasLiveRoom();
         if (!res) {
           await useTip({
             content: '你还没有直播间,是否立即开通?',
@@ -173,16 +167,10 @@ export function usePush() {
     { immediate: true }
   );
 
-  async function handleUserHasLiveRoom() {
-    const res = await fetchUserHasLiveRoom(userStore.userInfo!.id!);
-    if (res.code === 200 && res.data) {
-      appStore.liveRoomInfo = res.data.live_room;
-      router.push({
-        query: { ...route.query, roomId: appStore.liveRoomInfo?.id },
-      });
-      return true;
-    }
-    return false;
+  function handleUserHasLiveRoom() {
+    const res = userStore.userInfo?.live_rooms?.[0];
+    appStore.liveRoomInfo = res;
+    return res;
   }
 
   async function handleCreateUserLiveRoom() {
@@ -212,7 +200,7 @@ export function usePush() {
 
   async function startLive({ type, msrDelay, msrMaxDelay }) {
     if (!loginTip()) return;
-    const flag = await handleUserHasLiveRoom();
+    const flag = handleUserHasLiveRoom();
     if (!flag) {
       await useTip({
         content: '你还没有直播间,是否立即开通?',
@@ -225,7 +213,6 @@ export function usePush() {
       window.$message.warning('websocket未连接');
       return;
     }
-
     roomLiving.value = true;
     const el = appStore.allTrack.find((item) => {
       if (item.video === 1) {
@@ -261,17 +248,20 @@ export function usePush() {
   function endLive() {
     roomLiving.value = false;
     localStream.value = undefined;
+    closeRtc();
+  }
+
+  function sendRoomNoLive() {
     const instance = networkStore.wsMap.get(roomId.value);
     if (instance) {
       instance.send<WsRoomNoLiveType['data']>({
         requestId: getRandomString(8),
         msgType: WsMsgTypeEnum.roomNoLive,
         data: {
-          live_room: appStore.liveRoomInfo!,
+          live_room_id: appStore.liveRoomInfo?.id!,
         },
       });
     }
-    closeRtc();
   }
 
   function sendBlob(data: { blob; blobId: string; delay; max_delay }) {
@@ -335,6 +325,7 @@ export function usePush() {
     sendDanmu,
     keydownDanmu,
     sendBlob,
+    sendRoomNoLive,
     roomId,
     msgIsFile,
     mySocketId,

+ 15 - 17
src/interface.ts

@@ -434,21 +434,23 @@ export interface IWallet {
   deleted_at?: string;
 }
 
-export type IList<T> = {
-  nowPage?: number;
-  pageSize?: number;
+export type IListBase = {
+  nowPage?: number | string;
+  pageSize?: number | string;
   orderBy?: string;
   orderName?: string;
   keyWord?: string;
-  childNowPage?: string;
-  childPageSize?: string;
+  childNowPage?: number | string;
+  childPageSize?: number | string;
   childOrderBy?: string;
   childOrderName?: string;
   childKeyWord?: string;
   rangTimeType?: 'created_at' | 'updated_at' | 'deleted_at';
-  rangTimeStart?: string;
-  rangTimeEnd?: string;
-} & T;
+  rangTimeStart?: number | string;
+  rangTimeEnd?: number | string;
+};
+
+export type IList<T> = IListBase & T;
 
 export interface IPaging<T> {
   nowPage: number;
@@ -694,18 +696,11 @@ export interface ISrsPublishStream {
   srs_stream_id?: string;
 }
 
-export interface ILive extends ISrsPublishStream {
+export type ILive = {
   id?: number;
-  /** 用户信息 */
-  user?: IUser;
-  /** 直播间信息 */
-  live_room?: ILiveRoom;
 
   socket_id?: string;
-  user_id?: number;
   live_room_id?: number;
-  live_room_is_show?: LiveRoomIsShowEnum;
-  live_room_status?: LiveRoomStatusEnum;
   /** 1开启;2关闭 */
   track_video?: number;
   /** 1开启;2关闭 */
@@ -714,7 +709,10 @@ export interface ILive extends ISrsPublishStream {
   created_at?: string;
   updated_at?: string;
   deleted_at?: string;
-}
+} & ISrsPublishStream & {
+    /** 直播间信息 */
+    live_room?: ILiveRoom;
+  };
 
 export enum MediaTypeEnum {
   camera,

+ 1 - 1
src/store/user/index.ts

@@ -57,7 +57,7 @@ export const useUserStore = defineStore('user', {
       }
     },
     async updateMyWallet() {
-      const res = await fetchMyWallet();
+      const res = await fetchMyWallet({});
       if (res.code === 200) {
         if (this.userInfo?.wallet?.balance) {
           this.userInfo.wallet.balance = res.data.balance;

+ 25 - 10
src/types/websocket.ts

@@ -48,8 +48,6 @@ export enum WsMsgTypeEnum {
   getLiveUser = 'getLiveUser',
   /** 更新加入信息 */
   updateJoinInfo = 'updateJoinInfo',
-  /** 更新直播间预览图 */
-  updateLiveRoomCoverImg = 'updateLiveRoomCoverImg',
   /** 心跳 */
   heartbeat = 'heartbeat',
   /** 开始直播 */
@@ -82,6 +80,30 @@ export enum WsMsgTypeEnum {
   batchSendOffer = 'batchSendOffer',
 }
 
+/** 发送消息统一格式 */
+export interface IReqWsFormat<T> {
+  /** 消息id */
+  request_id: string;
+  /** 用户socket_id */
+  socket_id: string;
+  /** 用户信息 */
+  user_info?: IUser;
+  /** 用户token */
+  user_token?: string;
+  /** 消息时间戳 */
+  time: number;
+  data: T;
+}
+
+/** 接收消息统一格式 */
+export interface IResWsFormat<T> {
+  /** 消息id */
+  request_id: string;
+  /** 消息时间戳 */
+  time: number;
+  data: T;
+}
+
 export interface IWsFormat<T> {
   /** 消息id */
   request_id: string;
@@ -125,9 +147,7 @@ export type WsRoomLivingType = IWsFormat<{
 }>;
 
 /** 直播间没在直播 */
-export type WsRoomNoLiveType = IWsFormat<{
-  live_room: ILiveRoom;
-}>;
+export type WsRoomNoLiveType = IResWsFormat<{ live_room_id: number }>;
 
 export enum RemoteDeskBehaviorEnum {
   move,
@@ -218,11 +238,6 @@ export type WsStartLiveType = IWsFormat<{
   msrMaxDelay: number;
 }>;
 
-/** 更新直播间预览图 */
-export type WsUpdateLiveRoomCoverImg = IWsFormat<{
-  cover_img: string;
-}>;
-
 /** 用户加入直播间 */
 export type WsJoinType = IWsFormat<{
   live_room_id: number;

+ 16 - 0
src/views/about/release/index.vue

@@ -20,12 +20,28 @@
           <p>提交哈希:{{ serverInfo?.billd.commitHash }}</p>
           <p>最后构建:{{ serverInfo?.billd.lastBuildDate }}</p>
         </div>
+        <div class="hr"></div>
+        <div
+          v-loading="loading"
+          class="item"
+        >
+          <h2>服务器信息</h2>
+          <p>操作系统:{{ serverInfo?.server.uname }}</p>
+          <p>Node版本:{{ serverInfo?.server.nodeVersion }}</p>
+          <p>Npm版本:{{ serverInfo?.server.npmVersion }}</p>
+          <p>Pnpm版本:{{ serverInfo?.server.pnpmVersion }}</p>
+          <p>Pm2版本:{{ serverInfo?.server.pm2Version }}</p>
+          <p>Docker版本:{{ serverInfo?.server.dockerVersion }}</p>
+          <p>Mysql版本:{{ serverInfo?.server.mysqlVersion }}</p>
+          <p>Redis版本:{{ serverInfo?.server.redisVersion }}</p>
+        </div>
       </div>
     </div>
     <div class="aside">
       <div class="title">本页目录</div>
       <div class="item">前端版本</div>
       <div class="item">后端版本</div>
+      <div class="item">服务器信息</div>
     </div>
   </div>
 </template>

+ 9 - 11
src/views/area/id/index.vue

@@ -99,17 +99,15 @@ watch(
 );
 
 function handleStatus() {
-  if (longListRef.value) {
-    if (loading.value) {
-      status.value = 'loading';
-    } else if (hasMore.value) {
-      status.value = 'normal';
-    } else {
-      status.value = 'allLoaded';
-    }
-    if (!liveRoomList.value?.length) {
-      status.value = 'nonedata';
-    }
+  if (loading.value) {
+    status.value = 'loading';
+  } else if (hasMore.value) {
+    status.value = 'normal';
+  } else {
+    status.value = 'allLoaded';
+  }
+  if (!liveRoomList.value?.length) {
+    status.value = 'nonedata';
   }
 }
 

+ 3 - 3
src/views/doc/privatizationDeployment/index.vue

@@ -265,7 +265,7 @@ const detail = ref({
         desc: '适用于个人/企业自建直播平台',
         price: {
           left: '¥',
-          center: '3999',
+          center: 'XXXX',
           right: '起',
         },
         tip: '涵盖Github全部/部分功能',
@@ -317,7 +317,7 @@ const detail = ref({
         },
       },
       {
-        color: 'blue',
+        color: 'green',
         name: '付费课程',
         desc: '适用于前端/音视频小白',
         price: {
@@ -360,7 +360,7 @@ const detail = ref({
         desc: '适用于个人/企业自建直播平台',
         price: {
           left: '¥',
-          center: '4999',
+          center: 'XXXX',
           right: '起',
         },
         tip: '',

+ 20 - 20
src/views/h5/area/index.vue

@@ -6,6 +6,7 @@
         :class="{
           list: 1,
         }"
+        :status="status"
         ref="longListRef"
         @get-list-data="getListData"
       >
@@ -46,19 +47,6 @@
           </div>
           <div class="desc">{{ iten?.name }}</div>
         </div>
-        <div v-if="loading"></div>
-        <div
-          v-else-if="!liveRoomList.length"
-          class="null"
-        >
-          {{ t('common.nonedata') }}
-        </div>
-        <div
-          v-else-if="!hasMore"
-          class="null"
-        >
-          {{ t('common.allLoaded') }}
-        </div>
       </LongList>
     </div>
   </div>
@@ -94,6 +82,7 @@ const height = ref(0);
 const loading = ref(false);
 const hasMore = ref(true);
 const longListRef = ref<InstanceType<typeof LongList>>();
+const status = ref<'loading' | 'nonedata' | 'allLoaded' | 'normal'>('loading');
 
 function goRoom(item: ILiveRoom) {
   if (!item.live) {
@@ -115,17 +104,28 @@ onMounted(() => {
   getData();
 });
 
+function handleStatus() {
+  if (loading.value) {
+    status.value = 'loading';
+  } else if (hasMore.value) {
+    status.value = 'normal';
+  } else {
+    status.value = 'allLoaded';
+  }
+  if (!liveRoomList.value?.length) {
+    status.value = 'nonedata';
+  }
+}
+
 async function getData() {
   try {
     if (loading.value) return;
     loading.value = true;
     pageParams.nowPage += 1;
-    if (longListRef.value) {
-      longListRef.value.loading = true;
-    }
+    status.value = 'loading';
     const res = await fetchLiveRoomList({
       id: Number(route.params.id),
-      live_room_is_show: LiveRoomIsShowEnum.yes,
+      is_show: LiveRoomIsShowEnum.yes,
       ...pageParams,
     });
     if (res.code === 200) {
@@ -137,9 +137,9 @@ async function getData() {
     console.log(error);
   }
   loading.value = false;
-  if (longListRef.value) {
-    longListRef.value.loading = false;
-  }
+  status.value = 'normal';
+  status.value = 'normal';
+  handleStatus();
 }
 function getListData() {
   if (!hasMore.value) return;

+ 7 - 5
src/views/h5/index.vue

@@ -121,8 +121,11 @@ const currentSwiper = ref(swiperList.value[0]);
 async function getLiveRoomList() {
   try {
     const res = await fetchAreaLiveRoomList({
-      live_room_is_show: LiveRoomIsShowEnum.yes,
-      live_room_status: LiveRoomStatusEnum.normal,
+      is_show: LiveRoomIsShowEnum.yes,
+      status: LiveRoomStatusEnum.normal,
+      // is_fake: 2,
+      // cdn: LiveRoomUseCDNEnum.yes,
+      // id: 2,
       orderName: 'priority',
       orderBy: 'desc',
       nowPage: 1,
@@ -131,7 +134,7 @@ async function getLiveRoomList() {
       childNowPage: 1,
       childOrderName: 'priority',
       childOrderBy: 'desc',
-      childKeyWord: '',
+      // childKeyWord: '',
     });
     if (res.code === 200) {
       liveRoomList.value = res.data.rows;
@@ -237,8 +240,7 @@ onUnmounted(() => {
         align-items: center;
         justify-content: space-between;
         margin-bottom: 10px;
-        .left {
-        }
+
         .right {
           color: #999;
           font-size: 14px;

+ 19 - 15
src/views/home/index.vue

@@ -60,7 +60,7 @@
             :style="{
               backgroundImage: `url(${
                 appStore.liveRoomInfo?.cover_img ||
-                appStore.liveRoomInfo?.user?.avatar
+                appStore.liveRoomInfo?.users?.[0]?.avatar
               })`,
             }"
           ></div>
@@ -104,11 +104,12 @@
               :key="index"
               :class="{
                 item: 1,
-                active: item.live_room_id === appStore.liveRoomInfo?.id,
+                active: item.live_room?.id === appStore.liveRoomInfo?.id,
               }"
               :style="{
                 backgroundImage: `url(${
-                  item.live_room?.cover_img || item?.user?.avatar
+                  item.live_room?.cover_img ||
+                  item.live_room?.users?.[0]?.avatar
                 })`,
               }"
               @click="changeLiveRoom(item)"
@@ -137,11 +138,11 @@
                 class="border"
                 :style="{
                   opacity:
-                    item.live_room_id === appStore.liveRoomInfo?.id ? 1 : 0,
+                    item.live_room?.id === appStore.liveRoomInfo?.id ? 1 : 0,
                 }"
               ></div>
               <div
-                v-if="item.live_room_id === appStore.liveRoomInfo?.id"
+                v-if="item.live_room?.id === appStore.liveRoomInfo?.id"
                 class="triangle"
               ></div>
               <div class="txt">{{ item.live_room?.name }}</div>
@@ -169,7 +170,8 @@
             <div
               class="cover"
               v-lazy:background-image="
-                iten?.live_room?.cover_img || iten?.user?.avatar
+                iten?.live_room?.cover_img ||
+                iten?.live_room?.users?.[0]?.avatar
               "
             >
               <PullAuthTip
@@ -190,7 +192,7 @@
               >
                 <div class="txt">CDN</div>
               </div>
-              <div class="txt">{{ iten?.user?.username }}</div>
+              <div class="txt">{{ iten?.live_room?.users?.[0].username }}</div>
             </div>
             <div class="desc">{{ iten?.live_room?.name }}</div>
           </div>
@@ -214,7 +216,8 @@
             <div
               class="cover"
               v-lazy:background-image="
-                iten?.live_room?.cover_img || iten?.user?.avatar
+                iten?.live_room?.cover_img ||
+                iten?.live_room?.users?.[0]?.avatar
               "
             >
               <PullAuthTip
@@ -235,7 +238,7 @@
               >
                 <div class="txt">CDN</div>
               </div>
-              <div class="txt">{{ iten?.user?.username }}</div>
+              <div class="txt">{{ iten?.live_room?.users?.[0].username }}</div>
             </div>
             <div class="desc">{{ iten?.live_room?.name }}</div>
           </div>
@@ -293,7 +296,6 @@ import { routerName } from '@/router';
 import { useAppStore } from '@/store/app';
 import {
   ILiveRoom,
-  LiveRoomIsShowEnum,
   LiveRoomPullIsShouldAuthEnum,
   LiveRoomTypeEnum,
   LiveRoomUseCDNEnum,
@@ -463,15 +465,17 @@ function changeLiveRoom(item: ILive) {
 async function getLiveRoomList() {
   try {
     const res = await fetchLiveList({
-      live_room_is_show: LiveRoomIsShowEnum.yes,
       orderName: 'created_at',
       orderBy: 'desc',
+      childOrderName: 'priority,name',
+      childOrderBy: 'desc,asc',
+      // status: 0,
+      // is_show: 0,
+      // cdn: 0,
+      // is_fake: 0,
+      // live_room_id: 1,
     });
     if (res.code === 200) {
-      // const arr: IBilibiliLiveUserRecommend[] = await handleBilibilData();
-      // first.value = false;
-      // @ts-ignore
-      // res.data.rows.push(...arr);
       topLiveRoomList.value = res.data.rows.slice(0, topNums.value);
       otherLiveRoomList.value = res.data.rows.slice(topNums.value);
       if (res.data.total) {

+ 15 - 11
src/views/pull/index.vue

@@ -912,18 +912,22 @@ async function handlePay(item: IGoods) {
   if (!loginTip()) {
     return;
   }
-  const res = await fetchGiftRecordCreate({
-    goodsId: item.id!,
-    goodsNums: 1,
-    liveRoomId: Number(roomId.value),
-    isBilibili: false,
-  });
-  if (res.code === 200) {
-    window.$message.success('打赏成功!');
-    sendDanmuReward(item.name || '');
+  try {
+    const res = await fetchGiftRecordCreate({
+      goodsId: item.id!,
+      goodsNums: 1,
+      liveRoomId: Number(roomId.value),
+      isBilibili: false,
+    });
+    if (res.code === 200) {
+      window.$message.success('打赏成功!');
+      sendDanmuReward(item.name || '');
+    }
+    userStore.updateMyWallet();
+    getGiftGroupList();
+  } catch (error) {
+    console.log(error);
   }
-  userStore.updateMyWallet();
-  getGiftGroupList();
 }
 
 function handleFullScreen() {

+ 10 - 13
src/views/push/index.vue

@@ -472,7 +472,7 @@ import {
   VolumeMuteOutline,
 } from '@vicons/ionicons5';
 import { AVRecorder } from '@webav/av-recorder';
-import { copyToClipBoard, getRandomString } from 'billd-utils';
+import { copyToClipBoard } from 'billd-utils';
 import { fabric } from 'fabric';
 import {
   Raw,
@@ -514,7 +514,6 @@ import { usePiniaCacheStore } from '@/store/cache';
 import { useNetworkStore } from '@/store/network';
 import { useUserStore } from '@/store/user';
 import { LiveRoomTypeEnum } from '@/types/ILiveRoom';
-import { WsMsgTypeEnum, WsUpdateLiveRoomCoverImg } from '@/types/websocket';
 import {
   base64ToFile,
   createVideo,
@@ -555,6 +554,7 @@ const {
   sendDanmu,
   keydownDanmu,
   sendBlob,
+  sendRoomNoLive,
   roomId,
   msgIsFile,
   mySocketId,
@@ -655,7 +655,7 @@ watch(
   () => roomLiving.value,
   (newval) => {
     if (!newval) {
-      handleEndLive();
+      endLive();
       useTip({
         content: '直播已结束',
         hiddenCancel: true,
@@ -1213,12 +1213,17 @@ function handleMixedAudio() {
 }
 
 function handleEndLive() {
+  clearLoop();
+  endLive();
+  sendRoomNoLive();
+}
+
+function clearLoop() {
   worker.value?.postMessage({
     type: 'request-clear-loop',
     timer: workerMsrTimerId.value,
   });
   recorder.value?.removeEventListener('dataavailable', handleSendBlob);
-  endLive();
 }
 
 async function handleHistoryMsg() {
@@ -1323,15 +1328,7 @@ async function uploadLivePreview() {
     file,
   });
   if (uploadRes.flag && uploadRes.resultUrl) {
-    networkStore.wsMap
-      .get(roomId.value)
-      ?.send<WsUpdateLiveRoomCoverImg['data']>({
-        requestId: getRandomString(8),
-        msgType: WsMsgTypeEnum.updateLiveRoomCoverImg,
-        data: {
-          cover_img: uploadRes.resultUrl,
-        },
-      });
+    fetchUpdateMyLiveRoom({ cover_img: uploadRes.resultUrl });
   }
 }
 

+ 8 - 4
src/views/rank/index.vue

@@ -170,7 +170,7 @@ const mockDataNums = 4;
 
 const pageParams = reactive({
   nowPage: 1,
-  pageSize: 100,
+  pageSize: 50,
 });
 
 const currRankType = ref(RankTypeEnum.liveRoom);
@@ -271,7 +271,11 @@ function handleJoin(item) {
 async function getWalletList() {
   try {
     fullLoading({ loading: true });
-    const res = await fetchWalletList({ ...pageParams });
+    const res = await fetchWalletList({
+      ...pageParams,
+      orderName: 'balance',
+      orderBy: 'desc',
+    });
     if (res.code === 200) {
       const length = res.data.rows.length;
       rankList.value = res.data.rows.map((item, index) => {
@@ -381,9 +385,9 @@ async function getSigninList() {
   try {
     fullLoading({ loading: true });
     const res = await fetchSigninList({
-      orderName: 'sum_nums',
-      orderBy: 'desc',
       ...pageParams,
+      orderName: 'sum_nums,max_nums,recently_signin_time',
+      orderBy: 'desc,desc,desc',
     });
     if (res.code === 200) {
       const length = res.data.rows.length;

+ 2 - 4
src/views/shop/index.vue

@@ -92,8 +92,8 @@ async function getGoodsList(type: GoodsTypeEnum) {
     loading.value = true;
     const res = await fetchGoodsList({
       type,
-      orderName: 'created_at',
-      orderBy: 'desc',
+      orderName: 'price,created_at',
+      orderBy: 'asc,desc',
     });
     if (res.code === 200) {
       list.value = res.data.rows;
@@ -214,8 +214,6 @@ function startPay(item: IGoods) {
         .title {
           font-size: 22px;
         }
-        .info {
-        }
         .price-wrap {
           display: flex;
           align-items: center;

+ 5 - 2
src/views/wallet/index.vue

@@ -95,7 +95,7 @@ onMounted(() => {
 });
 
 async function updateMyWallet() {
-  const res = await fetchMyWallet();
+  const res = await fetchMyWallet({});
   if (res.code === 200) {
     if (userStore.userInfo?.wallet?.balance !== undefined) {
       userStore.userInfo.wallet.balance = res.data.balance;
@@ -106,7 +106,10 @@ async function updateMyWallet() {
 async function getPayList() {
   try {
     fullLoading({ loading: true });
-    const res = await fetchWalletRecordMyList({});
+    const res = await fetchWalletRecordMyList({
+      orderName: 'created_at',
+      orderBy: 'desc',
+    });
     if (res.code === 200) {
       walletRecordList.value = res.data.rows;
     }