Skip to content

Commit 131c4bd

Browse files
committedSep 4, 2024
自定义文本支持富文本编辑
1 parent 997216f commit 131c4bd

File tree

2 files changed

+65
-24
lines changed

2 files changed

+65
-24
lines changed
 

‎web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"langfuse": "^3.12.2",
4545
"langfuse-core": "^3.12.2",
4646
"lodash-es": "^4.17.21",
47+
"md-editor-rt": "^4.19.2",
4748
"modern-screenshot": "^4.4.39",
4849
"monaco-editor": "^0.50.0",
4950
"numeral": "^2.0.6",

‎web/src/app/(main)/wiki-detail/features/UploadData.tsx

+64-24
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
import { useEffect, useState } from "react";
22
import { Table } from "antd";
33
import { Radio, Button } from "antd";
4+
import { ExposeParam, MdEditor } from "md-editor-rt";
45
import { EditableMessage, Input, TextArea } from "@lobehub/ui";
56
import { UploadFile } from "@/services/StorageService";
67
import { CreateWikiDetails } from "@/services/WikiService";
78
import { ProcessMode, TrainingPattern } from './index.d';
9+
import { useUserStore } from "@/store/user";
10+
import 'md-editor-rt/lib/style.css';
11+
import { userGeneralSettingsSelectors } from "@/store/user/selectors";
812

913
interface IUploadWikiDataProps {
1014
id: string;
1115
onChagePath(key: any): void;
1216
}
1317

18+
let isUploading = false;
1419
export default function UploadWikiData(props: IUploadWikiDataProps) {
1520
const [editing, setEdit] = useState(true)
1621
const [content, setContent] = useState('');
17-
22+
23+
const themeMode = useUserStore(userGeneralSettingsSelectors.currentThemeMode);
1824
const [processMode, setProcessMode] = useState(ProcessMode.Auto);
1925
const [trainingPattern, setTrainingPattern] = useState(TrainingPattern.Subsection);
2026
const [maxTokensPerParagraph, setMaxTokensPerParagraph] = useState(1000); // 每个段落标记的最大数量。当对文档进行分区时,每个分区通常包含一个段落。
@@ -57,44 +63,78 @@ export default function UploadWikiData(props: IUploadWikiDataProps) {
5763
props.onChagePath('data-item');
5864
}
5965

66+
67+
function getTheme() {
68+
if (themeMode === 'dark') {
69+
return 'dark'
70+
} else if (themeMode === 'light') {
71+
return 'light'
72+
}
73+
else if (themeMode === 'auto') {
74+
// 得到系统的主题
75+
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
76+
return 'dark'
77+
}
78+
return 'light'
79+
}
80+
81+
return 'light'
82+
}
83+
84+
6085
return (
6186
<>
6287

6388
<div >
6489
<Button onClick={() => {
6590
props.onChagePath('data-item')
6691
}}>返回</Button>
92+
<Button
93+
type="primary"
94+
onClick={save} style={{
95+
marginLeft: 10
96+
}}>保存</Button>
97+
6798
</div>
6899

69100
<div style={{
70101
display: 'flex',
71102
padding: '20px',
72103
}}>
73-
<EditableMessage
74-
styles={{
75-
input: {
76-
width: '100%',
77-
height: '100%'
78-
},
79-
markdown: {
80-
width: '100%',
81-
height: '100%'
82-
}
83-
}}
84-
editing={editing}
85-
text={{
86-
cancel: "取消",
87-
confirm: "保存",
88-
edit: "编辑",
104+
105+
<MdEditor
106+
showCodeRowNumber={true}
107+
style={{
108+
height: '100%',
109+
borderRadius: 8,
110+
overflow: 'auto',
111+
maxHeight: '500px',
89112
}}
90-
placeholder="请输入您的内容"
91-
onEditingChange={() => {
92-
//
93-
save();
113+
autoFocus={true}
114+
onUploadImg={(files, callback) => {
115+
if (isUploading) return;
116+
isUploading = true;
117+
for (let i = 0; i < files.length; i++) {
118+
const file = files[i];
119+
UploadFile(file).then((data) => {
120+
callback([
121+
{
122+
url: data.path,
123+
alt: file.name,
124+
title: file.name
125+
}
126+
]);
127+
isUploading = false;
128+
})
129+
130+
}
94131
}}
95-
value={content}
96-
onChange={setContent}
97-
/>
132+
autoDetectCode={true}
133+
theme={getTheme()}
134+
modelValue={content}
135+
onChange={(v) => {
136+
setContent(v);
137+
}} />
98138
</div>
99139

100140
<div style={{

0 commit comments

Comments
 (0)
Please sign in to comment.