chore: message page list support sharedworker.js

This commit is contained in:
duorameng
2026-05-09 09:02:43 +08:00
parent f5f761e7ef
commit 0dad9dd541
7 changed files with 56 additions and 3 deletions
+1
View File
@@ -105,6 +105,7 @@ const (
// 其他事件类型
EventSystemNotice = "system_notice"
EventNotifySent = "notify_sent"
EventAppLogAdded = "app_log_added"
// WebSocket 消息类型
WSTypeHeartbeat = "heartbeat"
+8 -1
View File
@@ -32,7 +32,14 @@ func (s *AppLogService) Add(log *models.AppLog) error {
if log.ID == "" {
log.ID = utils.GenerateID()
}
return database.DB.Create(log).Error
err := database.DB.Create(log).Error
if err == nil {
eventbus.DefaultBus.Publish(eventbus.Event{
Type: constant.EventAppLogAdded,
Payload: log,
})
}
return err
}
func (s *AppLogService) List(category string, status string, level string, page, pageSize int, keyword string) ([]models.AppLog, int64, error) {
+8 -1
View File
@@ -33,7 +33,14 @@ func (s *LoginLogService) Create(username, ip, userAgent, status, message string
RefID: ip,
ErrorMsg: models.BigText(message),
}
return database.DB.Create(log).Error
err := database.DB.Create(log).Error
if err == nil {
eventbus.DefaultBus.Publish(eventbus.Event{
Type: constant.EventAppLogAdded,
Payload: log,
})
}
return err
}
// SubscribeEvents 注册订阅事件
+5
View File
@@ -72,3 +72,8 @@ export const TASK_EVENTS = {
RUNNING: 'task_running',
QUEUED: 'task_queued',
} as const
// 日志事件类型
export const LOG_EVENTS = {
ADDED: 'app_log_added',
} as const
+12 -1
View File
@@ -3,9 +3,11 @@ import { ref, onMounted } from 'vue'
import Pagination from '@/components/Pagination.vue'
import { Loader2 } from 'lucide-vue-next'
import TextOverflow from '@/components/TextOverflow.vue'
import { api } from '@/api'
import { api, LOG_CATEGORY } from '@/api'
import { toast } from 'vue-sonner'
import { useSiteSettings } from '@/composables/useSiteSettings'
import { useEventBus } from '@/composables/useEventBus'
import { LOG_EVENTS } from '@/constants'
import BaihuDialog from '@/components/ui/BaihuDialog.vue'
const props = defineProps<{
@@ -91,6 +93,15 @@ function handlePageChange(page: number) {
onMounted(loadLogs)
// 实时更新:当有新登录产生且用户在第一页时刷新
useEventBus([LOG_EVENTS.ADDED], (payload) => {
if (payload && payload.category === LOG_CATEGORY.LOGIN_LOG) {
if (currentPage.value === 1) {
loadLogs()
}
}
})
defineExpose({
loadLogs
})
@@ -11,6 +11,8 @@ import BaihuDialog from '@/components/ui/BaihuDialog.vue'
import { toast } from 'vue-sonner'
import { format } from 'date-fns'
import { useSiteSettings } from '@/composables/useSiteSettings'
import { useEventBus } from '@/composables/useEventBus'
import { LOG_EVENTS } from '@/constants'
const props = defineProps<{
filters: {
@@ -85,6 +87,15 @@ onMounted(() => {
fetchLogs()
})
// 实时更新:当有新系统事件产生且用户在第一页时刷新
useEventBus([LOG_EVENTS.ADDED], (payload) => {
if (payload && payload.category === LOG_CATEGORY.SYSTEM_NOTICE) {
if (currentPage.value === 1) {
fetchLogs()
}
}
})
const selectedLog = computed(() => logs.value.find((l: AppLog) => l.id === selectedLogId.value))
defineExpose({
@@ -19,6 +19,8 @@ import {
AlertDialogTitle,
} from '@/components/ui/alert-dialog'
import { useSiteSettings } from '@/composables/useSiteSettings'
import { useEventBus } from '@/composables/useEventBus'
import { LOG_EVENTS } from '@/constants'
import BaihuDialog from '@/components/ui/BaihuDialog.vue'
const props = defineProps<{
@@ -94,6 +96,15 @@ onMounted(() => {
fetchLogs()
})
// 实时更新:当有新推送产生且用户在第一页时刷新
useEventBus([LOG_EVENTS.ADDED], (payload) => {
if (payload && payload.category === LOG_CATEGORY.PUSH_LOG) {
if (currentPage.value === 1) {
fetchLogs()
}
}
})
const selectedLog = computed(() => logs.value.find((l: AppLog) => l.id === selectedLogId.value))
defineExpose({