diff --git a/src/compenents/tree-category/index.tsx b/src/compenents/tree-category/index.tsx index aedc7ea..9f0a259 100644 --- a/src/compenents/tree-category/index.tsx +++ b/src/compenents/tree-category/index.tsx @@ -5,13 +5,13 @@ import { resourceCategory } from "../../api/index"; interface Option { key: string | number; title: any; - children?: Option[]; } interface PropInterface { type: string; text: string; + selected: any; onUpdate: (keys: any, title: any) => void; } @@ -20,6 +20,12 @@ export const TreeCategory = (props: PropInterface) => { const [loading, setLoading] = useState(true); const [selectKey, setSelectKey] = useState([]); + useEffect(() => { + if (props.selected && props.selected.length > 0) { + setSelectKey(props.selected); + } + }, [props.selected]); + useEffect(() => { resourceCategory.resourceCategoryList().then((res: any) => { const categories = res.data.categories; diff --git a/src/compenents/tree-department/index.tsx b/src/compenents/tree-department/index.tsx index 1da5c94..249d7a2 100644 --- a/src/compenents/tree-department/index.tsx +++ b/src/compenents/tree-department/index.tsx @@ -13,6 +13,7 @@ interface PropInterface { text: string; refresh: boolean; showNum: boolean; + selected: any; onUpdate: (keys: any, title: any) => void; } @@ -22,6 +23,12 @@ export const TreeDepartment = (props: PropInterface) => { const [selectKey, setSelectKey] = useState([]); const [userTotal, setUserTotal] = useState(0); + useEffect(() => { + if (props.selected && props.selected.length > 0) { + setSelectKey(props.selected); + } + }, [props.selected]); + useEffect(() => { setLoading(true); department.departmentList().then((res: any) => { diff --git a/src/compenents/upload-image-button/index.tsx b/src/compenents/upload-image-button/index.tsx index 89fc6bb..0506914 100644 --- a/src/compenents/upload-image-button/index.tsx +++ b/src/compenents/upload-image-button/index.tsx @@ -110,6 +110,7 @@ export const UploadImageButton = (props: PropsInterface) => { { diff --git a/src/compenents/upload-video-sub/index.tsx b/src/compenents/upload-video-sub/index.tsx index ce9179f..530e63c 100644 --- a/src/compenents/upload-video-sub/index.tsx +++ b/src/compenents/upload-video-sub/index.tsx @@ -173,6 +173,7 @@ export const UploadVideoSub = (props: PropsInterface) => { setCategoryIds(keys)} diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 6f15feb..61c6be5 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -21,7 +21,7 @@ import { import type { MenuProps } from "antd"; import type { ColumnsType } from "antd/es/table"; import { dateFormat } from "../../utils/index"; -import { useNavigate } from "react-router-dom"; +import { useNavigate, useLocation } from "react-router-dom"; import { TreeDepartment, TreeCategory, PerButton } from "../../compenents"; import type { TabsProps } from "antd"; import { CourseCreate } from "./compenents/create"; @@ -40,6 +40,7 @@ interface DataType { } const CoursePage = () => { + const result = new URLSearchParams(useLocation().search); const navigate = useNavigate(); const [list, setList] = useState([]); const [refresh, setRefresh] = useState(false); @@ -50,18 +51,43 @@ const CoursePage = () => { const [category_ids, setCategoryIds] = useState([]); const [title, setTitle] = useState(""); const [dep_ids, setDepIds] = useState([]); - const [selLabel, setLabel] = useState("全部分类"); - const [selDepLabel, setDepLabel] = useState("全部部门"); + const [selLabel, setLabel] = useState( + result.get("label") ? String(result.get("label")) : "全部分类" + ); + const [selDepLabel, setDepLabel] = useState( + result.get("label") ? String(result.get("label")) : "全部部门" + ); const [course_category_ids, setCourseCategoryIds] = useState({}); const [course_dep_ids, setCourseDepIds] = useState({}); const [categories, setCategories] = useState({}); const [departments, setDepartments] = useState({}); - const [tabKey, setTabKey] = useState(1); + const [tabKey, setTabKey] = useState(result.get("did") ? "2" : "1"); const [createVisible, setCreateVisible] = useState(false); const [updateVisible, setUpdateVisible] = useState(false); const [updateHourVisible, setHourUpdateVisible] = useState(false); const [cid, setCid] = useState(0); + const [cateId, setCateId] = useState(Number(result.get("cid"))); + const [did, setDid] = useState(Number(result.get("did"))); + + useEffect(() => { + getList(); + }, [category_ids, dep_ids, refresh, page, size, tabKey]); + + useEffect(() => { + setCateId(Number(result.get("cid"))); + if (Number(result.get("cid"))) { + let arr = []; + arr.push(Number(result.get("cid"))); + setCategoryIds(arr); + } + setDid(Number(result.get("did"))); + if (Number(result.get("did"))) { + let arr = []; + arr.push(Number(result.get("did"))); + setDepIds(arr); + } + }, [result.get("cid"), result.get("did")]); const items: TabsProps["items"] = [ { @@ -70,6 +96,7 @@ const CoursePage = () => { children: (
{ @@ -90,6 +117,7 @@ const CoursePage = () => { children: (
{ setLoading(true); let categoryIds = ""; let depIds = ""; - if (tabKey === 1) { + if (tabKey === "1") { categoryIds = category_ids.join(","); } else { depIds = dep_ids.join(","); @@ -317,11 +345,6 @@ const CoursePage = () => { setRefresh(!refresh); }; - // 加载列表 - useEffect(() => { - getList(); - }, [category_ids, dep_ids, refresh, page, size, tabKey]); - const paginationProps = { current: page, //当前页码 pageSize: size, @@ -337,7 +360,7 @@ const CoursePage = () => { }; const onChange = (key: string) => { - setTabKey(Number(key)); + setTabKey(key); }; return ( @@ -345,7 +368,7 @@ const CoursePage = () => {
{
- 线上课 | {tabKey === 1 ? selLabel : selDepLabel} + 线上课 | {tabKey === "1" ? selLabel : selDepLabel}
@@ -406,8 +429,8 @@ const CoursePage = () => { rowKey={(record) => record.id} /> { setCreateVisible(false); diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index 631ec1f..be02a6a 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -89,7 +89,12 @@ const DepartmentPage = () => { removeItem(departments[id][i].id)} + onClick={() => + removeItem( + departments[id][i].id, + departments[id][i].name + ) + } /> )} @@ -124,7 +129,12 @@ const DepartmentPage = () => { removeItem(departments[id][i].id)} + onClick={() => + removeItem( + departments[id][i].id, + departments[id][i].name + ) + } /> )} @@ -144,7 +154,7 @@ const DepartmentPage = () => { setRefresh(!refresh); }; - const removeItem = (id: number) => { + const removeItem = (id: number, label: string) => { if (id === 0) { return; } @@ -187,7 +197,9 @@ const DepartmentPage = () => { style={{ paddingLeft: 4, paddingRight: 4 }} type="link" danger - onClick={() => navigate("/course")} + onClick={() => + navigate("/course?did=" + id + "&label=" + label) + } > ({res.data.courses.length}个线上课程), @@ -197,7 +209,9 @@ const DepartmentPage = () => { type="link" style={{ paddingLeft: 4, paddingRight: 4 }} danger - onClick={() => navigate("/member/index")} + onClick={() => + navigate("/member/index?did=" + id + "&label=" + label) + } > ({res.data.users.length}个学员), diff --git a/src/pages/member/index.tsx b/src/pages/member/index.tsx index cc2ced2..5b1c5b4 100644 --- a/src/pages/member/index.tsx +++ b/src/pages/member/index.tsx @@ -20,7 +20,7 @@ import { } from "@ant-design/icons"; import { user } from "../../api/index"; import { dateFormat } from "../../utils/index"; -import { Link, Navigate } from "react-router-dom"; +import { Link, Navigate, useLocation } from "react-router-dom"; import { TreeDepartment, PerButton } from "../../compenents"; import { MemberCreate } from "./compenents/create"; import { MemberUpdate } from "./compenents/update"; @@ -37,6 +37,7 @@ interface DataType { } const MemberPage = () => { + const result = new URLSearchParams(useLocation().search); const [loading, setLoading] = useState(true); const [page, setPage] = useState(1); const [size, setSize] = useState(10); @@ -47,12 +48,24 @@ const MemberPage = () => { const [nickname, setNickname] = useState(""); const [email, setEmail] = useState(""); const [dep_ids, setDepIds] = useState([]); - const [selLabel, setLabel] = useState("全部部门"); + const [selLabel, setLabel] = useState( + result.get("label") ? String(result.get("label")) : "全部部门" + ); const [createVisible, setCreateVisible] = useState(false); const [updateVisible, setUpdateVisible] = useState(false); const [mid, setMid] = useState(0); const [user_dep_ids, setUserDepIds] = useState({}); const [departments, setDepartments] = useState({}); + const [did, setDid] = useState(Number(result.get("did"))); + + useEffect(() => { + setDid(Number(result.get("did"))); + if (Number(result.get("did"))) { + let arr = []; + arr.push(Number(result.get("did"))); + setDepIds(arr); + } + }, [result.get("did")]); const columns: ColumnsType = [ { @@ -247,6 +260,7 @@ const MemberPage = () => {
{ + const result = new URLSearchParams(useLocation().search); const [imageList, setImageList] = useState([]); const [refresh, setRefresh] = useState(false); const [page, setPage] = useState(1); @@ -41,8 +43,20 @@ const ResourceImagesPage = () => { const [selectKey, setSelectKey] = useState([]); const [visibleArr, setVisibleArr] = useState([]); const [hoverArr, setHoverArr] = useState([]); - const [selLabel, setLabel] = useState("全部图片"); + const [selLabel, setLabel] = useState( + result.get("label") ? String(result.get("label")) : "全部图片" + ); const [loading, setLoading] = useState(false); + const [cateId, setCateId] = useState(Number(result.get("cid"))); + + useEffect(() => { + setCateId(Number(result.get("cid"))); + if (Number(result.get("cid"))) { + let arr = []; + arr.push(Number(result.get("cid"))); + setCategoryIds(arr); + } + }, [result.get("cid")]); // 删除图片 const removeResource = () => { @@ -151,6 +165,7 @@ const ResourceImagesPage = () => {
{ diff --git a/src/pages/resource/resource-category/index.tsx b/src/pages/resource/resource-category/index.tsx index a7427af..fb52712 100644 --- a/src/pages/resource/resource-category/index.tsx +++ b/src/pages/resource/resource-category/index.tsx @@ -88,7 +88,9 @@ const ResourceCategoryPage = () => { removeItem(categories[id][i].id)} + onClick={() => + removeItem(categories[id][i].id, categories[id][i].name) + } /> )}
@@ -123,7 +125,9 @@ const ResourceCategoryPage = () => { removeItem(categories[id][i].id)} + onClick={() => + removeItem(categories[id][i].id, categories[id][i].name) + } /> )}
@@ -142,7 +146,7 @@ const ResourceCategoryPage = () => { setRefresh(!refresh); }; - const removeItem = (id: number) => { + const removeItem = (id: number, label: string) => { if (id === 0) { return; } @@ -187,7 +191,9 @@ const ResourceCategoryPage = () => { style={{ paddingLeft: 4, paddingRight: 4 }} type="link" danger - onClick={() => navigate("/course")} + onClick={() => + navigate("/course?cid=" + id + "&label=" + label) + } > ({res.data.courses.length}个线上课程), @@ -197,7 +203,9 @@ const ResourceCategoryPage = () => { type="link" style={{ paddingLeft: 4, paddingRight: 4 }} danger - onClick={() => navigate("/videos")} + onClick={() => + navigate("/videos?cid=" + id + "&label=" + label) + } > ({res.data.videos.length}个视频文件), @@ -207,7 +215,9 @@ const ResourceCategoryPage = () => { type="link" style={{ paddingLeft: 4, paddingRight: 4 }} danger - onClick={() => navigate("/images")} + onClick={() => + navigate("/images?cid=" + id + "&label=" + label) + } > ({res.data.images.length}个图片文件), diff --git a/src/pages/resource/videos/index.tsx b/src/pages/resource/videos/index.tsx index 6d5a363..87e3e38 100644 --- a/src/pages/resource/videos/index.tsx +++ b/src/pages/resource/videos/index.tsx @@ -2,6 +2,7 @@ import { useEffect, useState } from "react"; import { Modal, Table, message, Space } from "antd"; import { resource } from "../../../api"; // import styles from "./index.module.less"; +import { useLocation } from "react-router-dom"; import { ExclamationCircleFilled } from "@ant-design/icons"; import type { ColumnsType } from "antd/es/table"; import { dateFormat } from "../../../utils/index"; @@ -18,6 +19,7 @@ interface DataType { } const ResourceVideosPage = () => { + const result = new URLSearchParams(useLocation().search); const [videoList, setVideoList] = useState([]); const [videosExtra, setVideoExtra] = useState([]); const [adminUsers, setAdminUsers] = useState({}); @@ -27,7 +29,19 @@ const ResourceVideosPage = () => { const [total, setTotal] = useState(0); const [loading, setLoading] = useState(true); const [category_ids, setCategoryIds] = useState([]); - const [selLabel, setLabel] = useState("全部视频"); + const [selLabel, setLabel] = useState( + result.get("label") ? String(result.get("label")) : "全部视频" + ); + const [cateId, setCateId] = useState(Number(result.get("cid"))); + + useEffect(() => { + setCateId(Number(result.get("cid"))); + if (Number(result.get("cid"))) { + let arr = []; + arr.push(Number(result.get("cid"))); + setCategoryIds(arr); + } + }, [result.get("cid")]); const columns: ColumnsType = [ // { @@ -170,6 +184,7 @@ const ResourceVideosPage = () => {
{