编辑器添加上传图片功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const BASE_URL = process.env.BASE_URL;
|
||||
import request from '@/utils/request';
|
||||
|
||||
// 默认加载插件
|
||||
const PLUGINS = [
|
||||
@@ -89,11 +90,31 @@ export const DEFAULT_CONFIG = {
|
||||
toolbar_mode: 'sliding',
|
||||
quickbars_insert_toolbar: '',
|
||||
images_upload_handler: (blobInfo, success, error) => {
|
||||
if (blobInfo.blob().size / 1024 > 400) {
|
||||
error('大小不能超过 400KB');
|
||||
if (blobInfo.blob().size / 1024 > 10000) {
|
||||
error('大小不能超过 10M');
|
||||
return;
|
||||
}
|
||||
success('data:image/jpeg;base64,' + blobInfo.base64());
|
||||
const formData = new FormData();
|
||||
formData.append('file', blobInfo.blob());
|
||||
request({
|
||||
url: '/upload',
|
||||
method: 'post',
|
||||
data: formData
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.data.code === 0) {
|
||||
success(res.data.data.full_url);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
error('上传失败!');
|
||||
});
|
||||
|
||||
// if (blobInfo.blob().size / 1024 > 400) {
|
||||
// error('大小不能超过 400KB');
|
||||
// return;
|
||||
// }
|
||||
// success('data:image/jpeg;base64,' + blobInfo.base64());
|
||||
},
|
||||
file_picker_types: 'media',
|
||||
file_picker_callback: () => {}
|
||||
|
||||
@@ -110,7 +110,7 @@
|
||||
height: 300,
|
||||
toolbar: [
|
||||
'code | forecolor backcolor bold italic underline strikethrough link anchor | alignleft aligncenter alignright alignjustify outdent indent | fontsizeselect | bullist numlist | \
|
||||
table emoticons hr preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs'
|
||||
table emoticons hr preview | fullscreen | bdmap indent2em lineheight formatpainter axupimgs| image emoticons hr '
|
||||
]
|
||||
},
|
||||
defaultForm,
|
||||
|
||||
Reference in New Issue
Block a user