import React, { useCallback, useEffect, useRef, useState } from 'react' import styles from './index.module.scss' import history, { HomeDataRow, isMobileFu, myData, myUrl } from '@/utils/history' import classNmaes from 'classnames' import A1info from './A1info' import { imgInitFu } from './data' import useMove from '@/components/useMove' declare global { //设置全局属性 interface Window { //window对象属性 getIndexFu: (index: number) => void moveFu: (val: any) => void } } function A1home() { // 当前索引 const [index, setIndex] = useState(-1) useEffect(() => { window.getIndexFu = index => { setIndex(index) // console.log('当前索引', index) } }, []) useEffect(() => { imgInitFu() }, []) const moveRef = useRef(null) 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) // console.log('返回的索引', index) window.moveFu = val => { moveRef.current = val if ([1, 2, 3, 4, 5, 6].includes(index)) val.go(-index) else if ([7, 8, 9, 10, 11].includes(index)) { const obj = { 11: 1, 10: 2, 9: 3, 8: 4, 7: 5 } val.go(Reflect.get(obj, index)) } } } } }, []) // 相关文物的滚动 const { touchstart, touchmove, touchend, MouseLeave, isPcMoveFlag } = useMove() const moveFu = useCallback((val: number) => { moveRef.current.go(val) }, []) // 点击进入详情页 const toInfoPage = useCallback(() => { if (isPcMoveFlag) { const id = myData.homeData[index].id history.replace(`/info/${id}`) } }, [index, isPcMoveFlag]) // 打开详情 const [open, setOpen] = useState({} as HomeDataRow) return (
{myData.homeData.map((v, i) => ( ))}
{/* */}
{/* 左右滑动 */}
touchstart(e.touches[0].pageX)} onTouchMove={e => touchmove(e.touches[0].pageX)} onTouchEnd={e => touchend(val => moveFu(val), 'mobile')} onClick={toInfoPage} onMouseUp={e => touchstart(e.clientX)} onMouseMove={e => touchmove(e.clientX)} onMouseDown={e => touchend(val => moveFu(val), 'pc')} onMouseLeave={MouseLeave} >
{/* 打开详情 */} {open.id ? setOpen({} as HomeDataRow)} /> : null}
) } const MemoA1home = React.memo(A1home) export default MemoA1home