翼度科技»论坛 编程开发 .net 查看内容

SignalR实战:在.NET Framework和.NET Core中如何使用SignalR?

8

主题

8

帖子

24

积分

新手上路

Rank: 1

积分
24
官网文档:https://learn.microsoft.com/zh-cn/aspnet/core/tutorials/signalr?view=aspnetcore-6.0&tabs=visual-studio
SignalR开源代码:https://github.com/signalr

很多小伙伴问:在前后端分离项目中,后端是.NET Core前端是Vue如何使用SignalR?在前后端不分离项目中,.NET Framework MVC项目中又如何使用SignalR技术呢?那就来看看下面这篇文章吧!本文主要介绍SignalR在实际项目中的应用,以及.NET Framework和.NET Core中如何去使用SignalR。

一、SignalR介绍

1.1-SignalR介绍

ASP.NET Core SignalR是一个开放源代码库,可用于简化向应用添加实时Web功能,实时Web功能使服务器端代码能够将内容推送到客户端。

1.2-SignalR的应用


  • 需要从服务器进行高频更新的应用:包括游戏、社交网络、投票、拍卖、地图和GPS引用。
  • 仪表盘和监视应用:包括公司仪表板、即时销售更新或旅行报警
  • 协作应用:包括白板应用和团队会议软件。
  • 通知应用:社交网络、电子邮件、聊天、游戏、旅行报警和其他应用都需要使用的通知。

二、.NET Framework使用SignalR

参考文献:
Owin介绍:https://www.cnblogs.com/Pinapple/p/6721361.html
Owin相关案例:https://blog.csdn.net/bifan546/article/details/77098896/

2.1-服务端(.NET Framework MVC)

(1)选择要使用Signalr的项目,点击【管理NuGet程序包】。

(2)搜索【SignalR】包,找到这个后然后点击下载。

会自动安装四个,注意他们之间有依赖关系:

(3).NET Framework平台需要添加Owin相关的包。
OWIN 是一种定义 Web 服务器和应用程序组件之间的交互的规范 。这一规范的目的是发展一个广阔且充满活力的、基于 Microsoft .NET Framework 的 Web 服务器和应用程序组件生态系统。
Microsoft.Owin.Hosting
Microsoft.Owin.Cors
Microsoft.Owin.Host.HttpListener
(4)在Web项目(要使用的Signal)中创建一个【Startup.cs】文件。
  1. using JiCai.Admin.Hubs;
  2. using Microsoft.Owin;
  3. using Owin;
  4. [assembly: OwinStartup(typeof(JiCai.Admin.Startup))]
  5. namespace JiCai.Admin
  6. {
  7.     public class Startup
  8.     {
  9.         /// <summary>
  10.         /// 应用程序配置
  11.         /// </summary>
  12.         /// <param name="app"></param>
  13.         public void Configuration(IAppBuilder app)
  14.         {
  15.             //启用SignalR
  16.             app.MapSignalR();
  17.             //绑定多个Hub
  18.             app.MapSignalR<DemoHub>("/demoHub");
  19.         }
  20.     }
  21. }
复制代码
例如:

(5)可以创建一个【Hubs】文件夹,专门放置Hub相关文件。[西瓜程序猿]这边是创建一个Hub文件,名为【DemoHub.cs】。
  1. using Fenqibao.DTO;
  2. using JiCai.Admin.Hubs.ConectionOperate;
  3. using JiCai.Admin.Hubs.Models;
  4. using log4net;
  5. using Microsoft.AspNet.SignalR;
  6. using Microsoft.AspNet.SignalR.Json;
  7. using Newtonsoft.Json;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace JiCai.Admin.Hubs
  13. {
  14.     /// <summary>
  15.     /// 报表管理-总表Hub
  16.     /// </summary>
  17.     public class SummaryTableHub :  PersistentConnection
  18.     {
  19.         public readonly BaseService _base = new BaseService();
  20.         private readonly ILog logger = LogManager.GetLogger(typeof(SummaryTableHub));
  21.         private ConnectionManagement summaryTableCon = new ConnectionManagement();
  22.         public CookieUserData LoginUserData
  23.         {
  24.             get
  25.             {
  26.                 IOperator oper = ContainerManager.Resolve<IOperator>();
  27.                 LoginUser loginUser = oper as LoginUser;
  28.                 if (loginUser != null && loginUser.UserData != null)
  29.                 {
  30.                     return loginUser.UserData;
  31.                 }
  32.                 return null;
  33.             }
  34.         }
  35.         /// <summary>
  36.         /// 连接成功后调用
  37.         /// </summary>
  38.         /// <param name="request"></param>
  39.         /// <param name="connectionId"></param>
  40.         /// <returns></returns>
  41.         protected override Task OnConnected(IRequest request, string connectionId)
  42.         {
  43.             //获得SignalR的连接id
  44.             var connid = connectionId;
  45.             //获得用户id
  46.             var userid = LoginUserData.Id.ToString();
  47.             Console.Write($"【{connid}】:已建立连接!");
  48.             //判断一下用户是不是已经链接了
  49.             var checkUserConn = summaryTableCon.IsConn(connid, userid);
  50.             if (!checkUserConn)
  51.             {
  52.                 //添加一个新的连接
  53.                 summaryTableCon.AddConnInfo(new SignalRConn()
  54.                 {
  55.                     UserId = userid,
  56.                     ConnectionId = connid
  57.                 });
  58.             }
  59.             //更新连接
  60.             else
  61.             {
  62.                 summaryTableCon.UpdateConnInfo(userid, connid);
  63.             }
  64.             return Connection.Send(connectionId, $"【用户:{connectionId}】真正连接成功!");
  65.             //return base.OnConnected(request, connectionId);
  66.         }
  67.         /// <summary>
  68.         /// 接收到请求的时候调用
  69.         /// </summary>
  70.         /// <param name="request"></param>
  71.         /// <param name="connectionId"></param>
  72.         /// <param name="data"></param>
  73.         /// <returns></returns>
  74.         protected override async Task OnReceived(IRequest request, string connectionId, string data)
  75.         {
  76.             //获得用户id
  77.             var userid = LoginUserData.Id.ToString();
  78.             await Task.Factory.StartNew(async () =>
  79.             {
  80.                 while (true)
  81.                 {
  82.                                         var list = GetSummaryTableList(userid);
  83.                     string json_jieshou_mes = "";
  84.                     if (list != null && list.Count > 0)
  85.                     {
  86.                                                 json_jieshou_mes = JsonConvert.SerializeObject(list);
  87.                     }
  88.                     await Connection.Send(connectionId, json_jieshou_mes);
  89.                     //每5秒同步一次
  90.                     await Task.Delay(5000);
  91.                 }
  92.             }, TaskCreationOptions.LongRunning);
  93.             //return base.OnReceived(request, connectionId, data);
  94.         }
  95.         /// <summary>
  96.         /// 连接中断的时候调用
  97.         /// </summary>
  98.         /// <param name="request"></param>
  99.         /// <param name="connectionId"></param>
  100.         /// <param name="stopCalled"></param>
  101.         /// <returns></returns>
  102.         protected override Task OnDisconnected(IRequest request, string connectionId, bool stopCalled)
  103.         {
  104.             Console.Write($"【{connectionId}】:已断开连接!");
  105.             //获得SignalR的连接id
  106.             var connid = connectionId;
  107.             //关闭连接
  108.             summaryTableCon.DelConnInfo(connid);
  109.             return base.OnDisconnected(request, connectionId, stopCalled);
  110.         }
  111.         /// <summary>
  112.         /// 连接超时重新连接的时候调用
  113.         /// </summary>
  114.         /// <param name="request"></param>
  115.         /// <param name="connectionId"></param>
  116.         /// <returns></returns>
  117.         protected override Task OnReconnected(IRequest request, string connectionId)
  118.         {
  119.             return base.OnReconnected(request, connectionId);
  120.         }
  121.                 /// <summary>
  122.                 /// 查询数据
  123.                 /// </summary>
  124.                 /// <param name="userId"></param>
  125.                 /// <returns></returns>
  126.                 private List<SummaryTableDataModel> GetSummaryTableList(string userId)
  127.         {
  128.             var result = _base.Query<SummaryTableDataModel>($@"
  129.                             select * from demo-data
  130.                                         ;
  131.             ").ToList();
  132.                         return result;
  133.         }
  134.     }
  135. }
复制代码
(6)在Hubs/ConectionOperate文件夹中,[西瓜程序猿]这边创建【ConnectionManagement】文件,用来管理所有连接。
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace JiCai.Admin.Hubs.ConectionOperate
  4. {
  5.     /// <summary>
  6.     /// 连接管理
  7.     /// </summary>
  8.     public class ConnectionManagement
  9.     {
  10.         /// <summary>
  11.         /// 用户连接集合
  12.         /// </summary>
  13.         public static  List<SignalRConn> SignalRConns { get; set; } = new List<SignalRConn>();
  14.         /// <summary>
  15.         /// 添加连接
  16.         /// </summary>
  17.         /// <param name="conn"></param>
  18.         public  void AddConnInfo(SignalRConn conn)
  19.         {
  20.             SignalRConns.Add(conn);
  21.         }
  22.         /// <summary>
  23.         /// 删除连接
  24.         /// </summary>
  25.         /// <param name="connid"></param>
  26.         public  void DelConnInfo(string connid)
  27.         {
  28.             var signalRConns = SignalRConns.FirstOrDefault(u => u.ConnectionId == connid);
  29.             if (signalRConns != null)
  30.             {
  31.                 SignalRConns.Remove(signalRConns);
  32.             }
  33.         }
  34.         /// <summary>
  35.         /// 更新链接(老的链接不起作用了)
  36.         /// 场景:客户端重连了,userid没变,但是connid变了
  37.         /// </summary>
  38.         /// <param name="userId">用户id</param>
  39.         /// <param name="newConnsId">新的链接id</param>
  40.         public  void UpdateConnInfo(string userId, string newConnsId)
  41.         {
  42.             var signalRConns = SignalRConns.FirstOrDefault(u => u.UserId.ToLower() == userId.ToLower());
  43.             if (signalRConns != null)
  44.             {
  45.                 signalRConns.ConnectionId = newConnsId;
  46.             }
  47.         }
  48.         /// <summary>
  49.         /// 判断用户是否已经链接
  50.         /// </summary>
  51.         /// <param name="connid">连接id</param>
  52.         /// <param name="userid">用户id</param>
  53.         /// <returns></returns>
  54.         public bool IsConn(string connid,string userid)
  55.         {
  56.             var userConn = SignalRConns.FirstOrDefault(u => u.ConnectionId.ToLower() == connid.ToLower() && u.UserId.ToLower() == userid.ToLower());
  57.             return userConn == null ? false : true;
  58.         }
  59.     }
  60. }
复制代码
(7)在Hubs/ConectionOperate文件夹中,创建【SignalRConn.cs】文件用来作为SignalR和系统用户的连接实体。
  1. namespace JiCai.Admin.Hubs.ConectionOperate
  2. {
  3.     /// <summary>
  4.     /// 连接
  5.     /// </summary>
  6.     public class SignalRConn
  7.     {
  8.         /// <summary>
  9.         /// 系统用户id
  10.         /// </summary>
  11.         public string UserId { get; set; }
  12.         /// <summary>
  13.         /// SignleR链接Id(每次链接SignalR都会分配一个id)
  14.         /// </summary>
  15.         public string ConnectionId { get; set; }
  16.     }
  17. }
复制代码
2.2-客户端(JS)

(1)下载相关jq/signalr相关包,分别是【jquery.signalR-2.4.3.js】和【jquery-1.6.4.min.js】。可以访问下载(如果失效了,请联系我[西瓜程序猿])。
下载地址(编码:yRLCRp81):https://yongteng.lanzoub.com/iXDlu1631ugd
密码:44x5
文件截图:


(2)创建一个js文件【data_list_table_hub.js】,用来连接signalR。
  1. // 连接服务
  2. var connection = $.connection("/summary_table_hub");
  3. // 建立链接
  4. connection.start(function () {
  5.     //连接成功
  6.     console.log("西瓜程序猿-【" + new Date().toLocaleString() +"】连接成功!");
  7.     //发送消息
  8.     connection.send("给我数据吧");
  9. });
  10. // 连接断开
  11. connection.disconnected(function () {
  12.     console.log("西瓜程序猿-【" + new Date().toLocaleString() +"】连接断开!");
  13. });
  14. // 接收服务器发来的消息
  15. connection.received(function (data) {
  16.     console.log("西瓜程序猿-【" + new Date().toLocaleString() +"】接收服务器发来的消息:");
  17.     console.log(data);
  18.     //显示数据
  19.     if (data != "" && checkJson(data)) {
  20.         var obj = JSON.parse(data);
  21.         var html_box = "";
  22.         for (var i = 0; i < obj.length; i++) {
  23.             html_box += `<tr>
  24.             <td>`+obj[i].project_name+`</td>
  25.             <td>`+ obj[i].zuori_sum+`</td>
  26.             <td>`+ obj[i].jinri_sum+`</td>
  27.             <td>`+ obj[i].qunian_sum+`</td>
  28.             <td>`+ obj[i].jinnian_sum+`</td>
  29.             <td>`+ obj[i].sum+`</td>
  30.             <td>`+ obj[i].yikaipiao_sum+`</td>
  31.             <td>`+ obj[i].weikaipiao_sum +`</td>
  32.             <td>`+ obj[i].yishoupiao_sum +`</td>
  33.             <td>`+ obj[i].weishoupiao_sum +`</td>
  34.             <td>`+ obj[i].kehu_yinghuikuan_sum+`</td>
  35.             <td>`+ obj[i].kehu_yihuikuan_sum+`</td>
  36.             <td>`+ obj[i].kehu_weihuikuan_sum +`</td>
  37.             <td>`+ obj[i].fuwu_yingfukuan_sum+`</td>
  38.             <td>`+ obj[i].fuwu_yifukuan_sum+`</td>
  39.             <td>`+ obj[i].fuwu_weifukuan_sum+`</td>
  40.             </tr>`
  41.         }
  42.         $("#last_async_date").text(new Date().toLocaleString());
  43.         $("#table_body").html(html_box);
  44.     }
  45. });
  46. //判断是不是json字符串
  47. function checkJson(str) {
  48.     if (typeof str == 'string') {
  49.         try {
  50.             var obj = JSON.parse(str);
  51.             // 等于这个条件说明就是JSON字符串 会返回true
  52.             if (typeof obj == 'object' && obj) {
  53.                 return true;
  54.             } else {
  55.                 //不是就返回false
  56.                 return false;
  57.             }
  58.         } catch (e) {
  59.             return false;
  60.         }
  61.     }
  62.     return false;
  63. }
复制代码
(3)创建要展示的文件,我这边是用MVC模式,所有前台文件是cshtml。
  1. @{
  2.     ViewBag.Title = "西瓜程序猿-明细表";
  3. }
  4. @section styles{
  5.    
  6. }
  7. @section scripts{
  8.    
  9.    
  10.    
  11. }
  12.    
  13.    
  14.    
  15.         
  16.             报表最新同步时间:
  17.         
  18.         
  19.             <table >
  20.                 <colgroup>
  21.                     <col>
  22.                     <col>
  23.                     <col>
  24.                     <col>
  25.                     <col>
  26.                     <col>
  27.                     <col>
  28.                     <col>
  29.                     <col>
  30.                     <col>
  31.                     <col>
  32.                     <col>
  33.                     <col>
  34.                 </colgroup>
  35.                 <thead>
  36.                     <tr>
  37.                         <th colspan="2" >项目信息</th>
  38.                         <th colspan="5" >销售情况</th>
  39.                         <th colspan="6" >款项情况</th>
  40.                     </tr>
  41.                     <tr>
  42.                         <th >项目名称</th>
  43.                         <th >服务商名称</th>
  44.                         <th >昨天订单总额</th>
  45.                         <th >今天订单总额</th>
  46.                         <th >去年订单总额</th>
  47.                         <th >今年订单总额</th>
  48.                         <th >订单总额</th>
  49.                         <th >客户应回款总额</th>
  50.                         <th >客户已回款总额</th>
  51.                         <th >客户未回款总额</th>
  52.                         <th >服务商应付款总额</th>
  53.                         <th >服务商已付款总额</th>
  54.                         <th >服务商未付款总额</th>
  55.                     </tr>
  56.                 </thead>
  57.                 <tbody id="table_body">
  58.                 </tbody>
  59.             </table>
  60.         
  61.    
复制代码
(4)效果展示:


三、.NET Core WebAPI使用SignalR

场景:项目中需要服务端主动向客户端发送通知消息,后端是使用.NETCore实现的,前端是使用Vue3全家桶项目,前后端分离模式。本次主要讲使用SignalR如何来实现的。

3.1-服务端(.NET Core WebAPI)

1、右击项目,点击【管理NuGet程序包】安装SignalR。

2、搜索【SignalR】,点击【安装】。


3、如果是.NET6以前的版本,在【Startup.cs】中配置:

如果是.NET6以后得版本,在【Program.cs】配置:
  1. var builder = WebApplication.CreateBuilder(args);
  2. //添加SignalR服务
  3. builder.Services.AddSignalR();
  4. app.UseEndpoints(endpoints =>
  5. {
  6.     endpoints.MapControllerRoute(
  7.         name: "default",
  8.         pattern: "{controller=Home}/{action=Index}/{id?}"
  9.     );
  10.     //添加SignalR端点
  11.     endpoints.MapHub<ServerMonitorHub>("/serverMonitorHub");
  12. });
复制代码

4、创建SignalR中心
中心是一个类,用于处理客户端服务器通信的高级管道。在SignalR_Demo项目文件夹中,创建Hubs文件夹。在Hubs文件夹中,使用已下代码创建ChatHub类。
  1.     public class ChatHub:Hub
  2.     {
  3.         /// <summary>
  4.         /// 发送消息
  5.         /// </summary>
  6.         /// <param name="user">用户名</param>
  7.         /// <param name="message">发送信息</param>
  8.         /// <returns></returns>
  9.         public async Task SendMessage(string user,string message)
  10.         {
  11.             await Clients.All.SendAsync("ReceiveMessage", user, message);
  12.         }
  13.     }
复制代码
3.2-客户端(Vue3+Vite+TS)

(1)安装SugbalR
  1. npm install @latelier/vue-signalr
复制代码
版本截图:

(2)然后新建一个文件,用来封装业务逻辑相关代码。[西瓜程序猿]是在【src/utils】目录下,创建了一个名为【signalr.ts】的文件,也可以是js文件,根据自己项目的需要去新建。

代码:
  1. import * as signalR  from '@microsoft/signalr';
  2. //如果需要身份验证
  3. //.withUrl('/messageHub', {accessTokenFactory: () => sessionStorage.getItem('token')})
  4. let connection;
  5. // 建立连接
  6. async function start(url) {
  7.   try {
  8.     connection = new signalR.HubConnectionBuilder()
  9.       .withUrl(url)//跨域需要使用绝对地址
  10.       .configureLogging(signalR.LogLevel.Information)
  11.       .withAutomaticReconnect() // 设置自动重连机制
  12.       .build();
  13.   } catch(err) {
  14.     console.log(err);
  15.     setTimeout(start, 10000);//错误重连
  16.   }
  17. }
  18. // 开始signalr连接
  19. const connect = async (url) => {
  20.   await start(url);
  21.   console.log(`【西瓜程序猿-${new Date().toLocaleString()}:SignalR已连接成功!`);
  22. };
  23. // 调用服务端方法
  24. async function send(methodName, param){
  25.   try {
  26.     await connection.invoke(methodName, param);
  27.   } catch (err) {
  28.     console.error(err);
  29.   }
  30. }
  31. //断开连接
  32. const disconnect = async ()=>{
  33.   await connection.stop();
  34.   console.log(`【西瓜程序猿-${new Date().toLocaleString()}:SignalR已断开连接!`);
  35. };
  36. export {
  37.   connection,
  38.   connect,
  39.   send,
  40.   disconnect
  41. };
复制代码
(3)然后再页面进行使用。[西瓜程序猿]这里以Echarts图表展示为例子,首先先安装Echarts包。
npm install echarts --save
版本截图:

(4)然后再页面写入如下代码,具体页面样式根据需要进行修改调整哦。
  1. <template>
  2.   
  3.   <breadcrumb  />
  4.   
  5.     <el-row>
  6.       <el-col :span="24" >
  7.         <el-card>
  8.           <template #header>
  9.             <i ></i> 服务器信息
  10.           </template>
  11.          
  12.             <table cellspacing="0" >
  13.               <tbody>
  14.                 <tr>
  15.                   <td >主机名称</td>
  16.                   <td >{{serverInfo.HostName}}</td>
  17.                   <td >系统名称</td>
  18.                   <td >{{serverInfo.OSDescription}}</td>
  19.                 </tr>
  20.                 <tr>
  21.                   <td >IP地址</td>
  22.                   <td >{{serverInfo.IpAddress}}</td>
  23.                   <td >操作系统</td>
  24.                   <td >{{serverInfo.OperatingSystem}} {{serverInfo.OsArchitecture}}</td>
  25.                 </tr>
  26.               </tbody>
  27.             </table>
  28.          
  29.         </el-card>
  30.       </el-col>
  31.       <el-col :span="24" >
  32.         <el-card>
  33.           <template #header>
  34.             <i ></i> 应用信息
  35.           </template>
  36.          
  37.             <table cellspacing="0" >
  38.               <tbody>
  39.                 <tr>
  40.                   <td >.NET Core版本</td>
  41.                   <td >{{serverInfo.FrameworkDescription}}</td>
  42.                   <td >内存占用</td>
  43.                   <td >{{serverInfo.MemoryFootprint}}</td>
  44.                 </tr>
  45.                 <tr>
  46.                   <td >环境变量</td>
  47.                   <td >{{serverInfo.EnvironmentName}}</td>
  48.                   <td >项目路径</td>
  49.                   <td >{{serverInfo.ContentRootPath}}</td>
  50.                 </tr>
  51.               </tbody>
  52.             </table>
  53.          
  54.         </el-card>
  55.       </el-col>
  56.       <el-col :span="24" >
  57.         <el-card>
  58.           <template #header>
  59.             <i ></i> 磁盘状态
  60.           </template>
  61.          
  62.             <table cellspacing="0"  >
  63.               <thead>
  64.                 <tr>
  65.                   <th >磁盘名称</th>
  66.                   <th >盘符路径</th>
  67.                   <th >文件系统</th>
  68.                   <th >盘符类型</th>
  69.                   <th >总大小</th>
  70.                   <th >已用大小</th>
  71.                   <th >可用大小</th>
  72.                   <th >已使用率</th>
  73.                 </tr>
  74.               </thead>
  75.               <tbody v-if="diskInfos" >
  76.                 <tr v-for="(sysFile, index) in diskInfos" :key="index">
  77.                   <td >{{ sysFile.DiskName }}</td>
  78.                   <td >{{ sysFile.RootPath }}</td>
  79.                   <td >{{ sysFile.DriveType }}</td>
  80.                   <td >{{ sysFile.FileSystem }}</td>
  81.                   <td >{{ sysFile.TotalSize }}</td>
  82.                   <td >{{ sysFile.UseSize }}</td>
  83.                   <td >{{ sysFile.ResidueSize }}</td>
  84.                   <td ><el-progress :percentage="sysFile.UseRate" :text-inside="true" :stroke-width="14" :color="customColor"/></td>
  85.                 </tr>
  86.               </tbody>
  87.             </table>
  88.          
  89.         </el-card>
  90.       </el-col>
  91.       <el-col :span="24" >
  92.         <el-card >
  93.           <template #header>
  94.             <i ></i> 状态
  95.           </template>
  96.          
  97.             <el-row>
  98.               <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6"  >
  99.                 CPU使用率
  100.                
  101.                   <el-progress type="dashboard" :percentage="cpuInfo.CPULoadVal" :color="customColor" />
  102.                
  103.          
  104.                 {{ cpuInfo.ProcessorCount }} 核心
  105.               </el-col>
  106.               
  107.               <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6"  >
  108.                 内存使用率
  109.                
  110.                   <el-progress type="dashboard" :percentage="memoryInfo.UsedPercentage" :color="customColor" />
  111.                
  112.                 {{ memoryInfo.UsedPhysicalMemory }} / {{ memoryInfo.TotalPhysicalMemory }}
  113.               </el-col>
  114.               <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6"  >
  115.                 网络监控上传
  116.                
  117.                   <el-progress type="dashboard" :percentage="networkInfo.SentSize" :color="customColor" >
  118.                     <template #default>
  119.                       {{networkInfo.SentSize}} {{ networkInfo.SentSizeType }}
  120.                     </template>
  121.                   </el-progress>
  122.                
  123.                  {{networkInfo.SentSize}} {{ networkInfo.SentSizeType }}/S
  124.               </el-col>
  125.               <el-col :xs="6" :sm="6" :md="6" :lg="6" :xl="6"  >
  126.                 网络监控下载
  127.                
  128.                   <el-progress type="dashboard" :percentage="networkInfo.ReceivedSize" :color="customColor" >
  129.                     <template #default>
  130.                       {{networkInfo.ReceivedSize}} {{ networkInfo.ReceivedSizeType }}
  131.                     </template>
  132.                   </el-progress>
  133.                
  134.                  {{networkInfo.ReceivedSize}} {{ networkInfo.ReceivedSizeType }}/S
  135.               </el-col>
  136.             </el-row>
  137.          
  138.         </el-card>
  139.       </el-col>
  140.       <el-col :span="24" >
  141.         <el-row :gutter="25">
  142.             <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" >
  143.               <el-card >
  144.                 <template #header>
  145.                   <i ></i> CPU使用率监控
  146.                 </template>
  147.                
  148.                   
  149.                
  150.               </el-card>
  151.             </el-col>
  152.             <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12" >
  153.               <el-card >
  154.                 <template #header>
  155.                   <i ></i> 内存使用率监控
  156.                 </template>
  157.                
  158.                   
  159.                
  160.               </el-card>
  161.             </el-col>
  162.           </el-row>
  163.       </el-col>
  164.     </el-row>
  165.   
  166. </template>
复制代码
(5)效果展示:



原文链接:https://www.cnblogs.com/kimiliucn/p/17648543.html

来源:https://www.cnblogs.com/kimiliucn/archive/2023/08/22/17648543.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】 我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x

举报 回复 使用道具