Notification

TsgcHTMLComponent_Notification — 由通知项目集合构建一个带未读徽章的铃铛图标下拉通知中心,适用于 Delphi、C++ Builder 和 .NET。

TsgcHTMLComponent_Notification

一个通知中心组件,发出 Bootstrap 5 下拉框。将项目添加到其 Items 集合(或调用 AddNotification),然后读取 HTML 属性 — 未读的 UnreadCount 驱动徽章。

组件类

TsgcHTMLComponent_Notification

渲染为

Bootstrap 5 下拉标记

语言

Delphi, C++ Builder, .NET

创建它、添加通知、渲染它

设置 TitleMaxVisible,为每个条目调用 AddNotification(title, message, color, timestamp),然后读取 HTML。未读计数会自动填充徽章。

uses
  sgcHTML_Enums, sgcHTML_Component_Notification;

var
  oNotif: TsgcHTMLComponent_Notification;
begin
  oNotif := TsgcHTMLComponent_Notification.Create(nil);
  try
    oNotif.Title := 'Notifications';
    oNotif.MaxVisible := 5;
    oNotif.ShowBadge := True;

    oNotif.AddNotification('New order',
      'Order #1042 was placed.', hcSuccess, '2 min ago');
    oNotif.AddNotification('Payment failed',
      'Invoice #88 could not be charged.', hcDanger, '10 min ago');

    WebModule.Response := oNotif.HTML;   // bell dropdown + badge
  finally
    oNotif.Free;
  end;
end;

// Or add items via the Items collection directly:
with oNotif.Items.Add do
begin
  Title := 'Welcome';
  Message := 'Your account is ready.';
  Color := hcInfo;
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_Notification.hpp

TsgcHTMLComponent_Notification *oNotif = new TsgcHTMLComponent_Notification(NULL);
try
{
  oNotif->Title = "Notifications";
  oNotif->MaxVisible = 5;
  oNotif->ShowBadge = true;

  oNotif->AddNotification("New order",
    "Order #1042 was placed.", hcSuccess, "2 min ago");
  oNotif->AddNotification("Payment failed",
    "Invoice #88 could not be charged.", hcDanger, "10 min ago");

  String html = oNotif->HTML;   // bell dropdown + badge
}
__finally
{
  delete oNotif;
}

// Or add items via the Items collection directly:
TsgcHTMLNotificationItem *item = oNotif->Items->Add();
item->Title = "Welcome";
item->Message = "Your account is ready.";
item->Color = hcInfo;
using esegece.sgcWebSockets;

var notif = new TsgcHTMLComponent_Notification();
notif.Title = "Notifications";
notif.MaxVisible = 5;
notif.ShowBadge = true;

notif.AddNotification("New order",
    "Order #1042 was placed.", TsgcHTMLColor.hcSuccess, "2 min ago");
notif.AddNotification("Payment failed",
    "Invoice #88 could not be charged.", TsgcHTMLColor.hcDanger, "10 min ago");

string html = notif.HTML;   // bell dropdown + badge

// Or add items via the Items collection directly:
var item = notif.Items.Add();
item.Title = "Welcome";
item.Message = "Your account is ready.";
item.Color = TsgcHTMLColor.hcInfo;

关键属性与方法

您最常使用的成员。

Items

Items 是一个 TsgcHTMLNotificationItems 集合;每个 TsgcHTMLNotificationItem 都有 TitleMessageTimestampColorIconHrefRead

添加通知

AddNotification(title, message, color, timestamp) 追加一个项目,省略时间戳时默认为当前时间。

未读徽章

UnreadCount 统计 ReadFalse 的项目;ShowBadge 切换红色胶囊,GetBadgeHTML 仅返回徽章标记。

页眉

Title 设置下拉框标题,EmptyText 设置无项目时的占位文本,BellIcon 设置触发器图标。

限制

MaxVisible 限制渲染的项目数量(默认 5),存在更多项目时显示"查看全部"链接;NotificationID 分配元素 id。

输出

HTML 返回带有作用域 CSS 的完整铃铛图标下拉框 — 直接提供服务,或将其赋给页面模板的 BodyContent

继续探索

所有 sgcHTML 组件浏览 60 多个组件的完整功能矩阵。
下载免费试用版30 天试用版附带 60.HTML 演示项目。
价格Single、Team 和 Site 授权,均含完整源代码。

准备好开始了吗?

下载免费试用版,开始在 Delphi、C++ Builder 和 .NET 中构建 Web 界面。