Files
crawler-plugin/admin-frontend-vue/src/api/notifications.ts
T
huangzd1997 873887460a feat(站内通知): 铃铛面板支持时间/内容搜索、按天分组与分页
- 列表接口加 keyword(标题/内容模糊)与 startDate/endDate(年月日闭区间)参数,
  两端控制器透传,服务端补筛选日志
- 两端铃铛面板:搜索框(防抖 300ms)+ 日期区间 + 按年月日分组 + 翻页,
  面板改 Teleport 到 body(挂在顶栏时会被页面 el-select 压住,提 z-index 无效)
- 固化可见范围回归测试:超管全量/管理员只看本组/普通用户只看自己,
  含读写两侧的 user_id+audience 裁剪断言与两端控制器身份来源断言
2026-09-13 23:59:06 +08:00

71 lines
2.0 KiB
TypeScript

import { http } from './http'
import { unwrap } from './envelope'
/** 单条通知(后台铃铛)。 */
export interface AdminNotificationItem {
id: number
scene: string
level: string
title: string
content: string
read: boolean
readAt: string | null
createdAt: string | null
}
export interface AdminNotificationPage {
items: AdminNotificationItem[]
total: number
page: number
pageSize: number
unreadCount: number
}
export interface AdminNotificationSummary {
unreadCount: number
latestId: number
}
/** 铃铛轮询:未读数 + 最新通知 id。 */
export async function fetchNotificationSummary(): Promise<AdminNotificationSummary> {
const { data } = await http.get('/api/admin/notifications/summary')
return unwrap<AdminNotificationSummary>(data)
}
/** 列表查询参数:关键字匹配标题/内容;startDate/endDate 为年月日闭区间(yyyy-MM-dd)。 */
export interface AdminNotificationListParams {
page?: number
pageSize?: number
onlyUnread?: boolean
keyword?: string
startDate?: string
endDate?: string
}
export async function fetchNotificationList(
params: AdminNotificationListParams = {},
): Promise<AdminNotificationPage> {
const keyword = (params.keyword ?? '').trim()
const { data } = await http.get('/api/admin/notifications', {
params: {
page: params.page ?? 1,
pageSize: params.pageSize ?? 20,
onlyUnread: params.onlyUnread ? 'true' : 'false',
keyword: keyword || undefined,
startDate: params.startDate || undefined,
endDate: params.endDate || undefined,
},
})
return unwrap<AdminNotificationPage>(data)
}
export async function markNotificationRead(id: number): Promise<boolean> {
const { data } = await http.post(`/api/admin/notifications/${id}/read`)
return unwrap<boolean>(data)
}
export async function markAllNotificationsRead(): Promise<number> {
const { data } = await http.post('/api/admin/notifications/read-all')
return unwrap<number>(data)
}