소스 검색

知识库及UI更新

537yaha 6 달 전
부모
커밋
5497c485ea
3개의 변경된 파일21개의 추가작업 그리고 17개의 파일을 삭제
  1. 1 1
      README.md
  2. 10 10
      backend/models/document.go
  3. 10 6
      frontend/hooks/useSoundNotification.ts

+ 1 - 1
README.md

@@ -28,7 +28,7 @@
 
 ### 方式一:预构建镜像一键部署(推荐,最简单)⭐
 
-> **最简单快捷的方式**,直接使用预构建的 Docker 镜像,无需构建,一行命令启动
+> **最简单快捷的方式**,直接使用预构建的 Docker 镜像,无需构建,一行命令启动
 
 #### 前置要求
 

+ 10 - 10
backend/models/document.go

@@ -6,14 +6,14 @@ import (
 
 // Document 文档模型
 type Document struct {
-	ID              uint       `json:"id" gorm:"primarykey"`
-	KnowledgeBaseID uint       `json:"knowledge_base_id" gorm:"index;not null"`
-	Title           string     `json:"title" gorm:"type:varchar(255);not null"`
-	Content         string     `json:"content" gorm:"type:text;not null"`
-	Summary         string     `json:"summary" gorm:"type:text"` // 摘要
-	Type            string     `json:"type" gorm:"type:varchar(50);default:'document'"` // 文档类型:document, url, file
-	Status          string     `json:"status" gorm:"type:varchar(20);default:'draft'"` // 状态:draft(草稿)、published(已发布)
-	EmbeddingStatus string     `json:"embedding_status" gorm:"type:varchar(20);default:'pending'"` // 向量化状态:pending(待处理)、processing(处理中)、completed(已完成)、failed(失败)
-	CreatedAt       time.Time  `json:"created_at"`
-	UpdatedAt       time.Time  `json:"updated_at"`
+	ID              uint      `json:"id" gorm:"primarykey"`
+	KnowledgeBaseID uint      `json:"knowledge_base_id" gorm:"index;not null"`
+	Title           string    `json:"title" gorm:"type:varchar(255);not null"`
+	Content         string    `json:"content" gorm:"type:text;not null"`
+	Summary         string    `json:"summary" gorm:"type:text"`                                   // 摘要
+	Type            string    `json:"type" gorm:"type:varchar(50);default:'document'"`            // 文档类型:document, url, file
+	Status          string    `json:"status" gorm:"type:varchar(20);default:'draft'"`             // 状态:draft(草稿)、published(已发布)
+	EmbeddingStatus string    `json:"embedding_status" gorm:"type:varchar(20);default:'pending'"` // 向量化状态:pending(待处理)、processing(处理中)、completed(已完成)、failed(失败)
+	CreatedAt       time.Time `json:"created_at"`
+	UpdatedAt       time.Time `json:"updated_at"`
 }

+ 10 - 6
frontend/hooks/useSoundNotification.ts

@@ -1,7 +1,7 @@
-import { useEffect, useRef } from "react";
-import { playNotificationSound } from "@/utils/sound";
+import { useCallback, useEffect, useRef, useState } from "react";
 
-export function useSoundNotification(enabled: boolean = true) {
+export function useSoundNotification(initialEnabled: boolean = true) {
+  const [enabled, setEnabled] = useState(initialEnabled);
   const audioRef = useRef<HTMLAudioElement | null>(null);
 
   useEffect(() => {
@@ -20,13 +20,17 @@ export function useSoundNotification(enabled: boolean = true) {
     };
   }, [enabled]);
 
-  const play = () => {
+  const play = useCallback(() => {
     if (enabled && audioRef.current) {
       audioRef.current.play().catch(() => {
         // 忽略播放错误
       });
     }
-  };
+  }, [enabled]);
+
+  const toggle = useCallback(() => {
+    setEnabled((prev) => !prev);
+  }, []);
 
-  return { play };
+  return { enabled, toggle, play };
 }