Files
crawler-plugin/frontend-vue/src/shared/components/NotificationBell.vue
T
huangzd1997 aea0e16279 feat(站内通知): 铃铛支持按类型大类筛选(系统异常/任务异常/配置异常/系统通知)
原来铃铛只能按关键字和日期筛,任务失败、密钥欠费、麦象异常全混在一起,
用户没法只看自己关心的那类。

后端 NotificationService 增加 scene→大类映射(未知 scene 归「系统通知」兜底),
列表接口新增 category 参数,落到 SQL 是 scene IN (...);「系统通知」作兜底类
还要纳入未登记的 scene,故表达为「= system 或 不在其它三类里」。列表项返回
category,前端不必各自维护一份 scene 映射。前后端两个通知接口同步加参数。

前端铃铛筛选区新增一行类型 chip(全部 + 四类),与关键字、日期一起参与
hasFilter 与重置;空分类不下发,避免后端查询落空。
2026-09-16 10:32:11 +08:00

1315 lines
33 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div ref="rootRef" class="notification-bell" :class="`notification-bell--${theme}`">
<button
type="button"
class="bell-trigger"
:class="{ 'bell-trigger--active': panelOpen }"
:title="unreadCount > 0 ? `通知(${unreadCount} 条未读)` : '通知'"
aria-label="通知"
@click="togglePanel"
>
<svg
class="bell-icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="1.8"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" />
<path d="M13.73 21a2 2 0 0 1-3.46 0" />
</svg>
<span v-if="badgeText" class="bell-badge">{{ badgeText }}</span>
</button>
<!-- 面板挂到 body 上(fixed 定位):顶栏内绝对定位时会被页面内容压住(如 el-select),提 z-index 无效 -->
<Teleport to="body">
<div
v-if="panelOpen"
ref="panelRef"
class="bell-panel"
:class="`bell-panel--${theme}`"
:style="panelStyle"
role="dialog"
aria-label="通知列表"
>
<header class="bell-head">
<div class="bell-head-title">
<span class="bell-title-text">通知</span>
<span v-if="unreadCount > 0" class="bell-unread-chip">{{ unreadChipText }}</span>
</div>
<button
v-if="unreadCount > 0"
type="button"
class="bell-read-all"
:disabled="markingAll"
@click="readAll"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.4"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<path d="m5 12 5 5L20 7" />
</svg>
{{ markingAll ? '处理中' : '全部已读' }}
</button>
</header>
<div class="bell-filters">
<div class="bell-search-box">
<svg
class="bell-search-icon"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
aria-hidden="true"
>
<circle cx="11" cy="11" r="7" />
<path d="m21 21-4.35-4.35" />
</svg>
<input
v-model="keyword"
type="text"
class="bell-search-input"
placeholder="搜索标题或内容"
aria-label="搜索通知"
@input="onKeywordInput"
/>
<button
v-if="keyword"
type="button"
class="bell-search-clear"
aria-label="清空搜索"
@click="clearKeyword"
>
<svg
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2.2"
stroke-linecap="round"
aria-hidden="true"
>
<path d="M18 6 6 18M6 6l12 12" />
</svg>
</button>
</div>
<div class="bell-category-chips" role="group" aria-label="按类型筛选">
<button
type="button"
class="bell-chip"
:class="{ 'is-active': !category }"
@click="selectCategory('')"
>
全部
</button>
<button
v-for="option in NOTIFICATION_CATEGORY_OPTIONS"
:key="option.value"
type="button"
class="bell-chip"
:class="{ 'is-active': category === option.value }"
@click="selectCategory(option.value)"
>
{{ option.label }}
</button>
</div>
<div class="bell-search-days">
<el-date-picker
:model-value="dateRange"
type="daterange"
value-format="YYYY-MM-DD"
start-placeholder="开始日期"
end-placeholder="结束日期"
range-separator="至"
class="bell-date-picker"
popper-class="bell-date-popper"
:clearable="true"
@update:model-value="onDateRangeChange"
@change="reload"
/>
<button v-if="hasFilter" type="button" class="bell-search-reset" @click="resetFilters">
重置
</button>
</div>
</div>
<div v-if="loading && !items.length" class="bell-skeleton" aria-label="正在加载">
<div v-for="row in 3" :key="row" class="bell-skeleton-row">
<span class="bell-skeleton-icon"></span>
<span class="bell-skeleton-lines">
<span class="bell-skeleton-bar bell-skeleton-bar--title"></span>
<span class="bell-skeleton-bar bell-skeleton-bar--text"></span>
</span>
</div>
</div>
<div v-else-if="loadError && !items.length" class="bell-state">
<span class="bell-state-icon bell-state-icon--error" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<circle cx="12" cy="12" r="9" />
<path d="M12 8v4" />
<path d="M12 16h.01" />
</svg>
</span>
<p class="bell-state-text">{{ loadError }}</p>
<button type="button" class="bell-state-action" @click="reload">重新加载</button>
</div>
<div v-else-if="!items.length" class="bell-state">
<span class="bell-state-icon" aria-hidden="true">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
<path d="M18 8a6 6 0 0 0-12 0c0 7-3 9-3 9h18s-3-2-3-9" />
<path d="M13.73 21a2 2 0 0 1-3.46 0" />
</svg>
</span>
<p class="bell-state-text">{{ hasFilter ? '没有符合条件的通知' : '暂无通知' }}</p>
<p v-if="hasFilter" class="bell-state-sub">试试调整类型、搜索词或时间范围</p>
</div>
<ul v-else class="bell-list">
<template v-for="group in groupedItems" :key="group.day || 'unknown'">
<li class="bell-day-head">{{ group.label }}</li>
<li
v-for="item in group.items"
:key="item.id"
class="bell-item"
:class="[`bell-item--${itemLevel(item)}`, { 'bell-item--unread': !item.read }]"
@click="onItemClick(item)"
>
<span class="bell-item-icon" aria-hidden="true">
<svg
v-if="itemLevel(item) === 'error'"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" />
<path d="M12 9v4" />
<path d="M12 17h.01" />
</svg>
<svg
v-else-if="itemLevel(item) === 'info'"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="9" />
<path d="M12 11v5" />
<path d="M12 8h.01" />
</svg>
<svg
v-else
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
>
<circle cx="12" cy="12" r="9" />
<path d="M12 8v4" />
<path d="M12 16h.01" />
</svg>
</span>
<div class="bell-item-main">
<div class="bell-item-head">
<span class="bell-item-title" :title="item.title">{{ item.title }}</span>
<span class="bell-item-dot" :class="{ 'bell-item-dot--on': !item.read }" aria-hidden="true"></span>
<span class="bell-item-time">{{ formatTime(item.createdAt) }}</span>
</div>
<p class="bell-item-content" :title="item.content">{{ item.content }}</p>
</div>
</li>
</template>
</ul>
<footer class="bell-foot">
<div class="bell-foot-meta">
<span class="bell-foot-total">共 {{ total }} 条</span>
<select
v-model="pageSize"
class="bell-size-select"
aria-label="每页条数"
@change="onPageSizeChange"
>
<option v-for="size in PAGE_SIZES" :key="size" :value="size">{{ size }}条/页</option>
</select>
</div>
<div class="bell-pager">
<button
type="button"
class="bell-page-btn"
:disabled="page <= 1 || loading"
@click="goPage(page - 1)"
>
上一页
</button>
<span class="bell-page-info">第 {{ page }} / {{ totalPages }} 页</span>
<button
type="button"
class="bell-page-btn"
:disabled="page >= totalPages || loading"
@click="goPage(page + 1)"
>
下一页
</button>
</div>
</footer>
</div>
</Teleport>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { ElMessage } from 'element-plus'
import {
NOTIFICATION_CATEGORY_OPTIONS,
fetchNotificationList,
fetchNotificationSummary,
markAllNotificationsRead,
markNotificationRead,
type NotificationItem,
} from '@/shared/api/types/modules/notification.ts'
import {
NOTIFICATION_POLL_INTERVAL_MS,
currentNotificationUid,
formatNotificationTime,
formatUnreadBadge,
groupNotificationsByDay,
hasNewNotification,
readLastNotifiedId,
writeLastNotifiedId,
} from '@/shared/utils/notification-bell.ts'
const DEFAULT_PAGE_SIZE = 10
const PAGE_SIZES = [10, 20, 50, 100]
/** 顶栏主题:工具页/配置页深色(dark),桌面入口首页浅色(light)。 */
const props = withDefaults(defineProps<{ theme?: 'dark' | 'light' }>(), {
theme: 'dark',
})
const theme = computed(() => props.theme)
const rootRef = ref<HTMLElement | null>(null)
const panelRef = ref<HTMLElement | null>(null)
const panelStyle = ref<Record<string, string>>({})
const uid = currentNotificationUid()
const unreadCount = ref(0)
const items = ref<NotificationItem[]>([])
const total = ref(0)
const page = ref(1)
/** 每页条数(面板底部下拉,取值同后台列表分页 10/20/50/100)。 */
const pageSize = ref(DEFAULT_PAGE_SIZE)
const panelOpen = ref(false)
const loading = ref(false)
const markingAll = ref(false)
const loadError = ref('')
const keyword = ref('')
/** 日期区间(el-date-picker daterange,YYYY-MM-DD 字符串;未选为 null)。 */
const dateRange = ref<[string, string] | null>(null)
/** 类型大类(system_error/task_error/config_error/system_notice);空串表示不按类型筛选。 */
const category = ref('')
const badgeText = computed(() => formatUnreadBadge(unreadCount.value))
const unreadChipText = computed(() =>
unreadCount.value > 99 ? '99+ 条未读' : `${unreadCount.value} 条未读`,
)
const groupedItems = computed(() => groupNotificationsByDay(items.value))
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
const hasFilter = computed(() =>
Boolean(keyword.value.trim() || dateRange.value || category.value),
)
let pollTimer: number | null = null
let searchTimer: number | null = null
/** 通知级别:后端只保证三类,非法值按 warning 兜底(配色与图标按级别区分)。 */
function itemLevel(item: NotificationItem): 'error' | 'warning' | 'info' {
return item.level === 'error' || item.level === 'info' ? item.level : 'warning'
}
/** 起止日期倒挂时自动交换,避免用户只看到「没有符合条件的通知」不知原因。 */
function normalizedDayRange(): { startDate?: string; endDate?: string } {
const range = dateRange.value
if (!range) {
return {}
}
let [start, end] = range
if (start && end && start > end) {
const swapped = start
start = end
end = swapped
}
return { startDate: start || undefined, endDate: end || undefined }
}
/** 日期区间变化(选择完成/清空都会触发):只保留「两端齐全」的区间。 */
function onDateRangeChange(value: unknown) {
if (Array.isArray(value) && value.length === 2 && value[0] && value[1]) {
dateRange.value = [String(value[0]), String(value[1])]
return
}
dateRange.value = null
}
/** 拉未读数:发现新通知提醒一次(localStorage 记录已提醒过的最大 id,避免重复弹)。 */
async function refreshSummary() {
try {
const summary = await fetchNotificationSummary()
unreadCount.value = Number(summary?.unreadCount ?? 0)
const latestId = Number(summary?.latestId ?? 0)
if (hasNewNotification(latestId, readLastNotifiedId(uid))) {
ElMessage.warning('收到新的告警通知,请点击右上角铃铛查看')
writeLastNotifiedId(uid, latestId)
console.log('[notification] 检测到新通知 latestId=', latestId)
}
} catch (error) {
// 通知接口失败静默降级:不显示红点、不打扰用户
console.warn('[notification] 未读数刷新失败(静默降级):', error)
}
}
async function loadPage(targetPage: number) {
if (loading.value) return
loading.value = true
try {
const result = await fetchNotificationList({
page: targetPage,
pageSize: pageSize.value,
keyword: keyword.value,
category: category.value,
...normalizedDayRange(),
})
const list = Array.isArray(result?.items) ? result.items : []
items.value = list
total.value = Number(result?.total ?? list.length)
unreadCount.value = Number(result?.unreadCount ?? unreadCount.value)
page.value = targetPage
loadError.value = ''
// 无筛选时首页就是最新数据,顺带记录「已提醒过的最大 id」;有筛选时最新 id 不代表真实最新
if (targetPage <= 1 && !hasFilter.value && list.length) {
const latest = Number(list[0].id)
if (latest > 0) {
writeLastNotifiedId(uid, Math.max(readLastNotifiedId(uid), latest))
}
}
} catch (error) {
// 列表加载失败在面板内提示,不弹全局消息打扰用户
console.warn('[notification] 通知列表加载失败:', error)
loadError.value = error instanceof Error ? error.message : '通知加载失败'
} finally {
loading.value = false
}
}
function goPage(targetPage: number) {
const safe = Math.min(Math.max(1, targetPage), totalPages.value)
if (safe === page.value || loading.value) return
void loadPage(safe)
}
/** 切换每页条数:回到第一页重新查询。 */
function onPageSizeChange() {
console.log('[notification] 每页条数切换为', pageSize.value)
void loadPage(1)
}
/** 搜索/日期变化后回到第一页重新查询。 */
function reload() {
void loadPage(1)
}
/** 关键字输入防抖 300ms,避免每敲一个字都打一次接口。 */
function onKeywordInput() {
if (searchTimer != null) {
window.clearTimeout(searchTimer)
}
searchTimer = window.setTimeout(() => {
searchTimer = null
void loadPage(1)
}, 300)
}
function clearKeyword() {
keyword.value = ''
void loadPage(1)
}
/** 类型筛选:重复点同一个不重复请求;切换后回到第一页。 */
function selectCategory(value: string) {
if (category.value === value) {
return
}
category.value = value
console.log('[notification] 类型筛选切换为', value || '全部')
void loadPage(1)
}
function resetFilters() {
keyword.value = ''
dateRange.value = null
category.value = ''
void loadPage(1)
}
/** 面板挂到 body 后用 fixed 定位,位置按触发器实时算(右对齐在铃铛下方)。 */
const PANEL_WIDTH = 376
function syncPanelPosition() {
const trigger = rootRef.value
if (!trigger) return
const rect = trigger.getBoundingClientRect()
// 窗口过窄时右对齐会把面板顶出左边界,这里把 right 收回来保证整块可见
const panelWidth = Math.min(PANEL_WIDTH, window.innerWidth - 24)
const maxRight = Math.max(8, window.innerWidth - panelWidth - 8)
const right = Math.min(Math.max(8, Math.round(window.innerWidth - rect.right)), maxRight)
panelStyle.value = {
top: `${Math.round(rect.bottom + 10)}px`,
right: `${right}px`,
}
}
function togglePanel() {
panelOpen.value = !panelOpen.value
if (panelOpen.value) {
syncPanelPosition()
void loadPage(1)
}
}
async function onItemClick(item: NotificationItem) {
if (item.read) return
try {
await markNotificationRead(item.id)
item.read = true
unreadCount.value = Math.max(0, unreadCount.value - 1)
} catch (error) {
console.warn('[notification] 标记已读失败:', error)
}
}
async function readAll() {
if (markingAll.value || unreadCount.value === 0) return
markingAll.value = true
try {
await markAllNotificationsRead()
for (const item of items.value) {
item.read = true
}
unreadCount.value = 0
} catch (error) {
console.warn('[notification] 全部已读失败:', error)
ElMessage.error(error instanceof Error ? error.message : '操作失败')
} finally {
markingAll.value = false
}
}
function formatTime(value: string | null) {
return formatNotificationTime(value)
}
/** 点击组件外部关闭面板(面板已 Teleport 到 body,需连同面板自身一起判断)。 */
function onDocumentMouseDown(event: MouseEvent) {
if (!panelOpen.value) return
const target = event.target
if (!(target instanceof Node)) return
if (rootRef.value?.contains(target) || panelRef.value?.contains(target)) return
// 日期选择面板同样挂在 body 上(el-popper),点它不应关闭通知面板
if (target instanceof Element && target.closest('.el-popper')) return
panelOpen.value = false
}
/** 窗口尺寸变化时重新对齐面板。 */
function onWindowResize() {
if (panelOpen.value) {
syncPanelPosition()
}
}
/** 页面回到前台时立即刷新一次未读数。 */
function onVisibilityChange() {
if (typeof document !== 'undefined' && document.visibilityState === 'visible') {
void refreshSummary()
}
}
onMounted(() => {
document.addEventListener('mousedown', onDocumentMouseDown)
document.addEventListener('visibilitychange', onVisibilityChange)
window.addEventListener('resize', onWindowResize)
void refreshSummary()
pollTimer = window.setInterval(() => {
if (typeof document !== 'undefined' && document.visibilityState !== 'visible') {
return
}
void refreshSummary()
}, NOTIFICATION_POLL_INTERVAL_MS)
})
onUnmounted(() => {
document.removeEventListener('mousedown', onDocumentMouseDown)
document.removeEventListener('visibilitychange', onVisibilityChange)
window.removeEventListener('resize', onWindowResize)
if (pollTimer != null) {
window.clearInterval(pollTimer)
pollTimer = null
}
if (searchTimer != null) {
window.clearTimeout(searchTimer)
searchTimer = null
}
})
</script>
<style scoped>
.notification-bell {
position: relative;
display: inline-flex;
align-items: center;
}
.bell-trigger {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
width: 34px;
height: 34px;
padding: 0;
border: none;
border-radius: 9px;
background: transparent;
color: #c8d2e2;
cursor: pointer;
transition: background 0.15s ease, color 0.15s ease;
}
.bell-trigger:hover,
.bell-trigger--active {
background: rgba(255, 255, 255, 0.08);
color: #f5f8fc;
}
.bell-icon {
width: 19px;
height: 19px;
}
.bell-badge {
position: absolute;
top: 1px;
right: 0;
min-width: 17px;
height: 17px;
padding: 0 4px;
box-sizing: border-box;
border-radius: 999px;
background: #e5484d;
color: #fff;
font-size: 10px;
font-weight: 700;
line-height: 17px;
text-align: center;
box-shadow: 0 1px 4px rgba(229, 72, 77, 0.45);
pointer-events: none;
}
/* ---------------- 面板 ---------------- */
.bell-panel {
--bell-bg: #151a26;
--bell-bg-elev: #1a2130;
--bell-border: #2b3548;
--bell-text: #ecf2fa;
--bell-text-dim: #9fabc0;
--bell-text-mute: #6f7d92;
--bell-accent: #6ea8ff;
--bell-accent-soft: rgba(110, 168, 255, 0.14);
--bell-hover: rgba(255, 255, 255, 0.045);
--bell-unread-bg: rgba(110, 168, 255, 0.07);
--bell-input-bg: #10151f;
--bell-shadow: 0 20px 48px rgba(0, 0, 0, 0.52), 0 2px 8px rgba(0, 0, 0, 0.32);
--bell-error: #ff7b7b;
--bell-error-bg: rgba(255, 123, 123, 0.14);
--bell-warning: #f0bb61;
--bell-warning-bg: rgba(240, 187, 97, 0.14);
--bell-info: #6ea8ff;
--bell-info-bg: rgba(110, 168, 255, 0.14);
--bell-skeleton: rgba(255, 255, 255, 0.07);
--bell-skeleton-shine: rgba(255, 255, 255, 0.13);
position: fixed;
z-index: 3200;
display: flex;
flex-direction: column;
width: 376px;
max-width: calc(100vw - 24px);
max-height: min(560px, calc(100vh - 96px));
border: 1px solid var(--bell-border);
border-radius: 14px;
background: var(--bell-bg);
box-shadow: var(--bell-shadow);
overflow: hidden;
font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "微软雅黑", sans-serif;
}
.bell-panel--light {
--bell-bg: #ffffff;
--bell-bg-elev: #f7f9fc;
--bell-border: #e6ecf3;
--bell-text: #1e2a3a;
--bell-text-dim: #5d6b7e;
--bell-text-mute: #93a1b3;
--bell-accent: #4c5bd4;
--bell-accent-soft: rgba(76, 91, 212, 0.1);
--bell-hover: #f2f6fb;
--bell-unread-bg: rgba(76, 91, 212, 0.055);
--bell-input-bg: #ffffff;
--bell-shadow: 0 20px 44px rgba(23, 43, 77, 0.16), 0 2px 8px rgba(23, 43, 77, 0.08);
--bell-error: #d64545;
--bell-error-bg: rgba(214, 69, 69, 0.1);
--bell-warning: #b57b23;
--bell-warning-bg: rgba(181, 123, 35, 0.12);
--bell-info: #4c5bd4;
--bell-info-bg: rgba(76, 91, 212, 0.1);
--bell-skeleton: #eef2f7;
--bell-skeleton-shine: #f8fafd;
}
/* 头部 */
.bell-head {
display: flex;
flex: 0 0 auto;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 13px 16px 11px;
}
.bell-head-title {
display: flex;
align-items: center;
gap: 8px;
min-width: 0;
}
.bell-title-text {
color: var(--bell-text);
font-size: 15px;
font-weight: 700;
letter-spacing: 0.01em;
}
.bell-unread-chip {
padding: 2px 8px;
border-radius: 999px;
background: var(--bell-accent-soft);
color: var(--bell-accent);
font-size: 11px;
font-weight: 600;
white-space: nowrap;
}
.bell-read-all {
display: inline-flex;
flex-shrink: 0;
align-items: center;
gap: 4px;
padding: 5px 10px;
border: 1px solid var(--bell-border);
border-radius: 8px;
background: transparent;
color: var(--bell-text-dim);
font-size: 12px;
cursor: pointer;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.bell-read-all svg {
width: 12px;
height: 12px;
}
.bell-read-all:hover:not(:disabled) {
border-color: var(--bell-accent);
background: var(--bell-hover);
color: var(--bell-accent);
}
.bell-read-all:disabled {
opacity: 0.55;
cursor: not-allowed;
}
/* 筛选区 */
.bell-filters {
display: flex;
flex: 0 0 auto;
flex-direction: column;
gap: 8px;
padding: 10px 12px 12px;
border-bottom: 1px solid var(--bell-border);
background: var(--bell-bg-elev);
}
.bell-search-box {
position: relative;
display: flex;
align-items: center;
}
.bell-search-icon {
position: absolute;
left: 10px;
width: 14px;
height: 14px;
color: var(--bell-text-mute);
pointer-events: none;
}
.bell-search-input {
width: 100%;
height: 32px;
padding: 0 30px 0 32px;
box-sizing: border-box;
border: 1px solid var(--bell-border);
border-radius: 9px;
background: var(--bell-input-bg);
color: var(--bell-text);
font-size: 12px;
outline: none;
transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.bell-search-input::placeholder {
color: var(--bell-text-mute);
}
.bell-search-input:focus {
border-color: var(--bell-accent);
box-shadow: 0 0 0 3px var(--bell-accent-soft);
}
.bell-search-clear {
position: absolute;
right: 8px;
display: inline-flex;
align-items: center;
justify-content: center;
width: 16px;
height: 16px;
padding: 0;
border: none;
border-radius: 50%;
background: var(--bell-border);
color: var(--bell-bg);
cursor: pointer;
}
.bell-search-clear svg {
width: 10px;
height: 10px;
}
.bell-search-clear:hover {
background: var(--bell-text-mute);
}
/* 类型筛选 chip 行:比下拉更省纵向空间,与深色控制台风格一致 */
.bell-category-chips {
display: flex;
flex-wrap: wrap;
gap: 6px;
}
.bell-chip {
height: 24px;
padding: 0 10px;
border: 1px solid var(--bell-border);
border-radius: 12px;
background: var(--bell-input-bg);
color: var(--bell-text-mute);
font-size: 12px;
line-height: 1;
cursor: pointer;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.bell-chip:hover {
color: var(--bell-text);
border-color: var(--bell-accent);
}
.bell-chip.is-active {
border-color: var(--bell-accent);
background: var(--bell-accent-soft);
color: var(--bell-accent);
font-weight: 500;
}
.bell-search-days {
display: flex;
align-items: center;
gap: 8px;
}
.bell-date-picker {
flex: 1;
min-width: 0;
width: 100%;
}
.bell-panel :deep(.bell-date-picker.el-date-editor) {
--el-fill-color-blank: var(--bell-input-bg);
--el-text-color-regular: var(--bell-text);
--el-text-color-placeholder: var(--bell-text-mute);
--el-text-color-secondary: var(--bell-text-mute);
--el-border-color: var(--bell-border);
--el-border-color-hover: var(--bell-accent);
--el-color-primary: var(--bell-accent);
height: 32px;
border-radius: 9px;
}
.bell-panel :deep(.bell-date-picker .el-range-input) {
font-size: 12px;
}
.bell-panel :deep(.bell-date-picker .el-range-separator) {
font-size: 12px;
color: var(--bell-text-mute);
}
.bell-search-reset {
flex-shrink: 0;
height: 32px;
padding: 0 12px;
border: 1px solid var(--bell-border);
border-radius: 9px;
background: var(--bell-input-bg);
color: var(--bell-text-dim);
font-size: 12px;
cursor: pointer;
transition: color 0.15s ease, border-color 0.15s ease;
}
.bell-search-reset:hover {
border-color: var(--bell-accent);
color: var(--bell-accent);
}
/* 列表 */
.bell-list {
flex: 1;
margin: 0;
padding: 0 0 4px;
list-style: none;
overflow-y: auto;
scrollbar-width: thin;
scrollbar-color: var(--bell-border) transparent;
}
.bell-list::-webkit-scrollbar {
width: 8px;
}
.bell-list::-webkit-scrollbar-track {
background: transparent;
}
.bell-list::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: var(--bell-border);
background-clip: content-box;
}
.bell-list::-webkit-scrollbar-thumb:hover {
background: var(--bell-text-mute);
background-clip: content-box;
}
.bell-day-head {
position: sticky;
top: 0;
z-index: 1;
padding: 9px 16px 6px;
background: var(--bell-bg);
color: var(--bell-text-mute);
font-size: 11px;
font-weight: 600;
letter-spacing: 0.04em;
}
.bell-item {
position: relative;
display: flex;
gap: 10px;
padding: 11px 16px;
border-top: 1px solid transparent;
cursor: pointer;
transition: background 0.12s ease;
}
.bell-item:hover {
background: var(--bell-hover);
}
.bell-item--unread {
background: var(--bell-unread-bg);
}
.bell-item-icon {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
margin-top: 1px;
border-radius: 50%;
background: var(--bell-bg-elev);
color: var(--bell-text-mute);
}
.bell-item-icon svg {
width: 14px;
height: 14px;
}
.bell-item--unread.bell-item--error .bell-item-icon {
background: var(--bell-error-bg);
color: var(--bell-error);
}
.bell-item--unread.bell-item--warning .bell-item-icon {
background: var(--bell-warning-bg);
color: var(--bell-warning);
}
.bell-item--unread.bell-item--info .bell-item-icon {
background: var(--bell-info-bg);
color: var(--bell-info);
}
.bell-item-main {
flex: 1;
min-width: 0;
}
.bell-item-head {
display: flex;
align-items: baseline;
gap: 8px;
}
.bell-item-title {
flex: 1;
min-width: 0;
overflow: hidden;
color: var(--bell-text-dim);
font-size: 13px;
font-weight: 500;
text-overflow: ellipsis;
white-space: nowrap;
}
.bell-item--unread .bell-item-title {
color: var(--bell-text);
font-weight: 700;
}
.bell-item--unread.bell-item--error .bell-item-title {
color: var(--bell-error);
}
.bell-item--unread.bell-item--warning .bell-item-title {
color: var(--bell-warning);
}
.bell-item-dot {
flex: 0 0 auto;
align-self: center;
width: 6px;
height: 6px;
border-radius: 50%;
background: transparent;
}
.bell-item-dot--on {
background: var(--bell-error);
}
.bell-item-time {
flex: 0 0 auto;
color: var(--bell-text-mute);
font-size: 11px;
font-variant-numeric: tabular-nums;
}
.bell-item-content {
display: -webkit-box;
margin: 3px 0 0;
overflow: hidden;
color: var(--bell-text-mute);
font-size: 12px;
line-height: 1.6;
overflow-wrap: anywhere;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
}
.bell-item--unread .bell-item-content {
color: var(--bell-text-dim);
}
/* 空态 / 加载态 */
.bell-state {
display: flex;
flex: 1;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 40px 20px;
text-align: center;
}
.bell-state-icon {
display: inline-flex;
align-items: center;
justify-content: center;
width: 46px;
height: 46px;
border-radius: 50%;
background: var(--bell-bg-elev);
color: var(--bell-text-mute);
}
.bell-state-icon svg {
width: 22px;
height: 22px;
}
.bell-state-icon--error {
background: var(--bell-error-bg);
color: var(--bell-error);
}
.bell-state-text {
margin: 0;
color: var(--bell-text-dim);
font-size: 13px;
}
.bell-state-sub {
margin: 0;
color: var(--bell-text-mute);
font-size: 12px;
}
.bell-state-action {
margin-top: 4px;
padding: 5px 14px;
border: 1px solid var(--bell-border);
border-radius: 8px;
background: transparent;
color: var(--bell-accent);
font-size: 12px;
cursor: pointer;
}
.bell-state-action:hover {
border-color: var(--bell-accent);
background: var(--bell-hover);
}
.bell-skeleton {
flex: 1;
padding: 8px 16px;
}
.bell-skeleton-row {
display: flex;
gap: 10px;
padding: 10px 0;
}
.bell-skeleton-icon {
flex: 0 0 auto;
width: 26px;
height: 26px;
border-radius: 50%;
background: var(--bell-skeleton);
animation: bell-pulse 1.4s ease-in-out infinite;
}
.bell-skeleton-lines {
display: flex;
flex: 1;
flex-direction: column;
gap: 8px;
padding-top: 2px;
}
.bell-skeleton-bar {
height: 10px;
border-radius: 5px;
background: var(--bell-skeleton);
animation: bell-pulse 1.4s ease-in-out infinite;
}
.bell-skeleton-bar--title {
width: 62%;
}
.bell-skeleton-bar--text {
width: 88%;
background: var(--bell-skeleton-shine);
}
@keyframes bell-pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.45;
}
}
/* 底部:结构对齐后台列表分页(共 N 条 + 每页条数下拉 + 上一页 / 第 x / y 页 / 下一页) */
.bell-foot {
display: flex;
flex: 0 0 auto;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 8px;
padding: 9px 12px 9px 16px;
border-top: 1px solid var(--bell-border);
background: var(--bell-bg-elev);
}
.bell-foot-meta {
display: flex;
align-items: center;
gap: 8px;
}
.bell-foot-total {
color: var(--bell-text-mute);
font-size: 12px;
font-variant-numeric: tabular-nums;
}
.bell-size-select {
height: 26px;
padding: 0 4px;
border: 1px solid var(--bell-border);
border-radius: 7px;
background: var(--bell-bg);
color: var(--bell-text-dim);
font-family: inherit;
font-size: 12px;
cursor: pointer;
outline: none;
color-scheme: dark;
}
.bell-panel--light .bell-size-select {
color-scheme: light;
}
.bell-size-select:hover,
.bell-size-select:focus {
border-color: var(--bell-accent);
color: var(--bell-accent);
}
.bell-size-select option {
background: var(--bell-bg);
color: var(--bell-text);
}
.bell-pager {
display: flex;
align-items: center;
gap: 8px;
}
.bell-page-btn {
min-height: 26px;
padding: 0 10px;
border: 1px solid var(--bell-border);
border-radius: 8px;
background: var(--bell-bg);
color: var(--bell-text-dim);
font-family: inherit;
font-size: 12px;
cursor: pointer;
transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}
.bell-page-btn:hover:not(:disabled) {
border-color: var(--bell-accent);
background: var(--bell-hover);
color: var(--bell-accent);
}
.bell-page-btn:disabled {
background: var(--bell-bg-elev);
color: var(--bell-text-mute);
opacity: 0.6;
cursor: not-allowed;
}
.bell-page-info {
min-width: 58px;
color: var(--bell-text-dim);
font-size: 12px;
font-variant-numeric: tabular-nums;
text-align: center;
}
/* ---- 浅色主题(桌面入口首页顶栏) ---- */
.notification-bell--light .bell-trigger {
color: #55627a;
}
.notification-bell--light .bell-trigger:hover,
.notification-bell--light .bell-trigger--active {
background: rgba(76, 91, 212, 0.1);
color: #4c5bd4;
}
</style>
<style>
/* 日期选择面板与通知面板同为 body 级浮层,须压在通知面板(3200)之上 */
.bell-date-popper {
z-index: 3300 !important;
}
</style>