|
@@ -96,6 +96,9 @@ onMounted(() => {
|
|
|
})
|
|
|
|
|
|
eventSource.onmessage = (event: MessageEvent) => {
|
|
|
+ // const data = JSON.parse()
|
|
|
+ console.log('Received message-----:', event)
|
|
|
+
|
|
|
const eventType = event.type
|
|
|
const notificationTitles: { [key: string]: string } = {
|
|
|
message: '消息',
|
|
@@ -113,16 +116,28 @@ onMounted(() => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ eventSource.addEventListener('remind', (event: MessageEvent) => {
|
|
|
+ const data = JSON.parse(event.data)
|
|
|
+ console.log('Received remind event:', event)
|
|
|
+ // 处理接收到的提醒消息
|
|
|
+ ElNotification({
|
|
|
+ title: data.title,
|
|
|
+ message: data.content,
|
|
|
+ type: 'success',
|
|
|
+ duration: 10000
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
eventSource.onerror = (error: any) => {
|
|
|
console.error('EventSource failed:', error)
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
- if (eventSource) {
|
|
|
- eventSource.close()
|
|
|
- }
|
|
|
-})
|
|
|
+// onBeforeUnmount(() => {
|
|
|
+// if (eventSource) {
|
|
|
+// eventSource.close()
|
|
|
+// }
|
|
|
+// })
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|