signalr.zlpms.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. function signalViewModel(account, name, personid, RYXZ, DbFactory) {
  2. var that = this;
  3. this.count = 0;
  4. //人员性质
  5. this.RYXZ = RYXZ;
  6. //本地数据库对象
  7. this.DbFactory = DbFactory;
  8. ///消息数
  9. this.Notify = [];
  10. //账户
  11. this.Account = account;
  12. //登录名
  13. this.Name = name;
  14. //人员ID
  15. this.PersonId = personid;
  16. //登录的集成代理类
  17. this.LoginProxy = $.connection.LoginHub;
  18. //初始化连接服务器成功后调用
  19. //this.LoginProxy.client.connectedSuccess = function (connectId) {
  20. // ZLPMS.Msg('成功获取到在线用户信息');
  21. //}
  22. //所有用户登录成功更新数量
  23. this.LoginProxy.client.userLoginCallback = function (cnt) {
  24. $("#onlineUser").text(cnt);
  25. }
  26. //提示断线
  27. $.connection.hub.disconnected(function () {
  28. alert("服务已断开连接,请刷新网页!")
  29. //if (that.count <= 3) {
  30. // debugger
  31. // setTimeout(function () {
  32. // that.count++
  33. // that.register()
  34. // }, 2000);
  35. //}
  36. })
  37. //尝试重连
  38. //$.connection.hub.reconnecting(function () {
  39. // that.register()
  40. //});
  41. //接收服务器新消息
  42. this.LoginProxy.client.newMessage = function (msg) {
  43. that.showNotification(msg);
  44. layer.open({
  45. offset: 'rb',
  46. title: false,
  47. area: '200px',
  48. shade: 0,
  49. type: 1,
  50. content: '<p style="padding:10px;color:#8e804b;font-size:15px">' + msg + '</p>',
  51. icon: 1,
  52. anim: 2
  53. //btn: '知道了',
  54. //yes: function(index){
  55. // layer.close(index);
  56. //}
  57. });
  58. }
  59. //被踢下线
  60. this.LoginProxy.client.offline = function () {
  61. alert('您的账号在其它客户端登录,被强制下线');
  62. window.onbeforeunload = function (e) { };
  63. ZLPMS.Loading3('正在退出...');
  64. window.location.href = "/Account/Login";
  65. //$.ajax({
  66. // type: "post",
  67. // url: "/Admin/Permissions/LoginHandler.ashx?tag=Logout",
  68. // data: null,
  69. // dataType: "text",
  70. // success: function (data, textStatus) {
  71. // G_SYSTEM_EXIT = true;
  72. // window.location.href = "/Account/Login";
  73. // },
  74. // error: function (XMLHttpRequest, textStatus, errorThrown) {
  75. // //DuiFn.MsgAlert(XMLHttpRequest.statusText);
  76. // },
  77. // complete: function (XHR, TS) {
  78. // G_SYSTEM_EXIT = true;
  79. // }
  80. //});
  81. }
  82. //返回用户列表(json)
  83. this.LoginProxy.client.users = function (json) {
  84. var html = '<div id="user" style="padding:10px; widht:100%; height:90%;">';
  85. var data = eval(json);
  86. $.each(data, function (i, n) {
  87. html += '<p style="font-size:18px;"><i class="fa fa-user-o"></i> ' + n.UserName + '</p>';
  88. });
  89. html += "</div>";
  90. layer.open({
  91. offset: 'r',
  92. id:'onLineUser',
  93. title: '在线用户',
  94. area: ['180px', '500px'],
  95. shade: 0,
  96. type: 1,
  97. content: html,
  98. icon: 1,
  99. anim: 2
  100. });
  101. }
  102. //向服务端发起注册
  103. this.register = function () {
  104. var that = this;
  105. //向服务器注册客户端
  106. $.connection.hub.start().done(function () {
  107. //客户端向服务器的Hub类注册成功事件(成功后,执行登录)
  108. that.LoginProxy.server.clientLogin(that.Account, that.Name, that.PersonId);
  109. }).fail(function () {
  110. //客户端向服务器的Hub类注册失败事件
  111. alert('客户端向服务器的Hub类注册失败事件');
  112. });
  113. };
  114. //获取在线用户
  115. this.getuser = function () {
  116. var that = this;
  117. that.LoginProxy.server.getuser();
  118. }
  119. //获取APP下载二维码
  120. this.GetApp = function () {
  121. layer.open({
  122. offset: 'auto',
  123. id: 'AppdownLoad',
  124. title: 'APP下载',
  125. area: ['460px', '330px'],
  126. shade: 0,
  127. type: 1,
  128. content:`<div style="display:flex;justify-content:space-around;align-items:center;flex-direction:row">`+
  129. `<div style="display:flex;justify-content:center;align-items:center;flex-direction:column"><img src="/Content/Images/APP_Android.PNG" style="width:200px;height:auto"><div style="font-size:15px;font-weight:500">Android版</div> </div>`+
  130. `<div style="display:flex;justify-content:center;align-items:center;flex-direction:column"><img src="/Content/Images/APP_IOS.png" style="width:200px;height:auto"><div style="font-size:15px;font-weight:500">IOS版</div> </div>` +
  131. `</div>`,
  132. icon: 1,
  133. anim: 2
  134. });
  135. }
  136. ///推送问题处理信息
  137. this.LoginProxy.client.SendDealMessage = function (ProblemId,Message, Type) {
  138. that.showNotification(Message);
  139. that.AddNotify(Message, ProblemId, Type);
  140. }
  141. //新问题推送
  142. this.LoginProxy.client.RefreshSupport = function (Type) {
  143. debugger
  144. var project = document.getElementById("if154")
  145. var surpport = document.getElementById("if203")
  146. var product = document.getElementById("if6")
  147. if (Type == "1" && project) {
  148. project.contentWindow.com.RefreshOnDeal();
  149. that.showNotification("收到一条新的项目问题");
  150. }
  151. if (Type == "2"&&surpport) {
  152. surpport.contentWindow.com.RefreshNoDeal();
  153. that.showNotification("收到一条新的技术支持问题");
  154. }
  155. if (Type == "3" && product) {
  156. product.contentWindow.com.RefreshNoDeal();
  157. that.showNotification("收到一条新的研发问题");
  158. }
  159. }
  160. this.LoginProxy.client.newMessageToRefrsh = function (Message,ProblemId) {
  161. var project = document.getElementById("if154")
  162. var surpport = document.getElementById("if203")
  163. var product = document.getElementById("if6")
  164. if (project) {
  165. project.contentWindow.com.RefreshOnDeal();
  166. }
  167. if (surpport) {
  168. surpport.contentWindow.com.RefreshNoDeal();
  169. }
  170. if (product) {
  171. product.contentWindow.com.RefreshNoDeal();
  172. }
  173. that.AddNotify(Message,ProblemId,0);
  174. that.showNotification(Message);
  175. }
  176. this.showNotification=function (message) {
  177. window.Notification.permission = "granted";
  178. if (window.Notification) {
  179. if (window.Notification.permission == "granted") {
  180. var notification = new Notification('你有一条新信息', {
  181. body: message,
  182. requireInteraction:true,
  183. icon: "/Content/Images/zllogo.png"
  184. });
  185. } else {
  186. window.Notification.requestPermission();
  187. }
  188. } else alert('你的浏览器不支持消息提示功能,请使用chrome内核的浏览器!');
  189. };
  190. this.OpenMessage = function (message) {
  191. layer.open({
  192. offset: 'rb',
  193. title: false,
  194. area: '200px',
  195. shade: 0,
  196. type: 1,
  197. content: '<p style="padding:10px;color:#8e804b;font-size:15px">' + message + '</p>',
  198. icon: 1,
  199. anim: 2,
  200. id:'OpenMessage'
  201. });
  202. }
  203. this.GetNotify = function () {
  204. DbFactory.get("Notify", function (data) {
  205. data = data.Value;
  206. that.Notify = data;
  207. for (var i in data) {
  208. var nof = data[i];
  209. if (i < 5)
  210. $("#Notify").append("<a href='#' onclick=\"checkproblem('" + nof.id + "','" + nof.rowId + "')\" class='list-item'><img src='" + nof.Img + "' style='width:25px' /><p class='item-center'>" + nof.Message + "</p><p class='item-fter'></p></a>");
  211. }
  212. if (data.length > 0)
  213. $("#NotifyCount").append("<span class='badge topbadge badge-danger' >" + data.length + "</span>");
  214. })
  215. }
  216. this.AddNotify = function (message, ProblemId,Type) {
  217. $("#Notify").empty();
  218. $('#NotifyCount').find('.badge').remove();
  219. var Img = that.GetIcon(Type);
  220. that.Notify.unshift({ rowId: that.GetId(4), Message: message, id: ProblemId, Img: Img });
  221. for (var i in that.Notify) {
  222. var nof = that.Notify[i];
  223. if(i<5)
  224. $("#Notify").append("<a href='#' onclick=\"checkproblem('" + nof.id + "','" + nof.rowId + "')\" class='list-item'><img src='" + nof.Img + "' style='width:25px' /><p class='item-center'>" + nof.Message + "</p><p class='item-fter'></p></a>");
  225. }
  226. if (that.Notify.length > 0)
  227. $("#NotifyCount").append("<span class='badge topbadge badge-danger' >" + that.Notify.length + "</span>");
  228. that.DbFactory.save({ id: "Notify", Value: that.Notify })
  229. }
  230. this.RemovedNotify = function (rowId) {
  231. $("#Notify").empty();
  232. $('#NotifyCount').find('.badge').remove();
  233. for (var i in that.Notify) {
  234. if (that.Notify[i].rowId == rowId) {
  235. that.Notify.splice(i, 1);
  236. break;
  237. }
  238. }
  239. for (var i in that.Notify) {
  240. var nof = that.Notify[i];
  241. if (i < 5)
  242. $("#Notify").append("<a href='#' onclick=\"checkproblem('" + nof.id + "','" + nof.rowId + "')\" class='list-item'><img src='" + nof.Img + "' style='width:25px' /><p class='item-center'>" + nof.Message + "</p><p class='item-fter'></p></a>");
  243. }
  244. if (that.Notify.length > 0)
  245. $("#NotifyCount").append("<span class='badge topbadge badge-danger' >" + that.Notify.length + "</span>");
  246. that.DbFactory.save({ id: "Notify", Value: that.Notify })
  247. }
  248. //清除所有消息
  249. $("#message-Clear").bind('click', function () {
  250. $("#Notify").empty();
  251. $('#NotifyCount').find('.badge').remove();
  252. that.Notify = [];
  253. })
  254. this.GetIcon = function (Type) {
  255. var Icon;
  256. switch (Type) {
  257. case 0: Icon = "/Content/Images/Problem/xin.png"; break;
  258. case 1: Icon = "/Content/Images/Problem/zhipai.png"; break;
  259. case 2: Icon = "/Content/Images/Problem/jiejue.png"; break;
  260. case 3: Icon = "/Content/Images/Problem/huitui.png"; break;
  261. case 4: Icon = "/Content/Images/Problem/zhongzhi.png"; break;
  262. case 5: Icon = "/Content/Images/Problem/tijiao.png"; break;
  263. case 6: Icon = "/Content/Images/Problem/daishouli.png"; break;
  264. case 7: Icon = "/Content/Images/Problem/daichuli.png"; break;
  265. default: Icon = "/Content/Images/Problem/xin.png"
  266. }
  267. return Icon;
  268. }
  269. this.GetTime = function (Time) {
  270. var sdate = new Date(Time);
  271. var now = new Date();
  272. var days = now.getTime() - sdate.getTime();
  273. var day = parseInt(days / (1000 * 60 * 60));
  274. if (day < 1) {
  275. day = parseInt(day * 60) + "分钟前";
  276. } else if (day < 24) {
  277. day = day + "小时前";
  278. } else if (48 > day > 24) {
  279. day = "昨天";
  280. } else {
  281. day = parseInt(day / 24) + '天' + '前';
  282. }
  283. return day;
  284. }
  285. this.GetId=function(n){
  286. var res = '';
  287. for (; res.length < n; res += Math.random().toString(36).substr(2).toUpperCase()) { }
  288. return res.substr(0, n);
  289. }
  290. //处理问题
  291. this.DealProblem=function (showAtt, IsSupport,ProblemId) {
  292. //是否为技术支持处理
  293. IsSupport = IsSupport || 0;
  294. //受理问题
  295. var receiveProblem = function (title,HJID) {
  296. var index = top.ZLPMS.Loading3(2);
  297. //受理问题
  298. $.ajax({
  299. url: '/Support/ReceiveProblem',
  300. data: { id: ProblemId },
  301. method: 'post',
  302. success: function (data) {
  303. top.ZLPMS.UnLoading(index);
  304. var url = "/Problem/ProductionPdeal?id=" + ProblemId + "&showAtt=" + showAtt + '&workflowid=' + HJID + '&IsSupport=' + IsSupport;
  305. //成功后调用
  306. if (data.code == 200) {
  307. top.ZLPMS.OpenNewWindow("处理问题:" + title, url, '1000px', '640px', function () {
  308. //回调用刷新(只有确定后才刷新)
  309. });
  310. } else {//显示具体原因,并提示是否强制处理
  311. top.ZLPMS.Confirm('该问题已被他人受理,您确定要继续处理吗?', 3, function (idx) {
  312. top.ZLPMS.CloseWindow(idx);
  313. top.ZLPMS.OpenNewWindow("处理问题", url, '1000px', '640px');
  314. })
  315. }
  316. }
  317. });
  318. };
  319. $.post('/Problem/GetProblemById/' + ProblemId, function (data) {
  320. var row = data[0];
  321. if (row) {
  322. /*已关闭的问题,已解决的问题,已受理的问题, 不需要处理*/
  323. if (row.是否终止 == 1) {
  324. top.ZLPMS.Msg('已终止的问题不需要再处理!');
  325. return;
  326. }
  327. if (row.是否解决 == 1) {
  328. top.ZLPMS.Msg('已解决的问题不需要再处理!');
  329. return;
  330. }
  331. if (row.环节ID > 3 && that.RYXZ != '1') {
  332. top.ZLPMS.Msg('非本部人员不能处理技术支持与研发处理环节问题,仅能查阅!');
  333. return;
  334. }
  335. if (row.环节ID == 3 && (that.RYXZ == '3' || that.RYXZ == '4' || that.RYXZ == '5')) {//客户,机构管理员,卫计委人员无法处理项目问题
  336. top.ZLPMS.Msg('客户,机构管理员,卫计委人员无法处理项目问题,仅能查阅!');
  337. return;
  338. }
  339. //打开处理窗口
  340. receiveProblem(row.编号, row.环节ID);
  341. } else {//提醒用户没有选择问题记录
  342. top.ZLPMS.Msg('没有选择需要处理的问题记录,请选择后再处理!');
  343. }
  344. })
  345. }
  346. //获取公告
  347. this.LoginProxy.client.GetNotice = function () {
  348. $.get("/Notice/PanDuanIsShow", function (data) {
  349. if (data == "True") {
  350. //显示公告通知
  351. top.ZLPMS.OpenNewWindow("公告通知", "/Notice/Notice_Window", "850px", "555px")
  352. }
  353. })
  354. }
  355. //超时推送
  356. this.OverTimePush = function () {
  357. //受理超时
  358. $.post("/Problem/GetAcceptOverTime", function (data) {
  359. if (data && data.length > 0) {
  360. that.AddNotifyMuti("问题待受理已超时,请注意受理",data,6);
  361. }
  362. //处理超时
  363. $.post("/Problem/GetDealOverTime", function (data2) {
  364. if (data2 && data2.length > 0) {
  365. that.AddNotifyMuti("问题处理已超时,请注意解决", data2, 7);
  366. }
  367. });
  368. })
  369. }
  370. this.AddNotifyMuti = function (message, ProblemIds, Type) {
  371. $("#Notify").empty();
  372. $('#NotifyCount').find('.badge').remove();
  373. var Img = that.GetIcon(Type);
  374. outer:
  375. for (var t in ProblemIds) {
  376. var Problem = ProblemIds[t].ID;
  377. var ProblemNum = ProblemIds[t].编号;
  378. //如果消息里面存在,则不添加
  379. inter:
  380. for (var i in that.Notify) {
  381. if (that.Notify[i].id == Problem) {
  382. continue outer;
  383. }
  384. }
  385. that.Notify.unshift({ rowId: that.GetId(4), Message: "编号【" + ProblemNum + "】" + message, id: Problem, Img: Img });
  386. }
  387. for (var i in that.Notify) {
  388. var nof = that.Notify[i];
  389. if (i < 5)
  390. $("#Notify").append("<a href='#' onclick=\"checkproblem('" + nof.id + "','" + nof.rowId + "')\" class='list-item'><img src='" + nof.Img + "' style='width:25px' /><p class='item-center'>" + nof.Message + "</p><p class='item-fter'></p></a>");
  391. }
  392. if (that.Notify.length > 0)
  393. $("#NotifyCount").append("<span class='badge topbadge badge-danger' >" + that.Notify.length + "</span>");
  394. }
  395. }