index.jsx 2.07 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
import AutoTable from "@/components/AutoTable";
import { Box, Container, Stack, Typography } from "@mui/material";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { useMemo, useRef } from "react";
import "./index.less";

dayjs.extend(duration);

function Record() {
  const actionRef = useRef();

  const columns = useMemo(() => {
    let res = [
      {
        title: "开始学习时间",
        dataIndex: "fromTime",
        key: "fromTimeRange",
        valueType: "dateTimeRange",
      },
      {
        title: "结束学习时间",
        dataIndex: "toTime",
        key: "toTimeRange",
        valueType: "dateTimeRange",
      },
      { title: "课程名称", dataIndex: "courseName", key: "courseName" },
      { title: "实训名称", dataIndex: "trainName", key: "trainName" },
      { title: "实验名称", dataIndex: "experimentName", key: "experimentName" },
      {
        title: "学习时长",
        dataIndex: "duration",
        key: "duration",
        formItemProps: {
          rules: [{ required: false, message: "此项为必填项" }],
        },
        hideInSearch: true,
        render: (txt, row) => {
          let text = row?.duration ?? 0;
          const duration = dayjs.duration(text, "seconds");
          const H = duration.format("HH");
          const m = duration.format("mm");
          const s = duration.format("ss");
          const resH = H != "00" ? `${H}小时` : "";
          const resm = m != "00" ? `${m}分钟` : "";
          const ress = s != "00" ? `${s}秒` : "-";
          return resH + resm + ress;
        },
      },
    ];
    return res;
  }, []);

  return (
    <Container maxWidth={false}>
      <Stack direction={"row"} mb={2}>
        <Typography variant="h5">学习记录</Typography>
      </Stack>

      <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
        <AutoTable
          actionRef={actionRef}
          scroll={{ x: 1366 }}
          columns={[...columns]}
          path={"/studyRecord/student/page"}
        ></AutoTable>
      </Box>
    </Container>
  );
}

export default Record;