diff --git a/src/pages/course/index.tsx b/src/pages/course/index.tsx index 44679e0..751c92a 100644 --- a/src/pages/course/index.tsx +++ b/src/pages/course/index.tsx @@ -1,8 +1,6 @@ import { useEffect, useState } from "react"; import { Button, - Row, - Col, Modal, Image, Table, @@ -12,7 +10,7 @@ import { Space, Tabs, } from "antd"; -import { course } from "../../api"; +import { course, department, resourceCategory } from "../../api"; import styles from "./index.module.less"; import { PlusOutlined, ExclamationCircleFilled } from "@ant-design/icons"; import type { ColumnsType } from "antd/es/table"; @@ -45,6 +43,7 @@ export const CoursePage = () => { const [dep_ids, setDepIds] = useState([]); const [selLabel, setLabel] = useState("全部课程"); const [categoryCount, setCategoryCount] = useState({}); + const [tabKey, setTabKey] = useState(1); const items: TabsProps["items"] = [ { @@ -136,7 +135,7 @@ export const CoursePage = () => { class="b-link c-red" icon={null} p="course" - onClick={() => removeItem(record.id)} + onClick={() => delItem(record.id)} disabled={null} /> @@ -145,7 +144,7 @@ export const CoursePage = () => { ]; // 删除课程 - const removeItem = (id: number) => { + const delItem = (id: number) => { if (id === 0) { return; } @@ -214,7 +213,7 @@ export const CoursePage = () => { }; const onChange = (key: string) => { - console.log(key); + setTabKey(Number(key)); }; return ( @@ -228,7 +227,6 @@ export const CoursePage = () => { onChange={onChange} /> -
{selLabel}
diff --git a/src/pages/department/index.tsx b/src/pages/department/index.tsx index 8e914d3..c198843 100644 --- a/src/pages/department/index.tsx +++ b/src/pages/department/index.tsx @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { Button, Tree, Modal, message, Tooltip } from "antd"; +import { Spin, Button, Tree, Modal, message, Tooltip } from "antd"; import styles from "./index.module.less"; import { PlusOutlined, ExclamationCircleFilled } from "@ant-design/icons"; import { department } from "../../api/index"; @@ -8,6 +8,7 @@ import type { DataNode, TreeProps } from "antd/es/tree"; import { DepartmentCreate } from "./compenents/create"; import { DepartmentUpdate } from "./compenents/update"; import { useSelector } from "../../store/hooks"; +import { useNavigate } from "react-router-dom"; const { confirm } = Modal; @@ -25,6 +26,7 @@ interface DataType { } export const DepartmentPage: React.FC = () => { + const navigate = useNavigate(); const permisssions = useSelector((state: any) => state.permisssions); const [loading, setLoading] = useState(true); const [refresh, setRefresh] = useState(false); @@ -34,12 +36,12 @@ export const DepartmentPage: React.FC = () => { const [createVisible, setCreateVisible] = useState(false); const [updateVisible, setUpdateVisible] = useState(false); const [did, setDid] = useState(0); + const [modal, contextHolder] = Modal.useModal(); const onSelect = (selectedKeys: any, info: any) => { setSelectKey(selectedKeys); }; - const through = (p: string) => { if (!permisssions) { return false; @@ -91,7 +93,7 @@ export const DepartmentPage: React.FC = () => { delUser(departments[id][i].id)} + onClick={() => removeItem(departments[id][i].id)} /> )} @@ -124,7 +126,7 @@ export const DepartmentPage: React.FC = () => { delUser(departments[id][i].id)} + onClick={() => removeItem(departments[id][i].id)} /> )} @@ -143,11 +145,83 @@ export const DepartmentPage: React.FC = () => { setRefresh(!refresh); }; - const delUser = (id: any) => { + const removeItem = (id: number) => { if (id === 0) { return; } + const instance = modal.warning({ + title: "操作确认", + centered: true, + content: ( +
+ +
+ ), + }); + department.checkDestroy(id).then((res: any) => { + setTimeout(() => { + instance.destroy(); + }, 500); + if ( + res.data.children.length === 0 && + res.data.courses.length === 0 && + res.data.users.length === 0 + ) { + delUser(id); + } else { + if (res.data.children.length > 0) { + modal.warning({ + title: "操作确认", + centered: true, + okText: "确认", + content: ( +

+ 此部门下包含 + + ({res.data.children.length}个子部门) + + ,请先解除关联再删除! +

+ ), + }); + } else { + modal.warning({ + title: "操作确认", + centered: true, + okText: "确认", + content: ( +

+ 此部门已关联 + {res.data.courses.length > 0 && ( + + )} + {res.data.users.length > 0 && ( + + )} + 请先解除关联再删除! +

+ ), + }); + } + } + }); + }; + const delUser = (id: any) => { confirm({ title: "操作确认", icon: , @@ -288,6 +362,7 @@ export const DepartmentPage: React.FC = () => { return ( <>
+ {contextHolder}
{ + const navigate = useNavigate(); const permisssions = useSelector((state: any) => state.permisssions); const [loading, setLoading] = useState(true); const [refresh, setRefresh] = useState(false); @@ -33,6 +35,7 @@ export const ResourceCategoryPage: React.FC = () => { const [createVisible, setCreateVisible] = useState(false); const [updateVisible, setUpdateVisible] = useState(false); const [cid, setCid] = useState(0); + const [modal, contextHolder] = Modal.useModal(); useEffect(() => { getData(); @@ -89,7 +92,7 @@ export const ResourceCategoryPage: React.FC = () => { delUser(categories[id][i].id)} + onClick={() => removeItem(categories[id][i].id)} /> )}
@@ -122,7 +125,7 @@ export const ResourceCategoryPage: React.FC = () => { delUser(categories[id][i].id)} + onClick={() => removeItem(categories[id][i].id)} /> )}
@@ -140,10 +143,94 @@ export const ResourceCategoryPage: React.FC = () => { setRefresh(!refresh); }; - const delUser = (id: any) => { + const removeItem = (id: number) => { if (id === 0) { return; } + const instance = modal.warning({ + title: "操作确认", + centered: true, + content: ( +
+ +
+ ), + }); + resourceCategory.checkDestroy(id).then((res: any) => { + setTimeout(() => { + instance.destroy(); + }, 500); + if ( + res.data.children.length === 0 && + res.data.courses.length === 0 && + res.data.images.length === 0 && + res.data.videos.length === 0 + ) { + delUser(id); + } else { + if (res.data.children.length > 0) { + modal.warning({ + title: "操作确认", + centered: true, + okText: "确认", + content: ( +

+ 此分类下包含 + + ({res.data.children.length}个子分类) + + ,请先解除关联再删除! +

+ ), + }); + } else { + modal.warning({ + title: "操作确认", + centered: true, + okText: "确认", + content: ( +

+ 此分类已关联 + {res.data.courses.length > 0 && ( + + )} + {res.data.videos.length > 0 && ( + + )} + {res.data.images.length > 0 && ( + + )} + 请先解除关联再删除! +

+ ), + }); + } + } + }); + }; + + const delUser = (id: any) => { confirm({ title: "操作确认", icon: , @@ -283,6 +370,7 @@ export const ResourceCategoryPage: React.FC = () => { return ( <>
+ {contextHolder}