index.jsx 20.8 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 13 14 15 16 17 18 19 20 21
import {
  Divider,
  Drawer,
  message,
  Segmented,
  Table,
  Tabs,
  Tag,
  Tooltip,
} from "antd";
wuhao's avatar
wuhao committed
22
import { useEffect, useMemo, useRef, useState } from "react";
wuhao's avatar
wuhao committed
23 24 25
import { history } from "umi";
import "./index.less";

wuhao's avatar
wuhao committed
26 27 28 29
function removeFirstAndLastChar(str) {
  return str.substring(1, str.length - 1);
}

wuhao's avatar
wuhao committed
30 31
function Dolessons() {
  const params = useParams();
wuhao's avatar
wuhao committed
32
  const formRefc = useRef();
wuhao's avatar
wuhao committed
33
  const [lessonDetail, setlessonDetail] = useState(null),
wuhao's avatar
wuhao committed
34
    [dialogprops, setdialogprops] = useState({
wuhao's avatar
wuhao committed
35 36
      open: false,
    }),
wuhao's avatar
wuhao committed
37
    [type, settype] = useState("2"),
wuhao's avatar
wuhao committed
38
    [active, setactive] = useState();
wuhao's avatar
wuhao committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
  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) => {
wuhao's avatar
wuhao committed
54 55 56
        if(data?.code !== "0000"){
          return;
        }
wuhao's avatar
wuhao committed
57 58 59 60 61 62 63 64 65
        setdatas((s) => ({
          ...s,
          tabs: data?.map((it) => ({
            ...it,
            label: it?.studentName,
            key: it?.id,
          })),
        }));
        if (dialogprops?.open) {
wuhao's avatar
wuhao committed
66 67
          setdialogprops((s) => ({
            ...s,
wuhao's avatar
wuhao committed
68 69 70
            open: true,
            defaultFormValue: { ...data[0] },
            title: "批阅",
wuhao's avatar
wuhao committed
71
          }));
wuhao's avatar
wuhao committed
72 73 74 75 76 77
        }

        formRefc?.current?.resetFields();
      },
    }
  );
wuhao's avatar
wuhao committed
78 79 80

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
wuhao's avatar
wuhao committed
81
    onSuccess: (res) => {
wuhao's avatar
wuhao committed
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      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
114 115 116 117 118 119
  const audit = (text, row, _, action) => {
    return row.reviewType == 1 ? (
      <PremButton
        btn={{
          size: "small",
          variant: "text",
wuhao's avatar
wuhao committed
120 121 122 123 124 125 126
          onClick: async () => {
            let res = await doFetch({
              url: "/studentExperiment/queryResultForPc",
              params: {
                id: row.id,
              },
            });
wuhao's avatar
wuhao committed
127 128 129 130
            setdialogprops({
              open: true,
              defaultFormValue: { ...row },
              title: "批阅",
wuhao's avatar
wuhao committed
131
              tabdata: res?.data?.data,
wuhao's avatar
wuhao committed
132 133 134 135 136 137 138
            });
          },
        }}
      >
        批阅
      </PremButton>
    ) : (
wuhao's avatar
wuhao committed
139 140 141 142
      <PremButton
        btn={{
          size: "small",
          variant: "text",
wuhao's avatar
wuhao committed
143
          color: "inherit",
wuhao's avatar
wuhao committed
144
          onClick: () => {
wuhao's avatar
wuhao committed
145
            setdialogprops({
wuhao's avatar
wuhao committed
146 147
              open: true,
              defaultFormValue: { ...row },
wuhao's avatar
wuhao committed
148 149 150 151
              title: "详情",
              maxWidth: "md",
              footer: false,
            });
wuhao's avatar
wuhao committed
152 153 154
          },
        }}
      >
wuhao's avatar
wuhao committed
155
        详情
wuhao's avatar
wuhao committed
156 157 158 159
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
160
  const remove = (text, row, _) => {
wuhao's avatar
wuhao committed
161 162 163
    return (
      <PremButton
        pop={{
wuhao's avatar
wuhao committed
164 165
          disabled: row?.reviewType !== 1,
          title: "是否退回该实训?",
wuhao's avatar
wuhao committed
166 167 168 169
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
wuhao's avatar
wuhao committed
170
              url: "/studentExperiment/remake",
wuhao's avatar
wuhao committed
171 172 173 174 175
              params: { id: row?.id },
            });
          },
        }}
        btn={{
wuhao's avatar
wuhao committed
176
          disabled: row?.reviewType !== 1,
wuhao's avatar
wuhao committed
177 178 179 180
          size: "small",
          color: "error",
        }}
      >
wuhao's avatar
wuhao committed
181
        退回
wuhao's avatar
wuhao committed
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 211 212 213 214 215 216 217 218 219 220 221 222 223
      </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
224
    return list?.data?.map((it) => ({
wuhao's avatar
wuhao committed
225 226 227 228 229 230 231 232 233 234 235 236 237
      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
238
                  audit(text, row, _, action),
wuhao's avatar
wuhao committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                  remove(text, row, _, action),
                ],
              },
            ]}
            path="/studentExperiment/queryPageByExperiment"
            extraparams={{
              experimentId: it?.id,
              type,
            }}
          />
        </Box>
      ),
    }));
  }, [list]);

  const handleClose = () => {
wuhao's avatar
wuhao committed
255
    setdialogprops((s) => ({
wuhao's avatar
wuhao committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
      ...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
274 275 276 277
      {
        value: "1",
        label: `待提交(${resdata?.submitNum})`,
      },
wuhao's avatar
wuhao committed
278 279 280
    ]);
  }, [active]);

wuhao's avatar
wuhao committed
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
  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
301

wuhao's avatar
wuhao committed
302 303 304 305 306 307 308 309 310 311
  const [drawer, setDrawer] = useState({
    open: false,
    onClose: () => {
      setDrawer((s) => ({
        ...s,
        open: false,
      }));
    },
  });

wuhao's avatar
wuhao committed
312 313 314
  return (
    <Container maxWidth={false}>
      <DraggableDialog
wuhao's avatar
wuhao committed
315 316 317
        handleClose={() => {
          handleClose();
        }}
wuhao's avatar
wuhao committed
318
        loading={loading}
wuhao's avatar
wuhao committed
319 320
        formRef={formRefc}
        dialogprops={dialogprops}
wuhao's avatar
wuhao committed
321
        maxWidth={dialogprops?.maxWidth ?? "md"}
wuhao's avatar
wuhao committed
322 323 324 325 326 327 328 329 330
        formdom={
          dialogprops?.title === "批阅" && (
            <InitForm
              fields={[
                {
                  title: "批阅信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
wuhao's avatar
wuhao committed
331
                },
wuhao's avatar
wuhao committed
332 333 334 335 336 337
                {
                  title: "打分",
                  dataIndex: "score",
                  key: "score",
                  colProps: { span: 24 },
                  valueType: "digit",
wuhao's avatar
wuhao committed
338
                },
wuhao's avatar
wuhao committed
339 340 341 342 343 344 345 346
                {
                  title: "评语",
                  dataIndex: "comment",
                  key: "comment",
                  valueType: "textarea",
                  colProps: {
                    span: 24,
                  },
wuhao's avatar
wuhao committed
347
                },
wuhao's avatar
wuhao committed
348 349 350 351 352 353 354 355 356 357
              ]}
              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
358
                });
wuhao's avatar
wuhao committed
359 360 361 362 363 364 365 366 367 368 369
                await blid?.runAsync();
              }}
            ></InitForm>
          )
        }
      >
        {dialogprops?.title === "批阅" ? (
          <>
            <Tabs
              items={datas?.tabs}
              activeKey={dialogprops?.defaultFormValue?.id}
wuhao's avatar
wuhao committed
370
              onChange={async (key) => {
wuhao's avatar
wuhao committed
371
                let currow = datas?.tabs?.filter((it) => it?.id == key)[0];
wuhao's avatar
wuhao committed
372 373 374 375 376 377
                let res = await doFetch({
                  url: "/studentExperiment/queryResultForPc",
                  params: {
                    id: currow.id,
                  },
                });
wuhao's avatar
wuhao committed
378 379 380 381
                setdialogprops({
                  open: true,
                  defaultFormValue: { ...currow },
                  title: "批阅",
wuhao's avatar
wuhao committed
382
                  tabdata: res?.data?.data,
wuhao's avatar
wuhao committed
383 384 385 386 387 388 389 390 391 392
                });
              }}
            ></Tabs>
            <Divider style={{ marginTop: 0 }}></Divider>
            <ProDescriptions
              columns={detailcolumns}
              column={2}
              style={{ marginBottom: 12 }}
              dataSource={dialogprops?.defaultFormValue}
            ></ProDescriptions>
wuhao's avatar
wuhao committed
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
            <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}
wuhao's avatar
wuhao committed
438
                width={"100%"} //fixer
wuhao's avatar
wuhao committed
439 440 441 442 443 444
                title={false}
                closable={false}
                destroyOnClose
              >
                <PointViewer
                  position={drawer?.position}
wuhao's avatar
wuhao committed
445
                  CurGongjianData={dialogprops?.tabdata?.CurGongjianData}
wuhao's avatar
wuhao committed
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 480 481 482 483 484 485 486 487 488 489 490 491 492 493
                  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
494 495 496 497 498 499 500 501 502 503
                    ? Object.values(dialogprops?.tabdata?.PeculiarityInfosDict)
                        ?.map((it, i) => {
                          return it?.map((item, index) => {
                            return {
                              ...item,
                              id: i + "," + index,
                            };
                          });
                        })
                        ?.flat()
wuhao's avatar
wuhao committed
504 505 506
                    : []
                }
                expandable={{
wuhao's avatar
wuhao committed
507
                  expandedRowRender: ({ ElementInfoList, PointList }) => {
wuhao's avatar
wuhao committed
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 540 541 542 543 544 545 546 547 548 549 550 551 552 553
                    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
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 579 580 581 582 583 584 585 586 587 588 589 590 591 592

                        <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
593 594 595 596 597 598
                      </div>
                    );
                  },
                }}
              ></Table>
            </div>
wuhao's avatar
wuhao committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
          </>
        ) : dialogprops?.title === "详情" ? (
          <Stack
            direction={"column"}
            alignItems={"center"}
            justifyContent={"center"}
            gap={1}
          >
            <SplitDesc
              columns={[
                detailcolumns,
                {
                  title: "批阅信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
                },
                [
                  {
                    title: "实验时长",
wuhao's avatar
wuhao committed
619 620
                    dataIndex: "testTime",
                    key: "testTime",
wuhao's avatar
wuhao committed
621
                    render: (text, record) => {
wuhao's avatar
wuhao committed
622 623
                      return record.testTime + '分';

wuhao's avatar
wuhao committed
624
                    },
wuhao's avatar
wuhao committed
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658
                  },
                  {
                    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
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 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
      </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;