From f7ec47306c744d703be466dc6f213c54c3513a44 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 16 Mar 2026 20:13:30 +0800 Subject: [PATCH] refactor: unify dropdown menu styles across components - Removed redundant dropdown menu styles from various components and centralized them in a new `dropdown-menu.less` file. - Updated components to use the unified styles, ensuring consistency in appearance and behavior across the application. This change simplifies maintenance and enhances the visual coherence of dropdown menus. --- .../2026-03-16-manual-knowledge-download.md | 241 ------------- ...-03-16-manual-knowledge-download-design.md | 132 ------- frontend/src/assets/dropdown-menu.less | 322 ++++++++++++++++++ frontend/src/components/menu.vue | 52 +-- frontend/src/main.ts | 1 + frontend/src/views/agent/AgentList.vue | 61 +--- .../src/views/knowledge/KnowledgeBase.vue | 133 +++----- .../src/views/knowledge/KnowledgeBaseList.vue | 61 +--- .../knowledge/components/FAQEntryManager.vue | 127 +------ .../views/organization/OrganizationList.vue | 61 +--- frontend/src/views/settings/ModelSettings.vue | 46 +-- 11 files changed, 390 insertions(+), 847 deletions(-) delete mode 100644 docs/superpowers/plans/2026-03-16-manual-knowledge-download.md delete mode 100644 docs/superpowers/specs/2026-03-16-manual-knowledge-download-design.md create mode 100644 frontend/src/assets/dropdown-menu.less diff --git a/docs/superpowers/plans/2026-03-16-manual-knowledge-download.md b/docs/superpowers/plans/2026-03-16-manual-knowledge-download.md deleted file mode 100644 index 4539a23b..00000000 --- a/docs/superpowers/plans/2026-03-16-manual-knowledge-download.md +++ /dev/null @@ -1,241 +0,0 @@ -# Manual Knowledge Download Implementation Plan - -> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development (if subagents available) or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking. - -**Goal:** Allow users to download `manual` type knowledge items as `.md` files via the existing download endpoint. - -**Architecture:** Add an early-return branch in `GetKnowledgeFile` that, for manual knowledge, reads `Metadata.content` from the database record and streams it as a `.md` file — no new routes or handlers needed. The frontend adds a download button to the manual UI block and fixes the `link.download` attribute to include the `.md` extension. - -**Tech Stack:** Go 1.24 (Gin, GORM), Vue 3 + TypeScript (TDesign UI, Pinia) - -**Spec:** `docs/superpowers/specs/2026-03-16-manual-knowledge-download-design.md` - ---- - -## Files Changed - -| Action | Path | What changes | -|--------|------|--------------| -| Modify | `internal/application/service/knowledge.go` | Add manual branch in `GetKnowledgeFile` (lines 2408–2425) | -| Modify | `frontend/src/components/doc-content.vue` | Add download button to manual block (line 694–700); fix `link.download` in `downloadFile()` (line 630) | - -No new files are created. - ---- - -## Chunk 1: Backend — GetKnowledgeFile manual branch - -### Task 1: Add manual type support to GetKnowledgeFile - -**Files:** -- Modify: `internal/application/service/knowledge.go:2408-2425` - -- [ ] **Step 1: Verify the current state of GetKnowledgeFile** - - Open `internal/application/service/knowledge.go` and confirm the method looks like this (lines 2408–2425): - - ```go - // GetKnowledgeFile retrieves the physical file associated with a knowledge entry - func (s *knowledgeService) GetKnowledgeFile(ctx context.Context, id string) (io.ReadCloser, string, error) { - // Get knowledge record - tenantID := ctx.Value(types.TenantIDContextKey).(uint64) - knowledge, err := s.repo.GetKnowledgeByID(ctx, tenantID, id) - if err != nil { - return nil, "", err - } - - // Resolve KB-level file service with FilePath fallback protection - kb, _ := s.kbService.GetKnowledgeBaseByID(ctx, knowledge.KnowledgeBaseID) - file, err := s.resolveFileServiceForPath(ctx, kb, knowledge.FilePath).GetFile(ctx, knowledge.FilePath) - if err != nil { - return nil, "", err - } - - return file, knowledge.FileName, nil - } - ``` - -- [ ] **Step 2: Add the manual branch** - - Replace the body of `GetKnowledgeFile` so it reads: - - ```go - // GetKnowledgeFile retrieves the physical file associated with a knowledge entry - func (s *knowledgeService) GetKnowledgeFile(ctx context.Context, id string) (io.ReadCloser, string, error) { - // Get knowledge record - tenantID := ctx.Value(types.TenantIDContextKey).(uint64) - knowledge, err := s.repo.GetKnowledgeByID(ctx, tenantID, id) - if err != nil { - return nil, "", err - } - - // Manual knowledge stores content in Metadata — stream it directly as a .md file. - if knowledge.IsManual() { - meta, err := knowledge.ManualMetadata() - if err != nil { - return nil, "", err - } - // ManualMetadata returns (nil, nil) when Metadata column is empty; treat as empty content. - content := "" - if meta != nil { - content = meta.Content - } - // Sanitize title: strip characters that are invalid or dangerous in HTTP headers / filenames. - safeName := strings.NewReplacer( - "\n", "", "\r", "", "/", "-", "\\", "-", "\"", "'", - ).Replace(knowledge.Title) - filename := safeName + ".md" - return io.NopCloser(strings.NewReader(content)), filename, nil - } - - // Resolve KB-level file service with FilePath fallback protection - kb, _ := s.kbService.GetKnowledgeBaseByID(ctx, knowledge.KnowledgeBaseID) - file, err := s.resolveFileServiceForPath(ctx, kb, knowledge.FilePath).GetFile(ctx, knowledge.FilePath) - if err != nil { - return nil, "", err - } - - return file, knowledge.FileName, nil - } - ``` - - The `strings` package is already imported in this file. `io` is also already imported. - -- [ ] **Step 3: Verify imports are present** - - Confirm that `"io"` and `"strings"` are already in the import block at the top of `internal/application/service/knowledge.go`. They are — do **not** add duplicate imports. - -- [ ] **Step 4: Verify the build compiles** - - Run from the repo root: - - ```bash - go build ./internal/application/service/... - ``` - - Expected: exits 0, no output. - -- [ ] **Step 5: Run the Go test suite** - - ```bash - go test -v ./... - ``` - - Expected: all existing tests pass (there are no tests for `GetKnowledgeFile` yet — that's fine, the suite should be green overall). - -- [ ] **Step 6: Commit** - - ```bash - git add internal/application/service/knowledge.go - git commit -m "feat: support manual knowledge download in GetKnowledgeFile" - ``` - ---- - -## Chunk 2: Frontend — download button + filename fix - -### Task 2: Add download button to manual knowledge UI block - -**Files:** -- Modify: `frontend/src/components/doc-content.vue:694-700` - -- [ ] **Step 1: Locate the manual block in the template** - - In `frontend/src/components/doc-content.vue`, find lines 694–700: - - ```vue - -
- {{ $t('knowledgeBase.documentTitle') }} -
- {{ details.title }} -
-
- ``` - -- [ ] **Step 2: Add the download button** - - Replace those lines with: - - ```vue - -
- {{ $t('knowledgeBase.documentTitle') }} -
- {{ details.title }} -
-
- -
-
- ``` - - The `.icon_box` and `.download_box` CSS classes are already defined in this component (used by the `file` type block above). - -- [ ] **Step 3: Fix the link.download attribute and a pre-existing removeChild bug in downloadFile()** - - In the same file, locate `downloadFile()` at lines 619–641. - - **Fix 1 — filename extension (line 630).** The current line is: - - ```ts - link.setAttribute("download", props.details.title); - ``` - - Replace it with: - - ```ts - link.setAttribute("download", props.details.type === 'manual' ? props.details.title + '.md' : props.details.title); - ``` - - **Fix 2 — pre-existing removeChild bug (line 633).** The link is created but never appended to `document.body`, so `document.body.removeChild(link)` throws a DOM exception at runtime. While fixing this is strictly out of scope, you will be touching this function anyway, so add the missing `appendChild` call right before `link.click()`: - - Before `link.click()`, add: - ```ts - document.body.appendChild(link); - ``` - - The full corrected block (lines 627–635) should read: - - ```ts - const link = document.createElement("a"); - link.style.display = "none"; - link.setAttribute("href", url.value); - link.setAttribute("download", props.details.type === 'manual' ? props.details.title + '.md' : props.details.title); - document.body.appendChild(link); - link.click(); - nextTick(() => { - document.body.removeChild(link); - URL.revokeObjectURL(url.value); - }) - ``` - -- [ ] **Step 4: Run TypeScript type check** - - ```bash - cd frontend && npm run type-check - ``` - - Expected: exits 0, no type errors. - -- [ ] **Step 5: Commit** - - ```bash - git add frontend/src/components/doc-content.vue - git commit -m "feat: add download button for manual knowledge in doc-content" - ``` - ---- - -## Manual Smoke Test (after both tasks) - -Start the dev server and verify end-to-end: - -1. Open a knowledge base that contains a `manual` type knowledge item. -2. Navigate to the knowledge detail page — confirm the download icon is visible (same icon as file type). -3. Click the download icon. -4. Verify the browser downloads a file named `{title}.md`. -5. Open the file and confirm the contents match the Markdown content in the editor. -6. Edge cases to spot-check: - - Knowledge item with empty content → downloads an empty `.md` file (not an error). - - Knowledge item whose title contains `/` or `"` → filename has `-` or `'` substituted respectively. diff --git a/docs/superpowers/specs/2026-03-16-manual-knowledge-download-design.md b/docs/superpowers/specs/2026-03-16-manual-knowledge-download-design.md deleted file mode 100644 index c11ed42e..00000000 --- a/docs/superpowers/specs/2026-03-16-manual-knowledge-download-design.md +++ /dev/null @@ -1,132 +0,0 @@ -# Manual Knowledge Download — Design Spec - -**Date:** 2026-03-16 -**Status:** Approved - ---- - -## Background - -WeKnora supports multiple knowledge types. The `manual` type stores content as Markdown in the database `Metadata.content` field — there is no physical file on disk or in object storage. The existing download endpoint (`GET /api/v1/knowledge/:id/download`) only works for `file` type knowledge; calling it for `manual` type would silently fail with an internal error because `FilePath` is empty. - -The frontend `doc-content.vue` component already omits the download button for `manual` type knowledge. This spec describes how to add proper download support. - ---- - -## Goal - -Allow users to download `manual` type knowledge as a `.md` file whose content is the Markdown stored in `Metadata.content` and whose filename is `{title}.md`. - ---- - -## Architecture - -### Backend — `internal/application/service/knowledge.go` - -**Method:** `GetKnowledgeFile(ctx, id) (io.ReadCloser, string, error)` - -Add an early-return branch before the existing file-service lookup: - -```go -if knowledge.IsManual() { - meta, err := knowledge.ManualMetadata() - if err != nil { - return nil, "", err - } - // ManualMetadata returns (nil, nil) when Metadata column is empty; - // treat as empty content rather than an error. - content := "" - if meta != nil { - content = meta.Content - } - // Sanitize title for use as a filename: strip newlines and path separators. - safeName := strings.NewReplacer( - "\n", "", "\r", "", "/", "-", "\\", "-", "\"", "'", - ).Replace(knowledge.Title) - filename := safeName + ".md" - return io.NopCloser(strings.NewReader(content)), filename, nil -} -``` - -- No new routes, handlers, or services required. -- All existing permission checks, logging, and error middleware remain intact. -- The handler sets `Content-Disposition: attachment; filename="{safeName}.md"` via the existing streaming logic. - -#### Non-ASCII filenames in `Content-Disposition` - -The existing handler writes the filename unquoted and without RFC 5987 encoding (`filename*=UTF-8''...`). This is a **known limitation inherited from the existing file-type download path** and is out of scope for this change. Most modern browsers (Chrome, Edge, Firefox) tolerate unquoted UTF-8 values in practice. A follow-up issue should address RFC 5987 encoding for all download types. - -### Frontend — `frontend/src/components/doc-content.vue` - -Two changes are required: - -**1. Add download button to the `manual` UI block:** - -```vue -
- {{ $t('knowledgeBase.documentTitle') }} -
- {{ details.title }} -
- -
- -
-
-``` - -**2. Fix `link.download` attribute in `downloadFile()` for manual type:** - -The existing `downloadFile()` function sets `link.setAttribute("download", props.details.title)` without an extension. Browsers use the `download` attribute — not `Content-Disposition` — as the saved filename when `URL.createObjectURL` is used. For `manual` type, append `.md`: - -```ts -const filename = details.value.type === 'manual' - ? details.value.title + '.md' - : details.value.title -link.setAttribute('download', filename) -``` - -`downloadFile()` otherwise calls `downKnowledgeDetails(id)` → `GET /api/v1/knowledge/:id/download` unchanged. - ---- - -## Data Flow - -``` -User clicks download - → downloadFile() [frontend, sets link.download = "{title}.md" for manual type] - → GET /api/v1/knowledge/:id/download - → DownloadKnowledgeFile handler [validates access] - → GetKnowledgeFile service - → if manual: sanitize title, read Metadata.content (empty string if nil) - → return (ReadCloser, "{safeName}.md", nil) - → handler streams response with Content-Disposition header - → browser saves "{title}.md" -``` - ---- - -## Side Effects - -`PreviewKnowledgeFile` also calls `GetKnowledgeFile` internally. After this change, preview requests for `manual` items will also succeed (returning the Markdown content with `text/markdown` MIME type via the existing `mimeTypeByExt(".md")` lookup). This is a desirable side effect and requires no additional changes. - ---- - -## Error Handling - -| Scenario | Behaviour | -|----------|-----------| -| `ManualMetadata()` parse error | Returns internal server error (existing error middleware handles it) | -| `ManualMetadata()` returns `nil` (empty Metadata column) | Treated as empty content; returns a valid empty `.md` file | -| Empty content (`""`) | Returns a valid empty `.md` file — not an error | -| Non-existent knowledge ID | Existing 404 handling unchanged | -| Insufficient permissions | Existing auth middleware unchanged | - ---- - -## Out of Scope - -- RFC 5987 encoding for non-ASCII `Content-Disposition` filenames (affects all download types, tracked separately) -- HTML / PDF / plain-text export formats -- Batch download of multiple knowledge items -- Version history download diff --git a/frontend/src/assets/dropdown-menu.less b/frontend/src/assets/dropdown-menu.less new file mode 100644 index 00000000..e9ae0def --- /dev/null +++ b/frontend/src/assets/dropdown-menu.less @@ -0,0 +1,322 @@ +/** + * 全局统一下拉菜单样式 + * + * 适用于所有场景的 popup/dropdown 菜单,包括: + * - 卡片操作菜单(知识库、智能体、组织) + * - 文档操作菜单 + * - 对话会话菜单 + * - 上传操作菜单 + * + * 使用方式: + * 1. + .popup-menu 自定义内容模式: overlayClassName="card-more-popup" + * 2. TDesign 下拉模式: 自动匹配全局样式 + */ + +/* 弹出动画 */ +@keyframes dropdownSlideIn { + from { + opacity: 0; + transform: translateY(-6px) scale(0.98); + } + to { + opacity: 1; + transform: translateY(0) scale(1); + } +} + +@keyframes dropdownSlideInUp { + from { + opacity: 0; + transform: translateY(6px) scale(0.98); + } + to { + opacity: 1; + transform: translateY(0) scale(1); + } +} + +/* ============================================ + 一、Popup 容器统一样式( 模式) + ============================================ */ +.card-more-popup { + z-index: 99 !important; + + .t-popup__content { + padding: 4px !important; + margin-top: 4px !important; + min-width: 148px; + border-radius: 10px !important; + background: var(--td-bg-color-container) !important; + border: 0.5px solid var(--td-component-stroke) !important; + box-shadow: + 0 0 0 0.5px rgba(0, 0, 0, 0.03), + 0 2px 4px rgba(0, 0, 0, 0.04), + 0 8px 24px rgba(0, 0, 0, 0.1) !important; + backdrop-filter: blur(20px) saturate(180%) !important; + -webkit-backdrop-filter: blur(20px) saturate(180%) !important; + animation: dropdownSlideIn 0.18s cubic-bezier(0.2, 0, 0, 1) both; + overflow: hidden; + } +} + +/* ============================================ + 二、自定义菜单项统一样式(.popup-menu 模式) + ============================================ */ +.popup-menu { + display: flex; + flex-direction: column; + gap: 1px; +} + +.popup-menu-item { + display: flex; + align-items: center; + gap: 10px; + padding: 8px 12px; + cursor: pointer; + transition: all 0.15s cubic-bezier(0.2, 0, 0, 1); + color: var(--td-text-color-primary); + font-size: 14px; + font-weight: 400; + line-height: 20px; + border-radius: 6px; + position: relative; + + .menu-icon { + font-size: 16px; + flex-shrink: 0; + color: var(--td-text-color-secondary); + transition: all 0.15s cubic-bezier(0.2, 0, 0, 1); + } + + &:hover { + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); + + .menu-icon { + color: var(--td-text-color-primary); + } + } + + &:active { + background: var(--td-bg-color-container-active); + transform: scale(0.98); + } + + &.delete, + &.danger { + color: var(--td-error-color-6); + margin-top: 4px; + position: relative; + + &::before { + content: ''; + position: absolute; + top: -3px; + left: 8px; + right: 8px; + height: 1px; + background: var(--td-component-stroke); + } + + .menu-icon { + color: var(--td-error-color-6); + } + + &:hover { + background: var(--td-error-color-1); + color: var(--td-error-color-6); + + .menu-icon { + color: var(--td-error-color-6); + } + } + + &:active { + background: var(--td-error-color-2); + } + } +} + +/* ============================================ + 三、文档操作菜单统一样式(.card-more 容器) + ============================================ */ +.card-more { + z-index: 99 !important; + + .t-popup__content { + padding: 4px !important; + margin-top: 4px !important; + min-width: 148px; + width: auto; + border-radius: 10px !important; + background: var(--td-bg-color-container) !important; + border: 0.5px solid var(--td-component-stroke) !important; + box-shadow: + 0 0 0 0.5px rgba(0, 0, 0, 0.03), + 0 2px 4px rgba(0, 0, 0, 0.04), + 0 8px 24px rgba(0, 0, 0, 0.1) !important; + backdrop-filter: blur(20px) saturate(180%) !important; + -webkit-backdrop-filter: blur(20px) saturate(180%) !important; + color: var(--td-text-color-primary); + animation: dropdownSlideIn 0.18s cubic-bezier(0.2, 0, 0, 1) both; + overflow: hidden; + } +} + +/* ============================================ + 四、TDesign Dropdown 统一样式 + 适用于 组件(挂载到 body 上) + ============================================ */ +.t-popup__content { + .t-dropdown__menu { + background: var(--td-bg-color-container); + border: 0.5px solid var(--td-component-stroke); + box-shadow: + 0 0 0 0.5px rgba(0, 0, 0, 0.03), + 0 2px 4px rgba(0, 0, 0, 0.04), + 0 8px 24px rgba(0, 0, 0, 0.1); + backdrop-filter: blur(20px) saturate(180%); + -webkit-backdrop-filter: blur(20px) saturate(180%); + padding: 4px; + min-width: 148px; + animation: dropdownSlideIn 0.18s cubic-bezier(0.2, 0, 0, 1) both; + overflow: hidden; + } + + .t-dropdown__item { + padding: 8px 12px; + border-radius: 6px; + margin: 1px 0; + transition: all 0.15s cubic-bezier(0.2, 0, 0, 1); + font-size: 14px; + color: var(--td-text-color-primary); + cursor: pointer; + min-width: auto !important; + max-width: 100% !important; + display: flex !important; + align-items: center; + width: 100%; + position: relative; + + &:hover { + background: var(--td-bg-color-container-hover); + color: var(--td-text-color-primary); + } + + &:active { + background: var(--td-bg-color-container-active); + transform: scale(0.98); + } + + .t-dropdown__item-icon { + flex-shrink: 0; + margin-right: 8px; + color: var(--td-text-color-secondary); + display: flex; + align-items: center; + transition: all 0.15s cubic-bezier(0.2, 0, 0, 1); + + .t-icon { + font-size: 16px; + } + } + + &:hover .t-dropdown__item-icon { + color: var(--td-text-color-primary); + } + + .t-dropdown__item-text { + color: inherit !important; + font-size: 14px !important; + line-height: 20px !important; + white-space: nowrap !important; + overflow: hidden !important; + text-overflow: ellipsis !important; + flex: 1; + min-width: 0; + display: block; + } + + /* TDesign error 主题项(删除操作) */ + &.t-dropdown__item--theme-error { + color: var(--td-error-color-6) !important; + margin-top: 4px; + position: relative; + + &::before { + content: ''; + position: absolute; + top: -3px; + left: 8px; + right: 8px; + height: 1px; + background: var(--td-component-stroke); + } + + .t-dropdown__item-icon { + color: var(--td-error-color-6); + } + + &:hover { + background: var(--td-error-color-1); + color: var(--td-error-color-6) !important; + + .t-dropdown__item-icon { + color: var(--td-error-color-6); + } + } + + &:active { + background: var(--td-error-color-2); + } + } + } +} + +/* tag 更多弹窗 */ +.tag-more-popup { + z-index: 99 !important; + + .t-popup__content { + padding: 4px !important; + margin-top: 4px !important; + min-width: 120px; + border-radius: 10px !important; + background: var(--td-bg-color-container) !important; + border: 0.5px solid var(--td-component-stroke) !important; + box-shadow: + 0 0 0 0.5px rgba(0, 0, 0, 0.03), + 0 2px 4px rgba(0, 0, 0, 0.04), + 0 8px 24px rgba(0, 0, 0, 0.1) !important; + backdrop-filter: blur(20px) saturate(180%) !important; + -webkit-backdrop-filter: blur(20px) saturate(180%) !important; + animation: dropdownSlideIn 0.18s cubic-bezier(0.2, 0, 0, 1) both; + overflow: hidden; + } +} + +/* ============================================ + 五、暗色模式增强 + ============================================ */ +:root[theme-mode="dark"] { + .card-more-popup .t-popup__content, + .card-more .t-popup__content, + .tag-more-popup .t-popup__content { + background: rgba(36, 36, 36, 0.85) !important; + border-color: rgba(255, 255, 255, 0.08) !important; + box-shadow: + 0 0 0 0.5px rgba(255, 255, 255, 0.05), + 0 2px 4px rgba(0, 0, 0, 0.12), + 0 8px 32px rgba(0, 0, 0, 0.28) !important; + } + + .t-popup__content .t-dropdown__menu { + background: rgba(36, 36, 36, 0.85); + border-color: rgba(255, 255, 255, 0.08); + box-shadow: + 0 0 0 0.5px rgba(255, 255, 255, 0.05), + 0 2px 4px rgba(0, 0, 0, 0.12), + 0 8px 32px rgba(0, 0, 0, 0.28); + } +} diff --git a/frontend/src/components/menu.vue b/frontend/src/components/menu.vue index a4063f0b..5c3220a1 100644 --- a/frontend/src/components/menu.vue +++ b/frontend/src/components/menu.vue @@ -77,7 +77,7 @@ {{ subitem.title }} @@ -124,7 +124,7 @@