From 1fd4f20ab0aeffc861f7e54641e733889a9a9c61 Mon Sep 17 00:00:00 2001 From: xxx Date: Sat, 23 Sep 2023 21:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AD=A6=E5=91=98=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/compenents/tree-department/index.tsx | 60 ++++++++---------------- src/pages/course/index.tsx | 2 - src/pages/member/index.tsx | 8 +++- src/playedu.d.ts | 4 ++ 4 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/compenents/tree-department/index.tsx b/src/compenents/tree-department/index.tsx index 9aed8da..e642101 100644 --- a/src/compenents/tree-department/index.tsx +++ b/src/compenents/tree-department/index.tsx @@ -10,19 +10,18 @@ interface Option { } interface PropInterface { - type: string; text: string; - refresh: boolean; showNum: boolean; selected: any; + depUserCount?: KeyNumberObject; + userCount?: number; onUpdate: (keys: any, title: any) => void; } export const TreeDepartment = (props: PropInterface) => { const [treeData, setTreeData] = useState([]); - const [loading, setLoading] = useState(true); const [selectKey, setSelectKey] = useState([]); - const [userTotal, setUserTotal] = useState(0); + // 本地缓存 const localDepartments = useSelector( (state: any) => state.systemConfig.value.departments ); @@ -34,44 +33,25 @@ export const TreeDepartment = (props: PropInterface) => { }, [props.selected]); useEffect(() => { - setLoading(true); - if (props.showNum) { - department.departmentList().then((res: any) => { - const departments: DepartmentsBoxModel = res.data.departments; - const departCount: DepIdsModel = res.data.dep_user_count; - setUserTotal(res.data.user_total); - if (JSON.stringify(departments) !== "{}") { - const new_arr: any[] = checkNewArr(departments, 0, departCount); - setTreeData(new_arr); - } else { - const new_arr: Option[] = [ - { - key: "", - title: "全部", - children: [], - }, - ]; - setTreeData(new_arr); - } - setLoading(false); - }); - } else { - if (JSON.stringify(localDepartments) !== "{}") { - const new_arr: any[] = checkArr(localDepartments, 0); - setTreeData(new_arr); + if (JSON.stringify(localDepartments) !== "{}") { + let data: any[] = []; + if (props.depUserCount) { + data = checkNewArr(localDepartments, 0, props.depUserCount); } else { - const new_arr: Option[] = [ - { - key: "", - title: "全部", - children: [], - }, - ]; - setTreeData(new_arr); + data = checkArr(localDepartments, 0); } - setLoading(false); + setTreeData(data); + } else { + const data: Option[] = [ + { + key: "", + title: "全部", + children: [], + }, + ]; + setTreeData(data); } - }, [props.refresh, localDepartments]); + }, [localDepartments, props.depUserCount]); const checkNewArr = ( departments: DepartmentsBoxModel, @@ -173,7 +153,7 @@ export const TreeDepartment = (props: PropInterface) => { onClick={() => onSelect([], "")} > 全部{props.text} - {props.showNum && userTotal ? "(" + userTotal + ")" : ""} + {props.showNum && props.userCount ? "(" + props.userCount + ")" : ""} {treeData.length > 0 && ( {
{ resetLocalSearchParams({ diff --git a/src/pages/member/index.tsx b/src/pages/member/index.tsx index 6d122d3..5684213 100644 --- a/src/pages/member/index.tsx +++ b/src/pages/member/index.tsx @@ -70,7 +70,9 @@ const MemberPage = () => { const [loading, setLoading] = useState(false); const [list, setList] = useState([]); const [total, setTotal] = useState(0); + const [pureTotal, setPureTotal] = useState(0); const [refresh, setRefresh] = useState(false); + const [depUserCount, setDepUserCount] = useState(); const [dep_ids, setDepIds] = useState([]); const [selLabel, setLabel] = useState( @@ -252,6 +254,8 @@ const MemberPage = () => { setDepartments(res.data.departments); setUserDepIds(res.data.user_dep_ids); setTotal(res.data.total); + setPureTotal(res.data.pure_total); + setDepUserCount(res.data.dep_user_count); setLoading(false); }); }; @@ -333,9 +337,9 @@ const MemberPage = () => {
{ resetLocalSearchParams({ diff --git a/src/playedu.d.ts b/src/playedu.d.ts index 48babd2..80fe456 100644 --- a/src/playedu.d.ts +++ b/src/playedu.d.ts @@ -1,4 +1,8 @@ declare global { + interface KeyNumberObject { + [key: number]: number; + } + interface FileItem { id: string; //上传文件的唯一id file: File; //上传的文件资源