perf: editor image upload

This commit is contained in:
xingyu4j 2022-08-06 23:17:02 +08:00
parent 48427994d4
commit ca3674b006
2 changed files with 43 additions and 12 deletions

View File

@ -26,10 +26,10 @@
}, },
"dependencies": { "dependencies": {
"@iconify/iconify": "^2.2.1", "@iconify/iconify": "^2.2.1",
"@vueuse/core": "^9.0.2", "@vueuse/core": "^9.1.0",
"@wangeditor/editor": "^5.1.14", "@wangeditor/editor": "^5.1.14",
"@wangeditor/editor-for-vue": "^5.1.10", "@wangeditor/editor-for-vue": "^5.1.10",
"@zxcvbn-ts/core": "^2.0.3", "@zxcvbn-ts/core": "^2.0.4",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
"axios": "^0.27.2", "axios": "^0.27.2",
"dayjs": "^1.11.4", "dayjs": "^1.11.4",
@ -49,7 +49,7 @@
"url": "^0.11.0", "url": "^0.11.0",
"vue": "3.2.37", "vue": "3.2.37",
"vue-cropper": "^1.0.3", "vue-cropper": "^1.0.3",
"vue-i18n": "9.2.0", "vue-i18n": "9.2.2",
"vue-router": "^4.1.3", "vue-router": "^4.1.3",
"vue-types": "^4.2.1", "vue-types": "^4.2.1",
"web-storage-cache": "^1.1.1" "web-storage-cache": "^1.1.1"
@ -62,7 +62,7 @@
"@purge-icons/generated": "^0.8.1", "@purge-icons/generated": "^0.8.1",
"@types/intro.js": "^5.1.0", "@types/intro.js": "^5.1.0",
"@types/lodash-es": "^4.17.6", "@types/lodash-es": "^4.17.6",
"@types/node": "^18.6.3", "@types/node": "^18.6.4",
"@types/nprogress": "^0.2.0", "@types/nprogress": "^0.2.0",
"@types/qrcode": "^1.4.2", "@types/qrcode": "^1.4.2",
"@types/qs": "^6.9.7", "@types/qs": "^6.9.7",
@ -92,7 +92,7 @@
"stylelint-config-standard": "^26.0.0", "stylelint-config-standard": "^26.0.0",
"stylelint-order": "^5.0.0", "stylelint-order": "^5.0.0",
"typescript": "4.7.4", "typescript": "4.7.4",
"unplugin-vue-define-options": "^0.7.1", "unplugin-vue-define-options": "^0.7.3",
"vite": "3.0.4", "vite": "3.0.4",
"vite-plugin-compression": "^0.5.1", "vite-plugin-compression": "^0.5.1",
"vite-plugin-eslint": "^1.7.0", "vite-plugin-eslint": "^1.7.0",
@ -101,7 +101,7 @@
"vite-plugin-style-import": "^2.0.0", "vite-plugin-style-import": "^2.0.0",
"vite-plugin-svg-icons": "^2.0.1", "vite-plugin-svg-icons": "^2.0.1",
"vite-plugin-windicss": "^1.8.7", "vite-plugin-windicss": "^1.8.7",
"vue-tsc": "^0.39.4", "vue-tsc": "^0.39.5",
"windicss": "^3.5.6" "windicss": "^3.5.6"
}, },
"engines": { "engines": {

View File

@ -8,6 +8,8 @@ import { ElMessage } from 'element-plus'
import { useLocaleStore } from '@/store/modules/locale' import { useLocaleStore } from '@/store/modules/locale'
import { getAccessToken, getTenantId } from '@/utils/auth' import { getAccessToken, getTenantId } from '@/utils/auth'
type InsertFnType = (url: string, alt: string, href: string) => void
const localeStore = useLocaleStore() const localeStore = useLocaleStore()
const currentLocale = computed(() => localeStore.getCurrentLocale) const currentLocale = computed(() => localeStore.getCurrentLocale)
@ -85,29 +87,58 @@ const editorConfig = computed((): IEditorConfig => {
['uploadImage']: { ['uploadImage']: {
server: import.meta.env.VITE_UPLOAD_URL, server: import.meta.env.VITE_UPLOAD_URL,
// 2M // 2M
maxFileSize: 2 * 1024 * 1024, maxFileSize: 5 * 1024 * 1024,
// 100 // 100
maxNumberOfFiles: 10, maxNumberOfFiles: 10,
// ['image/*'] [] // ['image/*'] []
allowedFileTypes: ['image/*'], allowedFileTypes: ['image/*'],
// token formData // token formData
meta: {}, meta: { updateSupport: 0 },
// meta url false // meta url false
metaWithUrl: false, metaWithUrl: true,
// http header // http header
headers: { headers: {
Accept: 'image/*', Accept: '*',
Authorization: 'Bearer ' + getAccessToken(), Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId() 'tenant-id': getTenantId()
}, },
// cookie false // cookie false
withCredentials: false, withCredentials: true,
// 10 // 10
timeout: 5 * 1000 // 5 timeout: 5 * 1000, // 5
// form-data fieldNamewangeditor-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) {
alert(res.message)
console.log('onFailed', file, res)
},
onError(file: File, err: any, res: any) {
alert(err.message)
console.error('onError', file, err, res)
},
//
customInsert(res: any, insertFn: InsertFnType) {
insertFn(res.data, 'image', res.data)
}
} }
}, },
uploadImgShowBase64: true uploadImgShowBase64: true