|
@ -42,6 +42,7 @@ import { PropType } from 'vue' |
|
|
import { propTypes } from '@/utils/propTypes' |
|
|
import { propTypes } from '@/utils/propTypes' |
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
import type { UploadInstance, UploadUserFile, UploadProps, UploadRawFile } from 'element-plus' |
|
|
import type { UploadInstance, UploadUserFile, UploadProps, UploadRawFile } from 'element-plus' |
|
|
|
|
|
const { t } = useI18n() // 国际化 |
|
|
|
|
|
|
|
|
defineOptions({ name: 'UploadFile' }) |
|
|
defineOptions({ name: 'UploadFile' }) |
|
|
|
|
|
|
|
@ -78,7 +79,7 @@ const uploadHeaders = ref({ |
|
|
// 文件上传之前判断 |
|
|
// 文件上传之前判断 |
|
|
const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => { |
|
|
const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => { |
|
|
if (fileList.value.length >= props.limit) { |
|
|
if (fileList.value.length >= props.limit) { |
|
|
message.error(`上传文件数量不能超过${props.limit}个!`) |
|
|
message.error(`${t('ts.上传文件数量不能超过')}${props.limit}!`) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
let fileExtension = '' |
|
|
let fileExtension = '' |
|
@ -91,14 +92,14 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => { |
|
|
}) |
|
|
}) |
|
|
const isLimit = file.size < props.fileSize * 1024 * 1024 |
|
|
const isLimit = file.size < props.fileSize * 1024 * 1024 |
|
|
if (!isImg) { |
|
|
if (!isImg) { |
|
|
message.error(`文件格式不正确, 请上传${props.fileType.join('/')}格式!`) |
|
|
message.error(`${t(`ts.${'文件格式不正确, 请上传'}`)}${props.fileType.join('/')}${t('ts.格式')}!`) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
if (!isLimit) { |
|
|
if (!isLimit) { |
|
|
message.error(`上传文件大小不能超过${props.fileSize}MB!`) |
|
|
message.error(`${t('ts.上传文件大小不能超过')}${props.fileSize}MB!`) |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
message.success('正在上传文件,请稍候...') |
|
|
message.success(t(`ts.${'正在上传文件,请稍候'}`)) |
|
|
uploadNumber.value++ |
|
|
uploadNumber.value++ |
|
|
} |
|
|
} |
|
|
// 处理上传的文件发生变化 |
|
|
// 处理上传的文件发生变化 |
|
@ -107,7 +108,7 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => { |
|
|
// } |
|
|
// } |
|
|
// 文件上传成功 |
|
|
// 文件上传成功 |
|
|
const handleFileSuccess: UploadProps['onSuccess'] = (res: any,uploadFile: any): void => { |
|
|
const handleFileSuccess: UploadProps['onSuccess'] = (res: any,uploadFile: any): void => { |
|
|
message.success('上传成功') |
|
|
message.success(t('ts.上传成功')) |
|
|
const fileListNew = fileList.value |
|
|
const fileListNew = fileList.value |
|
|
fileListNew.pop() |
|
|
fileListNew.pop() |
|
|
fileList.value = fileListNew |
|
|
fileList.value = fileListNew |
|
@ -121,11 +122,11 @@ const handleFileSuccess: UploadProps['onSuccess'] = (res: any,uploadFile: any): |
|
|
} |
|
|
} |
|
|
// 文件数超出提示 |
|
|
// 文件数超出提示 |
|
|
const handleExceed: UploadProps['onExceed'] = (): void => { |
|
|
const handleExceed: UploadProps['onExceed'] = (): void => { |
|
|
message.error(`上传文件数量不能超过${props.limit}个!`) |
|
|
message.error(`${t('ts.上传文件数量不能过')}${props.limit}!`) |
|
|
} |
|
|
} |
|
|
// 上传错误提示 |
|
|
// 上传错误提示 |
|
|
const excelUploadError: UploadProps['onError'] = (): void => { |
|
|
const excelUploadError: UploadProps['onError'] = (): void => { |
|
|
message.error('导入数据失败,请您重新上传!') |
|
|
message.error(t(`ts.导入数据失败,请您重新上传`)) |
|
|
} |
|
|
} |
|
|
// 删除上传文件 |
|
|
// 删除上传文件 |
|
|
const handleRemove = (file) => { |
|
|
const handleRemove = (file) => { |
|
|