diff --git a/src/api/department.ts b/src/api/department.ts index 00101a6..d94a077 100644 --- a/src/api/department.ts +++ b/src/api/department.ts @@ -54,3 +54,7 @@ export function dropDiffClass(id: number, parent_id: number, ids: number[]) { export function checkDestroy(id: number) { return client.get(`/backend/v1/department/${id}/destroy`, {}); } + +export function ldapSync() { + return client.post(`/backend/v1/department/ldap-sync`, {}); +} diff --git a/src/compenents/left-menu/index.tsx b/src/compenents/left-menu/index.tsx index 85f7715..e514641 100644 --- a/src/compenents/left-menu/index.tsx +++ b/src/compenents/left-menu/index.tsx @@ -37,16 +37,16 @@ const items = [ , null, null, - null + "resource-category-menu" ), getItem( "资源管理", "resource", , [ - getItem("视频", "/videos", null, null, null, null), - getItem("图片", "/images", null, null, null, null), - getItem("课件", "/courseware", null, null, null, null), + getItem("视频", "/videos", null, null, null, "resource-menu"), + getItem("图片", "/images", null, null, null, "resource-menu"), + getItem("课件", "/courseware", null, null, null, "resource-menu"), ], null, null @@ -92,7 +92,6 @@ const items = [ "admin-user-index" ), getItem("管理日志", "/system/adminlog", null, null, null, "admin-log"), - // getItem("角色配置", "/system/adminroles", null, null, null, null), ], null, null @@ -120,6 +119,7 @@ export const LeftMenu: React.FC = () => { } return []; }; + const openKeyMerge = (pathname: string): string[] => { let newOpenKeys = hit(pathname); for (let i = 0; i < openKeys.length; i++) { @@ -166,8 +166,14 @@ export const LeftMenu: React.FC = () => { for (let i in items) { let menuItem = items[i]; - if (!menuItem.children) { - // 一级菜单不做权限控制 + // 一级菜单=>没有子菜单&配置了权限 + if (menuItem.children === null) { + if ( + menuItem.permission !== null && + typeof permissions[menuItem.permission] === "undefined" + ) { + continue; + } menus.push(menuItem); continue; } diff --git a/src/compenents/permission-button/index.tsx b/src/compenents/permission-button/index.tsx index 97d73a1..0633c58 100644 --- a/src/compenents/permission-button/index.tsx +++ b/src/compenents/permission-button/index.tsx @@ -7,7 +7,7 @@ interface PropInterface { p: string; class: string; icon: any; - onClick: () => void; + onClick?: () => void; disabled: any; } @@ -30,7 +30,7 @@ export const PerButton = (props: PropInterface) => { danger icon={props.icon} onClick={() => { - props.onClick(); + props.onClick && props.onClick(); }} disabled={props.disabled} > @@ -43,7 +43,7 @@ export const PerButton = (props: PropInterface) => { type={props.type} icon={props.icon} onClick={() => { - props.onClick(); + props.onClick && props.onClick(); }} disabled={props.disabled} > diff --git a/src/compenents/tree-category/index.tsx b/src/compenents/tree-category/index.tsx index bc01a50..cf7cecd 100644 --- a/src/compenents/tree-category/index.tsx +++ b/src/compenents/tree-category/index.tsx @@ -1,6 +1,6 @@ import { Tree } from "antd"; import { useState, useEffect } from "react"; -import { resourceCategory } from "../../api/index"; +import { useSelector } from "react-redux"; interface Option { key: string | number; @@ -17,8 +17,10 @@ interface PropInterface { export const TreeCategory = (props: PropInterface) => { const [treeData, setTreeData] = useState([]); - const [loading, setLoading] = useState(true); const [selectKey, setSelectKey] = useState([]); + const resourceCategories = useSelector( + (state: any) => state.systemConfig.value.resourceCategories + ); useEffect(() => { if (props.selected && props.selected.length > 0) { @@ -27,21 +29,17 @@ export const TreeCategory = (props: PropInterface) => { }, [props.selected]); useEffect(() => { - resourceCategory.resourceCategoryList().then((res: any) => { - const categories: CategoriesBoxModel = res.data.categories; - if (JSON.stringify(categories) !== "{}") { - const new_arr: Option[] = checkArr(categories, 0); - if (props.type === "no-cate") { - new_arr.unshift({ - key: 0, - title: 未分类, - }); - } - - setTreeData(new_arr); + if (JSON.stringify(resourceCategories) !== "{}") { + const new_arr: Option[] = checkArr(resourceCategories, 0); + if (props.type === "no-cate") { + new_arr.unshift({ + key: 0, + title: 未分类, + }); } - }); - }, []); + setTreeData(new_arr); + } + }, [resourceCategories]); const checkArr = (categories: CategoriesBoxModel, id: number) => { const arr = []; diff --git a/src/compenents/tree-department/index.tsx b/src/compenents/tree-department/index.tsx index 3bba14d..e642101 100644 --- a/src/compenents/tree-department/index.tsx +++ b/src/compenents/tree-department/index.tsx @@ -1,6 +1,7 @@ -import { Button, Input, message, Tree } from "antd"; +import { Tree } from "antd"; import { useState, useEffect } from "react"; import { department } from "../../api/index"; +import { useSelector } from "react-redux"; interface Option { key: string | number; @@ -9,19 +10,21 @@ 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 + ); useEffect(() => { if (props.selected && props.selected.length > 0) { @@ -30,32 +33,25 @@ export const TreeDepartment = (props: PropInterface) => { }, [props.selected]); useEffect(() => { - setLoading(true); - 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) !== "{}") { - if (props.showNum) { - const new_arr: any[] = checkNewArr(departments, 0, departCount); - setTreeData(new_arr); - } else { - const new_arr: any[] = checkArr(departments, 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); - }); - }, [props.refresh]); + setTreeData(data); + } else { + const data: Option[] = [ + { + key: "", + title: "全部", + children: [], + }, + ]; + setTreeData(data); + } + }, [localDepartments, props.depUserCount]); const checkNewArr = ( departments: DepartmentsBoxModel, @@ -157,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 && ( { <> - {init && ( -
- -
- )} -
+
{ const result = new URLSearchParams(useLocation().search); + + const [searchParams, setSearchParams] = useSearchParams({ + page: "1", + size: "10", + title: "", + }); + const page = parseInt(searchParams.get("page") || "1"); + const size = parseInt(searchParams.get("size") || "10"); + const title = searchParams.get("title"); + const navigate = useNavigate(); const [list, setList] = useState([]); - const [refresh, setRefresh] = useState(false); - const [page, setPage] = useState(1); - const [size, setSize] = useState(10); const [total, setTotal] = useState(0); + const [refresh, setRefresh] = useState(false); const [loading, setLoading] = useState(true); const [category_ids, setCategoryIds] = useState([]); - const [title, setTitle] = useState(""); const [dep_ids, setDepIds] = useState([]); const [selLabel, setLabel] = useState( result.get("label") ? String(result.get("label")) : "全部分类" @@ -105,7 +118,9 @@ const CoursePage = () => { type="" text={"分类"} onUpdate={(keys: any, title: any) => { - setPage(1); + resetLocalSearchParams({ + page: 1, + }); setCategoryIds(keys); if (typeof title === "string") { setLabel(title); @@ -124,12 +139,12 @@ const CoursePage = () => {
{ - setPage(1); + resetLocalSearchParams({ + page: 1, + }); setDepIds(keys); setDepLabel(title); }} @@ -346,7 +361,7 @@ const CoursePage = () => { depIds = dep_ids.join(","); } course - .courseList(page, size, "", "", title, depIds, categoryIds) + .courseList(page, size, "", "", title ? title : "", depIds, categoryIds) .then((res: any) => { setTotal(res.data.total); setList(res.data.data); @@ -362,10 +377,12 @@ const CoursePage = () => { }; // 重置列表 const resetList = () => { - setPage(1); - setSize(10); + resetLocalSearchParams({ + page: 1, + size: 10, + title: "", + }); setList([]); - setTitle(""); setRefresh(!refresh); }; @@ -379,8 +396,28 @@ const CoursePage = () => { }; const handlePageChange = (page: number, pageSize: number) => { - setPage(page); - setSize(pageSize); + resetLocalSearchParams({ + page: page, + size: pageSize, + }); + }; + + const resetLocalSearchParams = (params: LocalSearchParamsInterface) => { + setSearchParams( + (prev) => { + if (typeof params.title !== "undefined") { + prev.set("title", params.title); + } + if (typeof params.page !== "undefined") { + prev.set("page", params.page + ""); + } + if (typeof params.size !== "undefined") { + prev.set("size", params.size + ""); + } + return prev; + }, + { replace: true } + ); }; const onChange = (key: string) => { @@ -419,9 +456,11 @@ const CoursePage = () => {
课程名称: { - setTitle(e.target.value); + resetLocalSearchParams({ + title: e.target.value, + }); }} allowClear style={{ width: 160 }} @@ -435,7 +474,9 @@ const CoursePage = () => {