shaogen1995 2 years ago
parent
commit
f101fd3343

+ 10 - 12
houtai/src/pages/B5Topic/TopicAdd/index.tsx

@@ -83,7 +83,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
 
   // 删除选项
   const delImgListFu = useCallback(
-    (label: string, ind: number) => {
+    (ind: number, value: string | string[]) => {
       const arr = answerArr.map((v, i) => {
         return {
           label: i > ind ? answerArr[i - 1].label : v.label,
@@ -92,6 +92,13 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
       });
       const newData = arr.filter((v, i) => i !== ind);
       setAnswerArr(newData);
+
+      // 如果删除的是已经选择的正确答案的值,把表单的正确答案的值清空
+      if (value === FormBoxRef.current.getFieldValue("correct")) {
+        FormBoxRef.current.setFieldValue("correct", "");
+        // 手动校验正确答案
+        FormBoxRef.current.validateFields(["correct"]);
+      }
     },
     [answerArr]
   );
@@ -232,16 +239,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
           <Form.Item
             label="正确答案"
             name="correct"
-            rules={[
-              { required: true, message: "请选择正确答案!" },
-              {
-                validator: async (rule, value) => {
-                  if (value && answerArr.every((v) => v.value !== value)) {
-                    return Promise.reject("请选择正确答案!");
-                  } else return Promise.resolve();
-                },
-              },
-            ]}
+            rules={[{ required: true, message: "请选择正确答案!" }]}
           >
             <Radio.Group>
               {answerArr.map((v) => (
@@ -273,7 +271,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
                     title="删除后无法恢复,是否删除?"
                     okText="删除"
                     cancelText="取消"
-                    onConfirm={() => delImgListFu(v.label, i)}
+                    onConfirm={() => delImgListFu(i, v.value)}
                   >
                     <div className="clearCover">
                       <CloseCircleOutlined />

+ 3 - 2
houtai/src/pages/Layout/index.tsx

@@ -10,7 +10,6 @@ import styles from "./index.module.scss";
 import SpinLoding from "@/components/SpinLoding";
 import { Route, Switch, useLocation } from "react-router-dom";
 import AuthRoute from "@/components/AuthRoute";
-import NotFound from "@/components/NotFound";
 import classNames from "classnames";
 import history from "@/utils/history";
 import { Button, Form, Input, Modal, Popconfirm } from "antd";
@@ -28,6 +27,8 @@ import { barrageGetUnauditedAPI } from "@/store/action/B4Barrage";
 import { RootState } from "@/store";
 import { getPermissionsAPI } from "@/store/action/C2Role";
 
+const NotFound = React.lazy(() => import("@/components/NotFound"));
+
 function Layout() {
   const dispatch = useDispatch();
 
@@ -312,7 +313,7 @@ function Layout() {
                     v2.path === path ? "active" : ""
                   )}
                 >
-                  {v2.id === 500 && barrageNum ? (
+                  {v2.id === 250 && barrageNum ? (
                     <div className="rowTip">{barrageNum}</div>
                   ) : null}
                   <div className="txt">{v2.name}</div>

+ 7 - 4
houtai/src/utils/http.ts

@@ -9,7 +9,7 @@ export const baseURL =
   process.env.NODE_ENV === "development"
     ? "http://192.168.20.55:8041/api/"
     : "";
-  // process.env.NODE_ENV === "development" ? "https://xuzhouwall.4dage.com" : "";
+// process.env.NODE_ENV === "development" ? "https://xuzhouwall.4dage.com" : "";
 
 // 处理  类型“AxiosResponse<any, any>”上不存在属性“code”
 declare module "axios" {
@@ -35,7 +35,8 @@ let axajInd = 0;
 http.interceptors.request.use(
   function (config: any) {
     // 发请求前打开加载提示
-    store.dispatch({ type: "login/asyncLoding", payload: true });
+    if (!store.getState().loginStore.asyncLoding)
+      store.dispatch({ type: "login/asyncLoding", payload: true });
 
     axajInd++;
 
@@ -56,7 +57,8 @@ http.interceptors.response.use(
     // 请求回来的关闭加载提示
     axajInd--;
     if (axajInd === 0) {
-      store.dispatch({ type: "login/asyncLoding", payload: false });
+      if (store.getState().loginStore.asyncLoding)
+        store.dispatch({ type: "login/asyncLoding", payload: false });
     }
     if (response.data.code === 5001 || response.data.code === 5002) {
       clearTimeout(timeId);
@@ -74,7 +76,8 @@ http.interceptors.response.use(
   },
   async function (err) {
     axajInd = 0;
-    store.dispatch({ type: "login/asyncLoding", payload: false });
+    if (store.getState().loginStore.asyncLoding)
+      store.dispatch({ type: "login/asyncLoding", payload: false });
 
     // 上传附件的进度条
     const UpAsyncLodingDom: any = document.querySelector("#UpAsyncLoding");