parent
5f0da7ce0f
commit
73cfd07fca
@ -0,0 +1,4 @@ |
||||
export default definePageConfig({ |
||||
navigationBarTitleText: '专业知识', |
||||
onReachBottomDistance: 30 |
||||
}) |
@ -0,0 +1,51 @@ |
||||
import {View} from "@tarojs/components"; |
||||
import {HomeApi} from "@/api"; |
||||
import {useEffect, useState} from "react"; |
||||
import Tabs, {OnChangOpt, TabList} from "@/components/tabs/tabs"; |
||||
import Empty from "@/components/empty/empty"; |
||||
|
||||
const Profession = () => { |
||||
const [tabs, setTabs] = useState<TabList[]>([]) |
||||
const [page, setPage] = useState(1) |
||||
const [categoryId, setCategoryId] = useState<number | null>(null) |
||||
const [data, setData] = useState([]) |
||||
|
||||
async function getData(categoryId: number) { |
||||
const res = await HomeApi.skillList(categoryId, page, 10) |
||||
} |
||||
|
||||
useEffect(() => { |
||||
categoryId && getData(categoryId) |
||||
}, [categoryId, page]) |
||||
|
||||
async function getCategory() { |
||||
const res = await HomeApi.skillCategory() |
||||
const newTabs = res.map<TabList>(d => ({title: d.name, value: d.id})) |
||||
setTabs(newTabs) |
||||
setCategoryId(newTabs[0].value as number) |
||||
} |
||||
|
||||
function tabsChange(tab: OnChangOpt) { |
||||
setPage(1) |
||||
setCategoryId(tab.tab?.value as number) |
||||
} |
||||
|
||||
useEffect(() => { |
||||
getCategory().then() |
||||
}, []) |
||||
|
||||
return ( |
||||
<> |
||||
<View className='bg-white'> |
||||
<Tabs tabList={tabs} onChange={tabsChange}/> |
||||
</View> |
||||
|
||||
{ |
||||
data.length > 0 |
||||
? data.map(d => <View>{JSON.stringify(d)}</View>) |
||||
: <Empty name='暂无数据'/> |
||||
} |
||||
</> |
||||
) |
||||
} |
||||
export default Profession |
Loading…
Reference in new issue