|
|
@@ -7,6 +7,7 @@ import classNames from 'classnames'
|
|
|
import { modalTxtTab } from './data'
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import { RootState } from '@/store'
|
|
|
+import Shufa from '../Shufa'
|
|
|
import { forwardRef, useImperativeHandle } from 'react'
|
|
|
|
|
|
type Props = {
|
|
|
@@ -21,6 +22,7 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle, setBottomTxt }: Props, r
|
|
|
|
|
|
const [selectedTab, setSelectedTab] = useState(0)
|
|
|
const [isOpenTrans, setIsOpenTrans] = useState(false)
|
|
|
+ const [isShowShufa, setIsShowShufa] = useState(false)
|
|
|
const selectedTabRef = useRef(0)
|
|
|
|
|
|
useEffect(() => {
|
|
|
@@ -36,19 +38,10 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle, setBottomTxt }: Props, r
|
|
|
sonSetStaFu
|
|
|
}))
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
- // console.log(selectedTab, ',============')
|
|
|
- // }, [selectedTab])
|
|
|
-
|
|
|
const [activeAId, setActiveAId] = useState<number | null>(null)
|
|
|
const [showTooltip, setShowTooltip] = useState(-1)
|
|
|
|
|
|
- const originRef = useRef<any>(null)
|
|
|
- const translateRef = useRef<any>(null)
|
|
|
const contentRef = useRef<any>(null)
|
|
|
- const originStartX = useRef<number>(0)
|
|
|
- const translateStartX = useRef<number>(0)
|
|
|
- // const contentStartX = useRef<number>(0)
|
|
|
|
|
|
useEffect(() => {
|
|
|
if (selectedTab !== 0) {
|
|
|
@@ -65,121 +58,6 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle, setBottomTxt }: Props, r
|
|
|
localStorage.setItem('selectedBeiwen', selectedTab.toString())
|
|
|
}, [selectedTab])
|
|
|
|
|
|
- useEffect(() => {
|
|
|
- // const tooltipContent = document.getElementById('tooltipContent')
|
|
|
- const OriContent = document.getElementById('OriContent')
|
|
|
- // const introContent = document.getElementById('introContent')
|
|
|
- const TransContent = document.getElementById('TransContent')
|
|
|
- // console.log(TransContent, 'TransContent')
|
|
|
- // // 新增滚动同步逻辑
|
|
|
- // let isSyncing = false
|
|
|
-
|
|
|
- // const syncScroll = (source: HTMLElement, target: HTMLElement) => {
|
|
|
- // if (!isSyncing) {
|
|
|
- // isSyncing = true
|
|
|
- // target.scrollTop = source.scrollTop
|
|
|
- // setTimeout(() => isSyncing = false, 100)
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- const handleOriScroll = () => {
|
|
|
- if (OriContent && TransContent) {
|
|
|
- // syncScroll(OriContent, TransContent)
|
|
|
- TransContent.scrollTop = OriContent.scrollTop
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const handleTransScroll = () => {
|
|
|
- if (TransContent && OriContent) {
|
|
|
- // syncScroll(TransContent, OriContent)
|
|
|
- OriContent.scrollTop = TransContent.scrollTop
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // if (OriContent) {
|
|
|
- // OriContent.addEventListener('scroll', handleOriScroll)
|
|
|
- // }
|
|
|
- // if (TransContent) {
|
|
|
- // TransContent.addEventListener('scroll', handleTransScroll)
|
|
|
- // }
|
|
|
-
|
|
|
- // return () => {
|
|
|
- // if (OriContent) {
|
|
|
- // OriContent.removeEventListener('scroll', handleOriScroll)
|
|
|
- // }
|
|
|
- // if (TransContent) {
|
|
|
- // TransContent.removeEventListener('scroll', handleTransScroll)
|
|
|
- // }
|
|
|
- // }
|
|
|
- const handleStart = (e: TouchEvent, startX: any) => {
|
|
|
- startX.current = e.touches[0].clientX
|
|
|
- }
|
|
|
- const handlerOri = (e: TouchEvent) => {
|
|
|
- // e.stopPropagation()
|
|
|
- const deltaX = e.touches[0].clientX - originStartX.current
|
|
|
-
|
|
|
- if (OriContent && TransContent) {
|
|
|
- OriContent.scrollTop += deltaX * 0.06
|
|
|
- // console.log(OriContent.scrollTop, 'scrollTop')
|
|
|
- TransContent.scrollTop = OriContent.scrollTop
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- const handlerTrans = (e: TouchEvent) => {
|
|
|
- // e.stopPropagation()
|
|
|
- const deltaX = e.touches[0].clientX - translateStartX.current
|
|
|
-
|
|
|
- if (TransContent && OriContent) {
|
|
|
- TransContent.scrollTop += deltaX * 0.06
|
|
|
- OriContent.scrollTop = TransContent.scrollTop
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 处理触摸开始事件
|
|
|
-
|
|
|
- if (OriContent) {
|
|
|
- OriContent.addEventListener('touchstart', e => {
|
|
|
- handleStart(e, originStartX)
|
|
|
- })
|
|
|
- OriContent.addEventListener('touchmove', handlerOri)
|
|
|
- OriContent.addEventListener('scroll', handleOriScroll)
|
|
|
- }
|
|
|
- // if (tooltipContent) {
|
|
|
- // tooltipContent.addEventListener('touchmove', handler)
|
|
|
- // return () => {
|
|
|
- // tooltipContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
- // }
|
|
|
- // }
|
|
|
- // if (introContent) {
|
|
|
- // introContent.addEventListener('touchmove', handler)
|
|
|
- // return () => {
|
|
|
- // introContent.removeEventListener('touchmove', handler) // 保持参数一致
|
|
|
- // }
|
|
|
- // }
|
|
|
- if (TransContent) {
|
|
|
- // 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('touchmove', handlerOri)
|
|
|
- OriContent.removeEventListener('scroll', handleOriScroll)
|
|
|
- TransContent.removeEventListener('touchstart', e => {
|
|
|
- handleStart(e, translateStartX)
|
|
|
- })
|
|
|
- TransContent.removeEventListener('touchmove', handlerTrans)
|
|
|
- TransContent.removeEventListener('scroll', handleTransScroll)
|
|
|
- }
|
|
|
- }
|
|
|
- }, [selectedTab])
|
|
|
-
|
|
|
//动态加入a标签
|
|
|
const CommentLink = ({
|
|
|
index,
|
|
|
@@ -358,105 +236,87 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle, setBottomTxt }: Props, r
|
|
|
'程哲碑碑文,31行楷书,满行45字,<br/>字径约2厘米,带方界格,总计1404字;<br/>无正式碑名,通篇颂德程氏家族的历史功绩。'
|
|
|
|
|
|
return (
|
|
|
- <div
|
|
|
- className={classNames(styles.modalTxt, myLangue === 'ZH' ? '' : styles.modalTxtEn)}
|
|
|
- id='modalTxt'
|
|
|
- >
|
|
|
- <div className='modalTxtContainner'>
|
|
|
-
|
|
|
-
|
|
|
- {!isOpenTrans && <div
|
|
|
- className='intro'
|
|
|
- id='introContent'
|
|
|
- style={{
|
|
|
- opacity: selectedTab !== 0 ? '1' : '0',
|
|
|
- height: selectedTab !== 0 ? '78%' : '0%',
|
|
|
- width: selectedTab !== 0 ? '100%' : '0%'
|
|
|
- }}
|
|
|
- >
|
|
|
- <div className="intro_title songFont">
|
|
|
- {selectedTab !== 0 && modalTxtTab[selectedTab - 1].name}
|
|
|
- </div>
|
|
|
- <div className="intro_txt"> {selectedTab !== 0 && myData.readDetail[selectedTab - 1].intro}</div>
|
|
|
-
|
|
|
- <div className="intro_btn" onClick={() => setIsOpenTrans(true)}>原文 | 译文</div>
|
|
|
- </div>}
|
|
|
-
|
|
|
- {/* {selectedTab !== 0 && (
|
|
|
- <div className='detailTxt'>
|
|
|
- <div className='left'>
|
|
|
- <div className='title'>原文</div>
|
|
|
- <div className='txt' ref={originRef} id='OriContent'>
|
|
|
- {CommentText({
|
|
|
- str: myData.readDetail[selectedTab - 1].origin,
|
|
|
- index: selectedTab - 1
|
|
|
- })}
|
|
|
- </div>
|
|
|
+ <>
|
|
|
+ <div
|
|
|
+ className={classNames(styles.modalTxt, myLangue === 'ZH' ? '' : styles.modalTxtEn)}
|
|
|
+ id='modalTxt'
|
|
|
+ >
|
|
|
+ <div className='modalTxtContainner'>
|
|
|
+
|
|
|
+
|
|
|
+ {!isOpenTrans && <div
|
|
|
+ className='intro'
|
|
|
+ id='introContent'
|
|
|
+ style={{
|
|
|
+ opacity: selectedTab !== 0 ? '1' : '0',
|
|
|
+ height: selectedTab !== 0 ? '78%' : '0%',
|
|
|
+ width: selectedTab !== 0 ? '100%' : '0%'
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <div className="intro_title songFont">
|
|
|
+ {selectedTab !== 0 && modalTxtTab[selectedTab - 1].name}
|
|
|
</div>
|
|
|
- <div className='right'>
|
|
|
- <div className='title'>译文</div>
|
|
|
+ <div className="intro_txt"> {selectedTab !== 0 && myData.readDetail[selectedTab - 1].intro}</div>
|
|
|
+
|
|
|
+ <div className="intro_btn" onClick={() => setIsOpenTrans(true)}>原文 | 译文</div>
|
|
|
+ </div>}
|
|
|
+
|
|
|
+ {selectedTab === 0 && (
|
|
|
+ <div className='content'>
|
|
|
+ <div className='title songFontc'>
|
|
|
+ {myLangue === 'EN' ? 'Overview of the Inscription' : '碑文概述'}
|
|
|
+ </div>
|
|
|
<div
|
|
|
- className='txt'
|
|
|
- ref={translateRef}
|
|
|
- id='TransContent'
|
|
|
- dangerouslySetInnerHTML={{ __html: myData.readDetail[selectedTab - 1].translate }}
|
|
|
+ className='text'
|
|
|
+ dangerouslySetInnerHTML={{ __html: myLangue === 'EN' ? gaiShuEn : gaiShu }}
|
|
|
></div>
|
|
|
+ <div className="shufaBtn" onClick={() => setIsShowShufa(true)}>书法赏析</div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- )} */}
|
|
|
+ )}
|
|
|
|
|
|
- {selectedTab === 0 && (
|
|
|
- <div className='content'>
|
|
|
- <div className='title songFontc'>
|
|
|
- {myLangue === 'EN' ? 'Overview of the Inscription' : '碑文概述'}
|
|
|
- </div>
|
|
|
- <div
|
|
|
- className='text'
|
|
|
- dangerouslySetInnerHTML={{ __html: myLangue === 'EN' ? gaiShuEn : gaiShu }}
|
|
|
- ></div>
|
|
|
- </div>
|
|
|
- )}
|
|
|
-
|
|
|
- <div className='topBar'>
|
|
|
- <div className='beie' hidden={selectedTab !== 0}>
|
|
|
- <img src={require('@/assets/img/beie.png')} alt='' />
|
|
|
- <div className='txt songFont' onClick={handleBeie}>
|
|
|
- {myLangue === 'EN' ? 'forehead' : '碑额'}
|
|
|
+ <div className='topBar'>
|
|
|
+ <div className='beie' hidden={selectedTab !== 0}>
|
|
|
+ <img src={require('@/assets/img/beie.png')} alt='' />
|
|
|
+ <div className='txt songFont' onClick={handleBeie}>
|
|
|
+ {myLangue === 'EN' ? 'forehead' : '碑额'}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
|
|
|
- {modalTxtTab.map((item, index) => (
|
|
|
- <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`)}
|
|
|
- alt=''
|
|
|
- />
|
|
|
- <div className={`tabNub songFont ${selectedTab === item.key ? 'tabNubAc' : ''}`}>
|
|
|
- {item.sonTxt}
|
|
|
- </div>
|
|
|
+ {modalTxtTab.map((item, index) => (
|
|
|
<div
|
|
|
- className={classNames('txt songFont', selectedTab === item.key ? 'txtAc' : '')}
|
|
|
- style={{ opacity: selectedTab === 0 ? '1' : '0' }}
|
|
|
+ key={item.key}
|
|
|
+ className={`tab${index}`}
|
|
|
+ onClick={() => handleTabClick(item.key, myData.readDetail[index]?.mzmtz?.title)}
|
|
|
>
|
|
|
- {myLangue === 'EN' ? item.nameEn : item.name}
|
|
|
+ <img
|
|
|
+ src={require(`@/assets/img/btn_ModalTxt_bg${selectedTab === item.key ? '_ac' : ''
|
|
|
+ }.png`)}
|
|
|
+ alt=''
|
|
|
+ />
|
|
|
+ <div className={`tabNub songFont ${selectedTab === item.key ? 'tabNubAc' : ''}`}>
|
|
|
+ {item.sonTxt}
|
|
|
+ </div>
|
|
|
+ <div
|
|
|
+ className={classNames('txt songFont', selectedTab === item.key ? 'txtAc' : '')}
|
|
|
+ style={{ opacity: selectedTab === 0 ? '1' : '0' }}
|
|
|
+ >
|
|
|
+ {myLangue === 'EN' ? item.nameEn : item.name}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- ))}
|
|
|
- </div>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
|
|
|
- {(isOpenTrans && selectedTab !== 0) && <div className="translateModal">
|
|
|
- <div className="txtWithTrans" onTouchMove={() => setShowTooltip(-1)}> {CommentText({
|
|
|
- str: myData.readDetail[selectedTab - 1].translate_v2,
|
|
|
- index: selectedTab - 1
|
|
|
- })}</div>
|
|
|
- </div>}
|
|
|
+ {(isOpenTrans && selectedTab !== 0) && <div className="translateModal">
|
|
|
+ <div className="txtWithTrans" onTouchMove={() => setShowTooltip(-1)}> {CommentText({
|
|
|
+ str: myData.readDetail[selectedTab - 1].translate_v2,
|
|
|
+ index: selectedTab - 1
|
|
|
+ })}</div>
|
|
|
+ </div>}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
+ {/* 书法赏析 */}
|
|
|
+ {isShowShufa && <Shufa setIsShowShufa={setIsShowShufa} />}
|
|
|
+ </>
|
|
|
)
|
|
|
}
|
|
|
export default forwardRef(ModalTxt)
|