11.18 修改获取下载路径的方法,让页面内pdf组件正常获取文件链接
This commit is contained in:
@ -2,10 +2,11 @@
|
||||
* @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-18 17:05:16
|
||||
*/
|
||||
|
||||
import { getDownloadSecretKey, getFilelist, getFilelistBySecond } from "@/services/download_";
|
||||
import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
|
||||
import { isEmpty, isNotEmpty } from "./CommonUtils";
|
||||
|
||||
/**
|
||||
@ -146,6 +147,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
|
||||
|
Reference in New Issue
Block a user