Notification.cshtml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. @using Abp.Notifications
  2. @using VberAdmin.Web.Models.Input
  3. @using VberAdmin.Web.Models.Modals
  4. @using VberAdmin.Web.Models.Search
  5. @using VberAdmin.Web.Models.Table
  6. @using VberZero
  7. @using VberZero.Tools.StringModel
  8. @{
  9. string activeMenu = PermissionNames.VberSystemMgNotificationMg;
  10. ViewBag.ActiveMenu = activeMenu;
  11. ViewBag.Title = L("NotificationTitle");
  12. string states = $"<option value=\"{UserNotificationState.Unread.ToStr()}\">{L("NoRead")}</option><option value=\"{UserNotificationState.Read.ToStr()}\">{L("HasRead")}</option>";
  13. var table = new VmTable(VzConsts.ApiAppUrl + "Notification/GetAll", ViewBag.ActiveMenu, new VmSearch(new List<VmSearchItem>()
  14. {
  15. new VmSearchItem("state", L("notificationState"), FType.I).WithRadio(L("NoRead"),UserNotificationState.Unread.ToStr(),L("HasRead"),UserNotificationState.Read.ToStr()),
  16. new VmSearchItem("date", L("notificationDate"), FType.Dn).WithDateRange()
  17. })).WithItems(new List<VmTableItem>()
  18. {
  19. new VmTableItem("name", L("notificationName")).WithSort(),
  20. new VmTableItem("text", L("notificationText")),
  21. new VmTableItem("time", L("notificationDate")).WithSort(),
  22. new VmTableItem("notificationState", L("notificationState"), "StateFormatter").WithSort(),
  23. new VmTableItem("", L("Actions"), "ActionFormatter").WithClassName("text-end"),
  24. });
  25. var modal = new VmModal().WithHeaderAndFooter("发送通知", "").WithBody( new VmModalBody(new List<VmInputBase>()
  26. {
  27. new VmInput("severity","通知类型").WithRadio("一般通知", NotificationSeverity.Success.ToStr(),"紧急通知",NotificationSeverity.Warn.ToStr()),
  28. new VmInputTextarea("message","通知内容")
  29. }));
  30. }
  31. <style>
  32. </style>
  33. @await Html.PartialAsync("_Table", table)
  34. @await Html.PartialAsync("_Modal", modal)
  35. @section scripts{
  36. <script type="text/javascript">
  37. let $table = $('#table');
  38. $(function() {
  39. $('#table_box #vber_search').find('div').eq(0).remove();
  40. $('#table_box [data-kt-table-toolbar="base"]').fadeOut();
  41. $('#table_box [data-kt-table-toolbar="ex-tool"]').hide()
  42. .append('<button type="button" class="btn btn-light-warning btn-sm me-2" onclick="ReadAll()"><i class="fas fa-book-reader"></i> 全部设为已读</button><button type="button" class="btn btn-light-danger btn-sm me-2" onclick=" DeleteAll()"><i class="far fa-minus-square"></i> 删除全部已读</button>')
  43. .append($('#table_box [data-kt-table-toolbar="base"] .menu').find('button').removeClass("mb-2")).fadeIn();
  44. $('#table_box [data-kt-table-toolbar="base"]').remove();
  45. var funs = LoadTable({
  46. table: 'table',
  47. responseHandler: function(res) {
  48. let json = jQuery.parseJSON(res);
  49. let result = {
  50. recordsTotal: 0,
  51. recordsFiltered: 0,
  52. data: []
  53. }
  54. if (json.success) {
  55. if (json.result.items.length > 0) {
  56. var notifications = [];
  57. json.result.items.forEach((v) => {
  58. notifications.push(abp.userNotificationHelper.format(v, false));
  59. });
  60. result.recordsTotal = json.result.totalCount;
  61. result.recordsFiltered = json.result.totalCount;
  62. result.data = notifications;
  63. console.log(result);
  64. }
  65. } else {
  66. console.log('Table load failed');
  67. if (json.error) {
  68. if (json.error.details) {
  69. return abp.message.error(json.error.details, json.error.message);
  70. } else {
  71. if (json.error.message && json.error.message.indexOf('登陆超时') >= 0) {
  72. return abp.message.error(json.error.message).done(function() {
  73. window.top.location.reload();
  74. });
  75. } else {
  76. return abp.message.error(json.error.message || abp.ajax.defaultError.message);
  77. }
  78. }
  79. }
  80. }
  81. return JSON.stringify(result);
  82. }
  83. });
  84. funs["btnSendNotification"] = function(url) {
  85. OpenModal({
  86. url: url,
  87. table:'table',
  88. modal: 'modal'
  89. });
  90. }
  91. });
  92. function SetRead(id) {
  93. $.vbAjax4({
  94. url: abp.appUrl + 'Notification/SetNotificationAsRead',
  95. data: { id: id },
  96. success: function() {
  97. abp.event.trigger('app.notifications.refresh', id);
  98. RefreshTable();
  99. abp.notify.success("已读成功!");
  100. }
  101. });
  102. }
  103. function ReadAll() {
  104. MsgConfirm("确认全部通知设为已读吗?",
  105. "全部已读",
  106. function() {
  107. abp.userNotificationHelper.setAllAsRead(RefreshTable);
  108. });
  109. }
  110. function Delete(id) {
  111. let row = $table.VbTable('getRow', id);
  112. if (row) {
  113. MsgConfirm(`确认删除 [${row.name}]?`,
  114. "删除通知",
  115. function() {
  116. $.vbAjax1({
  117. url: abp.appUrl + 'Notification/DeleteNotification',
  118. data: { id: id },
  119. success: function() {
  120. abp.event.trigger('app.notifications.refresh', id);
  121. RefreshTable();
  122. }
  123. });
  124. });
  125. }
  126. }
  127. function DeleteAll() {
  128. MsgConfirm("确认删除全部已读通知?",
  129. "删除全部",
  130. function() {
  131. $.vbAjax1({
  132. url: abp.appUrl + 'Notification/DeleteAllUserNotifications',
  133. data: { state: @(UserNotificationState.Read.ToStr()) },
  134. success: function() {
  135. abp.event.trigger('app.notifications.refresh');
  136. RefreshTable();
  137. }
  138. });
  139. });
  140. }
  141. </script>
  142. <script id="formatter-script">
  143. function ActionFormatter(v, r) {
  144. var readStr = `<span class="table-action" onclick="SetRead('${r.id}')">${icon}@(L("SetAsRead"))</span>`,
  145. deleteStr = `<span class="table-action" onclick="Delete('${r.id}')">${icon}@(L("DeleteNotification"))</span>`;
  146. var str = '';
  147. if (r.notificationState === 0) {
  148. str += readStr;
  149. }
  150. str += deleteStr;
  151. return str;
  152. }
  153. function StateFormatter(v) {
  154. var name = $('#hid-state option[value="' + v + '"]').text();
  155. if (v === 1) {
  156. return '<span class="badge badge-success">' + name + '</span>';
  157. } else
  158. return '<span class="badge badge-danger">' + name + '</span>';
  159. }
  160. </script>
  161. }
  162. <section style="display: none">
  163. <select id="hid-state">
  164. @Html.Raw(states)
  165. </select>
  166. </section>