|
|
@@ -3,8 +3,7 @@ import React, { useState, useEffect, useRef } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
import { myData } from '@/utils/http'
|
|
|
import { Tooltip } from 'antd'
|
|
|
-import { renderToString } from 'react-dom/server';
|
|
|
-import history, { callIframeFu, isMobiileFu } from '@/utils/history'
|
|
|
+import { callIframeFu, isMobiileFu } from '@/utils/history'
|
|
|
|
|
|
function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (isShowTabBar: boolean) => void; setIsShowMzmTitle: (isShowMzmTitle: boolean) => void }) {
|
|
|
const [selectedTab, setSelectedTab] = useState(0)
|
|
|
@@ -12,6 +11,11 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (is
|
|
|
const [activeAId, setActiveAId] = useState<number | null>(null)
|
|
|
const [showTooltip, setShowTooltip] = useState(-1)
|
|
|
|
|
|
+ const ori_touchStartX = useRef(0);
|
|
|
+ const trans_touchStartX = useRef(0);
|
|
|
+ const originRef = useRef<any>(null);
|
|
|
+ const translateRef = useRef<any>(null);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (selectedTab !== 0) {
|
|
|
setIsShowMzmTitle(true)
|
|
|
@@ -24,6 +28,30 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (is
|
|
|
localStorage.setItem('selectedBeiwen', selectedTab.toString())
|
|
|
}, [selectedTab])
|
|
|
|
|
|
+ // 由于移动端旋转得到,滚动的xy轴需要对调
|
|
|
+
|
|
|
+ // 处理触摸移动事件
|
|
|
+ const handleOriTouchMove = (e: any) => {
|
|
|
+ e.preventDefault();
|
|
|
+ const deltaX = e.touches[0].clientX - ori_touchStartX.current;
|
|
|
+ if (originRef.current) {
|
|
|
+ originRef.current.scrollTop += deltaX;
|
|
|
+ }
|
|
|
+ ori_touchStartX.current = e.touches[0].clientX;
|
|
|
+ };
|
|
|
+ const handleTransTouchMove = (e: any) => {
|
|
|
+ e.preventDefault();
|
|
|
+ const deltaX = e.touches[0].clientX - trans_touchStartX.current;
|
|
|
+ if (translateRef.current) {
|
|
|
+ translateRef.current.scrollTop += deltaX;
|
|
|
+ }
|
|
|
+ trans_touchStartX.current = e.touches[0].clientX;
|
|
|
+ };
|
|
|
+ // 处理触摸开始事件
|
|
|
+ const handleTouchStart = (e: any, start: any) => {
|
|
|
+ start.current = e.touches[0].clientX;
|
|
|
+ };
|
|
|
+
|
|
|
//动态加入a标签
|
|
|
const CommentLink = ({ index, word, define, inset }: { index: number; word: string; define: string; inset: string }) => {
|
|
|
const handleClick = () => {
|
|
|
@@ -49,7 +77,7 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (is
|
|
|
open={showTooltip === index}
|
|
|
trigger='click'
|
|
|
placement='topLeft'
|
|
|
- align={{ offset: [-30, 0] }}
|
|
|
+ align={{ offset: [-45, 0] }}
|
|
|
arrow={false}
|
|
|
>
|
|
|
<a key={index} className={activeAId === index ? 'active' : ''} onTouchEnd={handleClick} onClick={handleClick} >
|
|
|
@@ -197,7 +225,7 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (is
|
|
|
<div className='detailTxt'>
|
|
|
<div className='left'>
|
|
|
<div className='title'>原文</div>
|
|
|
- <div className='txt'>
|
|
|
+ <div className='txt' onTouchMove={handleOriTouchMove} onTouchStart={(e) => handleTouchStart(e, ori_touchStartX)} ref={originRef}>
|
|
|
{CommentText({
|
|
|
str: myData.readDetail[selectedTab - 1].origin,
|
|
|
index: selectedTab - 1
|
|
|
@@ -206,7 +234,7 @@ function ModalTxt({ setIsShowTabBar, setIsShowMzmTitle }: { setIsShowTabBar: (is
|
|
|
</div>
|
|
|
<div className='right'>
|
|
|
<div className='title'>译文</div>
|
|
|
- <div className='txt'>{myData.readDetail[selectedTab - 1].translate}</div>
|
|
|
+ <div className='txt' onTouchMove={handleTransTouchMove} onTouchStart={(e) => handleTouchStart(e, trans_touchStartX)} ref={translateRef} dangerouslySetInnerHTML={{ __html: myData.readDetail[selectedTab - 1].translate }}></div>
|
|
|
</div>
|
|
|
</div>
|
|
|
)}
|