Skip to content

Conversation

@brianxiadong
Copy link
Contributor

@brianxiadong brianxiadong commented Jan 14, 2026

Pull Request

描述 (Description)

本次 PR 实现了知识分类功能,允许用户在上传或创建知识时自动归类到选中的分类下。
image

核心功能:

  • 支持在文件上传(点击上传、拖拽上传、文件夹上传)时自动归类到选中的分类
  • 支持在 URL 导入时自动归类到选中的分类
  • 支持在线编辑创建知识时自动归类到选中的分类
  • 通过 UI Store 统一管理当前选中的分类ID,确保所有上传方式都能正确传递分类信息

技术实现:

  • 后端 API 新增 tag_id 参数支持,在创建知识时保存分类ID
  • 前端通过 Store 管理选中分类状态,所有上传入口统一读取并传递分类ID
  • 保持向后兼容,tag_id 为可选参数,未提供时默认为"未分类"

变更类型 (Type of Change)

  • ✨ 新功能 (New feature)

影响范围 (Scope)

  • 后端 API (Backend API)
  • 前端界面 (Frontend UI)

测试 (Testing)

  • 手动测试 (Manual testing)

测试步骤 (Test Steps)

  1. 文件上传测试

    • 选择一个分类(如"测试1")
    • 点击"上传文档"或拖拽文件上传
    • 验证文件自动归类到"测试1"分类下
  2. 文件夹上传测试

    • 选择一个分类(如"测试2")
    • 点击"上传文件夹",选择包含多个文件的文件夹
    • 验证所有文件自动归类到"测试2"分类下
  3. URL 导入测试

    • 选择一个分类(如"测试1")
    • 点击"导入网页",输入 URL 并确认
    • 验证导入的知识自动归类到"测试1"分类下
  4. 在线编辑测试

    • 选择一个分类(如"测试2")
    • 点击"在线编辑",创建新文档并发布
    • 验证创建的文档自动归类到"测试2"分类下
  5. 未分类测试

    • 选择"未分类"分类
    • 执行上述任意上传操作
    • 验证知识正确归类到"未分类"

检查清单 (Checklist)

  • 代码遵循项目的编码规范
  • 已进行自我代码审查
  • 代码变更已添加适当的注释
  • 相关文档已更新(如需要)
  • 变更不会产生新的警告
  • 新功能和变更已更新到相关文档(代码注释)

相关 Issue

Fixes #

变更文件列表

后端 (Backend)

  • internal/handler/knowledge.go: 添加 tag_id 参数接收(文件上传、URL导入、手工创建)
  • internal/application/service/knowledge.go: 在创建知识时保存 tag_id 到数据库
  • internal/types/knowledge.go: ManualKnowledgePayload 结构体添加 TagID 字段
  • internal/types/interfaces/knowledge.go: 接口定义添加 tagID 参数

前端 (Frontend)

  • frontend/src/stores/ui.ts: 添加 selectedTagId 状态和 setSelectedTagId 方法
  • frontend/src/views/knowledge/KnowledgeBase.vue: 分类切换时同步更新 Store
  • frontend/src/components/menu.vue: 上传文档和文件夹时从 Store 读取并传递 tag_id
  • frontend/src/components/manual-knowledge-editor.vue: 在线编辑创建时从 Store 读取并传递 tag_id
  • frontend/src/hooks/useKnowledgeBase.ts: 拖拽上传时从 Store 读取并传递 tag_id
  • frontend/src/api/knowledge-base/index.ts: API 函数添加 tag_id 参数支持

数据库迁移 (Database Migration)

  • 需要数据库迁移
  • 不需要数据库迁移(tag_id 字段已存在于 knowledge 表中)

配置变更 (Configuration Changes)

无需配置变更

部署说明 (Deployment Notes)

  • 本次变更向后兼容,不影响现有功能
  • 无需特殊部署步骤
  • 建议在部署后验证各上传方式是否正常工作

其他信息 (Additional Information)

设计说明:

  • 使用 Pinia Store (useUIStore) 统一管理选中分类状态,避免状态分散
  • 所有上传入口统一从 Store 读取 selectedTagId,确保行为一致
  • 后端统一处理 tag_id 参数,空字符串或 "__untagged__" 表示未分类

注意事项:

  • 如果用户未选择分类(默认"未分类"),tag_id 不会被传递,后端会保存为空字符串
  • 前端通过 selectedTagId !== '__untagged__' 判断是否需要传递 tag_id

…ploads

- Introduced tag_id parameter in various knowledge-related API functions to allow categorization of knowledge entries.
- Updated frontend components to handle tag_id during knowledge creation and file uploads.
- Enhanced UI store to manage the selected tag ID for better user experience in categorizing knowledge.
- Reformatted the API functions in the knowledge base module for consistent indentation and spacing.
- Enhanced overall code readability without altering functionality.
@begoniezhao begoniezhao merged commit 928d1c3 into Tencent:main Jan 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants