diff --git a/src/compenents/tree-category/index.tsx b/src/compenents/tree-category/index.tsx index c5a3e32..cca0ab8 100644 --- a/src/compenents/tree-category/index.tsx +++ b/src/compenents/tree-category/index.tsx @@ -4,12 +4,13 @@ import { resourceCategory } from "../../api/index"; interface Option { key: string | number; - title: string; + title: any; children?: Option[]; } interface PropInterface { text: string; + categoryCount: any; onUpdate: (keys: any, title: any) => void; } @@ -17,6 +18,7 @@ export const TreeCategory = (props: PropInterface) => { const [treeData, setTreeData] = useState([]); const [loading, setLoading] = useState(true); const [selectKey, setSelectKey] = useState([]); + useEffect(() => { setLoading(true); resourceCategory.resourceCategoryList().then((res: any) => { @@ -24,32 +26,39 @@ export const TreeCategory = (props: PropInterface) => { if (JSON.stringify(categories) !== "{}") { const new_arr: Option[] = checkArr(categories, 0); setTreeData(new_arr); - } else { - const new_arr: Option[] = [ - { - key: "", - title: "全部", - children: [], - }, - ]; - setTreeData(new_arr); } setLoading(false); }); - }, []); + }, [props.categoryCount]); const checkArr = (categories: any[], id: number) => { const arr = []; for (let i = 0; i < categories[id].length; i++) { if (!categories[categories[id][i].id]) { + let name = ( +
+ {categories[id][i].name} + + ({props.categoryCount[categories[id][i].id] || 0}) + +
+ ); arr.push({ - title: categories[id][i].name, + title: name, key: categories[id][i].id, }); } else { + let name = ( +
+ {categories[id][i].name} + + ({props.categoryCount[categories[id][i].id] || 0}) + +
+ ); const new_arr: Option[] = checkArr(categories, categories[id][i].id); arr.push({ - title: categories[id][i].name, + title: name, key: categories[id][i].id, children: new_arr, }); @@ -87,6 +96,9 @@ export const TreeCategory = (props: PropInterface) => { onClick={() => onSelect([], "")} > 全部{props.text} + {JSON.stringify(props.categoryCount) !== "{}" && ( + ({props.categoryCount["0"]}) + )} diff --git a/src/compenents/upload-image-button/index.tsx b/src/compenents/upload-image-button/index.tsx index b7dc097..19f2426 100644 --- a/src/compenents/upload-image-button/index.tsx +++ b/src/compenents/upload-image-button/index.tsx @@ -97,7 +97,11 @@ export const UploadImageButton = (props: PropsInterface) => { > - setCategoryIds(keys)} /> + setCategoryIds(keys)} + /> diff --git a/src/index.less b/src/index.less index 996ed82..4474e58 100644 --- a/src/index.less +++ b/src/index.less @@ -459,3 +459,7 @@ textarea.ant-input { height: 14px; background: #cccccc; } + +.tree-num { + color: rgba(0, 0, 0, 0.45); +} diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 078aeae..aaf1212 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -44,6 +44,7 @@ export const CoursePage = () => { const [title, setTitle] = useState(""); const [dep_ids, setDepIds] = useState([]); const [selLabel, setLabel] = useState("全部视频"); + const [categoryCount, setCategoryCount] = useState({}); const items: TabsProps["items"] = [ { @@ -53,9 +54,14 @@ export const CoursePage = () => {
{ setCategoryIds(keys); - setLabel(title); + if (typeof title == "string") { + setLabel(title); + } else { + setLabel(title.props.children[0]); + } }} />
@@ -172,6 +178,7 @@ export const CoursePage = () => { .then((res: any) => { setTotal(res.data.total); setList(res.data.data); + setCategoryCount(res.data.category_count); setLoading(false); }) .catch((err: any) => { diff --git a/src/pages/resource/images/index.tsx b/src/pages/resource/images/index.tsx index 447b0fb..90dbbc1 100644 --- a/src/pages/resource/images/index.tsx +++ b/src/pages/resource/images/index.tsx @@ -43,6 +43,7 @@ export const ResourceImagesPage = () => { const [hoverArr, setHoverArr] = useState([]); const [selLabel, setLabel] = useState("全部图片"); const [loading, setLoading] = useState(false); + const [categoryCount, setCategoryCount] = useState({}); // 删除图片 const removeResource = () => { @@ -87,6 +88,7 @@ export const ResourceImagesPage = () => { } setVisibleArr(arr); setHoverArr(arr); + setCategoryCount(res.data.category_count); setLoading(false); }) .catch((err: any) => { @@ -151,14 +153,19 @@ export const ResourceImagesPage = () => {
{ setCategoryIds(keys); - setLabel(title); + if (typeof title == "string") { + setLabel(title); + } else { + setLabel(title.props.children[0]); + } }} />
-
+
图片 / {selLabel}
diff --git a/src/pages/resource/videos/index.tsx b/src/pages/resource/videos/index.tsx index 9547f63..a2667c1 100644 --- a/src/pages/resource/videos/index.tsx +++ b/src/pages/resource/videos/index.tsx @@ -29,6 +29,7 @@ export const ResourceVideosPage = () => { const [loading, setLoading] = useState(true); const [category_ids, setCategoryIds] = useState([]); const [selLabel, setLabel] = useState("全部视频"); + const [categoryCount, setCategoryCount] = useState({}); const columns: ColumnsType = [ // { @@ -127,6 +128,7 @@ export const ResourceVideosPage = () => { setVideoList(res.data.result.data); setVideoExtra(res.data.videos_extra); setAdminUsers(res.data.admin_users); + setCategoryCount(res.data.category_count); setLoading(false); }) .catch((err: any) => { @@ -166,14 +168,19 @@ export const ResourceVideosPage = () => {
{ setCategoryIds(keys); - setLabel(title); + if (typeof title == "string") { + setLabel(title); + } else { + setLabel(title.props.children[0]); + } }} />
-
+
视频 / {selLabel}