线上课列表初步

This commit is contained in:
禺狨 2023-03-13 18:15:50 +08:00
parent f83fbc15d5
commit 87de8155e0
3 changed files with 144 additions and 104 deletions

View File

@ -9,24 +9,32 @@ interface Option {
} }
interface PropInterface { interface PropInterface {
text: string;
onUpdate: (keys: any) => void; onUpdate: (keys: any) => void;
} }
export const TreeDepartment = (props: PropInterface) => { export const TreeDepartment = (props: PropInterface) => {
const [treeData, setTreeData] = useState<any>([]); const [treeData, setTreeData] = useState<any>([]);
const [loading, setLoading] = useState<boolean>(true); const [loading, setLoading] = useState<boolean>(true);
const [selectKey, setSelectKey] = useState<any>([]);
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
department.departmentList().then((res: any) => { department.departmentList().then((res: any) => {
const departments = res.data.departments; const departments = res.data.departments;
if (JSON.stringify(departments) !== "{}") {
const new_arr: Option[] = checkArr(departments, 0);
setTreeData(new_arr);
} else {
const new_arr: Option[] = [ const new_arr: Option[] = [
{ {
key: "", key: "",
title: "全部", title: "全部",
children: checkArr(departments, 0), children: [],
}, },
]; ];
setTreeData(new_arr); setTreeData(new_arr);
}
setLoading(false); setLoading(false);
}); });
}, []); }, []);
@ -53,7 +61,22 @@ export const TreeDepartment = (props: PropInterface) => {
const onSelect = (selectedKeys: any, info: any) => { const onSelect = (selectedKeys: any, info: any) => {
props.onUpdate(selectedKeys); props.onUpdate(selectedKeys);
setSelectKey(selectedKeys);
}; };
return <Tree onSelect={onSelect} treeData={treeData} />; return (
<div>
<div
className={
selectKey.length === 0
? "mb-8 category-label active"
: "mb-8 category-label"
}
onClick={() => onSelect([], "")}
>
{props.text}
</div>
<Tree onSelect={onSelect} treeData={treeData} />
</div>
);
}; };

View File

@ -3,21 +3,25 @@ import {
Button, Button,
Row, Row,
Col, Col,
Popconfirm, Modal,
Image, Image,
Table, Table,
Typography, Typography,
Input, Input,
message, message,
Space, Space,
Tabs,
} from "antd"; } from "antd";
import { course } from "../../api"; import { course } from "../../api";
import styles from "./index.module.less"; import styles from "./index.module.less";
import { PlusOutlined, ReloadOutlined } from "@ant-design/icons"; import { PlusOutlined, ExclamationCircleFilled } from "@ant-design/icons";
import type { ColumnsType } from "antd/es/table"; import type { ColumnsType } from "antd/es/table";
import { dateFormat } from "../../utils/index"; import { dateFormat } from "../../utils/index";
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
import { TreeDepartment, TreeCategory, PerButton } from "../../compenents"; import { TreeDepartment, TreeCategory, PerButton } from "../../compenents";
import type { TabsProps } from "antd";
const { confirm } = Modal;
interface DataType { interface DataType {
id: React.Key; id: React.Key;
@ -40,28 +44,47 @@ export const CoursePage = () => {
const [title, setTitle] = useState<string>(""); const [title, setTitle] = useState<string>("");
const [dep_ids, setDepIds] = useState<any>([]); const [dep_ids, setDepIds] = useState<any>([]);
const columns: ColumnsType<DataType> = [ const items: TabsProps["items"] = [
{ {
title: "ID", key: "1",
key: "id", label: `分类`,
dataIndex: "id", children: (
}, <div className="float-left">
{ <TreeCategory
title: "封面", text={"课程"}
dataIndex: "thumb", onUpdate={(keys: any) => setCategoryIds(keys)}
render: (thumb: string) => ( />
<Image preview={false} width={120} height={80} src={thumb}></Image> </div>
), ),
}, },
{ {
title: "课程标题", key: "2",
dataIndex: "title", label: `部门`,
render: (text: string) => <span>{text}</span>, children: (
<div className="float-left">
<TreeDepartment
text={"部门"}
onUpdate={(keys: any) => setDepIds(keys)}
/>
</div>
),
}, },
];
const columns: ColumnsType<DataType> = [
{ {
title: "时间", title: "课程名称",
dataIndex: "created_at", render: (_, record: any) => (
render: (text: string) => <span>{dateFormat(text)}</span>, <div className="d-flex">
<Image
preview={false}
width={80}
height={60}
src={record.thumb}
></Image>
<span className="ml-8">{record.title}</span>
</div>
),
}, },
{ {
title: "是否显示", title: "是否显示",
@ -72,6 +95,11 @@ export const CoursePage = () => {
</span> </span>
), ),
}, },
{
title: "创建时间",
dataIndex: "created_at",
render: (text: string) => <span>{dateFormat(text)}</span>,
},
{ {
title: "操作", title: "操作",
key: "action", key: "action",
@ -81,44 +109,50 @@ export const CoursePage = () => {
<Space size="small"> <Space size="small">
<PerButton <PerButton
type="link" type="link"
text="详情" text="编辑"
class="b-link c-red" class="b-link c-red"
icon={null} icon={null}
p="course" p="course"
onClick={() => navigate(`/course/update/${record.id}`)} onClick={() => navigate(`/course/update/${record.id}`)}
disabled={null} disabled={null}
/> />
<Popconfirm <div className="form-column"></div>
title="警告"
description="即将删除此课程,确认操作?"
onConfirm={() => removeItem(record.id)}
okText="确定"
cancelText="取消"
>
<PerButton <PerButton
type="link" type="link"
text="删除" text="删除"
class="b-link c-red" class="b-link c-red"
icon={null} icon={null}
p="course" p="course"
onClick={() => null} onClick={() => removeItem(record.id)}
disabled={null} disabled={null}
/> />
</Popconfirm>
</Space> </Space>
), ),
}, },
]; ];
// 删除图片 // 删除课程
const removeItem = (id: number) => { const removeItem = (id: number) => {
if (id === 0) { if (id === 0) {
return; return;
} }
confirm({
title: "操作确认",
icon: <ExclamationCircleFilled />,
content: "确认删除此课程?",
okText: "确认",
okType: "danger",
cancelText: "取消",
onOk() {
course.destroyCourse(id).then(() => { course.destroyCourse(id).then(() => {
message.success("删除成功"); message.success("删除成功");
resetList(); resetList();
}); });
},
onCancel() {
console.log("Cancel");
},
});
}; };
// 获取视频列表 // 获取视频列表
@ -165,31 +199,36 @@ export const CoursePage = () => {
setSize(pageSize); setSize(pageSize);
}; };
const onChange = (key: string) => {
console.log(key);
};
return ( return (
<> <>
<Row> <Row>
<Col span={4}> <Col span={4}>
<div className="playedu-main-body" style={{ marginLeft: -24 }}> <div className="playedu-main-body" style={{ marginLeft: -24 }}>
<div className="float-left mb-24"> <Tabs defaultActiveKey="1" items={items} onChange={onChange} />
<div className="d-flex mb-24">
<Typography.Text></Typography.Text>
</div>
<TreeCategory
text={"资源"}
onUpdate={(keys: any) => setCategoryIds(keys)}
/>
</div>
<div className="float-left">
<div className="d-flex mb-24">
<Typography.Text></Typography.Text>
</div>
<TreeDepartment onUpdate={(keys: any) => setDepIds(keys)} />
</div>
</div> </div>
</Col> </Col>
<Col span={20}> <Col span={20}>
<div className="playedu-main-top mb-24"> <div className="playedu-main-body">
<div className="float-left d-flex"> <div className="playedu-main-title float-left mb-24"></div>
<div className="float-left j-b-flex mb-24">
<div className="d-flex">
<Link style={{ textDecoration: "none" }} to={`/course/create`}>
<PerButton
type="primary"
text="新建课程"
class="mr-16"
icon={<PlusOutlined />}
p="course"
onClick={() => null}
disabled={null}
/>
</Link>
</div>
<div className="d-flex">
<div className="d-flex mr-24"> <div className="d-flex mr-24">
<Typography.Text></Typography.Text> <Typography.Text></Typography.Text>
<Input <Input
@ -198,10 +237,10 @@ export const CoursePage = () => {
setTitle(e.target.value); setTitle(e.target.value);
}} }}
style={{ width: 160 }} style={{ width: 160 }}
placeholder="请输入课程名称" placeholder="请输入名称关键字"
/> />
</div> </div>
<div className="d-flex mr-24"> <div className="d-flex">
<Button className="mr-16" onClick={resetList}> <Button className="mr-16" onClick={resetList}>
</Button> </Button>
@ -217,32 +256,6 @@ export const CoursePage = () => {
</div> </div>
</div> </div>
</div> </div>
<div className="playedu-main-body only">
<div className="float-left j-b-flex mb-24">
<div className="d-flex">
<Link style={{ textDecoration: "none" }} to={`/course/create`}>
<PerButton
type="primary"
text="新建"
class="mr-16"
icon={<PlusOutlined />}
p="course"
onClick={() => null}
disabled={null}
/>
</Link>
</div>
<div className="d-flex">
<Button
type="link"
icon={<ReloadOutlined />}
style={{ color: "#333333" }}
onClick={() => {
setRefresh(!refresh);
}}
></Button>
</div>
</div>
<div className="float-left"> <div className="float-left">
<Table <Table
columns={columns} columns={columns}

View File

@ -90,6 +90,7 @@ export const MemberPage: React.FC = () => {
onClick={() => navigate(`/member/update/${record.id}`)} onClick={() => navigate(`/member/update/${record.id}`)}
disabled={null} disabled={null}
/> />
<div className="form-column"></div>
<Popconfirm <Popconfirm
title="警告" title="警告"
description="即将删除此账号,确认操作?" description="即将删除此账号,确认操作?"
@ -181,7 +182,10 @@ export const MemberPage: React.FC = () => {
<Row> <Row>
<Col span={4}> <Col span={4}>
<div className="playedu-main-body" style={{ marginLeft: -24 }}> <div className="playedu-main-body" style={{ marginLeft: -24 }}>
<TreeDepartment onUpdate={(keys: any) => setDepIds(keys)} /> <TreeDepartment
text={"部门"}
onUpdate={(keys: any) => setDepIds(keys)}
/>
</div> </div>
</Col> </Col>
<Col span={20}> <Col span={20}>