Commit ca3674b006528e69b7a44105b20d41bc38d157a7

Authored by xingyu4j
1 parent 48427994

perf: editor image upload

yudao-ui-admin-vue3/package.json
@@ -26,10 +26,10 @@ @@ -26,10 +26,10 @@
26 }, 26 },
27 "dependencies": { 27 "dependencies": {
28 "@iconify/iconify": "^2.2.1", 28 "@iconify/iconify": "^2.2.1",
29 - "@vueuse/core": "^9.0.2", 29 + "@vueuse/core": "^9.1.0",
30 "@wangeditor/editor": "^5.1.14", 30 "@wangeditor/editor": "^5.1.14",
31 "@wangeditor/editor-for-vue": "^5.1.10", 31 "@wangeditor/editor-for-vue": "^5.1.10",
32 - "@zxcvbn-ts/core": "^2.0.3", 32 + "@zxcvbn-ts/core": "^2.0.4",
33 "animate.css": "^4.1.1", 33 "animate.css": "^4.1.1",
34 "axios": "^0.27.2", 34 "axios": "^0.27.2",
35 "dayjs": "^1.11.4", 35 "dayjs": "^1.11.4",
@@ -49,7 +49,7 @@ @@ -49,7 +49,7 @@
49 "url": "^0.11.0", 49 "url": "^0.11.0",
50 "vue": "3.2.37", 50 "vue": "3.2.37",
51 "vue-cropper": "^1.0.3", 51 "vue-cropper": "^1.0.3",
52 - "vue-i18n": "9.2.0", 52 + "vue-i18n": "9.2.2",
53 "vue-router": "^4.1.3", 53 "vue-router": "^4.1.3",
54 "vue-types": "^4.2.1", 54 "vue-types": "^4.2.1",
55 "web-storage-cache": "^1.1.1" 55 "web-storage-cache": "^1.1.1"
@@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
62 "@purge-icons/generated": "^0.8.1", 62 "@purge-icons/generated": "^0.8.1",
63 "@types/intro.js": "^5.1.0", 63 "@types/intro.js": "^5.1.0",
64 "@types/lodash-es": "^4.17.6", 64 "@types/lodash-es": "^4.17.6",
65 - "@types/node": "^18.6.3", 65 + "@types/node": "^18.6.4",
66 "@types/nprogress": "^0.2.0", 66 "@types/nprogress": "^0.2.0",
67 "@types/qrcode": "^1.4.2", 67 "@types/qrcode": "^1.4.2",
68 "@types/qs": "^6.9.7", 68 "@types/qs": "^6.9.7",
@@ -92,7 +92,7 @@ @@ -92,7 +92,7 @@
92 "stylelint-config-standard": "^26.0.0", 92 "stylelint-config-standard": "^26.0.0",
93 "stylelint-order": "^5.0.0", 93 "stylelint-order": "^5.0.0",
94 "typescript": "4.7.4", 94 "typescript": "4.7.4",
95 - "unplugin-vue-define-options": "^0.7.1", 95 + "unplugin-vue-define-options": "^0.7.3",
96 "vite": "3.0.4", 96 "vite": "3.0.4",
97 "vite-plugin-compression": "^0.5.1", 97 "vite-plugin-compression": "^0.5.1",
98 "vite-plugin-eslint": "^1.7.0", 98 "vite-plugin-eslint": "^1.7.0",
@@ -101,7 +101,7 @@ @@ -101,7 +101,7 @@
101 "vite-plugin-style-import": "^2.0.0", 101 "vite-plugin-style-import": "^2.0.0",
102 "vite-plugin-svg-icons": "^2.0.1", 102 "vite-plugin-svg-icons": "^2.0.1",
103 "vite-plugin-windicss": "^1.8.7", 103 "vite-plugin-windicss": "^1.8.7",
104 - "vue-tsc": "^0.39.4", 104 + "vue-tsc": "^0.39.5",
105 "windicss": "^3.5.6" 105 "windicss": "^3.5.6"
106 }, 106 },
107 "engines": { 107 "engines": {
yudao-ui-admin-vue3/src/components/Editor/src/Editor.vue
@@ -8,6 +8,8 @@ import { ElMessage } from 'element-plus' @@ -8,6 +8,8 @@ import { ElMessage } from 'element-plus'
8 import { useLocaleStore } from '@/store/modules/locale' 8 import { useLocaleStore } from '@/store/modules/locale'
9 import { getAccessToken, getTenantId } from '@/utils/auth' 9 import { getAccessToken, getTenantId } from '@/utils/auth'
10 10
  11 +type InsertFnType = (url: string, alt: string, href: string) => void
  12 +
11 const localeStore = useLocaleStore() 13 const localeStore = useLocaleStore()
12 14
13 const currentLocale = computed(() => localeStore.getCurrentLocale) 15 const currentLocale = computed(() => localeStore.getCurrentLocale)
@@ -85,29 +87,58 @@ const editorConfig = computed((): IEditorConfig => { @@ -85,29 +87,58 @@ const editorConfig = computed((): IEditorConfig => {
85 ['uploadImage']: { 87 ['uploadImage']: {
86 server: import.meta.env.VITE_UPLOAD_URL, 88 server: import.meta.env.VITE_UPLOAD_URL,
87 // 单个文件的最大体积限制,默认为 2M 89 // 单个文件的最大体积限制,默认为 2M
88 - maxFileSize: 2 * 1024 * 1024, 90 + maxFileSize: 5 * 1024 * 1024,
89 // 最多可上传几个文件,默认为 100 91 // 最多可上传几个文件,默认为 100
90 maxNumberOfFiles: 10, 92 maxNumberOfFiles: 10,
91 // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 [] 93 // 选择文件时的类型限制,默认为 ['image/*'] 。如不想限制,则设置为 []
92 allowedFileTypes: ['image/*'], 94 allowedFileTypes: ['image/*'],
93 95
94 // 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。 96 // 自定义上传参数,例如传递验证的 token 等。参数会被添加到 formData 中,一起上传到服务端。
95 - meta: {}, 97 + meta: { updateSupport: 0 },
96 // 将 meta 拼接到 url 参数中,默认 false 98 // 将 meta 拼接到 url 参数中,默认 false
97 - metaWithUrl: false, 99 + metaWithUrl: true,
98 100
99 // 自定义增加 http header 101 // 自定义增加 http header
100 headers: { 102 headers: {
101 - Accept: 'image/*', 103 + Accept: '*',
102 Authorization: 'Bearer ' + getAccessToken(), 104 Authorization: 'Bearer ' + getAccessToken(),
103 'tenant-id': getTenantId() 105 'tenant-id': getTenantId()
104 }, 106 },
105 107
106 // 跨域是否传递 cookie ,默认为 false 108 // 跨域是否传递 cookie ,默认为 false
107 - withCredentials: false, 109 + withCredentials: true,
108 110
109 // 超时时间,默认为 10 秒 111 // 超时时间,默认为 10 秒
110 - timeout: 5 * 1000 // 5 秒 112 + timeout: 5 * 1000, // 5 秒
  113 +
  114 + // form-data fieldName,后端接口参数名称,默认值wangeditor-uploaded-image
  115 + fieldName: 'file',
  116 +
  117 + // 上传之前触发
  118 + onBeforeUpload(file: File) {
  119 + console.log(file)
  120 + return file
  121 + },
  122 + // 上传进度的回调函数
  123 + onProgress(progress: number) {
  124 + // progress 是 0-100 的数字
  125 + console.log('progress', progress)
  126 + },
  127 + onSuccess(file: File, res: any) {
  128 + console.log('onSuccess', file, res)
  129 + },
  130 + onFailed(file: File, res: any) {
  131 + alert(res.message)
  132 + console.log('onFailed', file, res)
  133 + },
  134 + onError(file: File, err: any, res: any) {
  135 + alert(err.message)
  136 + console.error('onError', file, err, res)
  137 + },
  138 + // 自定义插入图片
  139 + customInsert(res: any, insertFn: InsertFnType) {
  140 + insertFn(res.data, 'image', res.data)
  141 + }
111 } 142 }
112 }, 143 },
113 uploadImgShowBase64: true 144 uploadImgShowBase64: true