实时显示数据 SignalR 及时消息提醒( 立即向其推送内容)
实时显示数据 SignalR 及时消息提醒( 立即向其推送内容)
<!--Reference the SignalR library. -->
<script src="~/Scripts/jquery.signalR-2.2.1.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="~/signalr/hubs"></script>
//消息推送初始化连接
var msg = $.connection.messageHub;
msg.client.NotifyUser = function (id,message) {
var count = $('[data-msg-count]').html();
$('[data-msg-count]').html(parseInt(count) + 1);
$('[data-notification]').prepend(
'<li data-layoutnotify-msg="' + id + '"><p><small class="clear"><i class="glyphicon glyphicon-menu-right text-blue"></i> ' + message
+ '<br /><t class="addi">' + new Date().toLocaleString() + '</t><a class="mark-btn" href="#" data-layout-msgmarksingle="' + id + '">已读</a></small></p></li>'
);
ui.notify(message).sticky().effect('slide');
};
$.connection.hub.start();
$('[data-msg-btn]').click(function () {
$('[data-msg-panel]').slideToggle();
});
//标记为已读
$('[data-layoutnotify-markasread]').click(function () {
var ids = '';
$('[data-layoutnotify-msg]').each(function () {
ids += $(this).attr('data-layoutnotify-msg') + ',';
$(this).slideUp();
var count = $('[data-msg-count]').html();
$('[data-msg-count]').html(parseInt(count) - 1);
});
ids = ids.trim(',');
$.post('/Notification/MarkAsRead', { ids: ids });
});
$('[data-notification]').on('click','[data-layout-msgmarksingle]',function () {
var id = $(this).attr('data-layout-msgmarksingle');
$('[data-layoutnotify-msg=' + id + ']').slideUp();
var count = $('[data-msg-count]').html();
$('[data-msg-count]').html(parseInt(count) - 1);
$.post('/Notification/MarkAsRead', { ids: id });
});
Notifieaar.Process("0.00");
DoFunction(funcAttr[0].ToString(), orgId, projId, templateId, aid, leve);
Notifieaar.Process("100");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.SignalR;
using Microsoft.AspNet.SignalR.Hubs;
using System.Threading.Tasks;
namespace Haifeng.Zichabao.Hubs
{
[HubName("XEMHub")]
public class XEMHub : Hub
{
public static List<XEMProcess> ConnectPool = new List<XEMProcess>();
}
/// <summary>
/// 服务端通知Hub
/// </summary>
public class Notifieaar
{
private static readonly IHubContext Context = GlobalHost.ConnectionManager.GetHubContext<XEMHub>();
/// <summary>
/// 通知客户端信息
/// </summary>
///process 进度
public static void Process(string process)
{
Context.Clients.All.Show(process);
}
}
/// <summary>
/// 测试小而美进度
/// </summary>
public class XEMProcess
{
public decimal Process { get; set; }
}
}
滴水能把石穿透,成事功到自然成