|
@@ -1,58 +1,53 @@
|
|
|
-import React, { useCallback, useState } from "react";
|
|
|
-import styles from "./index.module.scss";
|
|
|
-import { baseURL } from "@/utils/http";
|
|
|
-import imgLoding from "@/assets/img/loading.gif";
|
|
|
-import imgErr from "@/assets/img/IMGerror.png";
|
|
|
-import { EyeOutlined } from "@ant-design/icons";
|
|
|
-import store from "@/store";
|
|
|
-import { Image } from "antd-mobile";
|
|
|
+import React, { useCallback, useState } from 'react'
|
|
|
+import styles from './index.module.scss'
|
|
|
+import { baseURL } from '@/utils/http'
|
|
|
+import imgLoding from '@/assets/img/loading.gif'
|
|
|
+import imgErr from '@/assets/img/IMGerror.png'
|
|
|
+import { EyeOutlined } from '@ant-design/icons'
|
|
|
+import store from '@/store'
|
|
|
+import { Image } from 'antd-mobile'
|
|
|
|
|
|
type Props = {
|
|
|
- width?: number | string;
|
|
|
- height?: number | string;
|
|
|
- src: string;
|
|
|
- noLook?: boolean;
|
|
|
- offline?: boolean;
|
|
|
-};
|
|
|
+ width?: number | string
|
|
|
+ height?: number | string
|
|
|
+ src: string
|
|
|
+ srcBig?: string
|
|
|
+ noLook?: boolean
|
|
|
+ offline?: boolean
|
|
|
+}
|
|
|
|
|
|
-function ImageLazy({
|
|
|
- width = 100,
|
|
|
- height = 100,
|
|
|
- src,
|
|
|
- noLook,
|
|
|
- offline = false,
|
|
|
-}: Props) {
|
|
|
+function ImageLazy({ width = 100, height = 100, src, srcBig, noLook, offline = false }: Props) {
|
|
|
// 默认不能预览图片,加载成功之后能预览
|
|
|
- const [lookImg, setLookImg] = useState(false);
|
|
|
+ const [lookImg, setLookImg] = useState(false)
|
|
|
|
|
|
// 图片加载完成
|
|
|
const onLoad = useCallback(() => {
|
|
|
- setLookImg(true);
|
|
|
- }, []);
|
|
|
+ setLookImg(true)
|
|
|
+ }, [])
|
|
|
|
|
|
// 点击预览图片
|
|
|
const lookBigImg = useCallback(() => {
|
|
|
store.dispatch({
|
|
|
- type: "layout/lookBigImg",
|
|
|
- payload: { url: offline ? src : baseURL + src, show: true },
|
|
|
- });
|
|
|
- }, [offline, src]);
|
|
|
+ type: 'layout/lookBigImg',
|
|
|
+ payload: { url: offline ? src : srcBig ? baseURL + srcBig : baseURL + src, show: true }
|
|
|
+ })
|
|
|
+ }, [offline, src, srcBig])
|
|
|
|
|
|
return (
|
|
|
<div className={styles.ImageLazy} style={{ width: width, height: height }}>
|
|
|
- <div className="lazyBox">
|
|
|
+ <div className='lazyBox'>
|
|
|
<Image
|
|
|
lazy
|
|
|
onLoad={onLoad}
|
|
|
- src={src ? (offline ? src : baseURL + src) : ""}
|
|
|
- placeholder={<img src={imgLoding} alt="" />}
|
|
|
- fallback={<img src={imgErr} alt="" />}
|
|
|
- fit="cover"
|
|
|
+ src={src ? (offline ? src : baseURL + src) : ''}
|
|
|
+ placeholder={<img src={imgLoding} alt='' />}
|
|
|
+ fallback={<img src={imgErr} alt='' />}
|
|
|
+ fit='cover'
|
|
|
/>
|
|
|
|
|
|
{/* 图片预览 */}
|
|
|
{noLook || !lookImg ? null : (
|
|
|
- <div className="lookImg" onClick={lookBigImg}>
|
|
|
+ <div className='lookImg' onClick={lookBigImg}>
|
|
|
<EyeOutlined rev={undefined} />
|
|
|
|
|
|
<div>预览</div>
|
|
@@ -60,9 +55,9 @@ function ImageLazy({
|
|
|
)}
|
|
|
</div>
|
|
|
</div>
|
|
|
- );
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
-const MemoImageLazy = React.memo(ImageLazy);
|
|
|
+const MemoImageLazy = React.memo(ImageLazy)
|
|
|
|
|
|
-export default MemoImageLazy;
|
|
|
+export default MemoImageLazy
|