import React, { useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import { HomeDataRow, myData, myUrl } from '@/utils/history' import classNmaes from 'classnames' import A1info from './A1info' function A1home() { const domRef = useRef(null) const [moveId, setMoveId] = useState(0) const timeRef = useRef(-1) const [time, setTime] = useState(false) const timeValRef = useRef(false) useEffect(() => { timeValRef.current = time }, [time]) useEffect(() => { if (moveId) { timeRef.current = window.setInterval(() => { setTime(!timeValRef.current) }, 500) } else clearInterval(timeRef.current) }, [moveId]) useEffect(() => { const urlAll = window.location.href if (urlAll.includes('?m=')) { const idArr = urlAll.split('?m=') if (idArr && idArr[1]) { const id = Number(idArr[1]) const index = myData.homeData.findIndex(v => v.id === id) if (index > -1 && domRef.current) { setMoveId(id) setTimeout(() => { setMoveId(0) }, 5000) domRef.current.scrollTo({ top: (index - 1) * 190, behavior: 'smooth' }) } } } }, []) // 打开详情 const [open, setOpen] = useState({} as HomeDataRow) return (
{myData.homeData.map(v => (
{ setOpen(v) setMoveId(0) }} className={classNmaes('A1row', moveId === v.id ? 'A1rowAcMove' : '')} key={v.id} >
{v.name}
{v.txt}
))}
{/* 打开详情 */} {open.id ? setOpen({} as HomeDataRow)} /> : null}
) } const MemoA1home = React.memo(A1home) export default MemoA1home