From 1b1738847d42781a256700db8a7e685ca04706da Mon Sep 17 00:00:00 2001 From: zhichao lei <442149704@qq.com> Date: Fri, 20 Nov 2020 14:27:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E9=80=81=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Learun.Application.IMServer/App.config | 2 +- .../Learun.Application.IMServer/Hubs/Chats.cs | 10 +++ .../Learun.Application.Web.csproj | 1 + .../Views/LR_Content/script/pushmessage.js | 75 +++++++++++++++++++ .../Views/Shared/_Admin.cshtml | 9 ++- .../Learun.Application.WebApi.csproj | 1 + .../Modules/PushMessageApi.cs | 61 +++++++++++++++ 7 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.Web/Views/LR_Content/script/pushmessage.js create mode 100644 Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/PushMessageApi.cs diff --git a/Learun.Framework.Ultimate V7/Learun.Application.IMServer/App.config b/Learun.Framework.Ultimate V7/Learun.Application.IMServer/App.config index e07370b1f..1392c4b86 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.IMServer/App.config +++ b/Learun.Framework.Ultimate V7/Learun.Application.IMServer/App.config @@ -70,7 +70,7 @@ - + diff --git a/Learun.Framework.Ultimate V7/Learun.Application.IMServer/Hubs/Chats.cs b/Learun.Framework.Ultimate V7/Learun.Application.IMServer/Hubs/Chats.cs index 99c57d6b7..96f615fe0 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.IMServer/Hubs/Chats.cs +++ b/Learun.Framework.Ultimate V7/Learun.Application.IMServer/Hubs/Chats.cs @@ -91,6 +91,16 @@ namespace Learun.Application.IMServer #endregion + + #region 推送消息 + + public void PushMessage(string msg) + { + Clients.All.broadcastMessage(msg); + } + + #endregion + #region 一般公用方法 /// /// 获取登录用户Id diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj index e717918ca..6b052f7ab 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Learun.Application.Web.csproj @@ -3833,6 +3833,7 @@ + diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/LR_Content/script/pushmessage.js b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/LR_Content/script/pushmessage.js new file mode 100644 index 000000000..33471a823 --- /dev/null +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/LR_Content/script/pushmessage.js @@ -0,0 +1,75 @@ +(function ($, learun) { + "use strict"; + + + learun._im = { + init: function () { + learun._im.registerServer(); + learun._im.connect(); + } + // 连接服务端 + , connect: function () { + var loginInfo = learun.clientdata.get(['userinfo']); + if (loginInfo.imOpen != 'true') { + setTimeout(learun._im.connect, 1000); + } + + $.ajax({ + url: loginInfo.imUrl + "/hubs", + type: "get", + dataType: "text", + success: function (data) { + eval(data); + //Set the hubs URL for the connection + $.connection.hub.url = loginInfo.imUrl; + $.connection.hub.qs = { "userId": loginInfo.userId }; + // Declare a proxy to reference the hub. + learun.imChat = $.connection.ChatsHub; + learun.imChat.client.broadcastMessage = function(message) { + top.layer.open({ + type: 1 //此处以iframe举例 + , title: '通知' + , area: ['390px', '330px'] + , shade: 0 + , offset: 'rb' + , maxmin: true + , content: message + , btn: null + , yes: function () { + $(that).click(); //此处只是为了演示,实际使用可以剔除 + } + , btn2: function () { + layer.closeAll(); + } + + , zIndex: layer.zIndex //重点1 + , success: function (layero) { + layer.setTop(layero); //重点2 + } + }); + } + if (!learun.imChat) { + setTimeout(learun._im.connect, 1000); + } + // 连接成功后注册服务器方法 + $.connection.hub.start().done(function () { + learun.imChat.server.pushMessage('123123'); + }); + //断开连接后 + $.connection.hub.disconnected(function () { + // + }); + }, + error: function (XMLHttpRequest, textStatus, errorThrown) { + isLoaded = 0; + }, + }); + } + }; + + + $(function() { + learun._im.connect(); + }) + +})(jQuery, top.learun); \ No newline at end of file diff --git a/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Shared/_Admin.cshtml b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Shared/_Admin.cshtml index 6b75f3534..a5f58eda7 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Shared/_Admin.cshtml +++ b/Learun.Framework.Ultimate V7/Learun.Application.Web/Views/Shared/_Admin.cshtml @@ -45,10 +45,10 @@
- +
- + @@ -75,12 +75,13 @@ "/Views/LR_Content/plugin/tree/lr-tree.js", "/Views/LR_Content/plugin/select/lr-select.js", - + "/Views/LR_Content/plugin/workflow/lr-workflow-api.js", "/Views/LR_Content/plugin/contextmenu/lr-contextmenu.js", "/Views/LR_Content/script/lr-im.js", - + "/Views/LR_Content/script/pushmessage.js", + "/Views/LR_Content/script/lr-admin.js" ) diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj index c567566d8..1a2d19159 100644 --- a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Learun.Application.WebApi.csproj @@ -196,6 +196,7 @@ + diff --git a/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/PushMessageApi.cs b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/PushMessageApi.cs new file mode 100644 index 000000000..540b23bfb --- /dev/null +++ b/Learun.Framework.Ultimate V7/Learun.Application.WebApi/Modules/PushMessageApi.cs @@ -0,0 +1,61 @@ +using Nancy; +using Learun.Util; +using System.Collections.Generic; +using Learun.Application.TwoDevelopment.EducationalAdministration; +using static Learun.Application.WebApi.Modules.StuInfoFreshApi; +using System; +using System.IO; +using Learun.Application.Base.SystemModule; + +namespace Learun.Application.WebApi +{ + /// + /// 版 本 Learun-ADMS-Ultimate V7.0.0 力软敏捷开发框架 + /// Copyright (c) 2013-2018 上海力软信息技术有限公司 + /// 创 建:超级管理员 + /// 日 期:2019-08-19 17:50 + /// 描 述:教师注册 + /// + + public class PushMessageApi : BaseNoLoginApi + { + + /// + /// 推送消息接口 + /// + public PushMessageApi() + : base("/Learun/adms/pushMessage") + { + Get["/msg"] = PushMessage; + } + + private Response PushMessage(dynamic _) + { + string msg = this.Request.Query["msg"].ToString(); + + if (!string.IsNullOrEmpty(msg)) + { + SendHubs.callMethod("pushMessage", msg); + } + return Success("成功"); + } + + #region 获取数据 + + + #endregion + + #region 私有类 + + /// + /// 表单实体类 + /// + private class ReqFormEntity + { + public string keyValue { get; set; } + public string strEntity { get; set; } + } + #endregion + + } +} \ No newline at end of file