diff --git a/src/components/image/image.tsx b/src/components/image/image.tsx new file mode 100644 index 0000000..d3591b8 --- /dev/null +++ b/src/components/image/image.tsx @@ -0,0 +1,60 @@ +import {FC, useEffect, useState} from "react"; +import {Image, View} from "@tarojs/components"; +import emptyImg from '@/static/img/empty.png' +import {AtActivityIndicator} from "taro-ui"; + +interface Props { + src: string + mode?: "scaleToFill" | "aspectFit" | "aspectFill" | "widthFix" | "heightFix" | "top" | "bottom" | "center" | "left" | "right" | "top left" | "top right" | "bottom left" | "bottom right" | undefined + width:number + height:number + fallback?: string +} + +const Img: FC = ({src,mode = 'aspectFill',width,height,fallback = emptyImg}) => { + const [isError,setIsError] = useState(false) + const [loading,setLoading] = useState(true) + + useEffect(()=>{ + console.log(src, !src) + if(!src){ + setIsError(true) + setLoading(false) + } else { + setIsError(false) + setLoading(false) + } + },[src]) + // 图片加载失败 + function onErrorHandler() { + setLoading(false) + setIsError(true) + } + function onLoadHandler() { + setLoading(false) + setIsError(false) + } + + return ( + + { !isError && + + + } + { loading && + + } + { isError && !loading && + + } + + + ) +} + +export default Img diff --git a/src/pages/home/components/feature_recommended.tsx b/src/pages/home/components/feature_recommended.tsx index 6283013..2cd2fc9 100644 --- a/src/pages/home/components/feature_recommended.tsx +++ b/src/pages/home/components/feature_recommended.tsx @@ -10,6 +10,7 @@ import brandTop from '@/static/img/brandTop.png' import illnessTop from '@/static/img/illnessTop.png' import healthTop from '@/static/img/healthTop.png' import professionTop from '@/static/img/professionTop.png' +import Img from "@/components/image/image"; interface DataContent { @@ -161,8 +162,12 @@ const FeatureRecommended: FC = (props) => { className='flex mb-3' key={c.id} onClick={() => jump(d.detailsUrl + c.path, c.id, d.type)}> - - + + + + + {/**/} + diff --git a/src/pages/home/home.module.scss b/src/pages/home/home.module.scss index 8820c50..1e406a9 100644 --- a/src/pages/home/home.module.scss +++ b/src/pages/home/home.module.scss @@ -117,6 +117,7 @@ } .ranking { + top:0; position: absolute; left: 24rpx; width: 30px;