index.jsx 20.4 KB
Newer Older
wuhao's avatar
wuhao committed
1 2 3
import AutoTable from "@/components/AutoTable";
import DraggableDialog from "@/components/DraggableDialog";
import InitForm from "@/components/InitForm";
wuhao's avatar
wuhao committed
4
import PointViewer from "@/components/PointViewer";
wuhao's avatar
wuhao committed
5
import PremButton from "@/components/PremButton";
wuhao's avatar
wuhao committed
6
import SplitDesc from "@/components/SplitDesc";
wuhao's avatar
wuhao committed
7
import { doFetch } from "@/utils/doFetch";
wuhao's avatar
wuhao committed
8
import { ProDescriptions } from "@ant-design/pro-components";
wuhao's avatar
wuhao committed
9 10 11
import { Box, Container, Stack, Typography } from "@mui/material";
import { useParams } from "@umijs/max";
import { useAsyncEffect, useRequest } from "ahooks";
wuhao's avatar
wuhao committed
12
import { Divider, Drawer, message, Segmented, Table, Tabs } from "antd";
wuhao's avatar
wuhao committed
13
import { useEffect, useMemo, useRef, useState } from "react";
wuhao's avatar
wuhao committed
14 15 16
import { history } from "umi";
import "./index.less";

wuhao's avatar
wuhao committed
17 18 19 20
function removeFirstAndLastChar(str) {
  return str.substring(1, str.length - 1);
}

wuhao's avatar
wuhao committed
21 22
function Dolessons() {
  const params = useParams();
wuhao's avatar
wuhao committed
23
  const formRefc = useRef();
wuhao's avatar
wuhao committed
24
  const [lessonDetail, setlessonDetail] = useState(null),
wuhao's avatar
wuhao committed
25
    [dialogprops, setdialogprops] = useState({
wuhao's avatar
wuhao committed
26 27
      open: false,
    }),
wuhao's avatar
wuhao committed
28
    [type, settype] = useState("2"),
wuhao's avatar
wuhao committed
29
    [active, setactive] = useState();
wuhao's avatar
wuhao committed
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
  const [datas, setdatas] = useState({
    tabs: [],
  });

  let blid = useRequest(
    async () => {
      let res = await doFetch({
        url: "/studentExperiment/queryAllByLoginTeacher",
        params: { experimentId: active },
      });
      return res?.data?.dataList;
    },
    {
      refreshDeps: [active],
      onSuccess: (data, params) => {
        setdatas((s) => ({
          ...s,
          tabs: data?.map((it) => ({
            ...it,
            label: it?.studentName,
            key: it?.id,
          })),
        }));
        if (dialogprops?.open) {
          setdialogprops({
            open: true,
            defaultFormValue: { ...data[0] },
            title: "批阅",
          });
        }

        formRefc?.current?.resetFields();
      },
    }
  );
wuhao's avatar
wuhao committed
65 66 67

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
wuhao's avatar
wuhao committed
68
    onSuccess: (res) => {
wuhao's avatar
wuhao committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
      if (res?.code == "0000") {
        handleClose();
        message.success("操作成功");
      }
    },
  });

  useEffect(() => {
    doFetch({ url: "/busTrain/detail", params: { id: params?.id } }).then(
      (res) => {
        if (res.code === "0000") {
          setlessonDetail(res?.data?.data);
        }
      }
    );
  }, []);

  const list = useRequest(
    async () => {
      let res = await doFetch({
        url: "/busTrainExperiment/list",
        params: { trainId: params?.id },
      });
      setactive(res?.data?.dataList?.[0]?.id ?? null);

      return res?.data?.dataList;
    },
    {
      debounceWait: 400,
    }
  );

wuhao's avatar
wuhao committed
101 102 103 104 105 106
  const audit = (text, row, _, action) => {
    return row.reviewType == 1 ? (
      <PremButton
        btn={{
          size: "small",
          variant: "text",
wuhao's avatar
wuhao committed
107 108 109 110 111 112 113
          onClick: async () => {
            let res = await doFetch({
              url: "/studentExperiment/queryResultForPc",
              params: {
                id: row.id,
              },
            });
wuhao's avatar
wuhao committed
114 115 116 117
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "批阅",
wuhao's avatar
wuhao committed
118
              tabdata: res?.data?.data,
wuhao's avatar
wuhao committed
119 120 121 122 123 124 125
            });
          },
        }}
      >
        批阅
      </PremButton>
    ) : (
wuhao's avatar
wuhao committed
126 127 128 129
      <PremButton
        btn={{
          size: "small",
          variant: "text",
wuhao's avatar
wuhao committed
130
          color: "inherit",
wuhao's avatar
wuhao committed
131
          onClick: () => {
wuhao's avatar
wuhao committed
132
            setdialogprops({
wuhao's avatar
wuhao committed
133 134
              open: true,
              defaultFormValue: { ...row },
wuhao's avatar
wuhao committed
135 136 137 138
              title: "详情",
              maxWidth: "md",
              footer: false,
            });
wuhao's avatar
wuhao committed
139 140 141
          },
        }}
      >
wuhao's avatar
wuhao committed
142
        详情
wuhao's avatar
wuhao committed
143 144 145 146
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
147
  const remove = (text, row, _) => {
wuhao's avatar
wuhao committed
148 149 150
    return (
      <PremButton
        pop={{
wuhao's avatar
wuhao committed
151 152
          disabled: row?.reviewType !== 1,
          title: "是否退回该实训?",
wuhao's avatar
wuhao committed
153 154 155 156
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
wuhao's avatar
wuhao committed
157
              url: "/studentExperiment/remake",
wuhao's avatar
wuhao committed
158 159 160 161 162
              params: { id: row?.id },
            });
          },
        }}
        btn={{
wuhao's avatar
wuhao committed
163
          disabled: row?.reviewType !== 1,
wuhao's avatar
wuhao committed
164 165 166 167
          size: "small",
          color: "error",
        }}
      >
wuhao's avatar
wuhao committed
168
        退回
wuhao's avatar
wuhao committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
      </PremButton>
    );
  };

  const experimentColumns = useMemo(() => {
    let col = [
      { title: "学生姓名", dataIndex: "studentName", key: "studentName" },
      { title: "学生账号", dataIndex: "studentAccount", key: "studentAccount" },
      { title: "分数", dataIndex: "score", key: "score", hideInSearch: true },
      {
        title: "提交时间",
        dataIndex: "finishTime",
        key: "finishTime",
        hideInSearch: true,
      },
      {
        title: "批阅时间",
        dataIndex: "reviewTime",
        key: "reviewTime",
        hideInSearch: true,
      },
      {
        title: "批阅状态",
        dataIndex: "reviewTypeName",
        key: "reviewType",
        valueType: "select",
        options: [
          {
            label: "待批阅",
            value: "1",
          },
          {
            label: "已批阅",
            value: "2",
          },
        ],
      },
    ];
    return col;
  }, []);

  const items = useMemo(() => {
wuhao's avatar
wuhao committed
211
    return list?.data?.map((it) => ({
wuhao's avatar
wuhao committed
212 213 214 215 216 217 218 219 220 221 222 223 224
      key: it?.id,
      label: it?.experimentName,
      children: (
        <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
          <AutoTable
            rerendered={it?.id === active}
            columns={[
              ...experimentColumns,
              {
                title: "操作",
                valueType: "option",
                width: 180,
                render: (text, row, _, action) => [
wuhao's avatar
wuhao committed
225
                  audit(text, row, _, action),
wuhao's avatar
wuhao committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
                  remove(text, row, _, action),
                ],
              },
            ]}
            path="/studentExperiment/queryPageByExperiment"
            extraparams={{
              experimentId: it?.id,
              type,
            }}
          />
        </Box>
      ),
    }));
  }, [list]);

  const handleClose = () => {
wuhao's avatar
wuhao committed
242
    setdialogprops((s) => ({
wuhao's avatar
wuhao committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
      ...s,
      open: false,
    }));
  };

  const [semlist, setsemlist] = useState();
  useAsyncEffect(async () => {
    if (!active) return;
    let res = await doFetch({
      url: "/studentExperiment/queryScoreStatistics",
      params: { experimentId: active },
    });
    let resdata = res?.data?.data;
    setsemlist([
      {
        value: "2",
        label: `已提交(${resdata?.notSubmitNum})`,
      },
wuhao's avatar
wuhao committed
261 262 263 264
      {
        value: "1",
        label: `待提交(${resdata?.submitNum})`,
      },
wuhao's avatar
wuhao committed
265 266 267
    ]);
  }, [active]);

wuhao's avatar
wuhao committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
  const detailcolumns = [
    { title: "学生姓名", dataIndex: "studentName", key: "studentName" },
    { title: "学生账号", dataIndex: "studentAccount", key: "studentAccount" },
    { title: "课程名称", dataIndex: "courseName", key: "courseName" },
    { title: "实训名称", dataIndex: "trainName", key: "trainName" },
    { title: "实验名称", dataIndex: "experimentName", key: "experimentName" },
    { title: "分数", dataIndex: "score", key: "score", hideInSearch: true },
    { title: "权重", dataIndex: "weight", key: "weight", hideInSearch: true },
    { title: "分数", dataIndex: "scoreWeight", key: "scoreWeight" },
    {
      title: "提交时间",
      dataIndex: "finishTime",
      key: "finishTimeRange",
    },
    {
      title: "批阅时间",
      dataIndex: "reviewTime",
      key: "reviewTimeRange",
    },
  ];
wuhao's avatar
wuhao committed
288

wuhao's avatar
wuhao committed
289 290 291 292 293 294 295 296 297 298
  const [drawer, setDrawer] = useState({
    open: false,
    onClose: () => {
      setDrawer((s) => ({
        ...s,
        open: false,
      }));
    },
  });

wuhao's avatar
wuhao committed
299 300 301
  return (
    <Container maxWidth={false}>
      <DraggableDialog
wuhao's avatar
wuhao committed
302 303 304
        handleClose={() => {
          handleClose();
        }}
wuhao's avatar
wuhao committed
305
        loading={loading}
wuhao's avatar
wuhao committed
306 307
        formRef={formRefc}
        dialogprops={dialogprops}
wuhao's avatar
wuhao committed
308
        maxWidth={dialogprops?.maxWidth ?? "md"}
wuhao's avatar
wuhao committed
309 310 311 312 313 314 315 316 317
        formdom={
          dialogprops?.title === "批阅" && (
            <InitForm
              fields={[
                {
                  title: "批阅信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
wuhao's avatar
wuhao committed
318
                },
wuhao's avatar
wuhao committed
319 320 321 322 323 324
                {
                  title: "打分",
                  dataIndex: "score",
                  key: "score",
                  colProps: { span: 24 },
                  valueType: "digit",
wuhao's avatar
wuhao committed
325
                },
wuhao's avatar
wuhao committed
326 327 328 329 330 331 332 333
                {
                  title: "评语",
                  dataIndex: "comment",
                  key: "comment",
                  valueType: "textarea",
                  colProps: {
                    span: 24,
                  },
wuhao's avatar
wuhao committed
334
                },
wuhao's avatar
wuhao committed
335 336 337 338 339 340 341 342 343 344
              ]}
              defaultFormValue={{ examineResult: "1" }}
              onFinish={async (val, extra) => {
                let postdata = {
                  ...val,
                  id: dialogprops?.defaultFormValue?.id,
                };
                await runAsync({
                  url: "/studentExperiment/giveScore",
                  params: postdata,
wuhao's avatar
wuhao committed
345
                });
wuhao's avatar
wuhao committed
346 347 348 349 350 351 352 353 354 355 356
                await blid?.runAsync();
              }}
            ></InitForm>
          )
        }
      >
        {dialogprops?.title === "批阅" ? (
          <>
            <Tabs
              items={datas?.tabs}
              activeKey={dialogprops?.defaultFormValue?.id}
wuhao's avatar
wuhao committed
357
              onChange={async (key) => {
wuhao's avatar
wuhao committed
358
                let currow = datas?.tabs?.filter((it) => it?.id == key)[0];
wuhao's avatar
wuhao committed
359 360 361 362 363 364
                let res = await doFetch({
                  url: "/studentExperiment/queryResultForPc",
                  params: {
                    id: currow.id,
                  },
                });
wuhao's avatar
wuhao committed
365 366 367 368
                setdialogprops({
                  open: true,
                  defaultFormValue: { ...currow },
                  title: "批阅",
wuhao's avatar
wuhao committed
369
                  tabdata: res?.data?.data,
wuhao's avatar
wuhao committed
370 371 372 373 374 375 376 377 378 379
                });
              }}
            ></Tabs>
            <Divider style={{ marginTop: 0 }}></Divider>
            <ProDescriptions
              columns={detailcolumns}
              column={2}
              style={{ marginBottom: 12 }}
              dataSource={dialogprops?.defaultFormValue}
            ></ProDescriptions>
wuhao's avatar
wuhao committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479
            <Divider></Divider>

            <b style={{ fontSize: 14, paddingBottom: 10, display: "block" }}>
              实验素养
            </b>
            <Table
              size="small"
              pagination={{
                pageSize: 6,
              }}
              columns={[
                {
                  title: "操作名称",
                  dataIndex: "config",
                  key: "config",
                  render: (text, row) => {
                    return row?.config?.name;
                  },
                },
                {
                  title: "是否操作",
                  dataIndex: "isComplete",
                  key: "isComplete",
                  width: 200,
                  render: (text, row) => {
                    return row?.isComplete ? (
                      "完成"
                    ) : (
                      <span style={{ color: "red" }}>未完成</span>
                    );
                  },
                },
              ]}
              dataSource={
                dialogprops?.tabdata?.recordDataDic
                  ? Object.values(dialogprops?.tabdata?.recordDataDic)
                  : []
              }
            ></Table>

            <Divider></Divider>

            <div style={{ position: "relative", minHeight: 360 }}>
              <Drawer
                {...drawer}
                getContainer={false}
                title={false}
                closable={false}
                destroyOnClose
              >
                <PointViewer
                  position={drawer?.position}
                  CoordinatePoint={dialogprops?.tabdata?.CoordinatePoint}
                  CurGongjianPoint={dialogprops?.tabdata?.CurGongjianPoint}
                ></PointViewer>
              </Drawer>
              <b style={{ fontSize: 14, paddingBottom: 10, display: "block" }}>
                实验报告
              </b>
              <Table
                size="small"
                pagination={{
                  pageSize: 6,
                }}
                columns={[
                  {
                    title: "名称",
                    dataIndex: "Name",
                    key: "Name",
                  },
                  {
                    title: "测量值",
                    dataIndex: "actualValue",
                    key: "actualValue",
                    render: (text, row) => {
                      return row?.actualValue?.toFixed(4) ?? "";
                    },
                  },
                  {
                    title: "名义值",
                    dataIndex: "normal",
                    key: "normal",
                    render: (text, row) => {
                      return row?.normal?.toFixed(4) ?? "";
                    },
                  },
                  {
                    title: "上公差",
                    dataIndex: "Upper",
                    key: "Upper",
                  },
                  {
                    title: "下公差",
                    dataIndex: "Down",
                    key: "Down",
                  },
                ]}
                rowKey={"id"}
                dataSource={
                  dialogprops?.tabdata?.PeculiarityInfosDict
wuhao's avatar
wuhao committed
480 481 482 483 484 485 486 487 488 489
                    ? Object.values(dialogprops?.tabdata?.PeculiarityInfosDict)
                        ?.map((it, i) => {
                          return it?.map((item, index) => {
                            return {
                              ...item,
                              id: i + "," + index,
                            };
                          });
                        })
                        ?.flat()
wuhao's avatar
wuhao committed
490 491 492
                    : []
                }
                expandable={{
wuhao's avatar
wuhao committed
493
                  expandedRowRender: ({ ElementInfoList, PointList }) => {
wuhao's avatar
wuhao committed
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
                    return (
                      <div style={{ display: "flex", gap: 6 }}>
                        {ElementInfoList?.map((it) => {
                          return (
                            <div
                              style={{
                                padding: 12,
                                backgroundColor: "#f0f0f0",
                                display: "inline-block",
                                borderRadius: 4,
                                marginBottom: 6,
                              }}
                            >
                              <span style={{ paddingRight: 12 }}>
                                {it?.Name}
                              </span>
                              {it?.PointList?.map((its) => (
                                <Tooltip
                                  key={its?.id}
                                  title={
                                    <div
                                      dangerouslySetInnerHTML={{
                                        __html: removeFirstAndLastChar(
                                          JSON.stringify(its.Position)
                                        ).replace(/,/g, "<br/>"),
                                      }}
                                    ></div>
                                  }
                                >
                                  <Tag
                                    onClick={() => {
                                      setDrawer((s) => ({
                                        ...s,
                                        position: its.Position,
                                        open: true,
                                      }));
                                    }}
                                    style={{ cursor: "pointer" }}
                                  >
                                    {its.Name}
                                  </Tag>
                                </Tooltip>
                              ))}
                            </div>
                          );
                        })}
wuhao's avatar
wuhao committed
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578

                        <div
                          style={{
                            padding: 12,
                            backgroundColor: "#f0f0f0",
                            display: "inline-block",
                            borderRadius: 4,
                            marginBottom: 6,
                          }}
                        >
                          <span style={{ paddingRight: 12 }}>点集合</span>
                          {PointList?.map((its) => (
                            <Tooltip
                              key={its?.id}
                              title={
                                <div
                                  dangerouslySetInnerHTML={{
                                    __html: removeFirstAndLastChar(
                                      JSON.stringify(its.Position)
                                    ).replace(/,/g, "<br/>"),
                                  }}
                                ></div>
                              }
                            >
                              <Tag
                                onClick={() => {
                                  setDrawer((s) => ({
                                    ...s,
                                    position: its.Position,
                                    open: true,
                                  }));
                                }}
                                style={{ cursor: "pointer" }}
                              >
                                {its.Name}
                              </Tag>
                            </Tooltip>
                          ))}
                        </div>
wuhao's avatar
wuhao committed
579 580 581 582 583 584
                      </div>
                    );
                  },
                }}
              ></Table>
            </div>
wuhao's avatar
wuhao committed
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
          </>
        ) : dialogprops?.title === "详情" ? (
          <Stack
            direction={"column"}
            alignItems={"center"}
            justifyContent={"center"}
            gap={1}
          >
            <SplitDesc
              columns={[
                detailcolumns,
                {
                  title: "批阅信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
                },
                [
                  {
                    title: "实验时长",
                    dataIndex: "useTime",
                    key: "useTime",
                  },
                  {
                    title: "批阅状态",
                    dataIndex: "reviewTypeName",
                    key: "reviewTypeName",
                  },
                  {
                    title: "批阅时间",
                    dataIndex: "reviewTime",
                    key: "reviewTime",
                  },
                  {
                    title: "批阅人",
                    dataIndex: "reviewUserName",
                    key: "reviewUserName",
                  },
                  {
                    title: "分数",
                    dataIndex: "score",
                    key: "score",
                    span: 2,
                  },
                  {
                    title: "评语",
                    dataIndex: "comment",
                    key: "comment",
                    span: 3,
                  },
                ],
              ]}
              dataSource={dialogprops?.defaultFormValue}
            ></SplitDesc>
          </Stack>
        ) : null}
wuhao's avatar
wuhao committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
      </DraggableDialog>

      <Box
        display={"flex"}
        justifyContent={"space-between"}
        alignItems={"center"}
        sx={{ mb: 2.5 }}
        mt={0}
      >
        <Typography variant="h5">
          {lessonDetail?.trainName ?? "暂无名称"}
        </Typography>
        <Stack spacing={2} direction="row">
          <PremButton
            btn={{
              variant: "outlined",
              onClick: (e) => {
                e.stopPropagation();
                history.back();
              },
            }}
          >
            返回
          </PremButton>
        </Stack>
      </Box>
      <Box>
        <Tabs
          activeKey={active}
          onChange={setactive}
          items={items}
          tabPosition="top"
          tabBarExtraContent={
            <Segmented
              value={type}
              onChange={(val) => {
                settype(val);
              }}
              options={semlist}
            />
          }
        />
      </Box>
    </Container>
  );
}

export default Dolessons;