From ffb6e93dc85d910206327af071bca53a4fffce40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 13 Apr 2025 16:09:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cms/article.tsx | 13 +++++- src/components/Header.tsx | 3 +- src/pages/index/Help.tsx | 2 +- src/pages/index/index.scss | 2 +- src/pages/index/index.tsx | 89 ++++++++++++++++++++++++++++++-------- 5 files changed, 85 insertions(+), 24 deletions(-) diff --git a/src/cms/article.tsx b/src/cms/article.tsx index 19b409d..539d185 100644 --- a/src/cms/article.tsx +++ b/src/cms/article.tsx @@ -5,6 +5,7 @@ import {CmsArticle} from "@/api/cms/cmsArticle/model"; import Taro from '@tarojs/taro' import {useRouter} from '@tarojs/taro' import Header from "@/components/Header"; +import {getCmsNavigation} from "@/api/cms/cmsNavigation"; /** * 文章终极列表 @@ -13,7 +14,15 @@ import Header from "@/components/Header"; const Article = () => { const {params} = useRouter(); const [list, setList] = useState([]) + const [title, setTitle] = useState() + const reload = () => { + getCmsNavigation(Number(params.id)).then(res => { + setTitle(res.title) + Taro.setNavigationBarTitle({ + title: `${res.title}` + }) + }) pageCmsArticle({categoryId: Number(params.id)}).then(res => { if (res?.list) { setList(res?.list) @@ -23,11 +32,11 @@ const Article = () => { useEffect(() => { reload() - }, []) + }, [params]) return ( <> -
+
diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 26d79d0..72e11cf 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -7,7 +7,8 @@ function Header(props) { <> { diff --git a/src/pages/index/Help.tsx b/src/pages/index/Help.tsx index b19833a..6b611fe 100644 --- a/src/pages/index/Help.tsx +++ b/src/pages/index/Help.tsx @@ -33,7 +33,7 @@ const Help = (props: any) => {
diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss index f79efd0..5b7e679 100644 --- a/src/pages/index/index.scss +++ b/src/pages/index/index.scss @@ -1,3 +1,3 @@ -page { +body { } diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 343ded3..a195f10 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,25 +1,27 @@ -import './index.scss' import Taro from '@tarojs/taro'; import {useEffect, useState} from "react"; import {getSiteInfo} from "@/api/layout"; import {CmsWebsite} from "@/api/cms/cmsWebsite/model"; -import {Avatar, NavBar, Grid} from '@nutui/nutui-react-taro' -import Help from "./Help"; +import {Avatar, NavBar} from '@nutui/nutui-react-taro' +// import Help from "./Help"; +import './index.scss' function Home() { const [website, setWebsite] = useState() - - const onNav = (item:any) => { - if(item.model == 'article'){ + const [screenWidth, setScreenWidth] = useState(390) + const onNav = (item: any) => { + if (item.model == 'article') { Taro.navigateTo({ url: `/cms/article?id=${item.navigationId}` }) } - if(item.model == 'links'){ + if (item.model == 'links') { window.open(item.path, '_self') } } const reload = () => { + const systemInfoSync = Taro.getSystemInfoSync(); + setScreenWidth(systemInfoSync.screenWidth) // 获取站点信息 getSiteInfo().then((data) => { console.log(data, 'siteInfo') @@ -39,7 +41,8 @@ function Home() { <> -
- - {website.topNavs?.map((item, index) => { - return ( - onNav(item)}> - - - ) - })} - +
390 ? 'url(https://oss.wsdns.cn/20250413/4650a6d214434159a5d6bf161c7a9367.png?x-oss-process=image/resize,m_fixed,w_2000/quality,Q_90) #fef2f2' : 'url(https://oss.wsdns.cn/20250413/4650a6d214434159a5d6bf161c7a9367.png?x-oss-process=image/resize,m_fixed,w_750/quality,Q_90) #fef2f2', + backgroundSize: screenWidth > 390 ? 'cover' : '100%', + backgroundPosition: 'bottom', + backgroundRepeat: 'no-repeat' + }}> + {/*PC*/} + {screenWidth > 800 && ( + <> + {website.topNavs?.map((item, index) => { + return ( +
onNav(item)}> +
+ +
+
{item.title}
+
{item.comments}
+
+
+
+ ) + })} + + )} + {/*H5*/} + { + screenWidth < 800 && ( + <> + {website.topNavs?.map((item, index) => { + return ( +
onNav(item)}> +
+ +
+
{item.title}
+
{item.comments}
+
+
+
+ ) + })} + + // <> + // + // {website.topNavs?.map((item, index) => { + // return ( + // onNav(item)}> + // + // + // ) + // })} + // + // + ) + }
- + {/**/}
)