import { baseURL } from '@/utils/http' import classNames from 'classnames' import styles from './index.module.scss' import logoImg from '@/assets/img/logo.png' import { Input, Pagination, Select } from 'antd' import { SearchOutlined, ExclamationOutlined, CloseCircleOutlined } from '@ant-design/icons'; import { useEffect, useRef, useState } from 'react' import { LazyLoadImage } from "react-lazy-load-image-component"; import { useDispatch, useSelector } from 'react-redux'; import { getListAction, getSortAction, getAgeAction } from '@/store/action/home'; import { RootState } from '@/store'; import Model from '@/components/Model' export default function Home() { const dispatch = useDispatch() // 进页面获取后端文物数据 useEffect(() => { dispatch(getSortAction()) dispatch(getAgeAction()) }, [dispatch]) // 滚动盒子ref const modelBoxRef = useRef(null) // 输入框变量 const [value, setValue] = useState('') // 清空输入框 const clearValueFu = () => { setValue('') setPageNum(1) const sroolDom = modelBoxRef.current sroolDom!.scrollTop = 0 dispatch(getListAction({ ...fromData.current, dictTextureId: fromData.current.dictTextureId === -1 ? null : fromData.current.dictTextureId, searchKey: '', pageNum: 1, dictAgeId: fromData.current.dictAgeId === -1 ? null : fromData.current.dictAgeId, })) } const searchKeyUpFu = (e: React.KeyboardEvent) => { if (e.key === 'Enter') searchBtnFu() } const searchBtnFu = () => { getModelList() } // 分类的数据和高亮 const { sortList, modelInfo, ageList } = useSelector((state: RootState) => state.homeStore) const { list, total } = modelInfo // 分类 const [sort, setSort] = useState(-1) // 分类下拉框改变 const sortChangeFu = (value: number) => { setSort(value) } // 年代 const [ageSerach, setAgeSerach] = useState(-1) // 年代下拉框改变 const ageChangeFu = (value: number) => { setAgeSerach(value) fromData.current.dictAgeId = value fromData.current.pageNum = 1 setPageNum(1) getModelList() } const [pageNum, setPageNum] = useState(1) const fromData = useRef({ pageNum: 1, pageSize: 12, searchKey: '', dictTextureId: -1, dictAgeId: -1 }) const pageChangeFu = (page: number) => { fromData.current.pageNum = page setPageNum(page) getModelList() } // 封装一个发送请求获取列表的函数 const getModelList = () => { const sroolDom = modelBoxRef.current sroolDom!.scrollTop = 0 dispatch(getListAction({ ...fromData.current, dictTextureId: fromData.current.dictTextureId === -1 ? null : fromData.current.dictTextureId, searchKey: value, dictAgeId: fromData.current.dictAgeId === -1 ? null : fromData.current.dictAgeId, })) } useEffect(() => { fromData.current.dictTextureId = sort fromData.current.pageNum = 1 setPageNum(1) getModelList() // eslint-disable-next-line react-hooks/exhaustive-deps }, [sort]) // 点击每个模型出来的页面 const [modelId, setModelId] = useState(0) return (
{/* 点击单个模型出来的详情页面 */}
setModelId(0)} />
{/* 筛选的盒子 */}
{/* 输入框 */}
{value.length > 0 ? (
) : null} setValue(e.target.value)} onKeyUp={(e) => searchKeyUpFu(e)} prefix={} />
{/* 分类下拉框 */}
{/* 页面渲染主体 */}
{ list && list.length > 0 ? list.map(item => (
setModelId(item.id)}> {/* 鼠标悬浮出来的盒子 */}
{item.name}

{item.dictTextureName ? {item.dictTextureName} : null} {item.name}

)) :

暂无内容

}
{/* 分页器 */}
) }