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

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

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

wuhao's avatar
wuhao committed
143
  const remove = (text, row, _) => {
wuhao's avatar
wuhao committed
144 145 146
    return (
      <PremButton
        pop={{
wuhao's avatar
wuhao committed
147 148
          disabled: row?.reviewType !== 1,
          title: "是否退回该实训?",
wuhao's avatar
wuhao committed
149 150 151 152
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
wuhao's avatar
wuhao committed
153
              url: "/studentExperiment/remake",
wuhao's avatar
wuhao committed
154 155 156 157 158
              params: { id: row?.id },
            });
          },
        }}
        btn={{
wuhao's avatar
wuhao committed
159
          disabled: row?.reviewType !== 1,
wuhao's avatar
wuhao committed
160 161 162 163
          size: "small",
          color: "error",
        }}
      >
wuhao's avatar
wuhao committed
164
        退回
wuhao's avatar
wuhao committed
165 166 167 168 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
      </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
207
    return list?.data?.map((it) => ({
wuhao's avatar
wuhao committed
208 209 210 211 212 213 214 215 216 217 218 219 220
      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
221
                  audit(text, row, _, action),
wuhao's avatar
wuhao committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
                  remove(text, row, _, action),
                ],
              },
            ]}
            path="/studentExperiment/queryPageByExperiment"
            extraparams={{
              experimentId: it?.id,
              type,
            }}
          />
        </Box>
      ),
    }));
  }, [list]);

  const handleClose = () => {
wuhao's avatar
wuhao committed
238
    setdialogprops((s) => ({
wuhao's avatar
wuhao committed
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
      ...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
257 258 259 260
      {
        value: "1",
        label: `待提交(${resdata?.submitNum})`,
      },
wuhao's avatar
wuhao committed
261 262 263
    ]);
  }, [active]);

wuhao's avatar
wuhao committed
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
  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
284

wuhao's avatar
wuhao committed
285 286 287 288 289 290 291 292 293 294
  const [drawer, setDrawer] = useState({
    open: false,
    onClose: () => {
      setDrawer((s) => ({
        ...s,
        open: false,
      }));
    },
  });

wuhao's avatar
wuhao committed
295 296 297
  return (
    <Container maxWidth={false}>
      <DraggableDialog
wuhao's avatar
wuhao committed
298 299 300
        handleClose={() => {
          handleClose();
        }}
wuhao's avatar
wuhao committed
301
        loading={loading}
wuhao's avatar
wuhao committed
302 303
        formRef={formRefc}
        dialogprops={dialogprops}
wuhao's avatar
wuhao committed
304
        maxWidth={dialogprops?.maxWidth ?? "md"}
wuhao's avatar
wuhao committed
305 306 307 308 309 310 311 312 313
        formdom={
          dialogprops?.title === "批阅" && (
            <InitForm
              fields={[
                {
                  title: "批阅信息",
                  dataIndex: "sort",
                  key: "sort",
                  valueType: "split",
wuhao's avatar
wuhao committed
314
                },
wuhao's avatar
wuhao committed
315 316 317 318 319 320
                {
                  title: "打分",
                  dataIndex: "score",
                  key: "score",
                  colProps: { span: 24 },
                  valueType: "digit",
wuhao's avatar
wuhao committed
321
                },
wuhao's avatar
wuhao committed
322 323 324 325 326 327 328 329
                {
                  title: "评语",
                  dataIndex: "comment",
                  key: "comment",
                  valueType: "textarea",
                  colProps: {
                    span: 24,
                  },
wuhao's avatar
wuhao committed
330
                },
wuhao's avatar
wuhao committed
331 332 333 334 335 336 337 338 339 340
              ]}
              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
341
                });
wuhao's avatar
wuhao committed
342 343 344 345 346 347 348 349 350 351 352
                await blid?.runAsync();
              }}
            ></InitForm>
          )
        }
      >
        {dialogprops?.title === "批阅" ? (
          <>
            <Tabs
              items={datas?.tabs}
              activeKey={dialogprops?.defaultFormValue?.id}
wuhao's avatar
wuhao committed
353
              onChange={async (key) => {
wuhao's avatar
wuhao committed
354
                let currow = datas?.tabs?.filter((it) => it?.id == key)[0];
wuhao's avatar
wuhao committed
355 356 357 358 359 360
                let res = await doFetch({
                  url: "/studentExperiment/queryResultForPc",
                  params: {
                    id: currow.id,
                  },
                });
wuhao's avatar
wuhao committed
361 362 363 364
                setdialogprops({
                  open: true,
                  defaultFormValue: { ...currow },
                  title: "批阅",
wuhao's avatar
wuhao committed
365
                  tabdata: res?.data?.data,
wuhao's avatar
wuhao committed
366 367 368 369 370 371 372 373 374 375
                });
              }}
            ></Tabs>
            <Divider style={{ marginTop: 0 }}></Divider>
            <ProDescriptions
              columns={detailcolumns}
              column={2}
              style={{ marginBottom: 12 }}
              dataSource={dialogprops?.defaultFormValue}
            ></ProDescriptions>
wuhao's avatar
wuhao committed
376 377 378 379 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 480 481 482 483 484 485 486 487 488 489 490 491 492 493 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 540 541 542 543 544
            <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
                    ? Object.values(
                        dialogprops?.tabdata?.PeculiarityInfosDict
                      )?.map((it, i) =>
                        it?.[0]
                          ? {
                              ...it?.[0],
                              id: i + 1,
                            }
                          : {}
                      )
                    : []
                }
                expandable={{
                  expandedRowRender: ({ ElementInfoList }) => {
                    return (
                      <div style={{ display: "flex", gap: 6 }}>
                        {ElementInfoList?.map((it) => {
                          function removeFirstAndLastChar(str) {
                            return str.substring(1, str.length - 1);
                          }
                          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>
                          );
                        })}
                      </div>
                    );
                  },
                }}
              ></Table>
            </div>
wuhao's avatar
wuhao committed
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 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
          </>
        ) : 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
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 641 642 643 644 645 646 647 648
      </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;