|
@@ -5,6 +5,7 @@ import Right from '@/pages/components/Right'
|
|
|
import BottomSearch from '@/pages/components/BottomSearch'
|
|
import BottomSearch from '@/pages/components/BottomSearch'
|
|
|
import MapTab from '@/pages/components/MapTab'
|
|
import MapTab from '@/pages/components/MapTab'
|
|
|
import Detail from '@/pages/components/Detail'
|
|
import Detail from '@/pages/components/Detail'
|
|
|
|
|
+import isMobile from '@/utils/isMobile'
|
|
|
import { ReactComponent as MapSvg } from '@/assets/img/map.svg'
|
|
import { ReactComponent as MapSvg } from '@/assets/img/map.svg'
|
|
|
import svgPanZoom from 'svg-pan-zoom'
|
|
import svgPanZoom from 'svg-pan-zoom'
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
@@ -23,6 +24,7 @@ import { cityIdToName, addDefs, nameToCityId } from '@/pages/A1home/util'
|
|
|
function A1home() {
|
|
function A1home() {
|
|
|
const svgRef = useRef<SVGSVGElement>(null)
|
|
const svgRef = useRef<SVGSVGElement>(null)
|
|
|
const panZoomInstance = useRef<ReturnType<typeof svgPanZoom> | null>(null)
|
|
const panZoomInstance = useRef<ReturnType<typeof svgPanZoom> | null>(null)
|
|
|
|
|
+ // 控制动画效果
|
|
|
const [isAddClassName, setIsAddClassName] = useState(false)
|
|
const [isAddClassName, setIsAddClassName] = useState(false)
|
|
|
const [curCityId, setCurCityId] = useState('')
|
|
const [curCityId, setCurCityId] = useState('')
|
|
|
const [isDragging, setIsDragging] = useState(false)
|
|
const [isDragging, setIsDragging] = useState(false)
|
|
@@ -75,12 +77,15 @@ function A1home() {
|
|
|
const { list: listAll } = useSelector((state: RootState) => state.Martyr.tableInfo)
|
|
const { list: listAll } = useSelector((state: RootState) => state.Martyr.tableInfo)
|
|
|
const martyrListByCity = useMemo(
|
|
const martyrListByCity = useMemo(
|
|
|
() =>
|
|
() =>
|
|
|
- listAll.reduce((acc, current) => {
|
|
|
|
|
- const key = current.nativeCity
|
|
|
|
|
- if (!acc[key]) acc[key] = []
|
|
|
|
|
- acc[key].push(current)
|
|
|
|
|
- return acc
|
|
|
|
|
- }, {} as Record<string, typeof listAll>),
|
|
|
|
|
|
|
+ listAll.reduce(
|
|
|
|
|
+ (acc, current) => {
|
|
|
|
|
+ const key = current.nativeCity
|
|
|
|
|
+ if (!acc[key]) acc[key] = []
|
|
|
|
|
+ acc[key].push(current)
|
|
|
|
|
+ return acc
|
|
|
|
|
+ },
|
|
|
|
|
+ {} as Record<string, typeof listAll>
|
|
|
|
|
+ ),
|
|
|
[listAll]
|
|
[listAll]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
@@ -90,28 +95,35 @@ function A1home() {
|
|
|
getListFu()
|
|
getListFu()
|
|
|
getRelativeList().then(res => {
|
|
getRelativeList().then(res => {
|
|
|
setRelativeList(
|
|
setRelativeList(
|
|
|
- res.data.reduce((acc: Record<string, RelativeItem[]>, current: RelativeItem) => {
|
|
|
|
|
- const key = current.city
|
|
|
|
|
- if (!acc[key]) acc[key] = []
|
|
|
|
|
- acc[key].push(current)
|
|
|
|
|
- return acc
|
|
|
|
|
- }, {} as Record<string, typeof listAll>)
|
|
|
|
|
|
|
+ res.data.reduce(
|
|
|
|
|
+ (acc: Record<string, RelativeItem[]>, current: RelativeItem) => {
|
|
|
|
|
+ const key = current.city
|
|
|
|
|
+ if (!acc[key]) acc[key] = []
|
|
|
|
|
+ acc[key].push(current)
|
|
|
|
|
+ return acc
|
|
|
|
|
+ },
|
|
|
|
|
+ {} as Record<string, typeof listAll>
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
getClueList().then(res => {
|
|
getClueList().then(res => {
|
|
|
setClueList(
|
|
setClueList(
|
|
|
- res.data.reduce((acc: Record<string, ClueItem[]>, current: ClueItem) => {
|
|
|
|
|
- const key = current.city
|
|
|
|
|
- if (!acc[key]) acc[key] = []
|
|
|
|
|
- acc[key].push(current)
|
|
|
|
|
- return acc
|
|
|
|
|
- }, {} as Record<string, typeof listAll>)
|
|
|
|
|
|
|
+ res.data.reduce(
|
|
|
|
|
+ (acc: Record<string, ClueItem[]>, current: ClueItem) => {
|
|
|
|
|
+ const key = current.city
|
|
|
|
|
+ if (!acc[key]) acc[key] = []
|
|
|
|
|
+ acc[key].push(current)
|
|
|
|
|
+ return acc
|
|
|
|
|
+ },
|
|
|
|
|
+ {} as Record<string, typeof listAll>
|
|
|
|
|
+ )
|
|
|
)
|
|
)
|
|
|
})
|
|
})
|
|
|
}, [getClueList, getListFu, getRelativeList])
|
|
}, [getClueList, getListFu, getRelativeList])
|
|
|
|
|
|
|
|
// 聚焦到指定城市
|
|
// 聚焦到指定城市
|
|
|
const focusOnCity = useCallback((cityId: string) => {
|
|
const focusOnCity = useCallback((cityId: string) => {
|
|
|
|
|
+ console.log('00000000000000000000000')
|
|
|
if (panZoomInstance.current && svgRef.current && cityId) {
|
|
if (panZoomInstance.current && svgRef.current && cityId) {
|
|
|
const zoomLevel = 1.8
|
|
const zoomLevel = 1.8
|
|
|
const svgPoint = svgRef.current.createSVGPoint()
|
|
const svgPoint = svgRef.current.createSVGPoint()
|
|
@@ -254,14 +266,14 @@ function A1home() {
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// 鼠标移入移出点击城市版块
|
|
// 鼠标移入移出点击城市版块
|
|
|
- const mouseEnter = useCallback((e: MouseEvent) => {
|
|
|
|
|
|
|
+ const mouseEnter = useCallback((e: MouseEvent | TouchEvent) => {
|
|
|
const target = e.target as SVGElement
|
|
const target = e.target as SVGElement
|
|
|
const tooltip = svgRef.current?.querySelector(`#tap-${target.id}Tooltip`)
|
|
const tooltip = svgRef.current?.querySelector(`#tap-${target.id}Tooltip`)
|
|
|
if (tooltip) {
|
|
if (tooltip) {
|
|
|
;(tooltip as HTMLElement).style.opacity = '1'
|
|
;(tooltip as HTMLElement).style.opacity = '1'
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
- const mouseLeave = useCallback((e: MouseEvent) => {
|
|
|
|
|
|
|
+ const mouseLeave = useCallback((e: MouseEvent | TouchEvent) => {
|
|
|
const target = e.target as SVGElement
|
|
const target = e.target as SVGElement
|
|
|
const tooltip = svgRef.current?.querySelector(`#tap-${target.id}Tooltip`)
|
|
const tooltip = svgRef.current?.querySelector(`#tap-${target.id}Tooltip`)
|
|
|
if (tooltip) {
|
|
if (tooltip) {
|
|
@@ -269,7 +281,7 @@ function A1home() {
|
|
|
}
|
|
}
|
|
|
}, [])
|
|
}, [])
|
|
|
const clickCity = useCallback(
|
|
const clickCity = useCallback(
|
|
|
- (e: MouseEvent) => {
|
|
|
|
|
|
|
+ (e: MouseEvent | TouchEvent) => {
|
|
|
if (isDragging) {
|
|
if (isDragging) {
|
|
|
// 添加拖拽状态判断
|
|
// 添加拖拽状态判断
|
|
|
setIsDragging(false)
|
|
setIsDragging(false)
|
|
@@ -391,9 +403,9 @@ function A1home() {
|
|
|
svgRef.current.style.height = '100%'
|
|
svgRef.current.style.height = '100%'
|
|
|
panZoomInstance.current = svgPanZoom(svgRef.current, {
|
|
panZoomInstance.current = svgPanZoom(svgRef.current, {
|
|
|
zoomEnabled: true,
|
|
zoomEnabled: true,
|
|
|
- dblClickZoomEnabled: false,
|
|
|
|
|
|
|
+ dblClickZoomEnabled: isMobile() ? true : false,
|
|
|
|
|
+ controlIconsEnabled: true,
|
|
|
panEnabled: true,
|
|
panEnabled: true,
|
|
|
- controlIconsEnabled: false,
|
|
|
|
|
fit: true,
|
|
fit: true,
|
|
|
center: true,
|
|
center: true,
|
|
|
onPan: () => {
|
|
onPan: () => {
|
|
@@ -414,6 +426,11 @@ function A1home() {
|
|
|
setEnableTooltipEvents(true)
|
|
setEnableTooltipEvents(true)
|
|
|
removeArrows()
|
|
removeArrows()
|
|
|
})
|
|
})
|
|
|
|
|
+ viewport.addEventListener('touchend', e => {
|
|
|
|
|
+ setIsAddClassName(false)
|
|
|
|
|
+ setEnableTooltipEvents(true)
|
|
|
|
|
+ removeArrows()
|
|
|
|
|
+ })
|
|
|
viewport.dispatchEvent(new MouseEvent('click'))
|
|
viewport.dispatchEvent(new MouseEvent('click'))
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -453,11 +470,12 @@ function A1home() {
|
|
|
item.removeEventListener('mouseenter', mouseEnter)
|
|
item.removeEventListener('mouseenter', mouseEnter)
|
|
|
item.removeEventListener('mouseleave', mouseLeave)
|
|
item.removeEventListener('mouseleave', mouseLeave)
|
|
|
item.removeEventListener('click', clickCity)
|
|
item.removeEventListener('click', clickCity)
|
|
|
-
|
|
|
|
|
|
|
+ item.removeEventListener('touchend', clickCity)
|
|
|
if (enableTooltipEvents) {
|
|
if (enableTooltipEvents) {
|
|
|
item.addEventListener('mouseenter', mouseEnter)
|
|
item.addEventListener('mouseenter', mouseEnter)
|
|
|
item.addEventListener('mouseleave', mouseLeave)
|
|
item.addEventListener('mouseleave', mouseLeave)
|
|
|
item.addEventListener('click', clickCity)
|
|
item.addEventListener('click', clickCity)
|
|
|
|
|
+ item.addEventListener('touchend', clickCity)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
return () => {
|
|
return () => {
|
|
@@ -465,6 +483,7 @@ function A1home() {
|
|
|
item.removeEventListener('mouseenter', mouseEnter)
|
|
item.removeEventListener('mouseenter', mouseEnter)
|
|
|
item.removeEventListener('mouseleave', mouseLeave)
|
|
item.removeEventListener('mouseleave', mouseLeave)
|
|
|
item.removeEventListener('click', clickCity)
|
|
item.removeEventListener('click', clickCity)
|
|
|
|
|
+ item.removeEventListener('touchend', clickCity)
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|