main
king 1 year ago
parent b6134378f0
commit af5acef018
  1. 9
      src/api/illness.ts
  2. 2
      src/pages/preview/illness/article/article.config.ts
  3. 1
      src/pages/preview/illness/article/article.tsx
  4. 4
      src/pages/preview/illness/list/list.config.ts
  5. 38
      src/pages/preview/illness/list/list.module.scss
  6. 51
      src/pages/preview/illness/list/list.tsx
  7. 20
      src/pages/preview/illness/sort/sort.module.scss
  8. 31
      src/pages/preview/illness/sort/sort.tsx

@ -4,12 +4,9 @@ import {request} from "@/api/request";
export const illnessApi = { export const illnessApi = {
/** 疾病列表 */ /** 疾病列表 */
list(id: number, page: number, page_size: number) { list(id: number, page: number, page_size: number) {
return request<{ return request<{ list: any[], total: number }>(`/home/v1/illness/list`, "GET", {page, page_size, id})
list: any[],
total: number,
}>(`/home/v1/illness/list?page=${page}&page_size=${page_size}&id=${id}` , "GET")
}, },
articleInfo(id: number ) { articleInfo(owner_id: number, page: number, page_size: number) {
return request<{ content: string }>(`/home/v1/article/${id}` , "GET") return request<{ list: any[], total: number }>(`/home/v1/article/illness_list`, "GET", {page, page_size, owner_id})
}, },
} }

@ -1,4 +1,4 @@
export default definePageConfig({ export default definePageConfig({
navigationBarTitleText: '', navigationBarTitleText: '',
onReachBottomDistance: 30 onReachBottomDistance: 50
}) })

@ -13,7 +13,6 @@ const article:FC = () => {
const [show,setShow] = useState(false) const [show,setShow] = useState(false)
const [articleInfo,setArticleInfo] = useState<ArticleRecord>() const [articleInfo,setArticleInfo] = useState<ArticleRecord>()
const { children, headings } = useMemo(() => parse(articleInfo?.content || ''), [articleInfo]) const { children, headings } = useMemo(() => parse(articleInfo?.content || ''), [articleInfo])
console.log(headings,'headings')
const query = Taro.createSelectorQuery() const query = Taro.createSelectorQuery()

@ -1,4 +1,4 @@
export default definePageConfig({ export default definePageConfig({
navigationBarTitleText: '疾病知识列表', navigationBarTitleText: '文章列表',
onReachBottomDistance: 30 onReachBottomDistance: 50
}) })

@ -1,34 +1,8 @@
page{ .brands {
background-color: #fff !important; font-size: 28rpx;
} font-family: PingFang SC-Medium, PingFang SC;
.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;
font-weight: 500; font-weight: 500;
color: #909795; color: #323635;
line-height: 34rpx; padding: 30rpx;
display: -webkit-box; border-bottom: 1px solid #F5F8F7;
word-break: break-all;
text-overflow: ellipsis;
overflow: hidden;
-webkit-box-orient:vertical;
-webkit-line-clamp:2;
} }

@ -2,7 +2,6 @@ import {FC, useCallback, useEffect, useState} from "react";
import {View} from "@tarojs/components"; import {View} from "@tarojs/components";
import styles from './list.module.scss' import styles from './list.module.scss'
import Taro, {useReachBottom, useRouter} from "@tarojs/taro"; import Taro, {useReachBottom, useRouter} from "@tarojs/taro";
import Collapse from "@/components/collapse/collapse";
import {illnessApi} from "@/api/illness"; import {illnessApi} from "@/api/illness";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
@ -14,29 +13,25 @@ const BrandList: FC = () => {
const [fetchDone, setFetchDone] = useState(false) const [fetchDone, setFetchDone] = useState(false)
useEffect(() => { useEffect(() => {
Taro.showLoading({ Taro.showLoading({title: '加载中', mask: true})
title: '加载中', getData().then()
mask: true
})
setTimeout(function () {
Taro.hideLoading()
setFetchDone(true)
}, 800)
getData()
}, [page]) }, [page])
const getData = useCallback(async () => { const getData = useCallback(async () => {
try { try {
const data = await illnessApi.list(params.id, 1, 100) const data = await illnessApi.articleInfo(params.id, page, 20)
setTotal(data.total) setTotal(data.total)
setBrands([ setBrands([...brands, ...data.list])
...data.list
])
Taro.setNavigationBarTitle({title: data.list?.[0].resourceCategories?.[0]?.name ?? '文章列表'})
} catch (e) { } catch (e) {
} }
setFetchDone(true)
Taro.hideLoading()
}, [page]) }, [page])
function jump(id: number) {
Taro.navigateTo({url: '/pages/preview/illness/article/article?id=' + id})
}
useReachBottom(useCallback(() => { useReachBottom(useCallback(() => {
if (brands?.length < total) { if (brands?.length < total) {
@ -46,29 +41,13 @@ const BrandList: FC = () => {
return ( return (
<View className='p-2' style={{display:fetchDone?'block':'none'}}> <View style={{display: fetchDone ? 'block' : 'none'}} className='px-2 pt-2 bg-white'>
{ {
brands.length > 0 ? brands.length > 0 ?
brands.map((d) => brands.map((d, index) => <View key={d.id} className={styles.brands} onClick={() => jump(d.id)}>
<View className={styles.box}> {index + 1} . {d.title}
<View className={styles.rightBox}> </View>)
<Collapse title={d.name} children={ : <Empty name='暂无文章'/>
<>
{
d.articles?.map((d) => <View
onClick={() => {
Taro.navigateTo({url: `/pages/preview/illness/article/article?id=${d.id}`})
}}
className='py-3 font-36'
style={{borderBottom: "1px solid #ddd"}}
>{d.title}</View>
)
}
</>
}></Collapse>
</View>
</View>
) : <Empty name='暂无数据'/>
} }
</View> </View>
) )

@ -1,6 +1,16 @@
.scrollView{
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
display: flex;
}
.firstOrder { .firstOrder {
width: 300rpx; width: 300rpx;
height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 200rpx); height: 100%;
View { View {
width: 100%; width: 100%;
@ -54,10 +64,16 @@
padding: 0 15rpx; padding: 0 15rpx;
background: #fff; background: #fff;
box-sizing: border-box; box-sizing: border-box;
height: calc(100vh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 200rpx) height: 100%;
} }
.list { .list {
padding: 20rpx; padding: 20rpx;
border-bottom: 1px solid #F5F8F7; border-bottom: 1px solid #F5F8F7;
width: 100%;
min-height: 100rpx;
color: #323635;
box-sizing: border-box;
display: flex;
align-items: center;
} }

@ -4,7 +4,6 @@ import {Category, HomeApi} from "@/api";
import Taro from "@tarojs/taro"; import Taro from "@tarojs/taro";
import styles from './sort.module.scss' import styles from './sort.module.scss'
import Tabs, {TabList} from "@/components/tabs/tabs"; import Tabs, {TabList} from "@/components/tabs/tabs";
import {Search} from "@/pages/home/components/search";
import {illnessApi} from "@/api/illness"; import {illnessApi} from "@/api/illness";
import Empty from "@/components/empty/empty"; import Empty from "@/components/empty/empty";
import leftArrow from "@/static/img/leftArrow.png" import leftArrow from "@/static/img/leftArrow.png"
@ -16,10 +15,10 @@ const Sort: FC = () => {
const [secondId, setSecondId] = useState<number | undefined>(undefined) const [secondId, setSecondId] = useState<number | undefined>(undefined)
const [list, setList] = useState<any[]>([]) const [list, setList] = useState<any[]>([])
const globalData = Taro.getApp().globalData const globalData = Taro.getApp().globalData
const menu = Taro.getMenuButtonBoundingClientRect() const menu = Taro.getMenuButtonBoundingClientRect()
async function getData() { async function getData() {
const res = await HomeApi.category(3) const res = await HomeApi.category(3)
setData(res) setData(res)
@ -30,7 +29,7 @@ const Sort: FC = () => {
} }
function jump(id: number) { 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[] => { const getTabList = useMemo((): TabList[] => {
@ -48,10 +47,6 @@ const Sort: FC = () => {
paddingLeft: '10px' paddingLeft: '10px'
} }
function onConfirm(value: string) {
console.log(value)
}
function firstIdChange(id: number) { function firstIdChange(id: number) {
setFirstId(id) setFirstId(id)
const resource_category = data.find(d => d.id === id)?.resource_category const resource_category = data.find(d => d.id === id)?.resource_category
@ -64,16 +59,14 @@ const Sort: FC = () => {
if (secondId) { if (secondId) {
Taro.showLoading({title: '加载中'}) Taro.showLoading({title: '加载中'})
illnessApi.list(secondId, 1, 100).then(res => { illnessApi.list(secondId, 1, 100).then(res => {
const data = [] setList(res.list)
res.list.forEach(d => {
data.push(...d.articles as [])
})
setList(data)
}).finally(() => { }).finally(() => {
Taro.hideLoading() Taro.hideLoading()
}).catch(() => { }).catch(() => {
setList([]) setList([])
}) })
} else {
setList([])
} }
}, [secondId]) }, [secondId])
@ -86,13 +79,11 @@ const Sort: FC = () => {
onClick={() => Taro.navigateBack()}/> onClick={() => Taro.navigateBack()}/>
<Tabs tabList={getTabList} onChange={(data) => firstIdChange(data.tab?.value as number)}/> <Tabs tabList={getTabList} onChange={(data) => firstIdChange(data.tab?.value as number)}/>
</View> </View>
<Search onConfirm={onConfirm}/>
<View className='flex'> {/*<Search onConfirm={onConfirm}/>*/}
<ScrollView
scrollY <View className={styles.scrollView} style={{top: `${globalData.statusBarHeight + 59}px`}}>
scrollWithAnimation <ScrollView scrollY className={styles.firstOrder}>
scrollIntoView={`${prefix}-${secondId}`}
className={styles.firstOrder}>
{ {
data.find(d => d.id === firstId)?.resource_category?.map(d => <View data.find(d => d.id === firstId)?.resource_category?.map(d => <View
id={`${prefix}-${d.id}`} id={`${prefix}-${d.id}`}
@ -110,7 +101,7 @@ const Sort: FC = () => {
scrollWithAnimation> scrollWithAnimation>
{ {
list.length ? list.length ?
list.map(d => <View className={styles.list} onClick={() => jump(d.id)}>{d.title}</View>) list.map(d => <View className={styles.list} onClick={() => jump(d.id)}>{d.name}</View>)
: <Empty name='暂无数据'/> : <Empty name='暂无数据'/>
} }
</ScrollView> </ScrollView>

Loading…
Cancel
Save