shuisheng 1 år sedan
förälder
incheckning
7d29afe1be
6 ändrade filer med 129 tillägg och 7 borttagningar
  1. 30 1
      src/App.vue
  2. 17 0
      src/api/globalMsg.ts
  3. 8 0
      src/api/loginRecord.ts
  4. 29 0
      src/hooks/use-pull.ts
  5. 42 0
      src/interface.ts
  6. 3 6
      src/views/pull/index.vue

+ 30 - 1
src/App.vue

@@ -19,7 +19,7 @@ export default {
 <script lang="ts" setup>
 import { isMobile } from 'billd-utils';
 import { GlobalThemeOverrides, NConfigProvider } from 'naive-ui';
-import { onMounted, ref } from 'vue';
+import { onMounted, ref, watch } from 'vue';
 import { useRoute } from 'vue-router';
 
 import { fetchSettingsList } from '@/api/settings';
@@ -32,6 +32,9 @@ import { getHostnameUrl } from '@/utils';
 import { getLastBuildDate, setLastBuildDate } from '@/utils/localStorage/app';
 import { getToken } from '@/utils/localStorage/user';
 
+import { fetchGlobalMsgMyList } from './api/globalMsg';
+import { useTip } from './hooks/use-tip';
+
 const { checkUpdate } = useCheckUpdate();
 const cacheStore = usePiniaCacheStore();
 const userStore = useUserStore();
@@ -47,6 +50,18 @@ const themeOverrides: GlobalThemeOverrides = {
   },
 };
 
+watch(
+  () => userStore.userInfo,
+  (newval) => {
+    if (newval) {
+      handleGlobalMsgMyList();
+    }
+  },
+  {
+    immediate: true,
+  }
+);
+
 onMounted(() => {
   initSettings();
   checkUpdate({
@@ -77,6 +92,20 @@ onMounted(() => {
   }
 });
 
+async function handleGlobalMsgMyList() {
+  const res = await fetchGlobalMsgMyList({});
+  if (res.code === 200) {
+    const data = res.data.rows[0];
+    if (data) {
+      useTip({
+        content: data.content!,
+        hiddenCancel: true,
+        hiddenClose: true,
+      });
+    }
+  }
+}
+
 function initSettings() {
   setTimeout(async () => {
     if (route.path !== '/') {

+ 17 - 0
src/api/globalMsg.ts

@@ -0,0 +1,17 @@
+import { IGlobalMsg, IPaging } from '@/interface';
+import request from '@/utils/request';
+
+export function fetchGlobalMsgList(params) {
+  return request.get('/global_msg/list', {
+    params,
+  });
+}
+
+export function fetchGlobalMsgMyList(params) {
+  return request.get<IPaging<IGlobalMsg>>('/global_msg/my_list', {
+    params,
+  });
+}
+export function fetchGlobalMsgCreate(data) {
+  return request.post('/global_msg/create', data);
+}

+ 8 - 0
src/api/loginRecord.ts

@@ -0,0 +1,8 @@
+import { ILoginRecord, IPaging } from '@/interface';
+import request from '@/utils/request';
+
+export function fetchloginRecordList(params) {
+  return request.get<IPaging<ILoginRecord>>('/login_record/list', {
+    params,
+  });
+}

+ 29 - 0
src/hooks/use-pull.ts

@@ -440,6 +440,33 @@ export function usePull(roomId: string) {
     }
   }
 
+  function sendDanmuReward(txt: string) {
+    if (!loginTip()) {
+      return;
+    }
+    if (!commentAuthTip()) {
+      return;
+    }
+    if (!txt.trim().length) {
+      window.$message.warning('请输入弹幕内容!');
+      return;
+    }
+    const instance = networkStore.wsMap.get(roomId);
+    if (!instance) return;
+    const messageData: WsMessageType['data'] = {
+      content: txt,
+      content_type: WsMessageContentTypeEnum.txt,
+      msg_type: DanmuMsgTypeEnum.reward,
+      live_room_id: Number(roomId),
+      isBilibili: false,
+    };
+    instance.send({
+      requestId: getRandomString(8),
+      msgType: WsMsgTypeEnum.message,
+      data: messageData,
+    });
+  }
+
   function sendDanmuTxt(txt: string) {
     if (!loginTip()) {
       return;
@@ -465,6 +492,7 @@ export function usePull(roomId: string) {
       msgType: WsMsgTypeEnum.message,
       data: messageData,
     });
+    danmuStr.value = '';
   }
 
   function sendDanmuImg(url: string) {
@@ -504,6 +532,7 @@ export function usePull(roomId: string) {
     closeWs,
     closeRtc,
     keydownDanmu,
+    sendDanmuReward,
     sendDanmuTxt,
     sendDanmuImg,
     showPlayBtn,

+ 42 - 0
src/interface.ts

@@ -277,6 +277,48 @@ export interface IGiftRecord {
   deleted_at?: string;
 }
 
+export enum LoginRecordEnum {
+  registerUsername,
+  registerId,
+  registerQq,
+  loginUsername,
+  loginId,
+  loginQq,
+}
+
+export interface ILoginRecord {
+  id?: number;
+  user_id?: number;
+  user_agent?: string;
+  type?: LoginRecordEnum;
+  ip?: string;
+  remark?: string;
+
+  user?: IUser;
+
+  created_at?: string;
+  updated_at?: string;
+  deleted_at?: string;
+}
+
+export enum GlobalMsgTypeEnum {
+  system,
+}
+
+export interface IGlobalMsg {
+  id?: number;
+  user_id?: number;
+  type?: GlobalMsgTypeEnum;
+  content?: string;
+  remark?: string;
+
+  user?: IUser;
+
+  created_at?: string;
+  updated_at?: string;
+  deleted_at?: string;
+}
+
 export interface ISigninStatistics {
   id?: number;
   user_id?: number;

+ 3 - 6
src/views/pull/index.vue

@@ -533,11 +533,11 @@ const {
   closeWs,
   closeRtc,
   keydownDanmu,
+  sendDanmuReward,
   sendDanmuTxt,
   sendDanmuImg,
   handlePlay,
   videoWrapRef,
-  danmuMsgType,
   msgIsFile,
   mySocketId,
   videoResolution,
@@ -549,8 +549,6 @@ const {
   anchorInfo,
 } = usePull(roomId.value);
 
-// const { initWs } = useWebsocket();
-
 const rtcRtt = computed(() => {
   const arr: any[] = [];
   networkStore.rtcMap.forEach((rtc) => {
@@ -930,12 +928,11 @@ async function handlePay(item: IGoods) {
     goodsId: item.id!,
     goodsNums: 1,
     liveRoomId: Number(roomId.value),
-    isBilibili: isBilibili.value,
+    isBilibili: false,
   });
   if (res.code === 200) {
     window.$message.success('打赏成功!');
-    danmuMsgType.value = DanmuMsgTypeEnum.reward;
-    sendDanmuTxt(item.name || '');
+    sendDanmuReward(item.name || '');
   }
   userStore.updateMyWallet();
   getGiftGroupList();