index.jsx 13.3 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 Limit from "@/components/Limit";
wuhao's avatar
wuhao committed
5
import OnlineChat from "@/components/OnlineChat";
wuhao's avatar
wuhao committed
6 7 8
import PremButton from "@/components/PremButton";
import TreeRender from "@/components/TreeRender/sxtree";
import { doFetch } from "@/utils/doFetch";
wuhao's avatar
wuhao committed
9
import { Box, Container, Grid, Stack, Typography } from "@mui/material";
wuhao's avatar
wuhao committed
10 11
import { useParams } from "@umijs/max";
import { useRequest } from "ahooks";
wuhao's avatar
wuhao committed
12
import { message, Tabs } from "antd";
wuhao's avatar
wuhao committed
13 14 15 16 17 18
import { useEffect, useMemo, useRef, useState } from "react";
import { history } from "umi";
import "./index.less";

function Dolessons() {
  const params = useParams();
wuhao's avatar
wuhao committed
19
  const cksyactionRef = useRef(),
wuhao's avatar
wuhao committed
20 21 22 23 24 25 26 27 28 29
    cjwtactionRef = useRef();
  const [lessonDetail, setlessonDetail] = useState(null),
    [courseContent, setCourseContent] = useState({}),
    [drawer, setDrawer] = useState({
      open: false,
    }),
    [active, setactive] = useState("1");

  const { runAsync, loading } = useRequest(doFetch, {
    manual: true,
wuhao's avatar
wuhao committed
30
    onSuccess: (res) => {
wuhao's avatar
wuhao committed
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
      if (res?.code == "0000") {
        handleClose();
        message.success("操作成功");
        if (active === "2") {
          cksyactionRef?.current?.reload();
        } else if (active === "3") {
          cjwtactionRef?.current?.reload();
        }
      }
    },
  });

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

  const ifs = useMemo(() => {
    let { type } = lessonDetail ?? {};
    return !(type === 1 || type === 3);
  }, [lessonDetail]);

  const checkCourse = (val) => {
    if (val.length) {
      doFetch({
        url: "/busTrainCatalogue/getCatalogueContent",
        params: { id: val[0] },
      }).then((res) => {
        setCourseContent(res?.data?.data);
      });
    }
  };

wuhao's avatar
wuhao committed
69
  const edit = (text, row, _) => {
wuhao's avatar
wuhao committed
70 71 72 73 74 75 76
    return (
      <PremButton
        btn={{
          size: "small",
          disabled: ifs,
          variant: "text",
          onClick: () => {
wuhao's avatar
wuhao committed
77
            setDrawer(() => ({
wuhao's avatar
wuhao committed
78 79 80 81 82 83 84 85 86 87 88 89
              open: true,
              defaultFormValue: { ...row },
              title: "编辑",
            }));
          },
        }}
      >
        编辑
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
90
  const remove = (text, row, _) => {
wuhao's avatar
wuhao committed
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
    return (
      <PremButton
        pop={{
          disabled: ifs,
          title: "是否删除该实验?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
              url: "/busTrainExperiment/remove",
              params: { id: row?.id },
            });
          },
        }}
        btn={{
          disabled: ifs,
          size: "small",
          color: "error",
        }}
      >
        删除
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
  const openActive = (text, row, _, action) => {
    return (
      <PremButton
        pop={{
          title: "确认开始该实验?",
          okText: "确认",
          cancelText: "取消",
          onConfirm: async () => {
            await runAsync({
              url: "/studentExperiment/startExperiment",
              params: { id: row?.id },
            });
            // add Jump





            

          },
        }}
        btn={{
          size: "small",
          color: "error",
        }}
      >
        开始实验
      </PremButton>
    );
  };

wuhao's avatar
wuhao committed
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
  const questionColumns = useMemo(() => {
    let col = [
      {
        title: "问题内容",
        dataIndex: "question",
        key: "question",
        width: 400,
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "参考答案",
        dataIndex: "answer",
        key: "answer",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
    ];
    return col;
  }, []);

  const experimentColumns = useMemo(() => {
    let col = [
      {
        title: "实验名称",
        dataIndex: "experimentName",
        key: "experimentName",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
        render: (_, row) => {
wuhao's avatar
wuhao committed
175
          return row?.experimentName;
wuhao's avatar
wuhao committed
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 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
        },
        search: false,
      },
      {
        title: "考试时间(分钟)",
        search: false,
        dataIndex: "testTime",
        key: "testTime",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "权重(%)",
        search: false,
        dataIndex: "weight",
        key: "weight",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        search: false,
        title: "创建人",
        dataIndex: "updateUserName",
        key: "updateUserName",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "创建时间",
        dataIndex: "updateTime",
        search: false,
        key: "updateTime",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "截止时间",
        dataIndex: "deadline",
        search: false,
        key: "deadline",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
      {
        title: "实验完成率",
        dataIndex: "finishPer",
        search: false,
        key: "finishPer",
        formItemProps: { rules: [{ required: true, message: "此项为必填项" }] },
      },
    ];
    return col;
  }, []);

  const items = [
    {
      key: "1",
      label: `课程目录`,
      children: (
        <Grid container spacing={2}>
          <Grid item width={340}>
            <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2} padding={2}>
              <TreeRender
                onselected={checkCourse}
                maxWidth={170}
wuhao's avatar
wuhao committed
236
                url="/studentTrain/queryCatalogueTree"
wuhao's avatar
wuhao committed
237
                submitKey="catalogue"
wuhao's avatar
wuhao committed
238
                hidden={true}
wuhao's avatar
wuhao committed
239
                params={{
wuhao's avatar
wuhao committed
240
                  id: params?.id,
wuhao's avatar
wuhao committed
241 242 243 244 245 246
                }}
              />
            </Box>
          </Grid>
          <Grid item flex={1}>
            <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2} padding={2}>
wuhao's avatar
wuhao committed
247 248 249 250 251 252 253
              <Limit
                content={
                  courseContent?.parentId !== "0"
                    ? courseContent?.trainContent
                    : '<span style="font-weight:bloder;color:#1890ff">-- 请选择左侧小节 </span>'
                }
              ></Limit>
wuhao's avatar
wuhao committed
254 255 256 257 258 259 260
            </Box>
          </Grid>
        </Grid>
      ),
    },
    {
      key: "2",
wuhao's avatar
wuhao committed
261
      label: "查看实验",
wuhao's avatar
wuhao committed
262 263 264 265 266
      children: (
        <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
          <AutoTable
            rerendered={false}
            actionRef={cksyactionRef}
wuhao's avatar
wuhao committed
267 268 269 270 271 272 273 274 275 276 277
            columns={[
              ...experimentColumns,
              {
                title: "操作",
                valueType: "option",
                width: 180,
                render: (text, row, _, action) => [
                  openActive(text, row, _, action),
                ],
              },
            ]}
wuhao's avatar
wuhao committed
278
            path="/studentTrain/experimentPage"
wuhao's avatar
wuhao committed
279
            extraparams={{
wuhao's avatar
wuhao committed
280
              id: params?.id,
wuhao's avatar
wuhao committed
281 282 283 284 285 286 287 288 289 290 291 292 293
            }}
          />
        </Box>
      ),
    },
    {
      key: "3",
      label: "常见问题",
      children: (
        <Box boxShadow={"0 0 18px #f0f0f0"} borderRadius={2}>
          <AutoTable
            rerendered={false}
            actionRef={cjwtactionRef}
wuhao's avatar
wuhao committed
294
            columns={[...questionColumns]}
wuhao's avatar
wuhao committed
295
            path="/studentTrain/questionPage"
wuhao's avatar
wuhao committed
296
            extraparams={{
wuhao's avatar
wuhao committed
297
              id: params?.id,
wuhao's avatar
wuhao committed
298 299 300 301 302
            }}
          />
        </Box>
      ),
    },
wuhao's avatar
wuhao committed
303 304 305
    {
      key: "4",
      label: "在线沟通",
wuhao's avatar
wuhao committed
306
      children: active == "4" && <OnlineChat trainId={params?.id}></OnlineChat>,
wuhao's avatar
wuhao committed
307
    },
wuhao's avatar
wuhao committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
  ];

  const handleClose = () => {
    setDrawer((s) => ({
      ...s,
      open: false,
    }));
  };

  return (
    <Container maxWidth={false}>
      <DraggableDialog
        handleClose={handleClose}
        dialogprops={drawer}
        loading={loading}
        maxWidth={drawer?.maxWidth ?? "sm"}
      >
        {active === "2" ? (
          <InitForm
            defaultFormValue={drawer?.defaultFormValue ?? null}
            fields={[
              {
                title: "实验",
                dataIndex: "id",
                key: "id",
                valueType: "select",
                options: {
                  path: "/busTrainExperiment/selection",
                  params: { trainId: params?.id },
                },
                formItemProps: {
                  rules: [
                    {
                      required: true,
                      message: "此项为必填项",
                    },
                  ],
                },
              },
              {
                title: "权重(%)",
                dataIndex: "weight",
                key: "weight",
                valueType: "digit",
                formItemProps: {
                  rules: [
                    {
                      required: true,
                      message: "此项为必填项",
                    },
                  ],
                },
              },
              {
                title: "考试时间(分钟)",
                dataIndex: "testTime",
                key: "testTime",
                valueType: "digit",
                formItemProps: {
                  rules: [
                    {
                      required: true,
                      message: "此项为必填项",
                    },
                  ],
                },
              },
              {
                title: "截止时间",
                dataIndex: "deadline",
                key: "deadline",
                valueType: "date",
                formItemProps: {
                  rules: [
                    {
                      required: true,
                      message: "此项为必填项",
                    },
                  ],
                },
              },
            ]}
wuhao's avatar
wuhao committed
390
            onFinish={(val) => {
wuhao's avatar
wuhao committed
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
              let postdata;
              switch (drawer?.title) {
                case "添加实验":
                  postdata = {
                    ...val,
                    trainId: params?.id,
                  };
                  break;
                case "编辑":
                  postdata = {
                    ...val,
                    id: drawer?.defaultFormValue?.id,
                    trainId: params?.id,
                  };
                default:
                  break;
              }
              runAsync({
                url: "/busTrainExperiment/update",
                params: postdata,
              });
            }}
            onValuesChange={(curval, vals, formRef) => {
              if (Object.keys(curval)[0] === "id") {
                doFetch({
                  url: "/busTrainExperiment/detail",
                  params: { id: Object.values(curval)[0] },
                }).then((res) => {
                  formRef?.current?.setFieldsValue({
                    weight: res?.data?.data?.weight,
                  });
                });
              }
            }}
          ></InitForm>
        ) : (
          <InitForm
            defaultFormValue={drawer?.defaultFormValue ?? null}
            fields={[
              {
                title: "问题内容",
                dataIndex: "question",
                key: "question",
                valueType: "textarea",
              },
              {
                title: "参考答案",
                dataIndex: "answer",
                key: "answer",
                valueType: "textarea",
              },
            ]}
wuhao's avatar
wuhao committed
443
            onFinish={(val) => {
wuhao's avatar
wuhao committed
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
              let postdata;
              switch (drawer?.title) {
                case "添加问题":
                  postdata = {
                    ...val,
                    trainId: params?.id,
                  };
                  break;
                case "编辑":
                  postdata = {
                    ...val,
                    id: drawer?.defaultFormValue?.id,
                    trainId: params?.id,
                  };
                default:
                  break;
              }
              runAsync({
                url: "/busTrainQuestion/saveOrUpdate",
                params: postdata,
              });
            }}
          ></InitForm>
        )}
      </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"
          animated={true}
        />
      </Box>
    </Container>
  );
}

export default Dolessons;