|
|
|
@ -21,16 +21,20 @@ const Profession = () => { |
|
|
|
|
* more 开启加载更多 |
|
|
|
|
*/ |
|
|
|
|
async function getData(more = false) { |
|
|
|
|
if (categoryId) { |
|
|
|
|
const oldData = new Map<number, KillData>(data) |
|
|
|
|
const categoryData = oldData.get(categoryId) |
|
|
|
|
const page = more ? (categoryData?.page || 0) + 1 : categoryData?.page || 1 |
|
|
|
|
if (!categoryId) return; |
|
|
|
|
const oldData = new Map<number, KillData>(data) |
|
|
|
|
const categoryData = oldData.get(categoryId) |
|
|
|
|
const page = more ? (categoryData?.page || 0) + 1 : categoryData?.page || 1 |
|
|
|
|
|
|
|
|
|
/** 无更多 */ |
|
|
|
|
if (more && categoryData && categoryData.data.length >= categoryData.total) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** 无更多 */ |
|
|
|
|
if (more && categoryData && categoryData.data.length >= categoryData.total) { |
|
|
|
|
return |
|
|
|
|
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) |
|
|
|
@ -42,14 +46,15 @@ const Profession = () => { |
|
|
|
|
return pre |
|
|
|
|
}, categoryData?.data || []) |
|
|
|
|
oldData.delete(categoryId) |
|
|
|
|
|
|
|
|
|
oldData.set(categoryId, { |
|
|
|
|
data: dataList, |
|
|
|
|
total: res.total, |
|
|
|
|
page: page |
|
|
|
|
}) |
|
|
|
|
setData(oldData) |
|
|
|
|
} catch (e) { |
|
|
|
|
} |
|
|
|
|
Taro.hideLoading() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|