diff --git a/src/components/common/table/uploadImg.vue b/src/components/common/table/uploadImg.vue index dd3584b..1537bdd 100644 --- a/src/components/common/table/uploadImg.vue +++ b/src/components/common/table/uploadImg.vue @@ -1,29 +1,46 @@ @@ -32,15 +49,18 @@ import { ref, watch } from 'vue'; import { dataUploadAvatarApi } from '@/api/data/data'; import { Plus, View, Delete } from '@element-plus/icons-vue'; import { ElMessage } from 'element-plus'; +import FilePreview from '@/components/common/filePreview/index.vue'; interface Props { modelValue: any; disabled?: boolean; + viewMode?: string; } const props = withDefaults(defineProps(), { modelValue: '', disabled: false, + viewMode: 'card', // card卡片模式 text文本模式 }); const emit = defineEmits(['update:modelValue', 'change']); @@ -49,14 +69,20 @@ const env = import.meta.env; const uploading = ref(false); const percentage = ref(0); const imgUrl = ref(''); +const fileId = ref(''); +const previewVisible = ref(false); -watch(() => props.modelValue, (val: any) => { - if (val) { - imgUrl.value = `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${val}`; - } else { - imgUrl.value = ''; - } -}, { deep: true, immediate: true }); +watch( + () => props.modelValue, + (val: any) => { + if (val) { + imgUrl.value = `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${val}`; + } else { + imgUrl.value = ''; + } + }, + { deep: true, immediate: true } +); const beforeUploadFun = (file: any) => { uploading.value = true; @@ -67,20 +93,27 @@ const beforeUploadFun = (file: any) => { const { loaded, total } = event; const percent = (loaded / total) * 100; percentage.value = Number(percent.toFixed(2)); - }).then((res: any) => { - if (res.code === 200) { - const avatarId = res.data.avatarId; - updateFun(avatarId); - imgUrl.value = `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${avatarId}`; - ElMessage.success('上传成功'); - } - }).finally(() => { - uploading.value = false; - percentage.value = 0; - }); + }) + .then((res: any) => { + if (res.code === 200) { + const avatarId = res.data.avatarId; + updateFun(avatarId); + imgUrl.value = `${env.VITE_API_IMAGE_PREVIEW_URL}/data/previewImage?fileId=${avatarId}`; + ElMessage.success('上传成功'); + } + }) + .finally(() => { + uploading.value = false; + percentage.value = 0; + }); return false; }; +const previewFun = () => { + fileId.value = props.modelValue; + previewVisible.value = true; +}; + const delFun = () => { imgUrl.value = ''; updateFun(''); @@ -93,15 +126,43 @@ const updateFun = (data: any) => {