mirror of
https://github.com/imdap/ruoyi-plus-vben5.git
synced 2026-05-13 06:42:10 +08:00
feat(@vben/plugins): tiptap 支持图片上传功能
- 新增 imageUpload 配置项,支持自定义上传接口 - 支持文件选择、拖拽、粘贴三种上传方式 - 上传中显示 blob 预览图 + loading spinner / 进度条 - 支持 accept 和 maxSize 文件校验 - 支持 onUploadError 自定义错误处理 - 未配置 imageUpload 时保持原有 URL 插入行为不变 - 使用 NodeView 实现实时 DOM 控制的进度展示
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { Editor } from '@tiptap/vue-3';
|
||||
|
||||
import type { ToolbarAction, ToolbarMenuItem } from './types';
|
||||
import type { ImageUploadOptions, ToolbarAction, ToolbarMenuItem } from './types';
|
||||
|
||||
import {
|
||||
AlignCenter,
|
||||
@@ -155,7 +155,9 @@ async function handleImageAction(editor: Editor) {
|
||||
editor.chain().focus().setImage({ src: nextUrl }).run();
|
||||
}
|
||||
|
||||
export function createToolbarGroups(): ToolbarAction[][] {
|
||||
export function createToolbarGroups(
|
||||
imageUpload?: ImageUploadOptions,
|
||||
): ToolbarAction[][] {
|
||||
const headingMenuItems = createHeadingMenuItems();
|
||||
|
||||
return [
|
||||
@@ -278,6 +280,25 @@ export function createToolbarGroups(): ToolbarAction[][] {
|
||||
action: (editor) => handleImageAction(editor),
|
||||
icon: ImagePlus,
|
||||
label: $t('ui.tiptap.toolbar.image'),
|
||||
...(imageUpload
|
||||
? {
|
||||
action: () => {},
|
||||
menu: {
|
||||
items: [
|
||||
{
|
||||
action: (editor) => (editor.commands as any).uploadImage(),
|
||||
label: $t('ui.tiptap.toolbar.imageUpload'),
|
||||
shortLabel: 'UPL',
|
||||
},
|
||||
{
|
||||
action: (editor) => handleImageAction(editor),
|
||||
label: $t('ui.tiptap.toolbar.imageUrl'),
|
||||
shortLabel: 'URL',
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
],
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user