diff --git a/src/app.config.ts b/src/app.config.ts index 63cda8d..6ecb75a 100644 --- a/src/app.config.ts +++ b/src/app.config.ts @@ -4,7 +4,7 @@ export default { 'pages/cart/cart', 'pages/find/find', 'pages/user/user', - 'pages/cms/category/index' + 'pages/category/index' ], "subpackages": [ { @@ -116,7 +116,7 @@ export default { text: "首页", }, { - pagePath: "pages/cms/category/index", + pagePath: "pages/category/index", iconPath: "assets/tabbar/category.png", selectedIconPath: "assets/tabbar/category-active.png", text: "基地生活", diff --git a/src/app.ts b/src/app.ts index 83dac88..8284745 100644 --- a/src/app.ts +++ b/src/app.ts @@ -53,7 +53,6 @@ function App(props: { children: any; }) { // 处理小程序启动参数中的邀请信息 const options = Taro.getLaunchOptionsSync() handleLaunchOptions(options) - handleTheme() }) // 处理启动参数 @@ -103,6 +102,7 @@ function App(props: { children: any; }) { // 对应 onHide useDidHide(() => { + handleTheme() }) return props.children diff --git a/src/pages/cms/category/components/ArticleList.tsx b/src/pages/category/components/ArticleList.tsx similarity index 50% rename from src/pages/cms/category/components/ArticleList.tsx rename to src/pages/category/components/ArticleList.tsx index 3f46857..ffe5d29 100644 --- a/src/pages/cms/category/components/ArticleList.tsx +++ b/src/pages/category/components/ArticleList.tsx @@ -1,15 +1,25 @@ import {Image, Cell} from '@nutui/nutui-react-taro' +import {View, Text} from '@tarojs/components' import Taro from '@tarojs/taro' const ArticleList = (props: any) => { return ( <> -
- {props.data.map((item, index) => { + + {props.data.map((item: any, index: number) => { return ( + {item.title} + {item.comments && ( + + {item.comments} + + )} + + } extra={ } @@ -18,7 +28,7 @@ const ArticleList = (props: any) => { /> ) })} -
+ ) } diff --git a/src/pages/cms/category/components/ArticleTabs.tsx b/src/pages/category/components/ArticleTabs.tsx similarity index 100% rename from src/pages/cms/category/components/ArticleTabs.tsx rename to src/pages/category/components/ArticleTabs.tsx diff --git a/src/pages/cms/category/components/Banner.tsx b/src/pages/category/components/Banner.tsx similarity index 100% rename from src/pages/cms/category/components/Banner.tsx rename to src/pages/category/components/Banner.tsx diff --git a/src/pages/cms/category/index.config.ts b/src/pages/category/index.config.ts similarity index 100% rename from src/pages/cms/category/index.config.ts rename to src/pages/category/index.config.ts diff --git a/src/pages/cms/category/index.scss b/src/pages/category/index.scss similarity index 100% rename from src/pages/cms/category/index.scss rename to src/pages/category/index.scss diff --git a/src/pages/category/index.tsx b/src/pages/category/index.tsx new file mode 100644 index 0000000..3592f21 --- /dev/null +++ b/src/pages/category/index.tsx @@ -0,0 +1,96 @@ +import Taro from '@tarojs/taro' +import {useShareAppMessage} from "@tarojs/taro" +import {useEffect, useState} from "react" +import {useRouter} from '@tarojs/taro' +import {View} from '@tarojs/components' +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 () => { + try { + setLoading(true) + // 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}` + }) + } catch (error) { + console.error('文章分类加载失败:', error) + } finally { + setLoading(false) + } + }; + + useEffect(() => { + reload() + }, []); + + useShareAppMessage(() => { + return { + title: `${nav?.categoryName}_时里院子市集`, + path: `/shop/category/index?id=${categoryId}`, + success: function () { + console.log('分享成功'); + }, + fail: function () { + console.log('分享失败'); + } + }; + }); + + // 骨架屏组件 + const ArticleSkeleton = () => ( + + {[1, 2, 3, 4, 5].map(i => ( + + {/* 左侧文字骨架屏 */} + + {/* 标题骨架屏 */} + + {/* 副标题骨架屏 */} + + + {/* 右侧图片骨架屏 */} + + + ))} + + ) + + if (loading) { + return + } + + if(category.length > 0){ + return + } + + return +} + +export default Category diff --git a/src/pages/cms/category/index.tsx b/src/pages/cms/category/index.tsx deleted file mode 100644 index 6886cc3..0000000 --- a/src/pages/cms/category/index.tsx +++ /dev/null @@ -1,71 +0,0 @@ -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 deleted file mode 100644 index d74c9f2..0000000 --- a/src/pages/cms/detail/index.config.ts +++ /dev/null @@ -1,3 +0,0 @@ -export default definePageConfig({ - navigationBarTitleText: '文章详情' -}) diff --git a/src/pages/cms/detail/index.scss b/src/pages/cms/detail/index.scss deleted file mode 100644 index e69de29..0000000 diff --git a/src/pages/cms/detail/index.tsx b/src/pages/cms/detail/index.tsx deleted file mode 100644 index f92c890..0000000 --- a/src/pages/cms/detail/index.tsx +++ /dev/null @@ -1,53 +0,0 @@ -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 diff --git a/src/pages/index/Banner.tsx b/src/pages/index/Banner.tsx index d31d4ec..a019d1d 100644 --- a/src/pages/index/Banner.tsx +++ b/src/pages/index/Banner.tsx @@ -13,24 +13,32 @@ const MyPage = () => { const [carouselData, setCarouselData] = useState() const [hotToday, setHotToday] = useState() const [item, setItem] = useState() + const [loading, setLoading] = useState(true) // 加载数据 const loadData = async () => { - // 轮播图 - const flash = await getCmsAdByCode('flash') - // 今日热卖 - const hotToday = await getCmsAdByCode('hot_today') - // 时里动态 - const news = await pageCmsArticle({limit:1,recommend:1}) - // 赋值 - if(flash){ - setCarouselData(flash) - } - if(hotToday){ - setHotToday(hotToday) - } - if(news && news.list.length > 0){ - setItem(news.list[0]) + try { + setLoading(true) + // 轮播图 + const flash = await getCmsAdByCode('flash') + // 今日热卖 + const hotToday = await getCmsAdByCode('hot_today') + // 时里动态 + const news = await pageCmsArticle({limit:1,recommend:1}) + // 赋值 + if(flash){ + setCarouselData(flash) + } + if(hotToday){ + setHotToday(hotToday) + } + if(news && news.list.length > 0){ + setItem(news.list[0]) + } + } catch (error) { + console.error('Banner数据加载失败:', error) + } finally { + setLoading(false) } } @@ -41,30 +49,91 @@ const MyPage = () => { // 轮播图高度,默认200px const carouselHeight = carouselData?.height || 200; + // 骨架屏组件 + const BannerSkeleton = () => ( + + {/* 左侧轮播图骨架屏 */} + + + + + {/* 右侧骨架屏 */} + + {/* 上层骨架屏 */} + + + + + + {[1, 2].map(i => ( + + + + + ))} + + + + {/* 下层骨架屏 */} + + + + + + + + + + + ) + + // 如果正在加载,显示骨架屏 + if (loading) { + return + } + return ( {/* 左侧轮播图区域 */} - - {carouselData?.imageList?.map((img, index) => ( - - navTo(`${img.path}`)} - lazyLoad={false} - style={{height: `${carouselHeight}px`, borderRadius: '4px'}} - /> - - ))} - + + {carouselData && carouselData?.imageList?.map((img, index) => ( + + navTo(`${img.path}`)} + lazyLoad={false} + style={{ + height: `${carouselHeight}px`, + borderRadius: '4px', + pointerEvents: 'auto' + }} + /> + + ))} + + {/* 右侧上下图片区域 - 从API获取数据 */} diff --git a/src/pages/index/BestSellers.tsx b/src/pages/index/BestSellers.tsx index 109d200..c06d0e7 100644 --- a/src/pages/index/BestSellers.tsx +++ b/src/pages/index/BestSellers.tsx @@ -1,5 +1,5 @@ import {useEffect, useState} from "react"; -import {Image} from '@nutui/nutui-react-taro' +import {Image, Tabs, Empty} from '@nutui/nutui-react-taro' import {Share} from '@nutui/icons-react-taro' import {View, Text} from '@tarojs/components'; import Taro from "@tarojs/taro"; @@ -7,6 +7,7 @@ import {ShopGoods} from "@/api/shop/shopGoods/model"; import {pageShopGoods} from "@/api/shop/shopGoods"; const BestSellers = () => { + const [tab1value, setTab1value] = useState('0') const [list, setList] = useState([]) const [goods, setGoods] = useState() @@ -57,8 +58,29 @@ const BestSellers = () => { return ( <> + {/* Tabs切换组件 */} + { + setTab1value(value) + }} + style={{ + backgroundColor: 'transparent', + }} + activeType="smile" + > + + + + + + + + - {list?.map((item, index) => { + {/* 今日主推 */} + {tab1value == '0' && list?.map((item, index) => { return ( { ) })} + + {/* 即将到期 */} + {tab1value == '1' && ( + + )} + + {/* 活动预告 */} + {tab1value == '2' && ( + + )} diff --git a/src/pages/user/components/IsDealer.tsx b/src/pages/user/components/IsDealer.tsx index ec9302f..b5280aa 100644 --- a/src/pages/user/components/IsDealer.tsx +++ b/src/pages/user/components/IsDealer.tsx @@ -21,7 +21,7 @@ const IsDealer = () => { setConfig(data) }) }, []) - + console.log(dealerUser,'dealerUserdealerUserdealerUserdealerUserdealerUser') /** * 管理中心 */