From 59f771d5422f647a13e424f4265deb5dc45b1b73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 7 Jul 2025 13:24:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8ETaro.js=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E7=9A=84H5=E5=BA=94=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/cms/cmsNavigation/index.ts | 2 - src/api/cms/cmsNavigation/model/index.ts | 2 + src/app.config.ts | 15 ++- src/app.scss | 5 + src/article/detail.config.ts | 4 + src/article/detail.scss | 128 +++++++++++++++++++++++ src/article/detail.tsx | 52 +++++++++ src/article/index.config.ts | 3 + src/article/index.tsx | 109 +++++++++++++++++++ src/custom/article/article.config.ts | 3 + src/custom/article/article.tsx | 72 +++++++++++++ src/pages/article/article.tsx | 50 --------- src/pages/article/detail.tsx | 54 ++++++++++ src/pages/index/Banner.tsx | 8 +- src/pages/index/Image.tsx | 36 +++++++ src/pages/index/Menu.tsx | 120 ++++----------------- src/pages/index/TopBanner.tsx | 33 ------ src/pages/index/index.scss | 14 +++ src/pages/index/index.tsx | 9 +- src/pages/user/user.tsx | 4 +- src/photo/detail.config.ts | 4 + src/photo/detail.scss | 128 +++++++++++++++++++++++ src/photo/detail.tsx | 52 +++++++++ src/photo/index.config.ts | 3 + src/photo/index.tsx | 109 +++++++++++++++++++ src/styles/mobile-container.scss | 93 ++++++++++++++++ 26 files changed, 919 insertions(+), 193 deletions(-) create mode 100644 src/article/detail.config.ts create mode 100644 src/article/detail.scss create mode 100644 src/article/detail.tsx create mode 100644 src/article/index.config.ts create mode 100644 src/article/index.tsx create mode 100644 src/custom/article/article.config.ts create mode 100644 src/custom/article/article.tsx delete mode 100644 src/pages/article/article.tsx create mode 100644 src/pages/article/detail.tsx create mode 100644 src/pages/index/Image.tsx delete mode 100644 src/pages/index/TopBanner.tsx create mode 100644 src/photo/detail.config.ts create mode 100644 src/photo/detail.scss create mode 100644 src/photo/detail.tsx create mode 100644 src/photo/index.config.ts create mode 100644 src/photo/index.tsx create mode 100644 src/styles/mobile-container.scss diff --git a/src/api/cms/cmsNavigation/index.ts b/src/api/cms/cmsNavigation/index.ts index fde8369..4661364 100644 --- a/src/api/cms/cmsNavigation/index.ts +++ b/src/api/cms/cmsNavigation/index.ts @@ -8,9 +8,7 @@ import type { CmsNavigation, CmsNavigationParam } from './model'; export async function pageCmsNavigation(params: CmsNavigationParam) { const res = await request.get>>( '/cms/cms-navigation/page', - { params - } ); if (res.code === 0) { return res.data; diff --git a/src/api/cms/cmsNavigation/model/index.ts b/src/api/cms/cmsNavigation/model/index.ts index 8262bff..a684b2f 100644 --- a/src/api/cms/cmsNavigation/model/index.ts +++ b/src/api/cms/cmsNavigation/model/index.ts @@ -30,6 +30,8 @@ export interface CmsNavigation { banner?: string; // 图标颜色 color?: string; + // 栅格宽度 + span?: string; // 是否隐藏, 0否, 1是(仅注册路由不显示在左侧菜单) hide?: number; // 可见类型 0所有人 1登录可见 2密码可见 diff --git a/src/app.config.ts b/src/app.config.ts index 842edf9..51c4030 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -3,7 +3,6 @@ export default defineAppConfig({ 'pages/index/index', 'pages/kefu/kefu', 'pages/user/user', - 'pages/article/article', 'pages/study/study' ], "subpackages": [ @@ -27,6 +26,20 @@ export default defineAppConfig({ "userVerify/index", "userVerify/admin" ] + }, + { + "root": "article", + "pages": [ + "index", + "detail" + ] + }, + { + "root": "photo", + "pages": [ + "index", + "detail" + ] } ], window: { diff --git a/src/app.scss b/src/app.scss index c546fd5..c5ded95 100644 --- a/src/app.scss +++ b/src/app.scss @@ -1,3 +1,6 @@ +// 引入手机版容器样式 +//@use './styles/mobile-container.scss'; + /* ./src/index.css */ @tailwind base; @tailwind components; @@ -10,6 +13,8 @@ page{ background-position: bottom; } + + // 在全局样式文件中添加 button { &::after { diff --git a/src/article/detail.config.ts b/src/article/detail.config.ts new file mode 100644 index 0000000..349c0e2 --- /dev/null +++ b/src/article/detail.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '详情', + navigationBarBackgroundColor: '#ffe0e0' +}) diff --git a/src/article/detail.scss b/src/article/detail.scss new file mode 100644 index 0000000..94aed36 --- /dev/null +++ b/src/article/detail.scss @@ -0,0 +1,128 @@ +.content { + padding: 32px; + line-height: 2.4rem; + + // 富文本内容样式 + :global { + // 段落样式 + p { + margin: 16px 0; + line-height: 1.8; + text-align: justify; + } + + // 标题样式 + h1, h2, h3, h4, h5, h6 { + margin: 24px 0 16px 0; + font-weight: bold; + line-height: 1.4; + } + + h1 { font-size: 24px; } + h2 { font-size: 22px; } + h3 { font-size: 20px; } + h4 { font-size: 18px; } + h5 { font-size: 16px; } + h6 { font-size: 14px; } + + // 图片样式 + img { + max-width: 100%; + height: auto; + border-radius: 8px; + margin: 16px 0; + display: block; + } + + // 列表样式 + ul, ol { + margin: 16px 0; + padding-left: 24px; + + li { + margin: 8px 0; + line-height: 1.6; + } + } + + // 引用样式 + blockquote { + margin: 16px 0; + padding: 16px; + background-color: #f5f5f5; + border-left: 4px solid #ddd; + border-radius: 4px; + + p { + margin: 0; + font-style: italic; + } + } + + // 代码样式 + code { + background-color: #f5f5f5; + padding: 2px 6px; + border-radius: 4px; + font-family: 'Courier New', monospace; + font-size: 14px; + } + + pre { + background-color: #f5f5f5; + padding: 16px; + border-radius: 8px; + overflow-x: auto; + margin: 16px 0; + + code { + background: none; + padding: 0; + } + } + + // 表格样式 + table { + width: 100%; + border-collapse: collapse; + margin: 16px 0; + + th, td { + border: 1px solid #ddd; + padding: 12px; + text-align: left; + } + + th { + background-color: #f5f5f5; + font-weight: bold; + } + } + + // 链接样式 + a { + color: #1890ff; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } + + // 分割线样式 + hr { + margin: 24px 0; + border: none; + border-top: 1px solid #eee; + } + + // 强调样式 + strong, b { + font-weight: bold; + } + + em, i { + font-style: italic; + } + } +} diff --git a/src/article/detail.tsx b/src/article/detail.tsx new file mode 100644 index 0000000..1fa7125 --- /dev/null +++ b/src/article/detail.tsx @@ -0,0 +1,52 @@ +import {useEffect, useState} from 'react' +import {Tag} from '@nutui/nutui-react-taro' +import {useRouter} from '@tarojs/taro' +import {Divider} from '@nutui/nutui-react-taro' +import {CmsArticle} from "@/api/cms/cmsArticle/model" +import {Eye} from '@nutui/icons-react-taro' +// 显示html富文本 +import {View, RichText} from '@tarojs/components' +import './detail.scss' +import Line from "@/components/Gap"; +import {getCmsArticle} from "@/api/cms/cmsArticle"; + +function Detail() { + const {params} = useRouter(); + // 文章详情 + const [item, setItem] = useState() + // 浏览量 + const [views, setViews] = useState() + + const reload = () => { + getCmsArticle(Number(params.id)).then(data => { + if (data) { + setItem(data) + setViews(data.actualViews) + } + }) + } + + useEffect(() => { + reload(); + }, []); + + return ( +
+
{item?.title}
+
+ {item?.categoryName} +
{views}
+
+ + + + + +
+ ) +} + +export default Detail diff --git a/src/article/index.config.ts b/src/article/index.config.ts new file mode 100644 index 0000000..5601dad --- /dev/null +++ b/src/article/index.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '红色资源' +}) diff --git a/src/article/index.tsx b/src/article/index.tsx new file mode 100644 index 0000000..09818cb --- /dev/null +++ b/src/article/index.tsx @@ -0,0 +1,109 @@ +import {useEffect, useState} from "react"; +import {pageCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model"; +import Taro from '@tarojs/taro' +import {useRouter} from '@tarojs/taro' +import {Image} from '@nutui/nutui-react-taro' +import {getCmsNavigation, pageCmsNavigation} from "@/api/cms/cmsNavigation"; +import {CmsNavigation} from "@/api/cms/cmsNavigation/model"; + +/** + * 文章终极列表 + * @constructor + */ +const Index = () => { + const {params} = useRouter(); + const [navigation, setNavigation] = useState() + const [childCategory, setChildCategory] = useState([]) + const [list, setList] = useState([]) + + const reload = async () => { + // 获取栏目ID + const categoryId = Number(params.id); + // 当前栏目信息 + const navs = await getCmsNavigation(categoryId); + // 二级栏目 + const childCateogry = await pageCmsNavigation({parentId: categoryId}); + // 终极新闻列表 + const articles = await pageCmsArticle({categoryId}); + + // 当前栏目信息 + if (navs) { + setNavigation(navs); + } + // 获取子级栏目 + if (childCateogry) { + setChildCategory(childCateogry.list) + } + // 新闻列表 + if (articles) { + setList(articles?.list || []) + } + } + + useEffect(() => { + reload() + }, []) + + return ( + <> +
+ +
+
+
+ { + // 子级栏目 + childCategory.map((item, index) => { + return ( +
Taro.navigateTo({url: `./index?id=${item.navigationId}`})} + > + {/* 图片容器 */} +
+ {item.title +
+
+ ) + }) + } +
+
+ { + // 终极文章列表 + list.map((item, index) => { + return ( +
Taro.navigateTo({url: `./detail?id=${item.articleId}`})} + > + {/* 图片容器 */} +
+ {item.title +
+ {/* 标题 */} +
+ {item.title} +
+
+ ) + }) + } +
+
+ + ) +} +export default Index diff --git a/src/custom/article/article.config.ts b/src/custom/article/article.config.ts new file mode 100644 index 0000000..5601dad --- /dev/null +++ b/src/custom/article/article.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '红色资源' +}) diff --git a/src/custom/article/article.tsx b/src/custom/article/article.tsx new file mode 100644 index 0000000..39772cc --- /dev/null +++ b/src/custom/article/article.tsx @@ -0,0 +1,72 @@ +import {useEffect, useState} from "react"; +import {pageCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model"; +import Taro from '@tarojs/taro' +import {useRouter} from '@tarojs/taro' +import {Image} from '@nutui/nutui-react-taro' +import {getCmsNavigation} from "@/api/cms/cmsNavigation"; +import {CmsNavigation} from "@/api/cms/cmsNavigation/model"; + +/** + * 文章终极列表 + * @constructor + */ +const Article = () => { + const {params} = useRouter(); + const [navigation, setNavigation] = useState() + const [list, setList] = useState([]) + + const reload = async () => { + const categoryId = Number(params.id); + const nav = await getCmsNavigation(categoryId); + const articles = await pageCmsArticle({categoryId}); + + if(nav){ + setNavigation(nav); + } + if(articles){ + setList(articles?.list) + } + } + + useEffect(() => { + reload() + }, []) + + return ( +
+ +
+ {/* 宫格布局容器 */} +
+ { + list.map((item, index) => { + return ( +
Taro.navigateTo({url: `/pages/article/detail?id=${item.articleId}`})} + > + {/* 图片容器 */} +
+ {item.title +
+ {/* 标题 */} +
+ {item.title} +
+
+ ) + }) + } +
+
+
+ ) +} +export default Article diff --git a/src/pages/article/article.tsx b/src/pages/article/article.tsx deleted file mode 100644 index 913112e..0000000 --- a/src/pages/article/article.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import {useEffect, useState} from "react"; -import {ArrowRight} from '@nutui/icons-react-taro' -import {pageCmsArticle} from "@/api/cms/cmsArticle"; -import {CmsArticle} from "@/api/cms/cmsArticle/model"; -import Taro from '@tarojs/taro' - -/** - * 文章终极列表 - * @constructor - */ -const Article = () => { - // const {params} = useRouter(); - // const [categoryId, setCategoryId] = useState(3494) - const [list, setList] = useState([]) - - const reload = () => { - // if (params.id) { - // setCategoryId(Number(params.id)) - // } - pageCmsArticle({}).then(res => { - if (res?.list) { - setList(res?.list) - } - }) - } - - useEffect(() => { - reload() - }, []) - - return ( -
-
-
- { - list.map((item, index) => { - return ( -
Taro.navigateTo({url: `/cms/help?id=${item.articleId}`}) }> -
{item.title}
- -
- ) - }) - } -
-
-
- ) -} -export default Article diff --git a/src/pages/article/detail.tsx b/src/pages/article/detail.tsx new file mode 100644 index 0000000..5e9b326 --- /dev/null +++ b/src/pages/article/detail.tsx @@ -0,0 +1,54 @@ +import {useEffect, useState} from 'react' +import {Tag} from '@nutui/nutui-react-taro' +import {useRouter} from '@tarojs/taro' +import {Divider} from '@nutui/nutui-react-taro' +import {CmsArticle} from "@/api/cms/cmsArticle/model" +import {Eye} from '@nutui/icons-react-taro' +// 显示html富文本 +import {View, RichText} from '@tarojs/components' +import './detail.scss' +import Line from "@/components/Gap"; +import {getCmsArticle} from "@/api/cms/cmsArticle"; + +function Detail() { + const {params} = useRouter(); + // 文章详情 + const [item, setItem] = useState() + // 浏览量 + const [views, setViews] = useState() + + const reload = () => { + getCmsArticle(Number(params.id)).then(data => { + if (data) { + setItem(data) + setViews(data.actualViews) + } + }) + } + + useEffect(() => { + reload(); + }, []); + + return ( +
+
+
{item?.title}
+
+ {item?.categoryName} +
{views}
+
+ + + + + +
+
+ ) +} + +export default Detail diff --git a/src/pages/index/Banner.tsx b/src/pages/index/Banner.tsx index 303049b..9f8d9ab 100644 --- a/src/pages/index/Banner.tsx +++ b/src/pages/index/Banner.tsx @@ -6,6 +6,7 @@ import {pageCmsAd} from "@/api/cms/cmsAd"; const MyPage = () => { const [item, setItem] = useState() const [height, setHeight] = useState() + const [width, setWidth] = useState() const reload = () => { pageCmsAd({keywords: '幻灯片'}).then(data => { @@ -13,6 +14,7 @@ const MyPage = () => { if(data && data?.count > 0){ const cmsAd = data.list[0]; setHeight(cmsAd.height) + setWidth(cmsAd.width) setItem(data.list[0]) } }) @@ -23,15 +25,15 @@ const MyPage = () => { }, []) return ( - <> - +
+ {item?.imageList?.map((item) => ( ))} - +
) } export default MyPage diff --git a/src/pages/index/Image.tsx b/src/pages/index/Image.tsx new file mode 100644 index 0000000..b1381c8 --- /dev/null +++ b/src/pages/index/Image.tsx @@ -0,0 +1,36 @@ +import {useEffect, useState} from 'react' +import {CmsAd} from "@/api/cms/cmsAd/model"; +import {pageCmsAd} from "@/api/cms/cmsAd"; + +const MyPage = () => { + const [item, setItem] = useState() + const [image, setImage] = useState() + const [height, setHeight] = useState() + const [width, setWidth] = useState() + + const reload = () => { + pageCmsAd({keywords: 'TopBanner'}).then(data => { + if (data && data?.count > 0) { + const cmsAd = data.list[0]; + setItem(cmsAd) + console.log(item,'ad') + setHeight(cmsAd.height) + setWidth(cmsAd.width) + if (cmsAd.imageList && cmsAd.imageList.length > 0) { + setImage(cmsAd.imageList[0].url) + } + } + }) + } + + useEffect(() => { + reload() + }, []) + + return ( + <> + + + ) +} +export default MyPage diff --git a/src/pages/index/Menu.tsx b/src/pages/index/Menu.tsx index f9690b7..08556e8 100644 --- a/src/pages/index/Menu.tsx +++ b/src/pages/index/Menu.tsx @@ -1,113 +1,39 @@ import {useEffect, useState} from 'react' -import {navigateTo} from '@tarojs/taro' import Taro from '@tarojs/taro' -import {Button} from '@tarojs/components'; import {Image} from '@nutui/nutui-react-taro' import {getSiteInfo} from "@/api/layout"; -import {TenantId} from "@/utils/config"; import {CmsNavigation} from "@/api/cms/cmsNavigation/model"; const Page = () => { - const [loading, setLoading] = useState(true) - const [isLogin, setIsLogin] = useState(false) - const [navItems, setNavItems] = useState([]) + const [navItems, setNavItems] = useState([]) - /* 获取用户手机号 */ - const handleGetPhoneNumber = ({detail}) => { - const {code, encryptedData, iv} = detail - Taro.login({ - success: function () { - if (code) { - Taro.request({ - url: 'https://server.gxwebsoft.com/api/wx-login/loginByMpWxPhone', - method: 'POST', - data: { - code, - encryptedData, - iv, - notVerifyPhone: true, - refereeId: 0, - sceneType: 'save_referee', - tenantId: TenantId - }, - header: { - 'content-type': 'application/json', - TenantId - }, - success: function (res) { - Taro.setStorageSync('access_token', res.data.data.access_token) - Taro.setStorageSync('UserId', res.data.data.user.userId) - Taro.setStorageSync('Phone', res.data.data.user.phone) - setIsLogin(true) - Taro.showToast({ - title: '登录成功', - icon: 'success' - }); - } - }) - } else { - console.log('登录失败!') - } - } - }) - } + const reload = () => { + getSiteInfo().then(res => { + console.log(res); + console.log(res.topNavs, 'top'); + setNavItems(res.topNavs || []); + }) + }; - const onLogin = (item: any) => { - if(!isLogin){ - return navigateTo({url: `/pages/category/category?id=${item.navigationId}`}) - }else { - // 善款明细 - if(item.navigationId == 4119){ - return navigateTo({url: `/bszx/pay-record/pay-record`}) - } - return navigateTo({url: `/pages/category/category?id=${item.navigationId}`}) - } - } + useEffect(() => { + reload(); + }, []) - const reload = () => { - getSiteInfo().then(res => { - console.log(res); - console.log(res.topNavs,'top'); - setNavItems(res.topNavs || []); - }) - - setLoading(false); - }; - - useEffect(() => { - reload(); - }, []) - - return ( -
-
-
- { - navItems.map((item, index) => ( -
+ return ( +
+
{ - isLogin && !loading ? -
{ - onLogin(item) - }}> - -
{item?.title}
-
- : - + navItems.map((item) => ( +
Taro.navigateTo({url: `/${item.model}/index?id=${item.navigationId}`})}> + +
{item?.title}
+
+ )) } -
- )) - } +
-
-
- ) + ) } export default Page diff --git a/src/pages/index/TopBanner.tsx b/src/pages/index/TopBanner.tsx deleted file mode 100644 index 0c826d8..0000000 --- a/src/pages/index/TopBanner.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import { useEffect, useState } from 'react' -import { Swiper } from '@nutui/nutui-react-taro' -import {CmsAd} from "@/api/cms/cmsAd/model"; -import {pageCmsAd} from "@/api/cms/cmsAd"; - -const MyPage = () => { - const [item, setItem] = useState() - const reload = () => { - pageCmsAd({keywords: 'TopBanner'}).then(data => { - console.log(data,'幻灯片') - if(data && data?.count > 0){ - setItem(data.list[0]) - } - }) - } - - useEffect(() => { - reload() - }, []) - - return ( - <> - - {item?.imageList?.map((item) => ( - - - - ))} - - - ) -} -export default MyPage diff --git a/src/pages/index/index.scss b/src/pages/index/index.scss index 88f6ee6..0a07e09 100644 --- a/src/pages/index/index.scss +++ b/src/pages/index/index.scss @@ -1,2 +1,16 @@ page { } + +.mobile-container { + width: 100%; + min-height: 100vh; + + // PC端样式 + //@media screen and (min-width: 768px) { + // max-width: 414px; + // margin: 0 auto; + // min-height: auto; + // background-color: #fff; + // position: relative; + //} +} diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 47a5fb2..dc22bf1 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,13 +1,12 @@ import './index.scss' import Taro from '@tarojs/taro'; -// import {useShareAppMessage, useShareTimeline} from "@tarojs/taro" import {useEffect, useState} from "react"; import {getSiteInfo} from "@/api/layout"; import Login from "./Login"; import Banner from "./Banner"; import Menu from "./Menu"; -import TopBanner from "./TopBanner"; import TabBar from "@/components/TabBar"; +import Image from "./Image"; export interface Market { // 自增ID @@ -123,14 +122,14 @@ function Home() { }, []); return ( - <> +
{!IsLogin && search ? () : (<> - + )} - +
) } diff --git a/src/pages/user/user.tsx b/src/pages/user/user.tsx index 750ac24..28dab99 100644 --- a/src/pages/user/user.tsx +++ b/src/pages/user/user.tsx @@ -8,13 +8,13 @@ function User() { useEffect(() => { }, []); return ( - <> +
- +
) } diff --git a/src/photo/detail.config.ts b/src/photo/detail.config.ts new file mode 100644 index 0000000..349c0e2 --- /dev/null +++ b/src/photo/detail.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '详情', + navigationBarBackgroundColor: '#ffe0e0' +}) diff --git a/src/photo/detail.scss b/src/photo/detail.scss new file mode 100644 index 0000000..94aed36 --- /dev/null +++ b/src/photo/detail.scss @@ -0,0 +1,128 @@ +.content { + padding: 32px; + line-height: 2.4rem; + + // 富文本内容样式 + :global { + // 段落样式 + p { + margin: 16px 0; + line-height: 1.8; + text-align: justify; + } + + // 标题样式 + h1, h2, h3, h4, h5, h6 { + margin: 24px 0 16px 0; + font-weight: bold; + line-height: 1.4; + } + + h1 { font-size: 24px; } + h2 { font-size: 22px; } + h3 { font-size: 20px; } + h4 { font-size: 18px; } + h5 { font-size: 16px; } + h6 { font-size: 14px; } + + // 图片样式 + img { + max-width: 100%; + height: auto; + border-radius: 8px; + margin: 16px 0; + display: block; + } + + // 列表样式 + ul, ol { + margin: 16px 0; + padding-left: 24px; + + li { + margin: 8px 0; + line-height: 1.6; + } + } + + // 引用样式 + blockquote { + margin: 16px 0; + padding: 16px; + background-color: #f5f5f5; + border-left: 4px solid #ddd; + border-radius: 4px; + + p { + margin: 0; + font-style: italic; + } + } + + // 代码样式 + code { + background-color: #f5f5f5; + padding: 2px 6px; + border-radius: 4px; + font-family: 'Courier New', monospace; + font-size: 14px; + } + + pre { + background-color: #f5f5f5; + padding: 16px; + border-radius: 8px; + overflow-x: auto; + margin: 16px 0; + + code { + background: none; + padding: 0; + } + } + + // 表格样式 + table { + width: 100%; + border-collapse: collapse; + margin: 16px 0; + + th, td { + border: 1px solid #ddd; + padding: 12px; + text-align: left; + } + + th { + background-color: #f5f5f5; + font-weight: bold; + } + } + + // 链接样式 + a { + color: #1890ff; + text-decoration: none; + + &:hover { + text-decoration: underline; + } + } + + // 分割线样式 + hr { + margin: 24px 0; + border: none; + border-top: 1px solid #eee; + } + + // 强调样式 + strong, b { + font-weight: bold; + } + + em, i { + font-style: italic; + } + } +} diff --git a/src/photo/detail.tsx b/src/photo/detail.tsx new file mode 100644 index 0000000..1fa7125 --- /dev/null +++ b/src/photo/detail.tsx @@ -0,0 +1,52 @@ +import {useEffect, useState} from 'react' +import {Tag} from '@nutui/nutui-react-taro' +import {useRouter} from '@tarojs/taro' +import {Divider} from '@nutui/nutui-react-taro' +import {CmsArticle} from "@/api/cms/cmsArticle/model" +import {Eye} from '@nutui/icons-react-taro' +// 显示html富文本 +import {View, RichText} from '@tarojs/components' +import './detail.scss' +import Line from "@/components/Gap"; +import {getCmsArticle} from "@/api/cms/cmsArticle"; + +function Detail() { + const {params} = useRouter(); + // 文章详情 + const [item, setItem] = useState() + // 浏览量 + const [views, setViews] = useState() + + const reload = () => { + getCmsArticle(Number(params.id)).then(data => { + if (data) { + setItem(data) + setViews(data.actualViews) + } + }) + } + + useEffect(() => { + reload(); + }, []); + + return ( +
+
{item?.title}
+
+ {item?.categoryName} +
{views}
+
+ + + + + +
+ ) +} + +export default Detail diff --git a/src/photo/index.config.ts b/src/photo/index.config.ts new file mode 100644 index 0000000..d3c99ed --- /dev/null +++ b/src/photo/index.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '图文列表' +}) diff --git a/src/photo/index.tsx b/src/photo/index.tsx new file mode 100644 index 0000000..09818cb --- /dev/null +++ b/src/photo/index.tsx @@ -0,0 +1,109 @@ +import {useEffect, useState} from "react"; +import {pageCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model"; +import Taro from '@tarojs/taro' +import {useRouter} from '@tarojs/taro' +import {Image} from '@nutui/nutui-react-taro' +import {getCmsNavigation, pageCmsNavigation} from "@/api/cms/cmsNavigation"; +import {CmsNavigation} from "@/api/cms/cmsNavigation/model"; + +/** + * 文章终极列表 + * @constructor + */ +const Index = () => { + const {params} = useRouter(); + const [navigation, setNavigation] = useState() + const [childCategory, setChildCategory] = useState([]) + const [list, setList] = useState([]) + + const reload = async () => { + // 获取栏目ID + const categoryId = Number(params.id); + // 当前栏目信息 + const navs = await getCmsNavigation(categoryId); + // 二级栏目 + const childCateogry = await pageCmsNavigation({parentId: categoryId}); + // 终极新闻列表 + const articles = await pageCmsArticle({categoryId}); + + // 当前栏目信息 + if (navs) { + setNavigation(navs); + } + // 获取子级栏目 + if (childCateogry) { + setChildCategory(childCateogry.list) + } + // 新闻列表 + if (articles) { + setList(articles?.list || []) + } + } + + useEffect(() => { + reload() + }, []) + + return ( + <> +
+ +
+
+
+ { + // 子级栏目 + childCategory.map((item, index) => { + return ( +
Taro.navigateTo({url: `./index?id=${item.navigationId}`})} + > + {/* 图片容器 */} +
+ {item.title +
+
+ ) + }) + } +
+
+ { + // 终极文章列表 + list.map((item, index) => { + return ( +
Taro.navigateTo({url: `./detail?id=${item.articleId}`})} + > + {/* 图片容器 */} +
+ {item.title +
+ {/* 标题 */} +
+ {item.title} +
+
+ ) + }) + } +
+
+ + ) +} +export default Index diff --git a/src/styles/mobile-container.scss b/src/styles/mobile-container.scss new file mode 100644 index 0000000..7bd6efe --- /dev/null +++ b/src/styles/mobile-container.scss @@ -0,0 +1,93 @@ +// 手机版容器样式 - 用于PC端显示手机版效果 +.mobile-container { + width: 100%; + min-height: 100vh; + position: relative; + + // PC端样式 - 768px以上显示手机版效果 + @media screen and (min-width: 768px) { + max-width: 414px; + width: 414px !important; + margin: 0 auto; + min-height: auto; + background-color: #fff; + box-shadow: 0 0 20px rgba(0, 0, 0, 0.1); + border-radius: 12px; + overflow: hidden; + position: relative; + + // 确保内容不超出容器 + * { + max-width: 100%; + } + } + + // 大屏幕设备 - 1024px以上 + @media screen and (min-width: 1024px) { + max-width: 375px; + width: 375px !important; + } + + // 超大屏幕设备 - 1440px以上 + @media screen and (min-width: 1440px) { + max-width: 414px; + width: 414px !important; + } +} + +// PC端页面背景 +@media screen and (min-width: 768px) { + body { + background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); + min-height: 100vh; + display: flex; + justify-content: center; + align-items: flex-start; + padding: 40px 20px; + } + + // 主应用容器 + #app { + max-width: 414px !important; + width: 414px !important; + margin: 0 auto; + background-color: transparent; + position: relative; + } + + // 页面容器 + page { + max-width: 414px !important; + width: 414px !important; + margin: 0 auto; + background-color: #f5f5f5; + border-radius: 12px; + overflow: hidden; + box-shadow: 0 0 30px rgba(0, 0, 0, 0.15); + } + + // Taro页面容器 + .taro_page { + max-width: 414px !important; + width: 414px !important; + margin: 0 auto; + border-radius: 12px; + overflow: hidden; + } + + // 底部导航栏在PC端的样式调整 + .nut-tabbar { + max-width: 414px !important; + width: 414px !important; + margin: 0 auto; + border-radius: 0 0 12px 12px; + } +} + +// 移动端保持原有样式 +@media screen and (max-width: 767px) { + .mobile-container { + width: 100%; + min-height: 100vh; + } +}