|
|
@ -12,6 +12,7 @@ |
|
|
|
:headers="uploadHeaders" |
|
|
|
:limit="props.limit" |
|
|
|
:drag="drag" |
|
|
|
:accept="fileType.join(',')" |
|
|
|
:before-upload="beforeUpload" |
|
|
|
:on-exceed="handleExceed" |
|
|
|
:on-success="handleFileSuccess" |
|
|
@ -26,8 +27,9 @@ |
|
|
|
大小不超过 <b style="color: #f56c6c">{{ fileSize }}MB</b> |
|
|
|
</div> |
|
|
|
<div style="font-size: 8px;line-height: initial;"> |
|
|
|
格式为 <b style="color: #f56c6c">{{ fileType.join('/') }}</b> 的文件 |
|
|
|
格式为 <b style="color: #f56c6c">{{ fileType.join(',') }}</b> 的文件 |
|
|
|
</div> |
|
|
|
<Preview/> |
|
|
|
</template> |
|
|
|
<template v-if="!isShowFile" #file > |
|
|
|
<div> |
|
|
@ -38,6 +40,7 @@ |
|
|
|
</template> |
|
|
|
<script lang="ts" setup> |
|
|
|
import { PropType } from 'vue' |
|
|
|
import Preview from '@/components/UploadFile/src/Preview' |
|
|
|
|
|
|
|
import { propTypes } from '@/utils/propTypes' |
|
|
|
import { getAccessToken, getTenantId } from '@/utils/auth' |
|
|
@ -60,15 +63,16 @@ const props = defineProps({ |
|
|
|
fileSize: propTypes.number.def(5), // 大小限制(MB) |
|
|
|
limit: propTypes.number.def(5), // 数量限制 |
|
|
|
autoUpload: propTypes.bool.def(true), // 自动上传 |
|
|
|
drag: propTypes.bool.def(false), // 拖拽上传 |
|
|
|
isShowTip: propTypes.bool.def(true), // 是否显示提示 |
|
|
|
isShowFile: propTypes.bool.def(true), // 是否显示上传的文件 |
|
|
|
|
|
|
|
}) |
|
|
|
console.log('props.upData',props.upData) |
|
|
|
// ========== 上传相关 ========== |
|
|
|
const valueRef = ref(props.modelValue) |
|
|
|
const uploadRef = ref<UploadInstance>() |
|
|
|
const uploadList = ref<UploadUserFile[]>([]) |
|
|
|
console.log('props.modelValue',props.modelValue) |
|
|
|
const fileList = props.modelValue && props.modelValue.length > 0 ? ref<UploadUserFile[]>(props.modelValue) : ref<UploadUserFile[]>([]) |
|
|
|
const uploadNumber = ref<number>(0) |
|
|
|
const uploadHeaders = ref({ |
|
|
@ -91,7 +95,7 @@ const beforeUpload: UploadProps['beforeUpload'] = (file: UploadRawFile) => { |
|
|
|
}) |
|
|
|
const isLimit = file.size < props.fileSize * 1024 * 1024 |
|
|
|
if (!isImg) { |
|
|
|
message.error(`文件格式不正确, 请上传${props.fileType.join('/')}格式!`) |
|
|
|
message.error(`文件格式不正确, 请上传${props.fileType.join(',')}格式!`) |
|
|
|
return false |
|
|
|
} |
|
|
|
if (!isLimit) { |
|
|
@ -136,7 +140,9 @@ const handleRemove = (file) => { |
|
|
|
} |
|
|
|
} |
|
|
|
const handlePreview: UploadProps['onPreview'] = (uploadFile) => { |
|
|
|
console.log(uploadFile) |
|
|
|
console.log('uploadFile',uploadFile) |
|
|
|
window.open(uploadFile.url) |
|
|
|
|
|
|
|
} |
|
|
|
// 对象转成指定字符串分隔 |
|
|
|
const listToString = (list: UploadUserFile[], separator?: string) => { |
|
|
|