提交 049c18df authored 作者: 钟是志's avatar 钟是志

预览增加图片的放大预览

上级 c9e33643
...@@ -4,13 +4,13 @@ ...@@ -4,13 +4,13 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { checkIsImage } from '@/webPublic/one_stop_public/libs/UploadCom'; import { checkIsImage } from '@/webPublic/one_stop_public/libs/UploadCom';
import { getModal, getPopconfirm, isFromIframe } from '@/webPublic/one_stop_public/utils/utils'; import { getModal, getPopconfirm, isFromIframe } from '@/webPublic/one_stop_public/utils/utils';
import Viewer from 'react-viewer';
// const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer'); // const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer');
const FileViewer = null; const FileViewer = null;
const Modal = getModal(); const Modal = getModal();
const Popconfirm = getPopconfirm(); const Popconfirm = getPopconfirm();
export default class index extends Component { export default class index extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -29,22 +29,19 @@ export default class index extends Component { ...@@ -29,22 +29,19 @@ export default class index extends Component {
}); });
}; };
handleOk = (e) => { handleOk = e => {
this.setState({ this.setState({
visible: false, visible: false,
}); });
}; };
handleCancel = (e) => { handleCancel = e => {
this.setState({ this.setState({
visible: false, visible: false,
}); });
}; };
download = () => { download = () => {
let { let { path, pathName } = this.props;
path,
pathName
} = this.props;
if (window?.parent?.open && typeof window.parent.open === 'function') { if (window?.parent?.open && typeof window.parent.open === 'function') {
window.parent.open(path, '_blank'); window.parent.open(path, '_blank');
} else { } else {
...@@ -53,12 +50,7 @@ export default class index extends Component { ...@@ -53,12 +50,7 @@ export default class index extends Component {
}; };
render() { render() {
let { let { path, pathName, width, height } = this.props;
path,
pathName,
width,
height
} = this.props;
const { visible } = this.state; const { visible } = this.state;
let isShow = false; let isShow = false;
...@@ -67,7 +59,7 @@ export default class index extends Component { ...@@ -67,7 +59,7 @@ export default class index extends Component {
if (isImg) { if (isImg) {
isShow = true; isShow = true;
} else { } else {
let find = ['.pdf', '.mp3', '.mp4', '.csv'].find((x) => { let find = ['.pdf', '.mp3', '.mp4', '.csv'].find(x => {
return pathName.indexOf(x) > -1; return pathName.indexOf(x) > -1;
}); });
if (find) { if (find) {
...@@ -88,12 +80,12 @@ export default class index extends Component { ...@@ -88,12 +80,12 @@ export default class index extends Component {
title="查看附件" title="查看附件"
onConfirm={this.download} onConfirm={this.download}
okText="下载" okText="下载"
onCancel={this.showModal} onCancel={this.showModal}
cancelText={isFromIframe() ? '取消' : '预览'}> cancelText={isFromIframe() ? '取消' : '预览'}
>
{isImg ? ( {isImg ? (
<img <img
ref={(node) => { ref={node => {
this.imageDom = node; this.imageDom = node;
}} }}
style={{ style={{
...@@ -114,8 +106,7 @@ export default class index extends Component { ...@@ -114,8 +106,7 @@ export default class index extends Component {
{pathName} {pathName}
</a> </a>
)} )}
{ {visible && (
visible &&
<Modal <Modal
title={pathName} title={pathName}
visible={true} visible={true}
...@@ -123,7 +114,8 @@ export default class index extends Component { ...@@ -123,7 +114,8 @@ export default class index extends Component {
destroyOnClose destroyOnClose
centered={true} centered={true}
onOk={this.handleOk} onOk={this.handleOk}
onCancel={this.handleCancel}> onCancel={this.handleCancel}
>
{type === 'pdf' ? ( {type === 'pdf' ? (
<iframe <iframe
style={{ style={{
...@@ -137,25 +129,26 @@ export default class index extends Component { ...@@ -137,25 +129,26 @@ export default class index extends Component {
style={{ style={{
height: 650, height: 650,
maxWidth: 1200, maxWidth: 1200,
}}> }}
<a onClick={this.download}> >
下载文件 {!checkIsImage(path) && <a onClick={this.download}>下载文件</a>}
</a>
{ {!!checkIsImage(path) && (
!!checkIsImage(path) && <Viewer
<img src={path} style={{ maxWidth: '100%', }}/> visible={true}
} onClose={this.handleCancel}
{/* {FileViewer && ( images={[
<FileViewer {
fileType={type} src: path,
filePath={path} alt: '预览',
/> },
)}*/} ]}
/>
)}
</div> </div>
)} )}
</Modal> </Modal>
} )}
</> </>
); );
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论