|
|
@@ -1,6 +1,7 @@
|
|
|
import React, { useState, useEffect } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
-import { useNavigate } from 'react-router-dom'
|
|
|
+import { useNavigate, useSearchParams } from 'react-router-dom'
|
|
|
+import { buildIntroPath } from '@/utils/detailNav'
|
|
|
import closeBtn from '@/assets/img/closeBtn.png'
|
|
|
import searchIcon from '@/assets/img/searchIcon.png'
|
|
|
import { Pagination } from 'antd'
|
|
|
@@ -9,15 +10,48 @@ import Intro2D from '../A5Intro2D'
|
|
|
import Intro3D from '../A6Intro3D'
|
|
|
function DetailPanel() {
|
|
|
const navigate = useNavigate()
|
|
|
+ const [searchParams, setSearchParams] = useSearchParams()
|
|
|
// 三维文物0,二维文物1
|
|
|
const [showTabIndex, setShowTabIndex] = useState(0)
|
|
|
// 1级:1,2级:2,3级:3,未定级:0,全部:-1
|
|
|
const [showLevelIndex, setShowLevelIndex] = useState(-1)
|
|
|
const [inputVal, setInputVal] = useState('')
|
|
|
const [oreData, setOreData] = useState([])
|
|
|
- const [currentPage, setCurrentPage] = useState(1)
|
|
|
+ const [currentPage, setCurrentPage] = useState(() => {
|
|
|
+ const page = Number(searchParams.get('page'))
|
|
|
+ return page > 0 ? page : 1
|
|
|
+ })
|
|
|
// 遮罩层
|
|
|
const [showMoodIndex, setShowMoodIndex] = useState(-1)
|
|
|
+
|
|
|
+ const resetToFirstPage = () => {
|
|
|
+ setCurrentPage(1)
|
|
|
+ setSearchParams(prev => {
|
|
|
+ const next = new URLSearchParams(prev)
|
|
|
+ next.delete('page')
|
|
|
+ return next
|
|
|
+ }, { replace: true })
|
|
|
+ }
|
|
|
+
|
|
|
+ const handlePageChange = (page: number) => {
|
|
|
+ setCurrentPage(page)
|
|
|
+ setSearchParams(prev => {
|
|
|
+ const next = new URLSearchParams(prev)
|
|
|
+ if (page <= 1) next.delete('page')
|
|
|
+ else next.set('page', String(page))
|
|
|
+ return next
|
|
|
+ }, { replace: true })
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleTabChange = (index: number) => {
|
|
|
+ setShowTabIndex(index)
|
|
|
+ resetToFirstPage()
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleSearchChange = (value: string) => {
|
|
|
+ setInputVal(value)
|
|
|
+ resetToFirstPage()
|
|
|
+ }
|
|
|
const Mood: React.FC<{ title?: string; showMood?: boolean }> = ({ title, showMood }) => {
|
|
|
return (
|
|
|
<div className={styles.mood} style={{ opacity: showMood ? '1' : '0' }}>
|
|
|
@@ -26,25 +60,25 @@ function DetailPanel() {
|
|
|
)
|
|
|
}
|
|
|
const handleLevelClick = (index: number) => {
|
|
|
- console.log(index, showLevelIndex, index === showLevelIndex)
|
|
|
if (index === showLevelIndex) {
|
|
|
setShowLevelIndex(-1)
|
|
|
} else {
|
|
|
setShowLevelIndex(index)
|
|
|
}
|
|
|
+ resetToFirstPage()
|
|
|
}
|
|
|
const searchFc = () => {
|
|
|
console.log(inputVal)
|
|
|
}
|
|
|
|
|
|
useEffect(() => {
|
|
|
- setOreData(infoTemo.oreData)
|
|
|
- }, [])
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- setCurrentPage(1)
|
|
|
setOreData(infoTemo.oreData.filter(item => item.type === showTabIndex && (item.level === showLevelIndex || showLevelIndex === -1) && item.title.includes(inputVal)))
|
|
|
}, [showLevelIndex, showTabIndex, inputVal])
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ const page = Number(searchParams.get('page'))
|
|
|
+ setCurrentPage(page > 0 ? page : 1)
|
|
|
+ }, [searchParams])
|
|
|
return (
|
|
|
<div className={styles.detailPanel}>
|
|
|
{/* 侧边栏 */}
|
|
|
@@ -52,7 +86,7 @@ function DetailPanel() {
|
|
|
<img draggable={false} src={Logo} alt='' className='Logo2' />
|
|
|
<div className='searchInp'>
|
|
|
<div className='leftSearch'>
|
|
|
- <input className='search' placeholder='请输入搜索内容' type='text' value={inputVal} onChange={e => setInputVal(e.target.value)} />
|
|
|
+ <input className='search' placeholder='请输入搜索内容' type='text' value={inputVal} onChange={e => handleSearchChange(e.target.value)} />
|
|
|
</div>
|
|
|
<div className='rightSearch'>
|
|
|
<img draggable={false} src={searchIcon} alt='' />
|
|
|
@@ -75,10 +109,10 @@ function DetailPanel() {
|
|
|
<div className='rightContainner'>
|
|
|
{/* 顶部tab */}
|
|
|
<div className='topTab'>
|
|
|
- <div className={`tab ${showTabIndex === 0 ? 'tabActive' : ''}`} onClick={() => setShowTabIndex(0)}>
|
|
|
+ <div className={`tab ${showTabIndex === 0 ? 'tabActive' : ''}`} onClick={() => handleTabChange(0)}>
|
|
|
三维文物
|
|
|
</div>
|
|
|
- <div className={`tab ${showTabIndex === 1 ? 'tabActive' : ''}`} onClick={() => setShowTabIndex(1)}>
|
|
|
+ <div className={`tab ${showTabIndex === 1 ? 'tabActive' : ''}`} onClick={() => handleTabChange(1)}>
|
|
|
二维文物
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -92,7 +126,7 @@ function DetailPanel() {
|
|
|
{oreData
|
|
|
.filter((item, index) => index >= 8 * (currentPage - 1) && index < 8 * currentPage)
|
|
|
.map((item, index) => (
|
|
|
- <div className='Ditem' onClick={() => navigate(item.type === 0 ? `/intro3D?title=${item.title}` : `/intro2D?title=${item.title}`)} onMouseEnter={() => setShowMoodIndex(index)} onMouseLeave={() => setShowMoodIndex(-1)} key={index}>
|
|
|
+ <div className='Ditem' onClick={() => navigate(buildIntroPath(item.type, item.id, currentPage))} onMouseEnter={() => setShowMoodIndex(index)} onMouseLeave={() => setShowMoodIndex(-1)} key={item.id}>
|
|
|
<img src={item.src[0]} alt='' />
|
|
|
<Mood title={item.title} showMood={showMoodIndex === index} />
|
|
|
</div>
|
|
|
@@ -105,7 +139,7 @@ function DetailPanel() {
|
|
|
{/* </div> */}
|
|
|
</div>
|
|
|
{/* 分页 */}
|
|
|
- <Pagination current={currentPage} defaultCurrent={currentPage} defaultPageSize={8} total={oreData.length} showSizeChanger={false} onChange={setCurrentPage} />
|
|
|
+ <Pagination current={currentPage} defaultPageSize={8} total={oreData.length} showSizeChanger={false} onChange={handlePageChange} />
|
|
|
|
|
|
</div>
|
|
|
</div>
|