shaogen1995 vor 2 Jahren
Ursprung
Commit
4080ede195

+ 4 - 0
houtai/src/pages/B2Goods/GoodsAdd/index.module.scss

@@ -194,9 +194,13 @@
             display: flex;
             align-items: center;
           }
+          .laseFormRightRow1{
+            margin-top: 24px;
+          }
           .laseFormRightTit{
             font-size: 14px;
             color: rgb(126, 124, 124);
+            margin-bottom: 10px;
           }
         }
       }

+ 27 - 12
houtai/src/pages/B2Goods/GoodsAdd/index.tsx

@@ -3,6 +3,7 @@ import {
   Button,
   Checkbox,
   Form,
+  FormInstance,
   Input,
   Popconfirm,
   Radio,
@@ -38,6 +39,7 @@ import {
 import { baseURL } from "@/utils/http";
 import { FileListType, GoodsTableType } from "@/types";
 import { domShowFu, progressDomFu } from "@/utils/domShow";
+import { CheckboxValueType } from "antd/es/checkbox/Group";
 
 type Props = {
   id: number;
@@ -48,8 +50,23 @@ type Props = {
 
 function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
   // 后面添加的的知识驿站
+  const valueZS1Info = useMemo(() => {
+    return ["军事", "历史", "人物", "科学", "教育", "经济"];
+  }, []);
+
   const [valueZS1, setValueZS1] = useState("");
-  const [valueZS2, setValueZS2] = useState<any>([]);
+  // 取消选中
+  const valueZS1Close = useCallback(
+    (item: string) => {
+      if (item === valueZS1) {
+        setValueZS1("");
+        setValueZS2([]);
+      }
+    },
+    [valueZS1]
+  );
+
+  const [valueZS2, setValueZS2] = useState<CheckboxValueType[]>([]);
 
   // 上传附件的信息
   const [fileList, setFileList] = useState({
@@ -60,14 +77,14 @@ function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
   });
 
   // 表单的ref
-  const FormBoxRef = useRef<any>({});
+  const FormBoxRef = useRef<FormInstance>(null);
 
   // 文件的dirCode码
   const [dirCode, setDirCode] = useState("");
 
   const getInfoInAPIFu = useCallback(async (id: number) => {
     const res = await getGoodsInfoByIdAPI(id);
-    FormBoxRef.current.setFieldsValue(res.data.entity);
+    FormBoxRef.current?.setFieldsValue(res.data.entity);
     setCover(res.data.entity.thumb);
 
     if (res.data.entity.type) setTypeCheck(res.data.entity.type.split(","));
@@ -96,7 +113,7 @@ function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
     if (id > 0) getInfoInAPIFu(id);
     else {
       setDirCode(Date.now() + "");
-      FormBoxRef.current.setFieldsValue({
+      FormBoxRef.current?.setFieldsValue({
         topic: "不展示",
         display: 1,
         isBarrage: 0,
@@ -826,24 +843,22 @@ function GoodsAdd({ id, closeMoalFu, addListFu, editListFu }: Props) {
           <div className="myformBox">
             <div className="label">知识驿站:</div>
             <div className="laseFormRight">
-              <div className="laseFormRightRow">
+              <div className="laseFormRightRow laseFormRightRow1">
                 <div className="laseFormRightLabel">类别标签:</div>
                 <Radio.Group
                   onChange={(e) => setValueZS1(e.target.value)}
                   value={valueZS1}
                 >
-                  <Radio value={"军事"}>军事</Radio>
-                  <Radio value={"历史"}>历史</Radio>
-                  <Radio value={"人物"}>人物</Radio>
-                  <Radio value={"科学"}>科学</Radio>
-                  <Radio value={"教育"}>教育</Radio>
-                  <Radio value={"经济"}>经济</Radio>
+                  {valueZS1Info.map((v) => (
+                    <Radio key={v} value={v} onClick={() => valueZS1Close(v)}>
+                      {v}
+                    </Radio>
+                  ))}
                 </Radio.Group>
               </div>
               <div className="laseFormRightTit">
                 如需文物关联知识驿站,请至少标注类别标签
               </div>
-              <br />
               <div className="laseFormRightRow">
                 <div className="laseFormRightLabel">国家标签:</div>
                 <Checkbox.Group

+ 3 - 3
houtai/src/pages/B3Wall/WallAdd/index.tsx

@@ -1,5 +1,5 @@
 import { MessageFu } from "@/utils/message";
-import { Button, Form, Input, Popconfirm, Radio } from "antd";
+import { Button, Form, FormInstance, Input, Popconfirm, Radio } from "antd";
 import React, { useCallback, useEffect, useRef, useState } from "react";
 import { PlusOutlined, CloseOutlined } from "@ant-design/icons";
 import classNames from "classnames";
@@ -22,7 +22,7 @@ type Props = {
 function WallAdd({ id, closeMoalFu }: Props) {
   const getInfoFu = useCallback(async (id: number) => {
     const res = await getWallDetailAPI(id);
-    FormBoxRef.current.setFieldsValue({ name: res.data.entity.name });
+    FormBoxRef.current?.setFieldsValue({ name: res.data.entity.name });
     setImgNum(res.data.entity.type);
 
     const imgListRes = res.data.file;
@@ -35,7 +35,7 @@ function WallAdd({ id, closeMoalFu }: Props) {
   }, [getInfoFu, id]);
 
   // 表单的ref
-  const FormBoxRef = useRef<any>({});
+  const FormBoxRef = useRef<FormInstance>(null);
   // 上传封面图的ref
   const myInput = useRef<HTMLInputElement>(null);
 

+ 6 - 5
houtai/src/pages/B5Topic/TopicAdd/index.tsx

@@ -7,6 +7,7 @@ import {
 import {
   Button,
   Form,
+  FormInstance,
   Input,
   Popconfirm,
   Radio,
@@ -53,7 +54,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
       obj[v.val] = v.name;
     });
 
-    FormBoxRef.current.setFieldsValue(obj);
+    FormBoxRef.current?.setFieldsValue(obj);
 
     setAnswerArr(arrTemp);
 
@@ -94,10 +95,10 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
       setAnswerArr(newData);
 
       // 如果删除的是已经选择的正确答案的值,把表单的正确答案的值清空
-      if (value === FormBoxRef.current.getFieldValue("correct")) {
-        FormBoxRef.current.setFieldValue("correct", "");
+      if (value === FormBoxRef.current?.getFieldValue("correct")) {
+        FormBoxRef.current?.setFieldValue("correct", "");
         // 手动校验正确答案
-        FormBoxRef.current.validateFields(["correct"]);
+        FormBoxRef.current?.validateFields(["correct"]);
       }
     },
     [answerArr]
@@ -108,7 +109,7 @@ function TopicAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
   }, [getTopicDetailFu, id]);
 
   // 表单的ref
-  const FormBoxRef = useRef<any>({});
+  const FormBoxRef = useRef<FormInstance>(null);
   // 没有通过校验
   const onFinishFailed = useCallback(() => {}, []);
   // 通过校验点击确定

+ 3 - 3
houtai/src/pages/B6Smart/SmartAutoAdd/index.tsx

@@ -1,4 +1,4 @@
-import { Button, Form, Input, Modal, Popconfirm } from "antd";
+import { Button, Form, FormInstance, Input, Modal, Popconfirm } from "antd";
 import React, { useCallback, useEffect, useRef } from "react";
 import TextArea from "antd/es/input/TextArea";
 import { getSmartDetailAPI, smartSaveAPI } from "@/store/action/B6Smart";
@@ -15,12 +15,12 @@ type Props = {
 
 function SmartAutoAdd({ id, closeMoalFu, addTableFu, editTableFu }: Props) {
   // 表单的ref
-  const FormBoxRef = useRef<any>({});
+  const FormBoxRef = useRef<FormInstance>(null);
 
   // 是编辑,通过id获取详情
   const getInfoByIdFu = useCallback(async (id: number) => {
     const res = await getSmartDetailAPI(id);
-    FormBoxRef.current.setFieldsValue(res.data);
+    FormBoxRef.current?.setFieldsValue(res.data);
   }, []);
 
   useEffect(() => {

+ 12 - 4
houtai/src/pages/C1User/UserAdd/index.tsx

@@ -2,7 +2,15 @@ import { RootState } from "@/store";
 import { getUserInfoByIdAPI, userSaveAPI } from "@/store/action/C1User";
 import { SaveUserType } from "@/types";
 import { MessageFu } from "@/utils/message";
-import { Button, Form, Input, Modal, Popconfirm, Select } from "antd";
+import {
+  Button,
+  Form,
+  FormInstance,
+  Input,
+  Modal,
+  Popconfirm,
+  Select,
+} from "antd";
 import React, { useCallback, useEffect, useRef } from "react";
 import { useSelector } from "react-redux";
 import styles from "./index.module.scss";
@@ -16,11 +24,11 @@ type Props = {
 
 function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
   // 设置表单初始数据(区分编辑和新增)
-  const FormBoxRef = useRef<any>({});
+  const FormBoxRef = useRef<FormInstance>(null);
 
   const getInfoInAPIFu = useCallback(async (id: number) => {
     const res = await getUserInfoByIdAPI(id);
-    FormBoxRef.current.setFieldsValue(res.data);
+    FormBoxRef.current?.setFieldsValue(res.data);
     console.log("是编辑,在这里发请求拿数据", res);
   }, []);
 
@@ -32,7 +40,7 @@ function UserAdd({ id, closePage, upTableList, addTableList }: Props) {
   useEffect(() => {
     if (id) getInfoInAPIFu(id);
     else {
-      FormBoxRef.current.setFieldsValue({});
+      FormBoxRef.current?.setFieldsValue({});
     }
   }, [getInfoInAPIFu, id]);