提交 7ddefd36 authored 作者: 钟是志's avatar 钟是志

2695 多人并行 (违纪)上传的附件行文在线预览

上级 389f4372
/**
* 钟是志
* 2024年7月4日
* 解决禅道 http://scjoyedu.eicp.net:57400/zentao/task-view-2695.html
* 根据配置项来解决
* */
import React, { useMemo, Fragment, useState, useRef } from "react";
import { fileUrlToFilePath } from '@/webPublic/one_stop_public/utils/queryConfig';
import { requestOrigin } from '@/webPublic/one_stop_public/utils/request';
import { message, Modal } from 'antd';
import { getPdfFile } from "@/webPublic/one_stop_public/filePreview/utils";
export default function PreviewWordExtend({ src, fileName }) {
const extList = ['doc', 'docx', 'ppt', 'pptx', 'xls', 'xlsx', 'txt'];
const [isShow, setIsShow] = useState(false);
const filePdf = useRef(null);
const isOpen = useMemo(
() => {
return window.CONFIG.openPdfPreview && extList.includes(fileName.split('.').pop());
},
[src],
);
function showPdf() {
if(!filePdf.current){
const params = {
filePath: fileUrlToFilePath(src),
};
message.info('正在打开文件预览');
getPdfFile(params).then((url) => {
filePdf.current = url;
setIsShow(true);
});
}else{
setIsShow(true);
}
}
if (isOpen) {
return (
<Fragment>
<a onClick={showPdf}>{fileName}</a>
{
isShow &&
<Modal title={'文件预览'}
width={1000}
visible={isShow}
onCancel={() => setIsShow(false)}
bodyStyle={{
height: '600px',
overflowY: 'hidden',
}}
footer={null}
>
<a target={'_blank'} href={src}>
下载文件
</a>
<embed width="100%"
height='550'
name="plugin"
id="plugin"
src={filePdf.current}
type="application/pdf"
internalinstanceid="3"
title=""/>
</Modal>
}
</Fragment>
);
} else {
return (
<a src={src} target={'_blank'}>
{fileName}
</a>
);
}
}
......@@ -6,6 +6,7 @@ import { checkIsImage } from '@/webPublic/one_stop_public/libs/UploadCom';
import { getModal, getPopconfirm, isFromIframe } from '@/webPublic/one_stop_public/utils/utils';
import Viewer from 'react-viewer';
import styles from './styles.less';
import PreviewWordExtend from "@/webPublic/one_stop_public/filePreview/PreviewWordExtend";
// const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer');
const FileViewer = null;
......@@ -103,15 +104,11 @@ export default class index extends Component {
>
</div>
) : (
<a target="_blank" href={path}>
{pathName}
</a>
<PreviewWordExtend src={path} fileName={pathName}/>
)}
</Popconfirm>
) : (
<a target="_blank" href={path}>
{pathName}
</a>
<PreviewWordExtend src={path} fileName={pathName}/>
)}
{visible && (
<Modal
......
import { getHeaders } from '@/webPublic/zyd_public/utils/getHeaders';
import FormdataWrapper from '@/webPublic/zyd_public/utils/object-to-formdata-custom';
import { downloadFile } from "@/webPublic/zyd_public/utils/utils";
export function getPdfFile(params) {
let responseHeadersFileName = '';
const fetchParams = {
body: FormdataWrapper(params),
method: 'POST',
...getHeaders(),
credentials: 'omit',
mode: 'cors',
};
return fetch(window.CONFIG.fileServer + '/officePreviewApi/path', fetchParams)
.then((res) => {
return res.blob();
// 解码
})
.then((blob) => {
let url = window.URL.createObjectURL(new Blob([blob], {
type: 'application/pdf',
}));
return url;
});
}
......@@ -7,7 +7,6 @@ import { queryFileUrl } from '@/webPublic/one_stop_public/utils/queryConfig';
export default function UploadComReadOnly(props) {
const { obj, dataColumn, get, isPrint, otherProps = {} } = props;
console.log(otherProps);
let cm = '';
/**
* 查找不到数据 添加判断
......
......@@ -155,4 +155,11 @@ export const queryFileUrl = (url = '', defaultFile = '') => {
}
};
export function fileUrlToFilePath(url) {
const prefix = window.CONFIG['FILE_PATH'] || window.CONFIG['API_ACTION_PATH'];
if(url && typeof url === 'string' && url.includes(prefix)){
return url.replace(prefix, '');
}
}
export default queryConfig;
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论