Merge branch '20221118-修改获取下载路径方法' of http://gitlab.tianti.tg.unicom.local/eshop/fe_service_ebtp_frontend into release_electronic_bid_evaluation_room

This commit is contained in:
jl-zhoujl2
2022-11-21 11:04:49 +08:00
4 changed files with 45 additions and 10 deletions

View File

@ -2,11 +2,12 @@
* @Author: zhoujianlong
* @Date: 2022-03-03 09:06:36
* @Last Modified by: zhoujianlong
* @Last Modified time: 2022-05-18 17:23:26
* @Last Modified time: 2022-11-21 11:04:43
*/
import { getDownloadSecretKey, getFilelist, getFilelistBySecond } from "@/services/download_";
import { message } from "antd";
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
import { isEmpty, isNotEmpty } from "./CommonUtils";
/**
@ -149,6 +150,37 @@ export const getDownloadFileUrl = async (objectId: string) => {
}
return url;
}
/**
* objectId获取文件下载链接
* @param objectId
* @returns
*/
export const useDownLoadUrl = (objectId: string): string[] => {
const [url, setUrl] = useState<string>("");
useEffect(() => {
const getFileUrl = async () => {
console.log("objectId", objectId);
await getFilelist([objectId]).then(async res => {
if (res?.success && res?.data?.length > 0) {
const keyRes = await getDownloadSecretKey({ fileId: res?.data[res?.data?.length - 1].fileId });//获取key
let url = downloadAttachmentPath + '?fileId=' + res?.data[res?.data?.length - 1].fileId + '&documentSecretKey=' + keyRes?.data;
setUrl(url);
}
})
}
if (isNotEmpty(objectId)) {
if (checkObjectId(objectId)) {//判断3.0 objectId
getFileUrl();
} else {
let url = downloadPathBySecond + '?id=' + objectId + '&p=' + getTimeStamp();
setUrl(url);
}
}
}, [objectId])
return [url];
}
/**
* 获取文件列表
* @param objectId