1
hutongqing
2024-09-13 3ca95f10e441ff66d4d62f8dfe202bfb26c3c8e8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import * as signalR from '@microsoft/signalr';
import { ElNotification } from 'element-plus';
 
export default function (http, receive) {
  let connection;
  http.post('api/User/GetCurrentUserInfo').then((result) => {
    connection = new signalR.HubConnectionBuilder()
      .withAutomaticReconnect()
      .withUrl(`${http.ipAddress}message?userName=${result.data.userName}`)
     //.withUrl(`${http.ipAddress}message`)
      .build();
 
    connection.start().catch((err) => console.log(ex.message));
    //自动重连成功后的处理
    connection.onreconnected((connectionId) => {
      console.log(connectionId);
    });
    connection.on('ReceiveHomePageMessage', function (data) {
      console.log(data)
      ElNotification.success({
        title:data.title,
        message: data.message + '',
        type: 'info'
      });
      receive && receive(data);
    });
  });
}