123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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<any>(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 (
- <div
- className={styles.A1home}
- style={{ backgroundImage: `url(${myUrl + myData.homeBg})` }}
- >
- <div className='homeTitleImg'>
- <img src={myUrl + myData.homeTitleImg} alt='' />
- </div>
- <div className='box11'>
- <div className='wrap'>
- <div id='showcase' className='noselect'>
- {myData.homeData.map((v, i) => (
- <img
- key={v.id}
- className={classNmaes('cloud9-item', i === index ? 'imgAc' : '')}
- src={myUrl + v.cover}
- alt=''
- />
- ))}
- </div>
- </div>
- </div>
- {/* <div id='nav' className='noselect'>
- <button className='left'>←</button>
- <button className='right'>→</button>
- </div> */}
- <div className='A1Text'></div>
- {/* 左右滑动 */}
- <div
- className='A1MoveBox'
- onTouchStart={e => 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}
- ></div>
- {/* 打开详情 */}
- {open.id ? <A1info info={open} closeFu={() => setOpen({} as HomeDataRow)} /> : null}
- </div>
- )
- }
- const MemoA1home = React.memo(A1home)
- export default MemoA1home
|