Skip to content

Commit 813e7d2

Browse files
committed
refactor: 使用Editor组件替换WxEditor
1 parent f25a4d7 commit 813e7d2

File tree

5 files changed

+310
-378
lines changed

5 files changed

+310
-378
lines changed

src/components/Editor/src/Editor.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const props = defineProps({
2020
editorId: propTypes.string.def('wangeEditor-1'),
2121
height: propTypes.oneOfType([Number, String]).def('500px'),
2222
editorConfig: {
23-
type: Object as PropType<IEditorConfig>,
23+
type: Object as PropType<Partial<IEditorConfig>>,
2424
default: () => undefined
2525
},
2626
readonly: propTypes.bool.def(false),
@@ -147,6 +147,7 @@ const editorConfig = computed((): IEditorConfig => {
147147
props.editorConfig || {}
148148
)
149149
})
150+
150151
const editorStyle = computed(() => {
151152
return {
152153
height: isNumber(props.height) ? `${props.height}px` : props.height

src/views/mp/components/wx-editor/WxEditor.vue

Lines changed: 0 additions & 104 deletions
This file was deleted.

src/views/mp/components/wx-editor/quill-options.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/views/mp/draft/editor-config.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { IEditorConfig } from '@wangeditor/editor'
2+
import { getAccessToken, getTenantId } from '@/utils/auth'
3+
4+
const message = useMessage()
5+
6+
type InsertFnType = (url: string, alt: string, href: string) => void
7+
8+
export const createEditorConfig = (
9+
server: string,
10+
accountId: number | undefined
11+
): Partial<IEditorConfig> => {
12+
return {
13+
MENU_CONF: {
14+
['uploadImage']: {
15+
server,
16+
// 单个文件的最大体积限制,默认为 2M
17+
maxFileSize: 5 * 1024 * 1024,
18+
// 最多可上传几个文件,默认为 100
19+
maxNumberOfFiles: 10,
20+
// 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 []
21+
allowedFileTypes: ['image/*'],
22+
23+
// 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。
24+
meta: { accountId: accountId },
25+
// 将 meta 拼接到 url 参数中,默认 false
26+
metaWithUrl: true,
27+
28+
// 自定义增加 http header
29+
headers: {
30+
Accept: '*',
31+
Authorization: 'Bearer ' + getAccessToken(),
32+
'tenant-id': getTenantId()
33+
},
34+
35+
// 跨域是否传递 cookie ,默认为 false
36+
withCredentials: true,
37+
38+
// 超时时间,默认为 10 秒
39+
timeout: 5 * 1000, // 5 秒
40+
41+
// form-data fieldName,后端接口参数名称,默认值wangeditor-uploaded-image
42+
fieldName: 'file',
43+
44+
// 上传之前触发
45+
onBeforeUpload(file: File) {
46+
console.log(file)
47+
return file
48+
},
49+
// 上传进度的回调函数
50+
onProgress(progress: number) {
51+
// progress 是 0-100 的数字
52+
console.log('progress', progress)
53+
},
54+
onSuccess(file: File, res: any) {
55+
console.log('onSuccess', file, res)
56+
},
57+
onFailed(file: File, res: any) {
58+
message.alertError(res.message)
59+
console.log('onFailed', file, res)
60+
},
61+
onError(file: File, err: any, res: any) {
62+
message.alertError(err.message)
63+
console.error('onError', file, err, res)
64+
},
65+
// 自定义插入图片
66+
customInsert(res: any, insertFn: InsertFnType) {
67+
insertFn(res.data, 'image', res.data)
68+
}
69+
}
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)