修复bug

This commit is contained in:
al 2024-08-13 13:41:42 +08:00
parent 239ddd82e3
commit 8899b66b0c
2 changed files with 68 additions and 31 deletions

View File

@ -207,10 +207,10 @@ const FollowPostList = forwardRef(({ scrollHeight }, ref) => {
const [followPostList, setFollowPostList] = useState([]); const [followPostList, setFollowPostList] = useState([]);
const [currentTime, setCurrentTime] = useState(); const [currentTime, setCurrentTime] = useState();
const [offset, setOffset] = useState(0); const [offset, setOffset] = useState(0);
const [ids, setIds] = useState([]); const ids = useRef(null)
useEffect(() => { useEffect(() => {
getFollowIds().then((res) => { getFollowIds().then((res) => {
setIds(res); ids.current=res;
getFollowPostList(res, 0); getFollowPostList(res, 0);
}); });
}, []); }, []);
@ -229,10 +229,10 @@ const FollowPostList = forwardRef(({ scrollHeight }, ref) => {
// }); // });
// throw new Error("刷新失败"); // throw new Error("刷新失败");
// getRecommPostList(1); // getRecommPostList(1);
await getFollowPostList(ids, 0); await getFollowPostList(ids.current, 0);
} }
async function loadMore() { async function loadMore() {
await getFollowPostList(ids, offset); await getFollowPostList(ids.current, offset);
// const newList = [...followPostList, ...list]; // const newList = [...followPostList, ...list];
// setFollowPostList(newList); // setFollowPostList(newList);
} }
@ -250,6 +250,14 @@ const FollowPostList = forwardRef(({ scrollHeight }, ref) => {
return data; return data;
}; };
const getFollowPostList = async (data, offset) => { const getFollowPostList = async (data, offset) => {
console.log("ids", data);
if(!offset){
window.scrollTo({
top: 0,
left: 0,
behavior: "smooth", // 可选,平滑滚动效果
});
}
if (data.data.list.length > 0) { if (data.data.list.length > 0) {
//查关注主播展示资料 //查关注主播展示资料
const followsResponse = await requireAPI( const followsResponse = await requireAPI(
@ -276,7 +284,15 @@ const FollowPostList = forwardRef(({ scrollHeight }, ref) => {
// position: "top", // position: "top",
// }); // });
} else { } else {
setFollowPostList((old) => [...old, ...followsResponse.data.list]);
setFollowPostList((old) => {
if(followsResponse.data.offset==4){
return followsResponse.data.list;
}else{
return [...old, ...followsResponse.data.list]
}
});
} }
} else { } else {
setLoading(false); setLoading(false);

View File

@ -36,15 +36,15 @@ export default function Photos({
type: "img", type: "img",
url: item.urls?.[0], url: item.urls?.[0],
// fullwidth:item.w>item.h // fullwidth:item.w>item.h
w:item.w, w: item.w,
h:item.h, h: item.h,
})); }));
let videoArr = media.videos.map((item) => ({ let videoArr = media.videos.map((item) => ({
type: "video", type: "video",
url: item.cover_urls?.[0], url: item.cover_urls?.[0],
mp4: item.urls?.[0], mp4: item.urls?.[0],
w:item.cover_w, w: item.cover_w,
h:item.cover_h, h: item.cover_h,
// fullwidth:item.cover_w>item.cover_h // fullwidth:item.cover_w>item.cover_h
})); }));
let arr = [...imgArr, ...videoArr]; let arr = [...imgArr, ...videoArr];
@ -60,6 +60,8 @@ export default function Photos({
mp4: newPhotos[0]?.type === "video", mp4: newPhotos[0]?.type === "video",
url: newPhotos[0]?.url, url: newPhotos[0]?.url,
type: "hid", type: "hid",
w: newPhotos[0]?.w,
h: newPhotos[0]?.h,
}; };
}); });
} }
@ -71,15 +73,15 @@ export default function Photos({
setCurrentPhotos(newPhotos); setCurrentPhotos(newPhotos);
} }
}, [media]); }, [media]);
useEffect(()=>{ useEffect(() => {
// window.addEventListener('resize', (e)=>{ // window.addEventListener('resize', (e)=>{
// // alert(window.innerHeight) // // alert(window.innerHeight)
// setMaskHeight(window.innerHeight) // setMaskHeight(window.innerHeight)
// }); // });
return ()=>{ return () => {
// window.removeEventListener("resize") // window.removeEventListener("resize")
} };
},[]) }, []);
const showPhotos = (photos, index) => { const showPhotos = (photos, index) => {
currentIndex.current = index; currentIndex.current = index;
const interval = setInterval(() => { const interval = setInterval(() => {
@ -144,7 +146,7 @@ export default function Photos({
photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
}`; }`;
// mediaDom.appendChild(btns); // mediaDom.appendChild(btns);
document.body.style.overflow = 'hidden'; document.body.style.overflow = "hidden";
ImageViewer.clear(); ImageViewer.clear();
ImageViewer.Multi.show({ ImageViewer.Multi.show({
images: photos.map((item) => item?.url), images: photos.map((item) => item?.url),
@ -159,25 +161,29 @@ export default function Photos({
mediaDom.className = `${ mediaDom.className = `${
photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom" photos[index]?.type == "hid" ? "mediaDom photos-body" : "mediaDom"
}`; }`;
const leftBtn = document.getElementsByClassName("imagesBtnsControllerLeft")[0] const leftBtn = document.getElementsByClassName(
const rightBtn = document.getElementsByClassName("imagesBtnsControllerRight")[0] "imagesBtnsControllerLeft"
if(leftBtn && rightBtn){ )[0];
if(!index){ const rightBtn = document.getElementsByClassName(
leftBtn.style.opacity=0.5 "imagesBtnsControllerRight"
rightBtn.style.opacity=1 )[0];
}else if(index==currentPhotos.length-1){ if (leftBtn && rightBtn) {
leftBtn.style.opacity=1 if (!index) {
rightBtn.style.opacity=0.5 leftBtn.style.opacity = 0.5;
}else{ rightBtn.style.opacity = 1;
leftBtn.style.opacity=1 } else if (index == currentPhotos.length - 1) {
rightBtn.style.opacity=1 leftBtn.style.opacity = 1;
rightBtn.style.opacity = 0.5;
} else {
leftBtn.style.opacity = 1;
rightBtn.style.opacity = 1;
} }
} }
}, },
afterClose: () => { afterClose: () => {
mediaDom.remove(); mediaDom.remove();
clearInterval(interval); clearInterval(interval);
document.body.style.overflow = 'auto'; document.body.style.overflow = "auto";
}, },
classNames: { body: "photos-bodyBox" }, classNames: { body: "photos-bodyBox" },
}); });
@ -216,6 +222,7 @@ export default function Photos({
) )
); );
}} }}
style={{ marginTop: "calc(-85px )" }}
> >
此内容暂未解锁立即解锁 此内容暂未解锁立即解锁
</div> </div>
@ -226,7 +233,9 @@ export default function Photos({
<> <>
<div <div
className={`${ className={`${
currentPhotos.length > 1 ? "grid grid-cols-3 gap-1.5 min-h-[24vw]" : "w-max" currentPhotos.length > 1
? "grid grid-cols-3 gap-1.5 min-h-[24vw]"
: "auto"
}`} }`}
> >
{currentPhotos.map((item, index) => { {currentPhotos.map((item, index) => {
@ -266,12 +275,24 @@ export default function Photos({
placeholder={ placeholder={
<div className="w-full min-h-[24vw] bg-[#1d1d1d] rounded"></div> <div className="w-full min-h-[24vw] bg-[#1d1d1d] rounded"></div>
} }
width={currentPhotos.length > 1 ? "24vw" : item.w>item.h?`calc(100vw - 72px - 2rem)`:`calc(46vw * ${item.w/item.h})`} width={
height={currentPhotos.length > 1 ? "24vw" : item.w>item.h? `calc((100vw - 72px - 2rem) * ${item.h/item.w})`:"46vw"} currentPhotos.length > 1
? "24vw"
: item.w > item.h
? `calc(100vw - 72px - 2rem)`
: `calc(46vw * ${item.w / item.h})`
}
height={
currentPhotos.length > 1
? "24vw"
: item.w > item.h
? `calc((100vw - 72px - 2rem) * ${item.h / item.w})`
: "46vw"
}
className={`rounded max-w-full ${ className={`rounded max-w-full ${
item?.type == "hid" && type == "space" ? "imageBlur" : "" item?.type == "hid" && type == "space" ? "imageBlur" : ""
}`} }`}
fit={currentPhotos.length > 1?"cover":"contain"} fit={currentPhotos.length > 1 ? "cover" : "contain"}
src={item?.url} src={item?.url}
/> />
</div> </div>