diff --git a/src/layout/components/notice/index.vue b/src/layout/components/notice/index.vue index 497c5fe..16f8e9d 100644 --- a/src/layout/components/notice/index.vue +++ b/src/layout/components/notice/index.vue @@ -73,15 +73,26 @@ const dialog = reactive({ title: '' }); +const parseNoticeItem = (notice: any) => { + const rawMessage = String(notice.message ?? ''); + const [messagePart, videoIdPart] = rawMessage.split('|', 2); + return { + ...notice, + rawMessage, + message: messagePart?.trim() ?? rawMessage, + videoId: videoIdPart?.trim() ?? '' + }; +}; + //查看画面 const handleSee = async (row: any) => { - console.log('查看画面', row); - // 在这里可以添加打开画面的逻辑 - // if (!row || !row.videoUrl) { - // proxy?.$modal.msgError('视频地址不存在'); - // return; - // } - await videosStore.getVideos('2057338485989367810'); + const videoId = row?.videoId; + console.log('查看画面', row, 'videoId', videoId); + if (!videoId) { + proxy?.$modal.msgError('视频ID不存在'); + return; + } + await videosStore.getVideos(videoId); monitorVideoUrl.value = videosStore.hisUrl; dialog.visible = true; await nextTick(); @@ -115,8 +126,8 @@ const getTableData = async () => { state.loading = true; const allNotices = [...noticeStore.state.notices]; // 复制数组避免直接修改原数据 - // 过滤消息 - const filteredNotices = filterMessages(allNotices); + // 过滤消息并解析 message/videoId + const filteredNotices = filterMessages(allNotices).map(parseNoticeItem); newsList.value = filteredNotices; state.loading = false; }; @@ -125,7 +136,7 @@ const getTableData = async () => { watch( () => noticeStore.state.notices, (newNotices) => { - const filteredNotices = filterMessages([...newNotices]); + const filteredNotices = filterMessages([...newNotices]).map(parseNoticeItem); newsList.value = filteredNotices; console.log('监听消息队列', newsList.value); }, @@ -148,11 +159,13 @@ const onNewsClick = (item: any) => { // 辅助函数:找到原始索引 const findOriginalIndex = (filteredIndex: number) => { - const filteredNotices = filterMessages([...noticeStore.state.notices]); + const filteredNotices = filterMessages([...noticeStore.state.notices]).map(parseNoticeItem); const currentMessage = filteredNotices[filteredIndex]; // 在原始数组中查找对应消息的索引 - return noticeStore.state.notices.findIndex((notice: any) => notice.message === currentMessage.message && notice.time === currentMessage.time); + return noticeStore.state.notices.findIndex( + (notice: any) => String(notice.message) === currentMessage.rawMessage && notice.time === currentMessage.time + ); }; // 前往通知中心点击