diff --git a/src/app.config.ts b/src/app.config.ts index 63deeb4..fba1498 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -1,5 +1,6 @@ export default { pages: [ + 'pages/cms/category/index', 'pages/index/index', 'pages/cart/cart', 'pages/find/find', @@ -108,9 +109,9 @@ export default { text: "首页", }, { - pagePath: "pages/find/find", - iconPath: "assets/tabbar/find.png", - selectedIconPath: "assets/tabbar/find-active.png", + pagePath: "pages/cms/category/index", + iconPath: "assets/tabbar/tv.png", + selectedIconPath: "assets/tabbar/tv-active.png", text: "基地生活", }, { diff --git a/src/assets/tabbar/tv-active.png b/src/assets/tabbar/tv-active.png new file mode 100644 index 0000000..4852b4f Binary files /dev/null and b/src/assets/tabbar/tv-active.png differ diff --git a/src/assets/tabbar/tv.png b/src/assets/tabbar/tv.png new file mode 100644 index 0000000..2dd6bd0 Binary files /dev/null and b/src/assets/tabbar/tv.png differ diff --git a/src/pages/cms/category/components/ArticleList.tsx b/src/pages/cms/category/components/ArticleList.tsx new file mode 100644 index 0000000..3f46857 --- /dev/null +++ b/src/pages/cms/category/components/ArticleList.tsx @@ -0,0 +1,25 @@ +import {Image, Cell} from '@nutui/nutui-react-taro' +import Taro from '@tarojs/taro' + +const ArticleList = (props: any) => { + + return ( + <> +
+ {props.data.map((item, index) => { + return ( + + } + key={index} + onClick={() => Taro.navigateTo({url: '/cms/detail/index?id=' + item.articleId})} + /> + ) + })} +
+ + ) +} +export default ArticleList diff --git a/src/pages/cms/category/components/ArticleTabs.tsx b/src/pages/cms/category/components/ArticleTabs.tsx new file mode 100644 index 0000000..a995345 --- /dev/null +++ b/src/pages/cms/category/components/ArticleTabs.tsx @@ -0,0 +1,59 @@ +import {useEffect, useState} from "react"; +import {Tabs, Loading} from '@nutui/nutui-react-taro' +import {pageCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model"; +import ArticleList from "./ArticleList"; + +const ArticleTabs = (props: any) => { + const [loading, setLoading] = useState(true) + const [tab1value, setTab1value] = useState('0') + const [list, setList] = useState([]) + + const reload = async (value) => { + const {data} = props + pageCmsArticle({ + categoryId: data[value].navigationId, + page: 1, + status: 0, + limit: 10 + }).then((res) => { + res && setList(res?.list || []) + }) + .catch(err => { + console.log(err) + }) + .finally(() => { + setTab1value(value) + setLoading(false) + }) + } + + useEffect(() => { + reload(0).then() + }, []); + + if (loading) { + return ( + 加载中 + ) + } + + return ( + <> + { + reload(value).then() + }} + > + {props.data?.map((item, index) => { + return ( + + ) + })} + + + + ) +} +export default ArticleTabs diff --git a/src/pages/cms/category/components/Banner.tsx b/src/pages/cms/category/components/Banner.tsx new file mode 100644 index 0000000..7f3942d --- /dev/null +++ b/src/pages/cms/category/components/Banner.tsx @@ -0,0 +1,31 @@ +import { useEffect, useState } from 'react' +import { Swiper } from '@nutui/nutui-react-taro' +import {CmsAd} from "@/api/cms/cmsAd/model"; +import {Image} from '@nutui/nutui-react-taro' +import {getCmsAd} from "@/api/cms/cmsAd"; + +const MyPage = () => { + const [item, setItem] = useState() + const reload = () => { + getCmsAd(439).then(data => { + setItem(data) + }) + } + + useEffect(() => { + reload() + }, []) + + return ( + <> + + {item?.imageList?.map((item) => ( + + + + ))} + + + ) +} +export default MyPage diff --git a/src/pages/cms/category/index.config.ts b/src/pages/cms/category/index.config.ts new file mode 100644 index 0000000..689ba07 --- /dev/null +++ b/src/pages/cms/category/index.config.ts @@ -0,0 +1,4 @@ +export default definePageConfig({ + navigationBarTitleText: '文章列表', + navigationBarTextStyle: 'black' +}) diff --git a/src/pages/cms/category/index.scss b/src/pages/cms/category/index.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/cms/category/index.tsx b/src/pages/cms/category/index.tsx new file mode 100644 index 0000000..6886cc3 --- /dev/null +++ b/src/pages/cms/category/index.tsx @@ -0,0 +1,71 @@ +import Taro from '@tarojs/taro' +import {useShareAppMessage} from "@tarojs/taro" +import {Loading} from '@nutui/nutui-react-taro' +import {useEffect, useState} from "react" +import {useRouter} from '@tarojs/taro' +import {getCmsNavigation, listCmsNavigation} from "@/api/cms/cmsNavigation"; +import {CmsNavigation} from "@/api/cms/cmsNavigation/model"; +import {pageCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model"; +import ArticleList from './components/ArticleList' +import ArticleTabs from "./components/ArticleTabs"; +import './index.scss' + +function Category() { + const {params} = useRouter(); + const [categoryId, setCategoryId] = useState(0) + const [category, setCategory] = useState([]) + const [loading, setLoading] = useState(true) + const [nav, setNav] = useState() + const [list, setList] = useState([]) + + const reload = async () => { + // 1.加载远程数据 + const id = Number(params.id || 4328) + const nav = await getCmsNavigation(id) + const categoryList = await listCmsNavigation({parentId: id}) + const shopGoods = await pageCmsArticle({categoryId: id}) + + // 2.赋值 + setCategoryId(id) + setNav(nav) + setList(shopGoods?.list || []) + setCategory(categoryList) + Taro.setNavigationBarTitle({ + title: `${nav?.categoryName}` + }) + }; + + useEffect(() => { + reload().then(() => { + setLoading(false) + }) + }, []); + + useShareAppMessage(() => { + return { + title: `${nav?.categoryName}_时里院子市集`, + path: `/shop/category/index?id=${categoryId}`, + success: function () { + console.log('分享成功'); + }, + fail: function () { + console.log('分享失败'); + } + }; + }); + + if (loading) { + return ( + 加载中 + ) + } + + if(category.length > 0){ + return + } + + return +} + +export default Category diff --git a/src/pages/cms/detail/index.config.ts b/src/pages/cms/detail/index.config.ts new file mode 100644 index 0000000..d74c9f2 --- /dev/null +++ b/src/pages/cms/detail/index.config.ts @@ -0,0 +1,3 @@ +export default definePageConfig({ + navigationBarTitleText: '文章详情' +}) diff --git a/src/pages/cms/detail/index.scss b/src/pages/cms/detail/index.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/pages/cms/detail/index.tsx b/src/pages/cms/detail/index.tsx new file mode 100644 index 0000000..f92c890 --- /dev/null +++ b/src/pages/cms/detail/index.tsx @@ -0,0 +1,53 @@ +import Taro from '@tarojs/taro' +import {useEffect, useState} from 'react' +import {useRouter} from '@tarojs/taro' +import {Loading} from '@nutui/nutui-react-taro' +import {View, RichText} from '@tarojs/components' +import {wxParse} from "@/utils/common"; +import {getCmsArticle} from "@/api/cms/cmsArticle"; +import {CmsArticle} from "@/api/cms/cmsArticle/model" +import Line from "@/components/Gap"; +import './index.scss' + +function Detail() { + const {params} = useRouter(); + const [loading, setLoading] = useState(true) + // 文章详情 + const [item, setItem] = useState() + const reload = async () => { + const item = await getCmsArticle(Number(params.id)) + + if (item) { + item.content = wxParse(item.content) + setItem(item) + Taro.setNavigationBarTitle({ + title: `${item?.categoryName}` + }) + } + } + + useEffect(() => { + reload().then(() => { + setLoading(false) + }); + }, []); + + if (loading) { + return ( + 加载中 + ) + } + + return ( +
+
{item?.title}
+
{item?.createTime}
+ + + + +
+ ) +} + +export default Detail