From 131c4bd2252662449b8ebf3b6edffc70f759f382 Mon Sep 17 00:00:00 2001 From: token <239573049@qq.com> Date: Wed, 4 Sep 2024 22:35:36 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=AE=9A=E4=B9=89=E6=96=87=E6=9C=AC?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=AF=8C=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/package.json | 1 + .../wiki-detail/features/UploadData.tsx | 88 ++++++++++++++----- 2 files changed, 65 insertions(+), 24 deletions(-) diff --git a/web/package.json b/web/package.json index d9e8abac..9c166853 100644 --- a/web/package.json +++ b/web/package.json @@ -44,6 +44,7 @@ "langfuse": "^3.12.2", "langfuse-core": "^3.12.2", "lodash-es": "^4.17.21", + "md-editor-rt": "^4.19.2", "modern-screenshot": "^4.4.39", "monaco-editor": "^0.50.0", "numeral": "^2.0.6", diff --git a/web/src/app/(main)/wiki-detail/features/UploadData.tsx b/web/src/app/(main)/wiki-detail/features/UploadData.tsx index d0557eaa..4746e3d6 100644 --- a/web/src/app/(main)/wiki-detail/features/UploadData.tsx +++ b/web/src/app/(main)/wiki-detail/features/UploadData.tsx @@ -1,20 +1,26 @@ import { useEffect, useState } from "react"; import { Table } from "antd"; import { Radio, Button } from "antd"; +import { ExposeParam, MdEditor } from "md-editor-rt"; import { EditableMessage, Input, TextArea } from "@lobehub/ui"; import { UploadFile } from "@/services/StorageService"; import { CreateWikiDetails } from "@/services/WikiService"; import { ProcessMode, TrainingPattern } from './index.d'; +import { useUserStore } from "@/store/user"; +import 'md-editor-rt/lib/style.css'; +import { userGeneralSettingsSelectors } from "@/store/user/selectors"; interface IUploadWikiDataProps { id: string; onChagePath(key: any): void; } +let isUploading = false; export default function UploadWikiData(props: IUploadWikiDataProps) { const [editing, setEdit] = useState(true) const [content, setContent] = useState(''); - + + const themeMode = useUserStore(userGeneralSettingsSelectors.currentThemeMode); const [processMode, setProcessMode] = useState(ProcessMode.Auto); const [trainingPattern, setTrainingPattern] = useState(TrainingPattern.Subsection); const [maxTokensPerParagraph, setMaxTokensPerParagraph] = useState(1000); // 每个段落标记的最大数量。当对文档进行分区时,每个分区通常包含一个段落。 @@ -57,6 +63,25 @@ export default function UploadWikiData(props: IUploadWikiDataProps) { props.onChagePath('data-item'); } + + function getTheme() { + if (themeMode === 'dark') { + return 'dark' + } else if (themeMode === 'light') { + return 'light' + } + else if (themeMode === 'auto') { + // 得到系统的主题 + if (window.matchMedia('(prefers-color-scheme: dark)').matches) { + return 'dark' + } + return 'light' + } + + return 'light' + } + + return ( <> @@ -64,37 +89,52 @@ export default function UploadWikiData(props: IUploadWikiDataProps) { + +
- { - // - save(); + autoFocus={true} + onUploadImg={(files, callback) => { + if (isUploading) return; + isUploading = true; + for (let i = 0; i < files.length; i++) { + const file = files[i]; + UploadFile(file).then((data) => { + callback([ + { + url: data.path, + alt: file.name, + title: file.name + } + ]); + isUploading = false; + }) + + } }} - value={content} - onChange={setContent} - /> + autoDetectCode={true} + theme={getTheme()} + modelValue={content} + onChange={(v) => { + setContent(v); + }} />