|
|
|
@ -1,10 +1,12 @@ |
|
|
|
|
import {Image, ScrollView, Swiper, SwiperItem, View} from "@tarojs/components"; |
|
|
|
|
import {ScrollView, Swiper, SwiperItem, 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"; |
|
|
|
|
import Taro from "@tarojs/taro"; |
|
|
|
|
import styles from './profession.module.scss' |
|
|
|
|
import Spin from "@/components/spinner"; |
|
|
|
|
import Img from "@/components/image/image"; |
|
|
|
|
|
|
|
|
|
interface KillData { |
|
|
|
|
data: Kill[] |
|
|
|
@ -16,6 +18,7 @@ const Profession = () => { |
|
|
|
|
const [tabs, setTabs] = useState<TabList[]>([]) |
|
|
|
|
const [categoryId, setCategoryId] = useState<number | null>(null) |
|
|
|
|
const [data, setData] = useState<Map<number, KillData>>(new Map) |
|
|
|
|
const [enable, setEnable] = useState(true) |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* more 开启加载更多 |
|
|
|
@ -32,9 +35,6 @@ const Profession = () => { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (!data.has(categoryId)) { |
|
|
|
|
Taro.showLoading() |
|
|
|
|
} |
|
|
|
|
const res = await HomeApi.skillList(categoryId!, page, 10) |
|
|
|
|
const dataList = res.data.reduce((pre, cur) => { |
|
|
|
|
const index = pre.findIndex(d => d.id === cur.id) |
|
|
|
@ -54,7 +54,6 @@ const Profession = () => { |
|
|
|
|
setData(oldData) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -62,10 +61,14 @@ const Profession = () => { |
|
|
|
|
}, [categoryId]) |
|
|
|
|
|
|
|
|
|
async function getCategory() { |
|
|
|
|
try { |
|
|
|
|
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) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
setEnable(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function tabsChange(tab: OnChangOpt) { |
|
|
|
@ -96,7 +99,7 @@ const Profession = () => { |
|
|
|
|
{ |
|
|
|
|
data.data.map(d => |
|
|
|
|
<View className={styles.killBox} onClick={() => jump(d)}> |
|
|
|
|
<Image src={d.url_path} mode='widthFix'/> |
|
|
|
|
<Img width={320} height={180} src={d.url_path} mode='widthFix' className={styles.image}/> |
|
|
|
|
<View className='text-ellipsis flex-1'>{d?.resource?.name}</View> |
|
|
|
|
</View> |
|
|
|
|
) |
|
|
|
@ -108,6 +111,7 @@ const Profession = () => { |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<> |
|
|
|
|
<Spin enable={enable} overlay/> |
|
|
|
|
<View className='bg-white'> |
|
|
|
|
<Tabs tabList={tabs} onChange={tabsChange} current={categoryId!}/> |
|
|
|
|
</View> |
|
|
|
|