fix: upload

pull/2/head
xingyu 2022-07-20 13:05:09 +08:00
parent 88928901a7
commit 3c34888959
4 changed files with 38 additions and 10 deletions

View File

@ -6,6 +6,7 @@ import { propTypes } from '@/utils/propTypes'
import { isNumber } from '@/utils/is' import { isNumber } from '@/utils/is'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useLocaleStore } from '@/store/modules/locale' import { useLocaleStore } from '@/store/modules/locale'
import { getAccessToken, getTenantId } from '@/utils/auth'
const localeStore = useLocaleStore() const localeStore = useLocaleStore()
@ -80,12 +81,40 @@ const editorConfig = computed((): IEditorConfig => {
}, },
autoFocus: false, autoFocus: false,
scroll: true, scroll: true,
MENU_CONF: {
['uploadImage']: {
server: import.meta.env.VITE_UPLOAD_URL,
// 2M
maxFileSize: 2 * 1024 * 1024,
// 100
maxNumberOfFiles: 10,
// ['image/*'] []
allowedFileTypes: ['image/*'],
// token formData
meta: {},
// meta url false
metaWithUrl: false,
// http header
headers: {
Accept: 'image/*',
Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': getTenantId()
},
// cookie false
withCredentials: false,
// 10
timeout: 5 * 1000 // 5
}
},
uploadImgShowBase64: true uploadImgShowBase64: true
}, },
props.editorConfig || {} props.editorConfig || {}
) )
}) })
const editorStyle = computed(() => { const editorStyle = computed(() => {
return { return {
height: isNumber(props.height) ? `${props.height}px` : props.height height: isNumber(props.height) ? `${props.height}px` : props.height

View File

@ -7,8 +7,8 @@ import { useI18n } from '@/hooks/web/useI18n'
import type { FileVO } from '@/api/infra/file/types' import type { FileVO } from '@/api/infra/file/types'
import { allSchemas } from './fileList.data' import { allSchemas } from './fileList.data'
import * as FileApi from '@/api/infra/file' import * as FileApi from '@/api/infra/file'
import { useCache } from '@/hooks/web/useCache' import { getAccessToken, getTenantId } from '@/utils/auth'
const { wsCache } = useCache()
const { t } = useI18n() // const { t } = useI18n() //
// ========== ========== // ========== ==========
@ -29,7 +29,7 @@ const uploadHeaders = ref()
const beforeUpload = (file: UploadRawFile) => { const beforeUpload = (file: UploadRawFile) => {
const isImg = file.type === 'image/jpeg' || 'image/gif' || 'image/png' const isImg = file.type === 'image/jpeg' || 'image/gif' || 'image/png'
const isLt5M = file.size / 1024 / 1024 < 5 const isLt5M = file.size / 1024 / 1024 < 5
if (!isImg) ElMessage.error('上传文件只能是 xls / xlsx 格式!') if (!isImg) ElMessage.error('上传文件只能是 jpeg / gif / png 格式!')
if (!isLt5M) ElMessage.error('上传文件大小不能超过 5MB!') if (!isLt5M) ElMessage.error('上传文件大小不能超过 5MB!')
return isImg && isLt5M return isImg && isLt5M
} }
@ -40,8 +40,8 @@ const beforeUpload = (file: UploadRawFile) => {
// //
const submitFileForm = () => { const submitFileForm = () => {
uploadHeaders.value = { uploadHeaders.value = {
Authorization: 'Bearer ' + wsCache.get('ACCESS_TOKEN'), Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': wsCache.get('tenantId') 'tenant-id': getTenantId()
} }
uploadDisabled.value = true uploadDisabled.value = true
uploadRef.value!.submit() uploadRef.value!.submit()

View File

@ -30,9 +30,8 @@ import { listSimplePostsApi } from '@/api/system/post'
import { rules, allSchemas } from './user.data' import { rules, allSchemas } from './user.data'
import * as UserApi from '@/api/system/user' import * as UserApi from '@/api/system/user'
import download from '@/utils/download' import download from '@/utils/download'
import { useCache } from '@/hooks/web/useCache'
import { CommonStatusEnum } from '@/utils/constants' import { CommonStatusEnum } from '@/utils/constants'
const { wsCache } = useCache() import { getAccessToken, getTenantId } from '@/utils/auth'
interface Tree { interface Tree {
id: number id: number
name: string name: string
@ -216,8 +215,8 @@ const beforeExcelUpload = (file: UploadRawFile) => {
const uploadRef = ref<UploadInstance>() const uploadRef = ref<UploadInstance>()
const submitFileForm = () => { const submitFileForm = () => {
uploadHeaders.value = { uploadHeaders.value = {
Authorization: 'Bearer ' + wsCache.get('ACCESS_TOKEN'), Authorization: 'Bearer ' + getAccessToken(),
'tenant-id': wsCache.get('tenantId') 'tenant-id': getTenantId()
} }
uploadDisabled.value = true uploadDisabled.value = true
uploadRef.value!.submit() uploadRef.value!.submit()