feat: oss下载进度(已下载的KB 无法作为进度显示 total返回为null)

This commit is contained in:
dap 2025-01-17 11:13:03 +08:00
parent 77cd005f15
commit 14b7296200
4 changed files with 20 additions and 3 deletions

View File

@ -13,6 +13,7 @@
- 字典新增对Number类型的支持 -> `getDictOptions('', true);`即可获取number类型的value - 字典新增对Number类型的支持 -> `getDictOptions('', true);`即可获取number类型的value
- 文件上传 增加上传进度条 下方上传提示 - 文件上传 增加上传进度条 下方上传提示
- 图片上传 增加上传进度条 下方上传提示 - 图片上传 增加上传进度条 下方上传提示
- oss下载进度(已下载的KB 无法作为进度显示 total返回为null)
**BUG FIXES** **BUG FIXES**

View File

@ -1,3 +1,5 @@
import type { AxiosRequestConfig } from '@vben/request';
import type { OssFile } from './model'; import type { OssFile } from './model';
import type { ID, IDS, PageQuery, PageResult } from '#/api/common'; import type { ID, IDS, PageQuery, PageResult } from '#/api/common';
@ -48,13 +50,18 @@ export function ossUpload(file: Blob | File) {
/** /**
* *
* @param ossId ossId * @param ossId ossId
* @param onDownloadProgress ()
* @returns blob * @returns blob
*/ */
export function ossDownload(ossId: ID) { export function ossDownload(
ossId: ID,
onDownloadProgress?: AxiosRequestConfig['onDownloadProgress'],
) {
return requestClient.get<Blob>(`${Api.ossDownload}/${ossId}`, { return requestClient.get<Blob>(`${Api.ossDownload}/${ossId}`, {
responseType: 'blob', responseType: 'blob',
timeout: 30 * 1000, timeout: 30 * 1000,
isTransformResponse: false, isTransformResponse: false,
onDownloadProgress,
}); });
} }

View File

@ -45,6 +45,7 @@ const message = computed(() => {
v-model:value="fileList" v-model:value="fileList"
:accept="accept" :accept="accept"
:max-number="maxNumber" :max-number="maxNumber"
:max-size="5"
/> />
</div> </div>
</BasicModal> </BasicModal>

View File

@ -105,10 +105,18 @@ const [BasicTable, tableApi] = useVbenVxeGrid({
}); });
async function handleDownload(row: OssFile) { async function handleDownload(row: OssFile) {
const hideLoading = message.loading($t('pages.common.downloadLoading'), 0); const downloadSize = ref($t('pages.common.downloadLoading'));
const hideLoading = message.loading({
content: () => downloadSize.value,
duration: 0,
});
try { try {
const data = await ossDownload(row.ossId); const data = await ossDownload(row.ossId, (e) => {
// e.total
downloadSize.value = `已下载: ${Math.floor(e.loaded / 1024)}KB`;
});
downloadByData(data, row.originalName); downloadByData(data, row.originalName);
message.success('下载完成');
} finally { } finally {
hideLoading(); hideLoading();
} }