From b92acb7a353576bd10dd48a5379218662a1dc8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=BF=83=E5=AE=87?= Date: Wed, 17 Jan 2024 10:23:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E7=A7=BB=E5=8A=A8=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/forge/Information/Pages/newsDetail.jsx | 32 ++++++++-------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/forge/Information/Pages/newsDetail.jsx b/src/forge/Information/Pages/newsDetail.jsx index 713fe41ba..6ccd5c375 100644 --- a/src/forge/Information/Pages/newsDetail.jsx +++ b/src/forge/Information/Pages/newsDetail.jsx @@ -19,10 +19,16 @@ function NewsDetail(props){ const [ isSpin , setIsSpin]=useState(false); const [ commentReload, setCommentReload] = useState(undefined); const temp = props.temp; - const { zonedetail, sectionCmsTitle, mainTitle } = props.data; + const zonedetail = props.data; useEffect(()=>{ let initialContent = undefined; + // 设置网页标题 + if(detail){ + const { name, cmsDir, summary} = detail; + document.title = `${ name }/${ cmsDir.name }`; + addMeta('Keywords', `${ name },${ cmsDir.name },${ summary }`); + } if(IsPC() && zonedetail){ setTimeout(()=>{ window.scrollTo(0,1); @@ -33,10 +39,13 @@ function NewsDetail(props){ document.querySelector('meta[name="viewport"]').setAttribute('content','width=device-width, user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0'); } return()=>{ - document.title = mainTitle; if(IsPC()){ document.querySelector('meta[name="viewport"]').setAttribute('content', initialContent); } + if (zonedetail) { + document.title= zonedetail.mainTitle; + setSeoMeta(`${zonedetail.name},`, zonedetail.name, zonedetail.subTitle, `/zone/${deptId}`) + } } },[zonedetail,detail]) @@ -47,23 +56,6 @@ function NewsDetail(props){ } },[id]) - useEffect(()=>{ - // 设置网页标题 - if(detail){ - const { name, cmsDir, summary} = detail; - document.title = `${ name }/${ cmsDir.name }`; - addMeta('Keywords', `${ name },${ cmsDir.name },${ summary }`); - } - return componentWillUnmount - }, [detail]) - - function componentWillUnmount() { - if (zonedetail) { - document.title= zonedetail.name; - setSeoMeta(`${zonedetail.name},`, zonedetail.name, zonedetail.subTitle, `/zone/${deptId}`) - } - } - function getDetails(){ setIsSpin(true) getNewsDetail(id).then(result=>{ @@ -100,7 +92,7 @@ function NewsDetail(props){ { !IsPC() && - { sectionCmsTitle } + { zonedetail.sectionCmsTitle } { cmsDir && {cmsDir.name} } 正文