index.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react';
  2. import ReactZmage from 'react-zmage';
  3. import './index.less';
  4. export default function PreviewFile(props) {
  5. const { src, name, showName } = props;
  6. var reg = /\.(png|jpg|gif|jpeg|webp)$/;
  7. const controller = {
  8. // 关闭按钮
  9. close: true,
  10. // 旋转按钮
  11. rotate: true,
  12. // 缩放按钮
  13. zoom: false,
  14. // 下载按钮
  15. download: false,
  16. // 翻页按钮
  17. flip: false,
  18. // 多页指示
  19. pagination: false,
  20. };
  21. if (reg.test(name)) {
  22. if (showName) {
  23. return (
  24. <div style={{ display: 'flex', alignItems: 'center' }}>
  25. <ReactZmage
  26. controller={controller}
  27. backdrop="rgba(255,255,255,0.5)"
  28. style={{ width: '100px' }}
  29. src={src}
  30. />
  31. <div style={{ marginLeft: 20 }}>{name}</div>
  32. </div>
  33. );
  34. } else {
  35. return (
  36. <ReactZmage
  37. controller={controller}
  38. backdrop="rgba(255,255,255,0.5)"
  39. style={{ width: '100px' }}
  40. src={src}
  41. />
  42. );
  43. }
  44. } else {
  45. return <div>{name}</div>;
  46. }
  47. }