import { BetaSchemaForm, useToken } from "@ant-design/pro-components"; import styles from './index.less' import Header from "./header"; import { useModel } from "@umijs/max"; import { Key, useEffect, useMemo, useState } from "react"; import { Config } from "@/models/appPageConifg"; import { useAjax } from "@/Hook/useAjax"; import useApi from "@/Hook/useApi"; import { Empty } from "antd"; // 热门书 export function HotCategory(props: { data: { appComponentId: number | string; componentType: string; showRightButton?: boolean; componentName?: string; remark?: string; configs?: any[]; } }) { const { token } = useToken() const [tag, setTag] = useState(null) let { initialState } = useModel("@@initialState") let { state } = useModel("appPageConifg") const { data: { configs, componentName, showRightButton } } = props const [bookData, setBookData] = useState([]) let publicData = useMemo(() => { return { appId: initialState?.selectApp?.id || "", distributorId: initialState?.currentUser?.distributorId, appType: initialState?.selectApp?.appType || "", workDirection: state.tabs } }, [initialState?.selectApp, initialState?.currentUser?.distributorId, state.index]) let apiobj = useApi(initialState?.selectApp?.appCategory || 1) let getList = useAjax((params) => apiobj.getBookPageList(params)) useEffect(() => { if (!tag) { setTag(configs?.[0]?.categoryId) } if (tag) { getList.run({ ...publicData, categoryId: tag, pageNum: 1, pageSize: 8 }).then(res => { if (res.code === 200) { setBookData(res?.data?.records) } }) } if (configs) { let isExist = configs?.find(i => i.categoryId == tag) if (!isExist) { setTag(configs?.[0]?.categoryId) getList.run({ ...publicData, categoryId: configs?.[0]?.categoryId, pageNum: 1, pageSize: 8 }).then(res => { if (res.code === 200) { setBookData(res?.data?.records) } }) } if (configs.length === 0) { setTag(null) setBookData([]) } } }, [tag, configs, publicData]) return
{ configs?.map(item => { return
{ setTag(item.categoryId || "") }} > {item?.categoryInfo?.name}
}) }
{ configs?.find(i => i.categoryId == tag)?.bookIds ? configs?.find(i => i.categoryId == tag)?.bookInfos?.map((item: any) => { return
{ e.target.src = localStorage.getItem("nocover") }} /> {item?.bookName}
}) : bookData?.length > 0 ? bookData?.map((item: any) => { return
{ e.target.src = localStorage.getItem("nocover") }} /> {item?.longBookInfo?.bookName || item?.shortBookInfoVO?.bookName}
}) :
}
}