From af5acef0186cffb4a73986ab3aa10c6bff3953e7 Mon Sep 17 00:00:00 2001 From: king <2229249788@qq.com> Date: Fri, 25 Aug 2023 11:51:55 +0800 Subject: [PATCH] =?UTF-8?q?=E7=96=BE=E7=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/illness.ts | 11 ++-- .../preview/illness/article/article.config.ts | 2 +- src/pages/preview/illness/article/article.tsx | 1 - src/pages/preview/illness/list/list.config.ts | 4 +- .../preview/illness/list/list.module.scss | 38 +++---------- src/pages/preview/illness/list/list.tsx | 53 ++++++------------- .../preview/illness/sort/sort.module.scss | 20 ++++++- src/pages/preview/illness/sort/sort.tsx | 31 ++++------- 8 files changed, 58 insertions(+), 102 deletions(-) diff --git a/src/api/illness.ts b/src/api/illness.ts index 7e1aa21..ab0f905 100644 --- a/src/api/illness.ts +++ b/src/api/illness.ts @@ -3,13 +3,10 @@ import {request} from "@/api/request"; export const illnessApi = { /** 疾病列表 */ - list(id:number,page: number , page_size: number) { - return request<{ - list: any[], - total: number, - }>(`/home/v1/illness/list?page=${page}&page_size=${page_size}&id=${id}` , "GET") + list(id: number, page: number, page_size: number) { + return request<{ list: any[], total: number }>(`/home/v1/illness/list`, "GET", {page, page_size, id}) }, - articleInfo(id: number ) { - return request<{ content: string }>(`/home/v1/article/${id}` , "GET") + articleInfo(owner_id: number, page: number, page_size: number) { + return request<{ list: any[], total: number }>(`/home/v1/article/illness_list`, "GET", {page, page_size, owner_id}) }, } diff --git a/src/pages/preview/illness/article/article.config.ts b/src/pages/preview/illness/article/article.config.ts index 2a0a86b..6901b40 100644 --- a/src/pages/preview/illness/article/article.config.ts +++ b/src/pages/preview/illness/article/article.config.ts @@ -1,4 +1,4 @@ export default definePageConfig({ navigationBarTitleText: '', - onReachBottomDistance: 30 + onReachBottomDistance: 50 }) diff --git a/src/pages/preview/illness/article/article.tsx b/src/pages/preview/illness/article/article.tsx index 3670f1a..45f3250 100644 --- a/src/pages/preview/illness/article/article.tsx +++ b/src/pages/preview/illness/article/article.tsx @@ -13,7 +13,6 @@ const article:FC = () => { const [show,setShow] = useState(false) const [articleInfo,setArticleInfo] = useState() const { children, headings } = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) - console.log(headings,'headings') const query = Taro.createSelectorQuery() diff --git a/src/pages/preview/illness/list/list.config.ts b/src/pages/preview/illness/list/list.config.ts index 9fe364f..2881f86 100644 --- a/src/pages/preview/illness/list/list.config.ts +++ b/src/pages/preview/illness/list/list.config.ts @@ -1,4 +1,4 @@ export default definePageConfig({ - navigationBarTitleText: '疾病知识列表', - onReachBottomDistance: 30 + navigationBarTitleText: '文章列表', + onReachBottomDistance: 50 }) diff --git a/src/pages/preview/illness/list/list.module.scss b/src/pages/preview/illness/list/list.module.scss index a232e59..1665d7f 100644 --- a/src/pages/preview/illness/list/list.module.scss +++ b/src/pages/preview/illness/list/list.module.scss @@ -1,34 +1,8 @@ -page{ - background-color: #fff !important; -} -.box { - display: flex; - margin-bottom: 20rpx; - background-color: #fff; - border-radius: 16rpx; - box-sizing: border-box; -} -.image{ - width: 128rpx; - height:128rpx; - background-color: pink; - border-radius: 8rpx; -} -.rightBox{ - padding-left: 24rpx; - box-sizing: border-box; - flex: 1; -} -.desc{ - font-size: 24rpx; +.brands { + font-size: 28rpx; + font-family: PingFang SC-Medium, PingFang SC; font-weight: 500; - color: #909795; - line-height: 34rpx; - display: -webkit-box; - word-break: break-all; - text-overflow: ellipsis; - overflow: hidden; - -webkit-box-orient:vertical; - -webkit-line-clamp:2; + color: #323635; + padding: 30rpx; + border-bottom: 1px solid #F5F8F7; } - diff --git a/src/pages/preview/illness/list/list.tsx b/src/pages/preview/illness/list/list.tsx index 2fae725..19eb6a5 100644 --- a/src/pages/preview/illness/list/list.tsx +++ b/src/pages/preview/illness/list/list.tsx @@ -2,7 +2,6 @@ import {FC, useCallback, useEffect, useState} from "react"; import {View} from "@tarojs/components"; import styles from './list.module.scss' import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; -import Collapse from "@/components/collapse/collapse"; import {illnessApi} from "@/api/illness"; import Empty from "@/components/empty/empty"; @@ -11,32 +10,28 @@ const BrandList: FC = () => { const [page, setPage] = useState(1) const [brands, setBrands] = useState([]) const [total, setTotal] = useState(0) - const [fetchDone,setFetchDone] = useState(false) + const [fetchDone, setFetchDone] = useState(false) useEffect(() => { - Taro.showLoading({ - title: '加载中', - mask: true - }) - setTimeout(function () { - Taro.hideLoading() - setFetchDone(true) - }, 800) - getData() + Taro.showLoading({title: '加载中', mask: true}) + getData().then() }, [page]) const getData = useCallback(async () => { try { - const data = await illnessApi.list(params.id, 1, 100) + const data = await illnessApi.articleInfo(params.id, page, 20) setTotal(data.total) - setBrands([ - ...data.list - ]) - Taro.setNavigationBarTitle({title: data.list?.[0].resourceCategories?.[0]?.name ?? '文章列表'}) + setBrands([...brands, ...data.list]) } catch (e) { } + setFetchDone(true) + Taro.hideLoading() }, [page]) + function jump(id: number) { + Taro.navigateTo({url: '/pages/preview/illness/article/article?id=' + id}) + } + useReachBottom(useCallback(() => { if (brands?.length < total) { @@ -46,29 +41,13 @@ const BrandList: FC = () => { return ( - + { brands.length > 0 ? - brands.map((d) => - - - - { - d.articles?.map((d) => { - Taro.navigateTo({url: `/pages/preview/illness/article/article?id=${d.id}`}) - }} - className='py-3 font-36' - style={{borderBottom: "1px solid #ddd"}} - >{d.title} - ) - } - - }> - - - ) : + brands.map((d, index) => jump(d.id)}> + {index + 1} . {d.title} + ) + : } ) diff --git a/src/pages/preview/illness/sort/sort.module.scss b/src/pages/preview/illness/sort/sort.module.scss index 3e4d4fa..f5319b6 100644 --- a/src/pages/preview/illness/sort/sort.module.scss +++ b/src/pages/preview/illness/sort/sort.module.scss @@ -1,6 +1,16 @@ +.scrollView{ + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; + margin: auto; + display: flex; +} + .firstOrder { width: 300rpx; - height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 200rpx); + height: 100%; View { width: 100%; @@ -54,10 +64,16 @@ padding: 0 15rpx; background: #fff; box-sizing: border-box; - height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 200rpx) + height: 100%; } .list { padding: 20rpx; border-bottom: 1px solid #F5F8F7; + width: 100%; + min-height: 100rpx; + color: #323635; + box-sizing: border-box; + display: flex; + align-items: center; } diff --git a/src/pages/preview/illness/sort/sort.tsx b/src/pages/preview/illness/sort/sort.tsx index 230971e..3812077 100644 --- a/src/pages/preview/illness/sort/sort.tsx +++ b/src/pages/preview/illness/sort/sort.tsx @@ -4,7 +4,6 @@ import {Category, HomeApi} from "@/api"; import Taro from "@tarojs/taro"; import styles from './sort.module.scss' import Tabs, {TabList} from "@/components/tabs/tabs"; -import {Search} from "@/pages/home/components/search"; import {illnessApi} from "@/api/illness"; import Empty from "@/components/empty/empty"; import leftArrow from "@/static/img/leftArrow.png" @@ -16,10 +15,10 @@ const Sort: FC = () => { const [secondId, setSecondId] = useState(undefined) const [list, setList] = useState([]) - const globalData = Taro.getApp().globalData const menu = Taro.getMenuButtonBoundingClientRect() + async function getData() { const res = await HomeApi.category(3) setData(res) @@ -30,7 +29,7 @@ const Sort: FC = () => { } function jump(id: number) { - Taro.navigateTo({url: '/pages/preview/illness/article/article?id=' + id}) + Taro.navigateTo({url: '/pages/preview/illness/list/list?id=' + id}) } const getTabList = useMemo((): TabList[] => { @@ -48,10 +47,6 @@ const Sort: FC = () => { paddingLeft: '10px' } - function onConfirm(value: string) { - console.log(value) - } - function firstIdChange(id: number) { setFirstId(id) const resource_category = data.find(d => d.id === id)?.resource_category @@ -64,16 +59,14 @@ const Sort: FC = () => { if (secondId) { Taro.showLoading({title: '加载中'}) illnessApi.list(secondId, 1, 100).then(res => { - const data = [] - res.list.forEach(d => { - data.push(...d.articles as []) - }) - setList(data) + setList(res.list) }).finally(() => { Taro.hideLoading() }).catch(() => { setList([]) }) + } else { + setList([]) } }, [secondId]) @@ -86,13 +79,11 @@ const Sort: FC = () => { onClick={() => Taro.navigateBack()}/> firstIdChange(data.tab?.value as number)}/> - - - + + {/**/} + + + { data.find(d => d.id === firstId)?.resource_category?.map(d => { scrollWithAnimation> { list.length ? - list.map(d => jump(d.id)}>{d.title}) + list.map(d => jump(d.id)}>{d.name}) : }