提交 757f6e80 authored 作者: 李仕聪's avatar 李仕聪

feat: 完成多图片预览

上级 4d9d9d0a
import { useMemo } from 'react';
import Viewer from 'react-viewer';
import { checkIsImage } from '@/webPublic/one_stop_public/libs/UploadCom';
export const ImgViewer = (props) => {
const { onClose, path } = props;
const images = useMemo(
() => {
return props?.images?.filter(i => checkIsImage(i?.src));
},
[props.images]
);
const activeIndex = useMemo(
() => {
if(path) {
return images?.findIndex((item) => item?.src === path);
}
return 0
},
[path]
);
return (
<Viewer visible={true} onClose={onClose} activeIndex={activeIndex} images={images} />
);
};
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
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 } from 'antd'; import { message, Modal, Tooltip } from 'antd';
import { getPdfFile } from "@/webPublic/one_stop_public/filePreview/utils"; import { getPdfFile } from "@/webPublic/one_stop_public/filePreview/utils";
export default function PreviewWordExtend({ src, fileName }) { export default function PreviewWordExtend({ src, fileName }) {
...@@ -70,9 +70,21 @@ export default function PreviewWordExtend({ src, fileName }) { ...@@ -70,9 +70,21 @@ export default function PreviewWordExtend({ src, fileName }) {
); );
} else { } else {
return ( return (
<>
{
fileName?.length > 13 ?
<Tooltip title={fileName}>
<a src={src} target={'_blank'}>
{fileName.substring(0, 10)}...
</a>
</Tooltip>
:
<a src={src} target={'_blank'}> <a src={src} target={'_blank'}>
{fileName} {fileName}
</a> </a>
}
</>
); );
} }
} }
...@@ -4,12 +4,10 @@ ...@@ -4,12 +4,10 @@
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';
import styles from './styles.less'; import styles from './styles.less';
import PreviewWordExtend from "@/webPublic/one_stop_public/filePreview/PreviewWordExtend"; import PreviewWordExtend from "@/webPublic/one_stop_public/filePreview/PreviewWordExtend";
import { ImgViewer } from './ImgViewer';
// const FileViewer = CLIENT_TYPE === 'mobile' ? null : require('react-file-viewer');
const FileViewer = null;
const Modal = getModal(); const Modal = getModal();
const Popconfirm = getPopconfirm(); const Popconfirm = getPopconfirm();
...@@ -55,7 +53,7 @@ export default class index extends Component { ...@@ -55,7 +53,7 @@ export default class index extends Component {
/*** /***
* pathName 必须是个字符串 否则容易崩溃 * pathName 必须是个字符串 否则容易崩溃
* */ * */
let { path, pathName = '', width, height } = this.props; let { path, pathName = '', width, height, activeIndex, images } = this.props;
const { visible } = this.state; const { visible } = this.state;
let isShow = false; let isShow = false;
let type; let type;
...@@ -80,7 +78,6 @@ export default class index extends Component { ...@@ -80,7 +78,6 @@ export default class index extends Component {
} }
// return null; // return null;
return ( return (
<> <>
{isShow ? ( {isShow ? (
...@@ -138,15 +135,10 @@ export default class index extends Component { ...@@ -138,15 +135,10 @@ export default class index extends Component {
{!checkIsImage(path) && <a onClick={this.download}>下载文件</a>} {!checkIsImage(path) && <a onClick={this.download}>下载文件</a>}
{!!checkIsImage(path) && ( {!!checkIsImage(path) && (
<Viewer <ImgViewer
visible={true}
onClose={this.handleCancel} onClose={this.handleCancel}
images={[ images={images}
{ path={path}
src: path,
alt: '预览',
},
]}
/> />
)} )}
</div> </div>
......
...@@ -39,6 +39,13 @@ export default function UploadComReadOnly(props) { ...@@ -39,6 +39,13 @@ export default function UploadComReadOnly(props) {
type={'UploadCom'} type={'UploadCom'}
width={otherProps.readOnlyWebFileWidth || '100px'} width={otherProps.readOnlyWebFileWidth || '100px'}
height={otherProps.readOnlyWebFileHeight || '100px'} height={otherProps.readOnlyWebFileHeight || '100px'}
images={files?.map((item) => {
return {
src: queryFileUrl(item.path),
alt: '预览',
};
})}
activeIndex={index2}
/> />
</li> </li>
); );
......
...@@ -434,7 +434,17 @@ class TreeList extends React.Component { ...@@ -434,7 +434,17 @@ class TreeList extends React.Component {
{files.map((f, index2) => { {files.map((f, index2) => {
return ( return (
<li key={index2}> <li key={index2}>
<FilePreview path={queryFileUrl(f.path)} pathName={f.name} /> <FilePreview
path={queryFileUrl(f.path)}
pathName={f.name}
images={files?.map((item) => {
return {
src: queryFileUrl(item.path),
alt: '预览',
};
})}
activeIndex={index2}
/>
</li> </li>
); );
})} })}
......
...@@ -511,7 +511,17 @@ class FormList extends React.Component { ...@@ -511,7 +511,17 @@ class FormList extends React.Component {
{files.map((f, index2) => { {files.map((f, index2) => {
return ( return (
<li key={index2}> <li key={index2}>
<FilePreview path={queryFileUrl(f.path)} pathName={f.name}/> <FilePreview
path={queryFileUrl(f.path)}
pathName={f.name}
images={files?.map((item) => {
return {
src: queryFileUrl(item.path),
alt: '预览',
};
})}
activeIndex={index2}
/>
</li> </li>
); );
})} })}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论