diff --git a/backend/internal/http/handler/admin_read.go b/backend/internal/http/handler/admin_read.go index 75e5925..fbe3bb6 100644 --- a/backend/internal/http/handler/admin_read.go +++ b/backend/internal/http/handler/admin_read.go @@ -3,6 +3,7 @@ package handler import ( "net/http" "strconv" + "strings" "time" "backend/internal/model" @@ -57,7 +58,23 @@ func (h *AdminReadHandler) Logs(c *gin.Context) { } } - items, total, stats, err := h.admin.Logs(c.Request.Context(), limit, offset, kind, status, nil, since, "", "", c.Query("source"), false, false, false) + // ?user= — server-side 用户搜索: resolve the term to matching user ids + // (name/email/id contains, case-insensitive) and filter rows to those users. + // A term that matches nobody must return zero rows, not the unfiltered list. + var userIDs []string + if term := strings.TrimSpace(c.Query("user")); term != "" { + ids, uerr := h.admin.MatchUserIDs(c.Request.Context(), term) + if uerr != nil { + c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) + return + } + if len(ids) == 0 { + ids = []string{"__no_match__"} + } + userIDs = ids + } + + items, total, stats, err := h.admin.Logs(c.Request.Context(), limit, offset, kind, status, nil, since, "", userIDs, strings.TrimSpace(c.Query("q")), "", c.Query("source"), false, false, false) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) return diff --git a/backend/internal/http/handler/banned_words.go b/backend/internal/http/handler/banned_words.go index b28b769..e22cffa 100644 --- a/backend/internal/http/handler/banned_words.go +++ b/backend/internal/http/handler/banned_words.go @@ -77,6 +77,30 @@ func (h *BannedWordsHandler) Import(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"added": added, "skipped": skipped}) } +// Hits — 违禁词触发列表: who triggered which word and when, newest first, +// with server-side pagination + ?q= search (违禁词/用户名/提示词, 跨页). +func (h *BannedWordsHandler) Hits(c *gin.Context) { + limit := parseInt(c.Query("limit"), 50) + offset := parseInt(c.Query("offset"), 0) + items, total, err := h.words.ListHits(c.Request.Context(), strings.TrimSpace(c.Query("q")), limit, offset) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load banned word hits"}) + return + } + out := make([]gin.H, 0, len(items)) + for _, hit := range items { + out = append(out, gin.H{ + "id": hit.ID, + "word": hit.Word, + "user_id": hit.UserID, + "user_name": hit.UserName, + "prompt": hit.Prompt, + "created_at": hit.CreatedAt, + }) + } + c.JSON(http.StatusOK, gin.H{"data": out, "total": total}) +} + func (h *BannedWordsHandler) Delete(c *gin.Context) { n, err := h.words.Delete(c.Request.Context(), c.Param("id")) if err != nil { diff --git a/backend/internal/http/handler/payment.go b/backend/internal/http/handler/payment.go index acefa48..08be4a6 100644 --- a/backend/internal/http/handler/payment.go +++ b/backend/internal/http/handler/payment.go @@ -79,7 +79,7 @@ func (h *PaymentHandler) MyOrders(c *gin.Context) { } limit := parseInt(c.Query("limit"), 20) offset := parseInt(c.Query("offset"), 0) - orders, total, err := h.pay.ListByUser(c.Request.Context(), user.ID, c.Query("status"), limit, offset) + orders, total, err := h.pay.ListByUser(c.Request.Context(), user.ID, c.Query("status"), strings.TrimSpace(c.Query("q")), limit, offset) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load orders"}) return @@ -129,7 +129,7 @@ func (h *PaymentHandler) AdminOrders(c *gin.Context) { status := c.Query("status") limit := parseInt(c.Query("limit"), 100) offset := parseInt(c.Query("offset"), 0) - orders, total, err := h.pay.ListAll(c.Request.Context(), status, limit, offset) + orders, total, err := h.pay.ListAll(c.Request.Context(), status, strings.TrimSpace(c.Query("q")), limit, offset) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load orders"}) return diff --git a/backend/internal/http/handler/user_generation.go b/backend/internal/http/handler/user_generation.go index 5bd7a60..63d207b 100644 --- a/backend/internal/http/handler/user_generation.go +++ b/backend/internal/http/handler/user_generation.go @@ -229,7 +229,21 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { // media=1 (画图台 grid): only pending rows or rows with a stored file, so a // deleted work's blanked row doesn't consume one of the grid's slots. mediaOnly := c.Query("media") == "1" - items, total, stats, err := h.admin.Logs(c.Request.Context(), limit, offset, kind, status, statuses, nil, userID, excludeSource, source, hasFile, excludeShowcase, mediaOnly) + // ?user= — admin-only 用户搜索 (the 日志管理 page with scope=all). Ignored for + // normal users, whose rows are already pinned to their own userID. + var userIDs []string + if term := strings.TrimSpace(c.Query("user")); term != "" && userID == "" { + ids, uerr := h.admin.MatchUserIDs(c.Request.Context(), term) + if uerr != nil { + c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) + return + } + if len(ids) == 0 { + ids = []string{"__no_match__"} + } + userIDs = ids + } + items, total, stats, err := h.admin.Logs(c.Request.Context(), limit, offset, kind, status, statuses, nil, userID, userIDs, strings.TrimSpace(c.Query("q")), excludeSource, source, hasFile, excludeShowcase, mediaOnly) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"detail": "failed to load logs"}) return @@ -264,13 +278,18 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { } else { userName = item.UserID } - var accountName any - if item.AccountID != "" { - if label, ok := accountByID[item.AccountID]; ok { - accountName = label - } else { - accountName = item.AccountID + // Provider account identity is admin-only: normal users must not see + // which upstream account (email) fulfilled their generation. + var accountName, accountID any + if userID == "" { + if item.AccountID != "" { + if label, ok := accountByID[item.AccountID]; ok { + accountName = label + } else { + accountName = item.AccountID + } } + accountID = emptyStringNil(item.AccountID) } out = append(out, gin.H{ "id": item.ID, @@ -287,7 +306,7 @@ func (h *UserGenerationHandler) Logs(c *gin.Context) { "source": emptyStringNil(item.Source), "user_id": emptyStringNil(item.UserID), "user_name": userName, - "account_id": emptyStringNil(item.AccountID), + "account_id": accountID, "account": accountName, "cost": item.Cost, "elapsed_ms": item.ElapsedMS, diff --git a/backend/internal/http/router/router.go b/backend/internal/http/router/router.go index 9b489d8..0102428 100644 --- a/backend/internal/http/router/router.go +++ b/backend/internal/http/router/router.go @@ -144,6 +144,7 @@ func New(cfg *config.Config, auth *service.AuthService, handlers Handlers) *gin. authed.POST("/banned-words", handlers.BannedWords.Create) authed.POST("/banned-words/import", handlers.BannedWords.Import) authed.DELETE("/banned-words/:id", handlers.BannedWords.Delete) + authed.GET("/banned-word-hits", handlers.BannedWords.Hits) authed.GET("/refresh/profiles", handlers.ProviderAdmin.RefreshProfiles) authed.POST("/refresh/profiles/:profile_id/refresh-now", handlers.ProviderAdmin.RefreshNow) authed.PATCH("/refresh/profiles/:profile_id", handlers.ProviderAdmin.RefreshUpdate) diff --git a/backend/internal/model/models.go b/backend/internal/model/models.go index ec37cf3..6f370d6 100644 --- a/backend/internal/model/models.go +++ b/backend/internal/model/models.go @@ -45,6 +45,18 @@ type BannedWord struct { UpdatedAt time.Time } +// BannedWordHit records one blocked request: which word matched, who sent it, +// and when. Feeds the admin 违禁词触发列表. +type BannedWordHit struct { + ID string `gorm:"primaryKey;size:32"` + WordID string `gorm:"size:32;index"` + Word string `gorm:"size:255;index;not null"` + UserID string `gorm:"size:32;index"` + UserName string `gorm:"size:255"` // snapshot of name/email at hit time + Prompt string `gorm:"type:text"` + CreatedAt time.Time `gorm:"index"` +} + type APIKey struct { ID string `gorm:"primaryKey;size:32"` UserID string `gorm:"size:32;index;not null"` @@ -219,6 +231,7 @@ func AutoMigrateModels() []any { return []any{ &User{}, &BannedWord{}, + &BannedWordHit{}, &APIKey{}, &ShowcaseItem{}, &EventLog{}, diff --git a/backend/internal/repo/banned_word_repo.go b/backend/internal/repo/banned_word_repo.go index 3b30e83..70ea700 100644 --- a/backend/internal/repo/banned_word_repo.go +++ b/backend/internal/repo/banned_word_repo.go @@ -84,13 +84,43 @@ func (r *BannedWordRepository) Delete(ctx context.Context, id string) (int64, er return res.RowsAffected, res.Error } -// RecordHit bumps the word's block counter and, when userID is set, the user's -// 违禁词触发次数 shown on the admin users table. Best-effort bookkeeping. -func (r *BannedWordRepository) RecordHit(ctx context.Context, wordID, userID string) { +// RecordHit bumps the word's block counter, the user's 违禁词触发次数 (when userID +// is set), and appends a BannedWordHit row for the admin 违禁词触发列表. +// Best-effort bookkeeping. +func (r *BannedWordRepository) RecordHit(ctx context.Context, wordID, word, userID, userName, prompt string) { _ = r.db.WithContext(ctx).Model(&model.BannedWord{}).Where("id = ?", wordID). UpdateColumn("hits", gorm.Expr("hits + 1")).Error if userID != "" { _ = r.db.WithContext(ctx).Model(&model.User{}).Where("id = ?", userID). UpdateColumn("banned_word_hits", gorm.Expr("banned_word_hits + 1")).Error } + _ = r.db.WithContext(ctx).Create(&model.BannedWordHit{ + ID: strings.ReplaceAll(uuid.NewString(), "-", "")[:32], + WordID: wordID, + Word: word, + UserID: userID, + UserName: userName, + Prompt: prompt, + CreatedAt: time.Now(), + }).Error +} + +// ListHits returns trigger records newest first, with pagination + total. +// query — server-side search over 违禁词 / 用户名 / 提示词 (跨页). +func (r *BannedWordRepository) ListHits(ctx context.Context, query string, limit, offset int) ([]model.BannedWordHit, int64, error) { + var out []model.BannedWordHit + var total int64 + q := r.db.WithContext(ctx).Model(&model.BannedWordHit{}) + if term := strings.TrimSpace(query); term != "" { + like := "%" + term + "%" + q = q.Where("(word ILIKE ? OR user_name ILIKE ? OR user_id ILIKE ? OR prompt ILIKE ?)", like, like, like, like) + } + if err := q.Count(&total).Error; err != nil { + return nil, 0, err + } + if limit <= 0 { + limit = 50 + } + err := q.Order("created_at desc").Limit(limit).Offset(offset).Find(&out).Error + return out, total, err } diff --git a/backend/internal/repo/event_repo.go b/backend/internal/repo/event_repo.go index 10831fe..6890ba4 100644 --- a/backend/internal/repo/event_repo.go +++ b/backend/internal/repo/event_repo.go @@ -22,6 +22,8 @@ type EventListFilter struct { Statuses []string // multiple statuses (status IN (?)) — used by the 画图台 grid Since *time.Time UserID string + UserIDs []string // when set, keep ONLY rows whose user_id is in this list (admin 用户搜索) + Query string // free-text search over prompt / model / error (server-side, 跨页) ExcludeSource string // when set, omit rows with this source (e.g. hide API-key "v1" usage from the customer logs page) Source string // when set, keep ONLY rows with this source (admin 来源 filter): "v1" (API key) / "user" (前台) / "admin" (测试模型) HasFile bool // when true, keep ONLY rows with a non-empty file (the 创作记录 gallery — paginates over real media) @@ -59,6 +61,13 @@ func (r *EventRepository) List(ctx context.Context, filter EventListFilter) ([]m if filter.UserID != "" { q = q.Where("user_id = ?", filter.UserID) } + if len(filter.UserIDs) > 0 { + q = q.Where("user_id IN ?", filter.UserIDs) + } + if term := strings.TrimSpace(filter.Query); term != "" { + like := "%" + term + "%" + q = q.Where("(prompt ILIKE ? OR model ILIKE ? OR error ILIKE ?)", like, like, like) + } if filter.ExcludeSource != "" { q = q.Where("(source IS NULL OR source <> ?)", filter.ExcludeSource) } diff --git a/backend/internal/repo/order_repo.go b/backend/internal/repo/order_repo.go index b857bd6..f638e09 100644 --- a/backend/internal/repo/order_repo.go +++ b/backend/internal/repo/order_repo.go @@ -2,6 +2,7 @@ package repo import ( "context" + "strings" "time" "backend/internal/model" @@ -29,13 +30,18 @@ func (r *OrderRepository) Update(ctx context.Context, id string, patch map[strin } // ListByUser returns a user's own orders, newest first, with pagination + total. -func (r *OrderRepository) ListByUser(ctx context.Context, userID, status string, limit, offset int) ([]model.Order, int64, error) { +// query — server-side search over 订单号 / 支付方式 / 金额 (跨页). +func (r *OrderRepository) ListByUser(ctx context.Context, userID, status, query string, limit, offset int) ([]model.Order, int64, error) { var out []model.Order var total int64 q := r.db.WithContext(ctx).Model(&model.Order{}).Where("user_id = ?", userID) if status != "" { q = q.Where("status = ?", status) } + if term := strings.TrimSpace(query); term != "" { + like := "%" + term + "%" + q = q.Where("(id ILIKE ? OR method ILIKE ? OR CAST(amount AS TEXT) LIKE ?)", like, like, like) + } if err := q.Count(&total).Error; err != nil { return nil, 0, err } @@ -47,13 +53,23 @@ func (r *OrderRepository) ListByUser(ctx context.Context, userID, status string, } // List returns all orders (admin) with optional status filter + pagination. -func (r *OrderRepository) List(ctx context.Context, status string, limit, offset int) ([]model.Order, int64, error) { +// query — server-side search over 订单号 / 支付方式 / 金额; userIDs — additionally +// match orders belonging to these users (resolved from a 用户名 search upstream). +func (r *OrderRepository) List(ctx context.Context, status, query string, userIDs []string, limit, offset int) ([]model.Order, int64, error) { var out []model.Order var total int64 q := r.db.WithContext(ctx).Model(&model.Order{}) if status != "" { q = q.Where("status = ?", status) } + if term := strings.TrimSpace(query); term != "" { + like := "%" + term + "%" + if len(userIDs) > 0 { + q = q.Where("(id ILIKE ? OR method ILIKE ? OR CAST(amount AS TEXT) LIKE ? OR user_id IN ?)", like, like, like, userIDs) + } else { + q = q.Where("(id ILIKE ? OR method ILIKE ? OR CAST(amount AS TEXT) LIKE ?)", like, like, like) + } + } if err := q.Count(&total).Error; err != nil { return nil, 0, err } diff --git a/backend/internal/service/admin_read.go b/backend/internal/service/admin_read.go index 0cbf83f..b49e72b 100644 --- a/backend/internal/service/admin_read.go +++ b/backend/internal/service/admin_read.go @@ -112,7 +112,7 @@ func (s *AdminReadService) ModelsView(ctx context.Context) ([]map[string]any, er return out, nil } -func (s *AdminReadService) Logs(ctx context.Context, limit, offset int, kind, status string, statuses []string, since *time.Time, userID, excludeSource, source string, hasFile, excludeShowcase, mediaOnly bool) ([]model.EventLog, int64, *repo.EventStats, error) { +func (s *AdminReadService) Logs(ctx context.Context, limit, offset int, kind, status string, statuses []string, since *time.Time, userID string, userIDs []string, query, excludeSource, source string, hasFile, excludeShowcase, mediaOnly bool) ([]model.EventLog, int64, *repo.EventStats, error) { var excludeFiles []string if excludeShowcase { excludeFiles = s.showcaseFileList(ctx) @@ -125,6 +125,8 @@ func (s *AdminReadService) Logs(ctx context.Context, limit, offset int, kind, st Statuses: statuses, Since: since, UserID: userID, + UserIDs: userIDs, + Query: query, ExcludeSource: excludeSource, Source: source, HasFile: hasFile, @@ -147,6 +149,30 @@ func (s *AdminReadService) Logs(ctx context.Context, limit, offset int, kind, st return items, total, stats, nil } +// MatchUserIDs resolves an admin 用户搜索 term to the set of user ids whose +// name, email or id contains the term (case-insensitive). Returns a non-nil, +// possibly empty slice — an empty slice means "no user matched" and the caller +// should return zero rows rather than dropping the filter. +func (s *AdminReadService) MatchUserIDs(ctx context.Context, term string) ([]string, error) { + term = strings.ToLower(strings.TrimSpace(term)) + if term == "" { + return nil, nil + } + users, err := s.users.List(ctx) + if err != nil { + return nil, err + } + out := []string{} + for _, u := range users { + if strings.Contains(strings.ToLower(u.Name), term) || + strings.Contains(strings.ToLower(u.Email), term) || + strings.Contains(strings.ToLower(u.ID), term) { + out = append(out, u.ID) + } + } + return out, nil +} + // UserNameMap builds an id -> display name lookup (name, else email, else id) // used to annotate admin log rows with user_name (mirrors admin.py:584-596). func (s *AdminReadService) UserNameMap(ctx context.Context) (map[string]string, error) { diff --git a/backend/internal/service/payment.go b/backend/internal/service/payment.go index 56f3f39..12c0244 100644 --- a/backend/internal/service/payment.go +++ b/backend/internal/service/payment.go @@ -249,12 +249,26 @@ func (s *PaymentService) GetForUser(ctx context.Context, userID, orderID string) return o, nil } -func (s *PaymentService) ListByUser(ctx context.Context, userID, status string, limit, offset int) ([]model.Order, int64, error) { - return s.orders.ListByUser(ctx, userID, status, limit, offset) +func (s *PaymentService) ListByUser(ctx context.Context, userID, status, query string, limit, offset int) ([]model.Order, int64, error) { + return s.orders.ListByUser(ctx, userID, status, query, limit, offset) } -func (s *PaymentService) ListAll(ctx context.Context, status string, limit, offset int) ([]model.Order, int64, error) { - return s.orders.List(ctx, status, limit, offset) +// ListAll — admin order list. A search query also matches 用户名/邮箱: resolve +// the term to user ids first so "张三" finds that user's orders. +func (s *PaymentService) ListAll(ctx context.Context, status, query string, limit, offset int) ([]model.Order, int64, error) { + var userIDs []string + if term := strings.ToLower(strings.TrimSpace(query)); term != "" { + if users, err := s.users.List(ctx); err == nil { + for _, u := range users { + if strings.Contains(strings.ToLower(u.Name), term) || + strings.Contains(strings.ToLower(u.Email), term) || + strings.Contains(strings.ToLower(u.ID), term) { + userIDs = append(userIDs, u.ID) + } + } + } + } + return s.orders.List(ctx, status, query, userIDs, limit, offset) } // UserNames maps user id → display name (name, else email, else id) so the admin diff --git a/backend/internal/service/v1.go b/backend/internal/service/v1.go index 21a85e8..f8429f0 100644 --- a/backend/internal/service/v1.go +++ b/backend/internal/service/v1.go @@ -268,11 +268,15 @@ func (s *V1Service) checkBannedPrompt(ctx context.Context, principal *APIPrincip if term == "" || !strings.Contains(lower, term) { continue } - userID := "" + userID, userName := "", "" if principal != nil && principal.User != nil { userID = principal.User.ID + userName = principal.User.Name + if userName == "" { + userName = principal.User.Email + } } - s.banned.RecordHit(ctx, w.ID, userID) + s.banned.RecordHit(ctx, w.ID, w.Word, userID, userName, prompt) return fmt.Errorf("%w: banned word \"%s\"", ErrBannedPrompt, w.Word) } return nil diff --git a/frontend/src/layouts/AdminLayout.vue b/frontend/src/layouts/AdminLayout.vue index 8d5d647..12aea90 100644 --- a/frontend/src/layouts/AdminLayout.vue +++ b/frontend/src/layouts/AdminLayout.vue @@ -1,5 +1,5 @@ @@ -40,16 +59,34 @@ const currentLabel = computed(() => route.meta?.label || '') - - - - - {{ t.label }} - + + + + + + {{ t.label }} + + + + + + {{ t.label }} + + + + + {{ c.label }} + + + + @@ -114,6 +151,18 @@ const currentLabel = computed(() => route.meta?.label || '') .admin-link.active { color: var(--fg); background: var(--hover); } .admin-link.active > span:first-child { opacity: 1; } +.admin-sublink { + display: flex; + align-items: center; + padding: 0.45rem 0.875rem 0.45rem 2.6rem; + border-radius: 0.625rem; + color: var(--fg-2); + font-weight: 500; + transition: background 0.15s ease, color 0.15s ease; +} +.admin-sublink:hover { background: var(--hover); color: var(--fg); } +.admin-sublink.active { color: var(--fg); background: var(--hover); } + .fade-enter-active, .fade-leave-active { transition: opacity 0.15s ease, transform 0.15s ease; } .fade-enter-from { opacity: 0; transform: translateY(4px); } .fade-leave-to { opacity: 0; } diff --git a/frontend/src/main.js b/frontend/src/main.js index fa23986..c2e624c 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -24,6 +24,7 @@ import AccountsView from './views/AccountsView.vue' import UsersView from './views/UsersView.vue' import ConcurrencyView from './views/ConcurrencyView.vue' import BannedWordsView from './views/BannedWordsView.vue' +import BannedWordHitsView from './views/BannedWordHitsView.vue' import CdksView from './views/CdksView.vue' import InvitesAdminView from './views/InvitesAdminView.vue' import ImagesView from './views/ImagesView.vue' @@ -57,7 +58,8 @@ const routes = [ { path: 'accounts', component: AccountsView, meta: { label: '账号管理' } }, { path: 'users', component: UsersView, meta: { label: '用户管理' } }, { path: 'concurrency', component: ConcurrencyView, meta: { label: '并发分组' } }, - { path: 'banned-words', component: BannedWordsView, meta: { label: '违禁词管理' } }, + { path: 'banned-words', component: BannedWordsView, meta: { label: '违禁词列表' } }, + { path: 'banned-word-hits', component: BannedWordHitsView, meta: { label: '违禁词触发列表' } }, { path: 'orders', component: AdminOrdersView, meta: { label: '订单管理' } }, { path: 'cdks', component: CdksView, meta: { label: '兑换码管理' } }, { path: 'invites', component: InvitesAdminView, meta: { label: '邀请日志' } }, diff --git a/frontend/src/views/AdminOrdersView.vue b/frontend/src/views/AdminOrdersView.vue index 8651330..80fef2c 100644 --- a/frontend/src/views/AdminOrdersView.vue +++ b/frontend/src/views/AdminOrdersView.vue @@ -30,6 +30,7 @@ async function load() { loading.value = true const qs = new URLSearchParams({ limit: String(pageSize), offset: String((page.value - 1) * pageSize) }) if (status.value) qs.set('status', status.value) + if (search.value.trim()) qs.set('q', search.value.trim()) const r = await api('/pay/admin/orders?' + qs.toString()) loading.value = false if (r.ok) { @@ -39,14 +40,9 @@ async function load() { } onMounted(load) -const displayed = computed(() => { - const q = search.value.trim().toLowerCase() - if (!q) return items.value - return items.value.filter((o) => - (o.id || '').toLowerCase().includes(q) || - (o.user_name || '').toLowerCase().includes(q) || - String(o.amount).includes(q)) -}) +// 搜索走服务端(跨页),直接展示服务端返回的当页结果。 +const displayed = computed(() => items.value) +function doSearch() { page.value = 1; load() } const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize))) const pageStart = computed(() => total.value === 0 ? 0 : (page.value - 1) * pageSize + 1) const pageEnd = computed(() => Math.min(total.value, page.value * pageSize)) @@ -84,7 +80,8 @@ function goPage(n) { {{ s[1] }} - + 刷新 diff --git a/frontend/src/views/BannedWordHitsView.vue b/frontend/src/views/BannedWordHitsView.vue new file mode 100644 index 0000000..9719f86 --- /dev/null +++ b/frontend/src/views/BannedWordHitsView.vue @@ -0,0 +1,115 @@ + + + + + + + 违禁词触发列表 + {{ total }} 条触发记录 · 每次拦截记一条(违禁词 / 用户 / 时间 / 提示词) + + + + 刷新 + + + + + + + + + + + + + + 违禁词 + 用户 + 提示词 + 触发时间 + + + + 加载中… + {{ search.trim() ? '没有匹配的记录' : '还没有触发记录' }} + + {{ h.word }} + + {{ h.user_name || '—' }} + + + {{ h.prompt || '—' }} + + {{ new Date(h.created_at).toLocaleString() }} + + + + + {{ pageStart }}–{{ pageEnd }}/ {{ total }} 条 + + + … + {{ n }} + + + + + + + + diff --git a/frontend/src/views/LogsView.vue b/frontend/src/views/LogsView.vue index ea4cf98..3bc3d8a 100644 --- a/frontend/src/views/LogsView.vue +++ b/frontend/src/views/LogsView.vue @@ -14,6 +14,7 @@ const kindFilter = ref('') // '' | 'image' | 'video' const statusFilter = ref('') // '' | 'success' | 'failed' | 'pending' const sourceFilter = ref('') // '' | 'v1' | 'user' | 'admin' const search = ref('') +const userSearch = ref('') // 服务端用户搜索:名称 / 邮箱 / ID,跨页生效 const page = ref(1) const pageSize = ref(15) const total = ref(0) @@ -42,6 +43,8 @@ async function load() { if (kindFilter.value) qs.set('kind', kindFilter.value) if (statusFilter.value) qs.set('status', statusFilter.value) if (sourceFilter.value) qs.set('source', sourceFilter.value) + if (userSearch.value.trim()) qs.set('user', userSearch.value.trim()) + if (search.value.trim()) qs.set('q', search.value.trim()) const r = await api('/logs?' + qs.toString()) items.value = r.data?.data || [] total.value = Number(r.data?.total ?? items.value.length) @@ -83,16 +86,10 @@ function goPage(n) { function setKind(v) { kindFilter.value = v; page.value = 1; load() } function setStatus(v) { statusFilter.value = v; page.value = 1; load() } function setSource(v) { sourceFilter.value = v; page.value = 1; load() } +function doUserSearch() { page.value = 1; load() } -const filtered = computed(() => { - const q = search.value.trim().toLowerCase() - if (!q) return items.value - return items.value.filter((e) => - (e.model || '').toLowerCase().includes(q) || - (e.prompt || '').toLowerCase().includes(q) || - (e.error || '').toLowerCase().includes(q), - ) -}) +// 搜索全部走服务端(跨页),页面直接展示服务端返回的当页结果。 +const filtered = computed(() => items.value) function fmtMs(ms) { if (!ms) return '—' @@ -203,8 +200,13 @@ const sourcePill = (s) => ({ API 测试 + + + - + 刷新 @@ -216,9 +218,7 @@ const sourcePill = (s) => ({ 加载中… - - {{ search.trim() ? '当前页没有匹配的记录(搜索仅作用于本页)' : '还没有日志' }} + {{ (search.trim() || userSearch.trim()) ? '没有匹配的记录' : '还没有日志' }} - @@ -209,7 +204,6 @@ const params = (e) => { 预览 时间 状态 - 用户 / 账号 模型 提示词 / 错误 参数 @@ -242,10 +236,6 @@ const params = (e) => { {{ statusLabel(e.status) }} - - {{ e.user_name || '匿名' }} - {{ e.account }} - {{ e.model }} diff --git a/frontend/src/views/UserLogsView.vue b/frontend/src/views/UserLogsView.vue index 178eef4..c32c965 100644 --- a/frontend/src/views/UserLogsView.vue +++ b/frontend/src/views/UserLogsView.vue @@ -34,22 +34,16 @@ async function load() { source: 'user', // 创作记录 = 画图台作品;排除 API(v1,无存储文件)+ 测试 }) if (kindFilter.value) qs.set('kind', kindFilter.value) + if (search.value.trim()) qs.set('q', search.value.trim()) const r = await api('/logs?' + qs.toString()) items.value = (r.data?.data || []).filter((e) => e.status === 'success' && e.file) total.value = Number(r.data?.total ?? items.value.length) loading.value = false } -// Search narrows the CURRENT page (same as the admin 日志 page); the numbered -// pager still reflects the full server-side total. -const filtered = computed(() => { - const q = search.value.trim().toLowerCase() - if (!q) return items.value - return items.value.filter((e) => - (e.model || '').toLowerCase().includes(q) || - (e.prompt || '').toLowerCase().includes(q), - ) -}) +// 搜索走服务端(跨页),直接展示服务端返回的当页结果。 +const filtered = computed(() => items.value) +function doSearch() { page.value = 1; load() } const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize))) function setKind(v) { kindFilter.value = v; page.value = 1; load() } @@ -260,7 +254,8 @@ onUnmounted(() => { :class="kindFilter === 'video' ? 'bg-slate-900 text-white' : 'bg-slate-100 text-slate-600 hover:bg-slate-200'">视频 - +
{{ total }} 条触发记录 · 每次拦截记一条(违禁词 / 用户 / 时间 / 提示词)