|
|
@@ -1,5 +1,5 @@
|
|
|
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
|
-import React, { useState, useEffect, useRef } from 'react'
|
|
|
+import React, { useState, useEffect, useRef, useCallback } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
import { isPc } from '@/utils/http'
|
|
|
import { Tooltip } from 'antd'
|
|
|
@@ -8,28 +8,37 @@ import classNames from 'classnames'
|
|
|
import { modalTxtTab } from './data'
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import { RootState } from '@/store'
|
|
|
+import { forwardRef, useImperativeHandle } from 'react'
|
|
|
|
|
|
-function ModalTxt({
|
|
|
- setIsShowTabBar,
|
|
|
- setIsShowMzmTitle,
|
|
|
- setBottomTxt
|
|
|
-}: {
|
|
|
+type Props = {
|
|
|
setIsShowTabBar: (isShowTabBar: boolean) => void
|
|
|
setIsShowMzmTitle: (isShowMzmTitle: boolean) => void
|
|
|
setBottomTxt: (val: string) => void
|
|
|
-}) {
|
|
|
+ ref: any
|
|
|
+}
|
|
|
|
|
|
- const {myData} = useSelector((state: RootState) => state.A0Layout)
|
|
|
+function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle, setBottomTxt }: Props, ref: any) {
|
|
|
+ const { myData } = useSelector((state: RootState) => state.A0Layout)
|
|
|
|
|
|
const [selectedTab, setSelectedTab] = useState(0)
|
|
|
const selectedTabRef = useRef(0)
|
|
|
- useEffect(() => {
|
|
|
- selectedTabRef.current = selectedTab
|
|
|
- }, [selectedTab])
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- console.log(selectedTab, ',============')
|
|
|
- }, [selectedTab])
|
|
|
+ useEffect(()=>{
|
|
|
+ selectedTabRef.current=selectedTab
|
|
|
+ },[selectedTab])
|
|
|
+
|
|
|
+ const sonSetStaFu = useCallback(() => {
|
|
|
+ setSelectedTab(0)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // 可以让父组件调用子组件的方法
|
|
|
+ useImperativeHandle(ref, () => ({
|
|
|
+ sonSetStaFu
|
|
|
+ }))
|
|
|
+
|
|
|
+ // useEffect(() => {
|
|
|
+ // console.log(selectedTab, ',============')
|
|
|
+ // }, [selectedTab])
|
|
|
|
|
|
const [activeAId, setActiveAId] = useState<number | null>(null)
|
|
|
const [showTooltip, setShowTooltip] = useState(-1)
|
|
|
@@ -39,7 +48,7 @@ function ModalTxt({
|
|
|
const contentRef = useRef<any>(null)
|
|
|
const originStartX = useRef<number>(0)
|
|
|
const translateStartX = useRef<number>(0)
|
|
|
- const contentStartX = useRef<number>(0)
|
|
|
+ // const contentStartX = useRef<number>(0)
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (selectedTab !== 0) {
|
|
|
@@ -56,21 +65,21 @@ function ModalTxt({
|
|
|
}, [selectedTab])
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const tooltipContent = document.getElementById('tooltipContent')
|
|
|
+ // const tooltipContent = document.getElementById('tooltipContent')
|
|
|
const OriContent = document.getElementById('OriContent')
|
|
|
- const introContent = document.getElementById('introContent')
|
|
|
+ // const introContent = document.getElementById('introContent')
|
|
|
const TransContent = document.getElementById('TransContent')
|
|
|
- console.log(TransContent, 'TransContent')
|
|
|
+ // console.log(TransContent, 'TransContent')
|
|
|
// // 新增滚动同步逻辑
|
|
|
- let isSyncing = false
|
|
|
+ // let isSyncing = false
|
|
|
|
|
|
- const syncScroll = (source: HTMLElement, target: HTMLElement) => {
|
|
|
- if (!isSyncing) {
|
|
|
- isSyncing = true
|
|
|
- target.scrollTop = source.scrollTop
|
|
|
- setTimeout(() => isSyncing = false, 100)
|
|
|
- }
|
|
|
- }
|
|
|
+ // const syncScroll = (source: HTMLElement, target: HTMLElement) => {
|
|
|
+ // if (!isSyncing) {
|
|
|
+ // isSyncing = true
|
|
|
+ // target.scrollTop = source.scrollTop
|
|
|
+ // setTimeout(() => isSyncing = false, 100)
|
|
|
+ // }
|
|
|
+ // }
|
|
|
|
|
|
const handleOriScroll = () => {
|
|
|
if (OriContent && TransContent) {
|
|
|
@@ -110,7 +119,7 @@ function ModalTxt({
|
|
|
|
|
|
if (OriContent && TransContent) {
|
|
|
OriContent.scrollTop += deltaX * 0.06
|
|
|
- console.log(OriContent.scrollTop, 'scrollTop')
|
|
|
+ // console.log(OriContent.scrollTop, 'scrollTop')
|
|
|
TransContent.scrollTop = OriContent.scrollTop
|
|
|
}
|
|
|
}
|
|
|
@@ -128,7 +137,9 @@ function ModalTxt({
|
|
|
// 处理触摸开始事件
|
|
|
|
|
|
if (OriContent) {
|
|
|
- OriContent.addEventListener('touchstart', (e) => { handleStart(e, originStartX) })
|
|
|
+ OriContent.addEventListener('touchstart', e => {
|
|
|
+ handleStart(e, originStartX)
|
|
|
+ })
|
|
|
OriContent.addEventListener('touchmove', handlerOri)
|
|
|
OriContent.addEventListener('scroll', handleOriScroll)
|
|
|
}
|
|
|
@@ -145,25 +156,29 @@ function ModalTxt({
|
|
|
// }
|
|
|
// }
|
|
|
if (TransContent) {
|
|
|
- console.log(TransContent, 'TransContent')
|
|
|
- TransContent.addEventListener('touchstart', (e) => { handleStart(e, translateStartX) })
|
|
|
+ // console.log(TransContent, 'TransContent')
|
|
|
+ TransContent.addEventListener('touchstart', e => {
|
|
|
+ handleStart(e, translateStartX)
|
|
|
+ })
|
|
|
TransContent.addEventListener('touchmove', handlerTrans)
|
|
|
TransContent.addEventListener('scroll', handleTransScroll)
|
|
|
}
|
|
|
if (OriContent && TransContent) {
|
|
|
return () => {
|
|
|
- OriContent.removeEventListener('touchstart', (e) => { handleStart(e, originStartX) })
|
|
|
+ OriContent.removeEventListener('touchstart', e => {
|
|
|
+ handleStart(e, originStartX)
|
|
|
+ })
|
|
|
OriContent.removeEventListener('touchmove', handlerOri) // 保持参数一致
|
|
|
OriContent.removeEventListener('scroll', handleOriScroll)
|
|
|
- TransContent.removeEventListener('touchstart', (e) => { handleStart(e, translateStartX) })
|
|
|
+ TransContent.removeEventListener('touchstart', e => {
|
|
|
+ handleStart(e, translateStartX)
|
|
|
+ })
|
|
|
TransContent.removeEventListener('touchmove', handlerTrans) // 保持参数一致
|
|
|
TransContent.removeEventListener('scroll', handleTransScroll)
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}, [selectedTab])
|
|
|
|
|
|
-
|
|
|
//动态加入a标签
|
|
|
const CommentLink = ({
|
|
|
index,
|
|
|
@@ -176,10 +191,10 @@ function ModalTxt({
|
|
|
define: string
|
|
|
inset: string
|
|
|
}) => {
|
|
|
- const dragFlag = useRef(false); // 新增拖拽标志位
|
|
|
+ const dragFlag = useRef(false) // 新增拖拽标志位
|
|
|
|
|
|
const handleClick = () => {
|
|
|
- if (dragFlag.current) return; // 如果是拖拽操作则直接返回
|
|
|
+ if (dragFlag.current) return // 如果是拖拽操作则直接返回
|
|
|
setActiveAId(index)
|
|
|
setShowTooltip(index)
|
|
|
const tooltip = document.querySelector('.ant-tooltip') as HTMLElement
|
|
|
@@ -208,11 +223,7 @@ function ModalTxt({
|
|
|
<img src={require('@/assets/img/close.png')} alt='' draggable='false' />
|
|
|
</div>
|
|
|
</div>
|
|
|
- <div
|
|
|
- className='content'
|
|
|
- id='tooltipContent'
|
|
|
- ref={contentRef}
|
|
|
- >
|
|
|
+ <div className='content' id='tooltipContent' ref={contentRef}>
|
|
|
{define}
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -227,14 +238,15 @@ function ModalTxt({
|
|
|
<a
|
|
|
key={index}
|
|
|
className={activeAId === index ? 'active' : ''}
|
|
|
- onTouchStart={() => dragFlag.current = false} // 触摸开始时重置标志位
|
|
|
- onTouchMove={() => dragFlag.current = true} // 检测到移动时标记为拖拽
|
|
|
- onTouchEnd={(e) => {
|
|
|
- if (!dragFlag.current) { // 只有非拖拽操作才处理
|
|
|
- handleClick();
|
|
|
+ onTouchStart={() => (dragFlag.current = false)} // 触摸开始时重置标志位
|
|
|
+ onTouchMove={() => (dragFlag.current = true)} // 检测到移动时标记为拖拽
|
|
|
+ onTouchEnd={e => {
|
|
|
+ if (!dragFlag.current) {
|
|
|
+ // 只有非拖拽操作才处理
|
|
|
+ handleClick()
|
|
|
}
|
|
|
- e.preventDefault();
|
|
|
- e.stopPropagation();
|
|
|
+ e.preventDefault()
|
|
|
+ e.stopPropagation()
|
|
|
}}
|
|
|
onClick={handleClick}
|
|
|
>
|
|
|
@@ -311,18 +323,19 @@ function ModalTxt({
|
|
|
callIframeFu('showInscription', 0)
|
|
|
}
|
|
|
|
|
|
- const handleTabClick = (tabIndex: number, txt: string) => {
|
|
|
- setBottomTxt(txt)
|
|
|
-
|
|
|
+ const handleTabClick = useCallback((tabIndex: number, txt: string) => {
|
|
|
let index = tabIndex
|
|
|
- if (selectedTabRef.current === index) index = 0
|
|
|
|
|
|
+ const flag = selectedTabRef.current === index
|
|
|
+
|
|
|
+ if (flag) index = 0
|
|
|
+ setBottomTxt(flag ? '' : txt)
|
|
|
setSelectedTab(index)
|
|
|
callIframeFu('showInscription', index === 0 ? -1 : index)
|
|
|
|
|
|
if (index === 0) setIsShowMzmTitle(false)
|
|
|
}
|
|
|
-
|
|
|
+,[setBottomTxt, setIsShowMzmTitle])
|
|
|
return (
|
|
|
<div className={classNames(styles.modalTxt, isPc ? '' : styles.modalTxtMo)} id='modalTxt'>
|
|
|
<div className='modalTxtContainner'>
|
|
|
@@ -335,10 +348,15 @@ function ModalTxt({
|
|
|
</div>
|
|
|
|
|
|
{modalTxtTab.map((item, index) => (
|
|
|
- <div key={item.key} className={`tab${index}`} onClick={() => handleTabClick(item.key, myData.readDetail[index]?.mzmtz?.title)}>
|
|
|
+ <div
|
|
|
+ key={item.key}
|
|
|
+ className={`tab${index}`}
|
|
|
+ onClick={() => handleTabClick(item.key, myData.readDetail[index]?.mzmtz?.title)}
|
|
|
+ >
|
|
|
<img
|
|
|
- src={require(`@/assets/img/btn_ModalTxt_bg${selectedTab === item.key ? '_ac' : ''
|
|
|
- }.png`)}
|
|
|
+ src={require(`@/assets/img/btn_ModalTxt_bg${
|
|
|
+ selectedTab === item.key ? '_ac' : ''
|
|
|
+ }.png`)}
|
|
|
alt=''
|
|
|
/>
|
|
|
<div className={`tabNub ${selectedTab === item.key ? 'tabNubAc' : ''}`}>
|
|
|
@@ -352,8 +370,6 @@ function ModalTxt({
|
|
|
</div>
|
|
|
</div>
|
|
|
))}
|
|
|
-
|
|
|
-
|
|
|
</div>
|
|
|
|
|
|
<div
|
|
|
@@ -371,11 +387,7 @@ function ModalTxt({
|
|
|
<div className='detailTxt'>
|
|
|
<div className='left'>
|
|
|
<div className='title'>原文</div>
|
|
|
- <div
|
|
|
- className='txt'
|
|
|
- ref={originRef}
|
|
|
- id='OriContent'
|
|
|
- >
|
|
|
+ <div className='txt' ref={originRef} id='OriContent'>
|
|
|
{CommentText({
|
|
|
str: myData.readDetail[selectedTab - 1].origin,
|
|
|
index: selectedTab - 1
|
|
|
@@ -398,9 +410,7 @@ function ModalTxt({
|
|
|
<div className='content'>
|
|
|
<div className='title myFont'>碑文概述</div>
|
|
|
<div className='text'>
|
|
|
- <p>
|
|
|
- 碑额留出高约15厘米的空白范围,仅在碑额左侧题写造碑日期。《山西通志》指出:其“碑额题‘大魏天平元年岁次甲寅十一月庚辰朔三日壬午造讫’岁月书额,唐贞观晋祠铭以前,此为仅见”。
|
|
|
- </p>
|
|
|
+
|
|
|
<p>
|
|
|
程哲碑碑文,31行楷书,满行45字,字径约2厘米,带方界格,总计1404字;未刻正式碑名。通篇颂德程氏家族的历史功绩。
|
|
|
</p>
|
|
|
@@ -411,7 +421,4 @@ function ModalTxt({
|
|
|
</div>
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
-const MemoModalTxt = React.memo(ModalTxt)
|
|
|
-
|
|
|
-export default MemoModalTxt
|
|
|
+export default forwardRef(ModalTxt)
|