提交 68597be4 authored 作者: jinrb's avatar jinrb

资料填报页面-边界图片增加下载功能

上级 55fe34a2
...@@ -13,9 +13,9 @@ ...@@ -13,9 +13,9 @@
@change="handleChange" @change="handleChange"
@preview="handlePreview" @preview="handlePreview"
@download="handleDownload" @download="handleDownload"
:showUploadList="true" :showUploadList="uploadListShowConfig"
> >
<template #downloadIcon>download</template> <template #downloadIcon><DownloadOutlined /></template>
<div v-if="uploadVisible && buttonVisible"> <div v-if="uploadVisible && buttonVisible">
<div v-if="listType == 'picture-card'"> <div v-if="listType == 'picture-card'">
<LoadingOutlined v-if="loading" /> <LoadingOutlined v-if="loading" />
...@@ -35,19 +35,19 @@ ...@@ -35,19 +35,19 @@
</template> </template>
<script lang="ts"> <script lang="ts">
import { defineComponent, PropType, ref, reactive, watchEffect, computed, unref, watch, onMounted } from 'vue'; import { defineComponent, PropType, ref, reactive, watchEffect, computed, unref, watch, onMounted } from 'vue';
import { LoadingOutlined, UploadOutlined } from '@ant-design/icons-vue'; import { LoadingOutlined, UploadOutlined, DownloadOutlined } from '@ant-design/icons-vue';
import { useRuleFormItem } from '/@/hooks/component/useFormItem'; import { useRuleFormItem } from '/@/hooks/component/useFormItem';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
import { useAttrs } from '/@/hooks/core/useAttrs'; import { useAttrs } from '/@/hooks/core/useAttrs';
import { useMessage } from '/@/hooks/web/useMessage'; import { useMessage } from '/@/hooks/web/useMessage';
import { getFileAccessHttpUrl, getRandom } from '/@/utils/common/compUtils'; import { getFileAccessHttpUrl, getRandom } from '/@/utils/common/compUtils';
import { uploadUrl } from '/@/api/common/api'; import { uploadUrl, downloadFile } from '/@/api/common/api';
import { getToken } from '/@/utils/auth'; import { getToken } from '/@/utils/auth';
const { createMessage, createErrorModal } = useMessage(); const { createMessage, createErrorModal } = useMessage();
export default defineComponent({ export default defineComponent({
name: 'JImageUpload', name: 'JImageUpload',
components: { LoadingOutlined, UploadOutlined }, components: { LoadingOutlined, UploadOutlined, DownloadOutlined },
inheritAttrs: false, inheritAttrs: false,
props: { props: {
//绑定值 //绑定值
...@@ -127,6 +127,18 @@ ...@@ -127,6 +127,18 @@
return uploadFileList.value.length < props['fileMax']; return uploadFileList.value.length < props['fileMax'];
}); });
/** 照片墙模式显示下载图标 */
const uploadListShowConfig = computed(() => {
if (props.listType === 'picture-card') {
return {
showPreviewIcon: true,
showRemoveIcon: true,
showDownloadIcon: true,
};
}
return true;
});
/** /**
* 监听value变化 * 监听value变化
*/ */
...@@ -231,19 +243,28 @@ ...@@ -231,19 +243,28 @@
previewVisible.value = true; previewVisible.value = true;
} }
/** /**
* 下载图片 * 下载图片(走系统下载接口,支持需登录的静态资源)
*/ */
function handleDownload(file) { function handleDownload(file) {
console.log('download',file) let relativePath = file?.response?.message;
let url = file.url; if (!relativePath && file?.url) {
let link = document.createElement('a'); const u = String(file.url);
link.style.display = 'none'; const marker = '/sys/common/static/';
link.href = url; const idx = u.indexOf(marker);
link.setAttribute('download', fileName); if (idx !== -1) {
document.body.appendChild(link); relativePath = u.substring(idx + marker.length);
link.click(); }
document.body.removeChild(link); //下载完成移除元素 }
window.URL.revokeObjectURL(url); //释放掉blob对象 if (!relativePath) {
createMessage.warning('无法下载该文件');
return;
}
const normalized = String(relativePath).replace(/^\/+/, '');
const url = `/sys/common/static/${normalized}`;
const name = file?.name || getFileName(relativePath);
downloadFile(url, name).catch(() => {
createMessage.error('下载失败');
});
} }
function getAvatarView() { function getAvatarView() {
...@@ -273,6 +294,7 @@ ...@@ -273,6 +294,7 @@
handleCancel, handleCancel,
handleChange, handleChange,
handleDownload, handleDownload,
uploadListShowConfig,
getAvatarView getAvatarView
}; };
}, },
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论