safety-eval-service-frontend/src/pages/Container/EduTraining/ClassManage/Add/CourseTab.js

161 lines
4.2 KiB
JavaScript
Raw Normal View History

2026-08-21 17:43:57 +08:00
import { useEffect, useState } from "react";
import { Button, Form, Table, message } from "antd";
import ControlWrapper from "@cqsjjb/jjb-react-admin-component/ControlWrapper";
import SearchForm from "~/components/SearchForm";
import TableAction from "@cqsjjb/jjb-react-admin-component/TableAction";
import { Connect } from "@cqsjjb/jjb-dva-runtime";
import { NS_COURSEWARE } from "~/enumerate/namespace";
/** 视频累计时长(小时)→ “X分钟Y秒” */
const formatVideoDuration = (hours) => {
if (hours == null) return "-";
const totalSeconds = Math.round(hours * 3600);
return `${Math.floor(totalSeconds / 60)}分钟${totalSeconds % 60}`;
};
/** 班级详情 — 课程 Tab班级课程查询 */
function ClassCourseTab(props) {
const { classId } = props;
const [searchForm] = Form.useForm();
const [query, setQuery] = useState({ current: 1, size: 10 });
const {
classCourseList: dataSource,
classCourseTotal: total,
classCourseLoading: loading,
} = props.courseware || {};
const handleSearch = (params = query) => {
props.classCoursePage({ ...params, classId });
};
useEffect(() => {
if (!classId) return;
handleSearch(query);
}, [classId]);
const columns = [
{
title: "序号",
width: 70,
fixed: "left",
render: (_, __, index) => (query.current - 1) * query.size + index + 1,
},
{
title: "课程名称",
dataIndex: "courseName",
width: 320,
ellipsis: true,
render: (v) => v || "-",
},
{
title: "要求完成总学时",
dataIndex: "requiredTotalHours",
width: 130,
render: (v) => (v == null ? "-" : v),
},
{
title: "视频累计时长",
dataIndex: "videoDuration",
width: 130,
render: (v) => formatVideoDuration(v),
},
{
title: "上课学员数",
dataIndex: "studentCount",
width: 110,
render: (v) => (v == null ? "-" : v),
},
{
title: "已完成学员数",
dataIndex: "completedCount",
width: 120,
render: (v) => (v == null ? "-" : v),
},
{
title: "操作",
width: 140,
fixed: "right",
render: () => (
<TableAction>
<Button
type="link"
size="small"
onClick={() => message.info("课程查看功能待接入")}
>
查看
</Button>
<Button
danger
type="link"
size="small"
onClick={() => message.info("删除课程接口待接入")}
>
删除
</Button>
</TableAction>
),
},
];
return (
<>
<SearchForm
style={{ marginBottom: 16 }}
form={searchForm}
loading={loading}
formLine={[
<Form.Item key="courseName" name="courseName">
<ControlWrapper.Input
label="课程名称"
placeholder="请输入"
allowClear
maxLength={50}
/>
</Form.Item>,
]}
onReset={(value) => {
const next = { ...value, current: 1, size: 10 };
setQuery(next);
handleSearch(next);
}}
onFinish={(value) => {
const next = { ...value, current: 1, size: 10 };
setQuery(next);
handleSearch(next);
}}
/>
<Button
type="primary"
style={{ marginBottom: 12 }}
onClick={() => message.info("选择课程功能待接入")}
>
选择课程
</Button>
<Table
rowKey="id"
columns={columns}
dataSource={Array.isArray(dataSource) ? dataSource : []}
scroll={{ x: 1000 }}
loading={loading}
pagination={{
total,
showSizeChanger: true,
showQuickJumper: true,
showTotal: (t) => `${t}`,
current: query.current,
pageSize: query.size,
onChange: (page, pageSize) => {
const next = { ...query, current: page, size: pageSize };
setQuery(next);
handleSearch(next);
},
}}
/>
</>
);
}
export default Connect([NS_COURSEWARE], true)(ClassCourseTab);