重构图片上传
This commit is contained in:
@@ -44,7 +44,7 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// 处理文件上传需要的格式
|
// 处理成后端需要的格式
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append("dir", dir);
|
formData.append("dir", dir);
|
||||||
for (let i = 0; i < compressedFiles.length; i++) {
|
for (let i = 0; i < compressedFiles.length; i++) {
|
||||||
@@ -112,6 +112,7 @@ export default ({ dir, open, onCancel, onSuccess }: UploadFileProps) => {
|
|||||||
{ value: 0.2, label: '0.2' },
|
{ value: 0.2, label: '0.2' },
|
||||||
{ value: 0.1, label: '0.1' },
|
{ value: 0.1, label: '0.1' },
|
||||||
]}
|
]}
|
||||||
|
defaultValue={1}
|
||||||
placeholder="请选择图片压缩质量"
|
placeholder="请选择图片压缩质量"
|
||||||
className='min-w-44'
|
className='min-w-44'
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -71,13 +71,12 @@
|
|||||||
@apply leading-9 mb-2;
|
@apply leading-9 mb-2;
|
||||||
|
|
||||||
img {
|
img {
|
||||||
// 图片模糊
|
|
||||||
@apply rounded-xl cursor-pointer transition-all;
|
@apply rounded-xl cursor-pointer transition-all;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
strong {
|
strong {
|
||||||
@apply text-[15px];
|
@apply text-base;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr,
|
tr,
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
@import url(./editor.scss);
|
@import url(./editor.scss);
|
||||||
|
|
||||||
.bytemd {
|
.bytemd {
|
||||||
height: 80vh;
|
// height: 80vh;
|
||||||
|
height: calc(100vh - 200px);
|
||||||
border: none;
|
border: none;
|
||||||
|
|
||||||
.bytemd-toolbar {
|
.bytemd-toolbar {
|
||||||
|
|||||||
@@ -1,42 +1,63 @@
|
|||||||
import { Editor } from '@bytemd/react'
|
import { baseURL } from '@/utils/request';
|
||||||
import 'bytemd/dist/index.css'
|
import { useUserStore } from '@/stores';
|
||||||
import highlight from '@bytemd/plugin-highlight'
|
|
||||||
|
import { Editor } from '@bytemd/react';
|
||||||
|
import 'bytemd/dist/index.css';
|
||||||
|
import highlight from '@bytemd/plugin-highlight';
|
||||||
import 'highlight.js/styles/vs2015.css';
|
import 'highlight.js/styles/vs2015.css';
|
||||||
import "./index.scss"
|
|
||||||
|
|
||||||
const plugins = [
|
import './index.scss';
|
||||||
highlight()
|
import axios from 'axios';
|
||||||
]
|
import { Spin } from 'antd';
|
||||||
|
import { useState } from 'react';
|
||||||
// import FileUpload from "@/components/FileUpload";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
value: string,
|
value: string;
|
||||||
setValue: (value: string) => void
|
setValue: (value: string) => void;
|
||||||
|
onChange: (value: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const EditorMD = ({ value, setValue }: Props) => {
|
const EditorMD = ({ value, setValue, onChange }: Props) => {
|
||||||
|
const store = useUserStore();
|
||||||
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
|
const plugins = [
|
||||||
|
highlight()
|
||||||
|
];
|
||||||
|
|
||||||
|
const uploadImages = async (files: File[]) => {
|
||||||
|
setLoading(true);
|
||||||
|
|
||||||
|
// 处理成后端需要的格式
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("dir", "article");
|
||||||
|
for (let i = 0; i < files.length; i++) formData.append('files', files[i])
|
||||||
|
|
||||||
|
const { data: { code, data } } = await axios.post(`${baseURL}/file`, formData, {
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bearer ${store.token}`,
|
||||||
|
"Content-Type": "multipart/form-data"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
setLoading(false);
|
||||||
|
|
||||||
|
// 返回图片信息数组
|
||||||
|
return data.map((url: string) => ({ url }));
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Editor
|
<Spin spinning={loading} tip="图片上传中...">
|
||||||
value={value}
|
<Editor
|
||||||
plugins={plugins}
|
value={value}
|
||||||
onChange={setValue}
|
plugins={plugins}
|
||||||
/>
|
onChange={onChange}
|
||||||
|
uploadImages={uploadImages}
|
||||||
{/* 文件上传 */}
|
/>
|
||||||
{/* <FileUpload
|
</Spin>
|
||||||
dir="article"
|
|
||||||
open={openUploadModalOpen}
|
|
||||||
onSuccess={(urls: string[]) => {
|
|
||||||
urls.forEach((path: string) => {
|
|
||||||
vd?.insertValue(``);
|
|
||||||
});
|
|
||||||
}}
|
|
||||||
onCancel={() => setOpenUploadModalOpen(false)}
|
|
||||||
/> */}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default EditorMD;
|
export default EditorMD;
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ const CreatePage = () => {
|
|||||||
}, [content])
|
}, [content])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 解析接口数据
|
// 解析接口数据
|
||||||
const parsingData = async (command: string) => {
|
const parsingData = async (command: string) => {
|
||||||
const res = await fetch(`/ai/v1/chat/completions`, {
|
const res = await fetch(`/ai/v1/chat/completions`, {
|
||||||
@@ -166,7 +165,7 @@ const CreatePage = () => {
|
|||||||
</Title>
|
</Title>
|
||||||
|
|
||||||
<Card className='[&>.ant-card-body]:!p-0 overflow-hidden rounded-xl'>
|
<Card className='[&>.ant-card-body]:!p-0 overflow-hidden rounded-xl'>
|
||||||
<Editor value={content} setValue={(value) => setContent(value)} />
|
<Editor value={content} setValue={(value) => setContent(value)} onChange={(value) => setContent(value)} />
|
||||||
|
|
||||||
<Drawer
|
<Drawer
|
||||||
title={id ? "编辑文章" : "发布文章"}
|
title={id ? "编辑文章" : "发布文章"}
|
||||||
|
|||||||
Reference in New Issue
Block a user