Procházet zdrojové kódy

按照身份显示不同的操作按钮

visuddhinanda před 3 roky
rodič
revize
9feaa14dcc
1 změnil soubory, kde provedl 63 přidání a 3 odebrání
  1. 63 3
      dashboard/src/components/template/Exercise.tsx

+ 63 - 3
dashboard/src/components/template/Exercise.tsx

@@ -1,4 +1,10 @@
-import { Button, Card } from "antd";
+import { Button, Card, Space, Switch } from "antd";
+import { Link, useParams } from "react-router-dom";
+import { useAppSelector } from "../../hooks";
+import { courseUser } from "../../reducers/course-user";
+import SelectChannel from "../course/SelectChannel";
+import { currentUser as _currentUser } from "../../reducers/current-user";
+import { courseInfo } from "../../reducers/current-course";
 
 interface IWidgetExerciseCtl {
   id?: string;
@@ -7,12 +13,66 @@ interface IWidgetExerciseCtl {
   children?: React.ReactNode;
 }
 const ExerciseCtl = ({ id, title, channel, children }: IWidgetExerciseCtl) => {
+  const { type } = useParams(); //url 参数
+
   const cardTitle = title ? title : "练习";
+  const user = useAppSelector(courseUser);
+  const currUser = useAppSelector(_currentUser);
+  const currCourse = useAppSelector(courseInfo);
+
+  let exeButton = <></>;
+  switch (user?.role) {
+    case "student":
+      switch (type) {
+        case "textbook":
+          if (typeof user.channelId === "string") {
+            exeButton = (
+              <Link
+                to={`/article/exercise/${currCourse?.courseId}_${currCourse?.articleId}_${id}_${currUser?.realName}/wbw`}
+                target="_blank"
+              >
+                <Button type="primary">做练习</Button>
+              </Link>
+            );
+          } else {
+            exeButton = <SelectChannel exerciseId={id} channel={channel} />;
+          }
+          break;
+        default:
+          exeButton = (
+            <Space>
+              对答案
+              <Switch
+                onChange={(checked: boolean) => {
+                  console.log(`switch to ${checked}`);
+                }}
+              />
+            </Space>
+          );
+          break;
+      }
+
+      break;
+    case "assistant":
+      if (type === "textbook") {
+        exeButton = (
+          <Link
+            to={`/article/exercise-list/${currCourse?.courseId}_${currCourse?.articleId}_${id}/wbw`}
+            target="_blank"
+          >
+            <Button type="primary">查看作业列表</Button>
+          </Link>
+        );
+      }
+      break;
+    default:
+      break;
+  }
   return (
     <Card
       title={cardTitle}
-      extra={<Button type="primary">做练习</Button>}
-      style={{ backgroundColor: "wheat" }}
+      extra={exeButton}
+      style={{ backgroundColor: "beige" }}
     >
       {children}
     </Card>