From a1d7e81859f554f3a53680cc35f0f49bf1f77098 Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期四, 14 五月 2026 14:37:02 +0800
Subject: [PATCH] 导入项目
---
src/views/mp/draft/editor-config.ts | 75 +++++++++++++++++++++++++++++++++++++
1 files changed, 75 insertions(+), 0 deletions(-)
diff --git a/src/views/mp/draft/editor-config.ts b/src/views/mp/draft/editor-config.ts
new file mode 100644
index 0000000..a8bd4e7
--- /dev/null
+++ b/src/views/mp/draft/editor-config.ts
@@ -0,0 +1,75 @@
+import { IEditorConfig } from '@wangeditor-next/editor'
+import { getAccessToken, getTenantId } from '@/utils/auth'
+
+const message = useMessage()
+
+type InsertFnType = (url: string, alt: string, href: string) => void
+
+export const createEditorConfig = (
+ server: string,
+ accountId: number | undefined
+): Partial<IEditorConfig> => {
+ return {
+ MENU_CONF: {
+ ['uploadImage']: {
+ server,
+ // 鍗曚釜鏂囦欢鐨勬渶澶т綋绉檺鍒讹紝榛樿涓� 2M
+ maxFileSize: 5 * 1024 * 1024,
+ // 鏈�澶氬彲涓婁紶鍑犱釜鏂囦欢锛岄粯璁や负 100
+ maxNumberOfFiles: 10,
+ // 閫夋嫨鏂囦欢鏃剁殑绫诲瀷闄愬埗锛岄粯璁や负 ['image/*'] 銆傚涓嶆兂闄愬埗锛屽垯璁剧疆涓� []
+ allowedFileTypes: ['image/*'],
+
+ // 鑷畾涔変笂浼犲弬鏁帮紝渚嬪浼犻�掗獙璇佺殑 token 绛夈�傚弬鏁颁細琚坊鍔犲埌 formData 涓紝涓�璧蜂笂浼犲埌鏈嶅姟绔��
+ meta: {
+ accountId: accountId,
+ type: 'image'
+ },
+ // 灏� meta 鎷兼帴鍒� url 鍙傛暟涓紝榛樿 false
+ metaWithUrl: true,
+
+ // 鑷畾涔夊鍔� http header
+ headers: {
+ Accept: '*',
+ Authorization: 'Bearer ' + getAccessToken(),
+ 'tenant-id': getTenantId()
+ },
+
+ // 璺ㄥ煙鏄惁浼犻�� cookie 锛岄粯璁や负 false
+ withCredentials: true,
+
+ // 瓒呮椂鏃堕棿锛岄粯璁や负 10 绉�
+ timeout: 5 * 1000, // 5 绉�
+
+ // form-data fieldName锛屽悗绔帴鍙e弬鏁板悕绉帮紝榛樿鍊紈angeditor-uploaded-image
+ fieldName: 'file',
+
+ // 涓婁紶涔嬪墠瑙﹀彂
+ onBeforeUpload(file: File) {
+ console.log(file)
+ return file
+ },
+ // 涓婁紶杩涘害鐨勫洖璋冨嚱鏁�
+ onProgress(progress: number) {
+ // progress 鏄� 0-100 鐨勬暟瀛�
+ console.log('progress', progress)
+ },
+ onSuccess(file: File, res: any) {
+ console.log('onSuccess', file, res)
+ },
+ onFailed(file: File, res: any) {
+ message.alertError(res.message)
+ console.log('onFailed', file, res)
+ },
+ onError(file: File, err: any, res: any) {
+ message.alertError(err.message)
+ console.error('onError', file, err, res)
+ },
+ // 鑷畾涔夋彃鍏ュ浘鐗�
+ customInsert(res: any, insertFn: InsertFnType) {
+ insertFn(res.data.url, 'image', res.data.url)
+ }
+ }
+ }
+ }
+}
--
Gitblit v1.8.0