提交 8c5084ed authored 作者: 钟是志's avatar 钟是志

文件预览 下载功能完善

上级 49908136
...@@ -8,8 +8,9 @@ ...@@ -8,8 +8,9 @@
import React, { useMemo, Fragment, useState, useRef } from "react"; import React, { useMemo, Fragment, useState, useRef } from "react";
import { fileUrlToFilePath } from '@/webPublic/one_stop_public/utils/queryConfig'; import { fileUrlToFilePath } from '@/webPublic/one_stop_public/utils/queryConfig';
import { requestOrigin } from '@/webPublic/one_stop_public/utils/request'; import { requestOrigin } from '@/webPublic/one_stop_public/utils/request';
import { message, Modal, Tooltip } from 'antd'; import { message, Popconfirm, Tooltip } from 'antd';
import { getPdfFile } from "@/webPublic/one_stop_public/filePreview/utils"; import { getPdfFile } from "@/webPublic/one_stop_public/filePreview/utils";
import { isFromIframe } from "@/webPublic/one_stop_public/utils/utils";
export default function PreviewWordExtend({ src, fileName }) { export default function PreviewWordExtend({ src, fileName }) {
const extList = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'txt']; const extList = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'txt'];
...@@ -26,7 +27,7 @@ export default function PreviewWordExtend({ src, fileName }) { ...@@ -26,7 +27,7 @@ export default function PreviewWordExtend({ src, fileName }) {
const params = { const params = {
filePath: fileUrlToFilePath(src), filePath: fileUrlToFilePath(src),
}; };
message.info('正在打开文件预览'); message.info('正在打开文件预览,请耐心等待', 10);
getPdfFile(params).then((url) => { getPdfFile(params).then((url) => {
filePdf.current = url; filePdf.current = url;
setIsShow(true); setIsShow(true);
...@@ -37,10 +38,27 @@ export default function PreviewWordExtend({ src, fileName }) { ...@@ -37,10 +38,27 @@ export default function PreviewWordExtend({ src, fileName }) {
} }
function downloadFile() {
let a = document.createElement('a');
a.href = src;
a.target = '_blank';
a.download = fileName;
a.click();
}
if (isOpen) { if (isOpen) {
return ( return (
<Fragment> <Fragment>
<a onClick={showPdf}>{fileName}</a> <Popconfirm
title="查看附件"
onConfirm={downloadFile}
okText="下载"
onCancel={showPdf}
cancelText={'预览'}
>
<a>{fileName}</a>
</Popconfirm>
{ {
isShow && isShow &&
<Modal title={'文件预览'} <Modal title={'文件预览'}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论