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, Spin } from "antd"; import usePrevious from "@/Hook/usePrevious"; import { MyIcon } from "@/global"; // 热门书 export function HotCategory(props: { data: { appComponentId: number | string; componentType: string; showRightButton?: boolean; componentName?: string; remark?: string; configs?: any[]; } tabs?: any }) { const { token } = useToken() const [tag, setTag] = useState(null) const prevTag = usePrevious(tag); let { initialState } = useModel("@@initialState") let { state } = useModel("appPageConifg") const { data: { configs, componentName, showRightButton }, tabs } = props const [bookData, setBookData] = useState([]) let publicData = useMemo(() => { return { appId: initialState?.selectApp?.id || "", distributorId: initialState?.currentUser?.distributorId, appType: initialState?.selectApp?.appType || "", workDirection: tabs || state.tabs } }, [initialState?.selectApp, initialState?.currentUser?.distributorId, state.index, state.tabs, tabs]) let apiobj = useApi(initialState?.selectApp?.appCategory || 1) let getList = useAjax((params) => apiobj.getBookPageList(params)) useEffect(() => { if (tag && tag !== prevTag && configs && configs.length > 0 && configs?.[0]?.categoryId) { getList.run({ ...publicData, categoryId: tag, pageNum: 1, pageSize: 8 }).then(res => { if (res.code === 200) { setBookData(res?.data?.records) } }) } }, [tag, prevTag, configs, publicData]) useEffect(() => { if (configs && configs?.length > 0) { if (!tag && configs?.[0]?.categoryId) { setTag(configs?.[0]?.categoryId) } let isExist = configs?.find(i => i.categoryId == tag) if (!isExist) { setTag(configs?.[0]?.categoryId) } } if (configs && configs.length === 0) { setTag(null) setBookData([]) } }, [tag, configs]) return
{ configs?.map((item, index) => { return item?.categoryId &&
{ setTag(item.categoryId || "") }} > {item?.categoryInfo?.name}
}) }
{ configs?.find(i => i.categoryId == tag)?.bookIds ? configs?.find(i => i.categoryId == tag)?.bookInfos?.map((item: any, index: any) => { return
{item?.vipFree && } { e.target.src = localStorage.getItem("nocover") }} />
{item?.bookName}
}) : bookData?.length > 0 ? bookData?.map((item: any, index) => { return
{(item?.vipFree) && } { e.target.src = localStorage.getItem("nocover") }} />
{item?.longBookInfo?.bookName || item?.shortBookInfoVO?.bookName}
}) :
}
}