Notification
TsgcHTMLComponent_Notification — 由通知项目集合构建一个带未读徽章的铃铛图标下拉通知中心,适用于 Delphi、C++ Builder 和 .NET。
TsgcHTMLComponent_Notification — 由通知项目集合构建一个带未读徽章的铃铛图标下拉通知中心,适用于 Delphi、C++ Builder 和 .NET。
一个通知中心组件,发出 Bootstrap 5 下拉框。将项目添加到其 Items 集合(或调用 AddNotification),然后读取 HTML 属性 — 未读的 UnreadCount 驱动徽章。
设置 Title 和 MaxVisible,为每个条目调用 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 是一个 TsgcHTMLNotificationItems 集合;每个 TsgcHTMLNotificationItem 都有 Title、Message、Timestamp、Color、Icon、Href 和 Read。
AddNotification(title, message, color, timestamp) 追加一个项目,省略时间戳时默认为当前时间。
UnreadCount 统计 Read 为 False 的项目;ShowBadge 切换红色胶囊,GetBadgeHTML 仅返回徽章标记。
Title 设置下拉框标题,EmptyText 设置无项目时的占位文本,BellIcon 设置触发器图标。
MaxVisible 限制渲染的项目数量(默认 5),存在更多项目时显示"查看全部"链接;NotificationID 分配元素 id。
HTML 返回带有作用域 CSS 的完整铃铛图标下拉框 — 直接提供服务,或将其赋给页面模板的 BodyContent。