浏览代码

问卷-题目

shaogen1995 1 年之前
父节点
当前提交
aba42bfbb9

+ 1 - 0
README.md

@@ -19,4 +19,5 @@ export interface Action<T = any> {
   type?: T
 }
 
+2.使用 yarn。 npm有问题
 

+ 2 - 0
package.json

@@ -23,6 +23,8 @@
     "js-export-excel": "^1.1.4",
     "jspdf": "^2.5.1",
     "react": "^18.2.0",
+    "react-dnd": "^16.0.1",
+    "react-dnd-html5-backend": "^16.0.1",
     "react-dom": "^18.2.0",
     "react-redux": "^8.0.4",
     "react-router-dom": "5.3",

+ 4 - 0
src/components/ZRichText/index.module.scss

@@ -52,6 +52,10 @@
       max-width: 500px;
       max-height: 500px;
       text-align: center;
+      // 不让拖动放大缩小图片(会报错)
+      .bf-csize-icon{
+        display: none !important;
+      }
     }
 
   }

+ 47 - 29
src/pages/A6_1ques/A6Qadd/index.tsx

@@ -1,36 +1,37 @@
-import React, {
-  useCallback,
-  useEffect,
-  useRef,
-} from "react";
+import React, { useCallback, useEffect, useRef } from "react";
 import styles from "./index.module.scss";
-import { A6QInfoType} from "../data";
-import {
-  Button,
-  DatePicker,
-  Form,
-  FormInstance,
-  Input,
-  Select,
-} from "antd";
+import { A6QInfoType } from "../data";
+import { Button, DatePicker, Form, FormInstance, Input, Select } from "antd";
 import MyPopconfirm from "@/components/MyPopconfirm";
 import ZRichText from "@/components/ZRichText";
 import dayjs from "dayjs";
-
+import { A6Q_APIgetInfo, A6Q_APIsave } from "@/store/action/A6_1ques";
+import { MessageFu } from "@/utils/message";
 
 type Props = {
   sInfo: A6QInfoType;
   closeFu: () => void;
+  addTableFu: () => void;
+  editTableFu: () => void;
 };
 
-function A6Qadd({ sInfo, closeFu }: Props) {
+function A6Qadd({ sInfo, closeFu, addTableFu, editTableFu }: Props) {
   // 表单的ref
   const FormBoxRef = useRef<FormInstance>(null);
 
   const getInfoFu = useCallback(async (id: number) => {
-    FormBoxRef.current?.setFieldsValue({
-      // myTime: dayjs(data.releaseDate),
-    });
+    const res = await A6Q_APIgetInfo(id);
+    if (res.code === 0) {
+      const data = res.data;
+
+      ZRichTextRef.current?.ritxtShowFu(data.description);
+
+      FormBoxRef.current?.setFieldsValue({
+        myTime: dayjs(data.publishDate),
+        name: data.name,
+        display: data.display,
+      });
+    }
   }, []);
 
   useEffect(() => {
@@ -39,7 +40,7 @@ function A6Qadd({ sInfo, closeFu }: Props) {
       // 新增
       FormBoxRef.current?.setFieldsValue({
         myTime: dayjs(Date.now()),
-        aaaaaaa: 1,
+        display: 1,
       });
     }
   }, [getInfoFu, sInfo]);
@@ -51,12 +52,30 @@ function A6Qadd({ sInfo, closeFu }: Props) {
   const onFinishFailed = useCallback(() => {}, []);
 
   //  通过校验点击确定
-  const onFinish = useCallback(async (values: any) => {
-    // 发布日期
-    // const releaseDate = dayjs(values.myTime).format("YYYY-MM-DD");
-
-    console.log("提交拉");
-  }, []);
+  const onFinish = useCallback(
+    async (values: any) => {
+      // 发布日期
+      const publishDate = dayjs(values.myTime).format("YYYY-MM-DD");
+
+      // 富文本
+      const description = ZRichTextRef.current?.fatherBtnOkFu();
+      const obj = {
+        name: values.name,
+        display: values.display,
+        id: sInfo.txt === "新增" ? null : sInfo.id,
+        publishDate,
+        description: description.val,
+      };
+
+      const res = await A6Q_APIsave(obj);
+      if (res.code === 0) {
+        MessageFu.success(`${sInfo.txt}成功!`);
+        sInfo.txt === "新增" ? addTableFu() : editTableFu();
+        closeFu();
+      }
+    },
+    [addTableFu, closeFu, editTableFu, sInfo.id, sInfo.txt]
+  );
 
   return (
     <div className={styles.A6Qadd}>
@@ -91,8 +110,7 @@ function A6Qadd({ sInfo, closeFu }: Props) {
                 dirCode="A6QText"
                 isLook={false}
                 ref={ZRichTextRef}
-                // 待完善路径
-                myUrl="cms/exhibition/upload"
+                myUrl="cms/questionnaire/upload"
               />
             </div>
           </div>
@@ -107,7 +125,7 @@ function A6Qadd({ sInfo, closeFu }: Props) {
 
           <Form.Item
             label="问卷状态"
-            name="aaaaaaa"
+            name="display"
             rules={[{ required: true, message: "请选择问卷状态!" }]}
           >
             <Select

+ 106 - 16
src/pages/A6_1ques/A6Qtopic/QTadd.tsx

@@ -1,12 +1,24 @@
-import React, { useCallback, useEffect, useMemo, useState } from "react";
+import React, {
+  useCallback,
+  useEffect,
+  useMemo,
+  useRef,
+  useState,
+} from "react";
 import styles from "./index.module.scss";
 import { Button, Checkbox, Input, Modal, Select } from "antd";
 import MyPopconfirm from "@/components/MyPopconfirm";
-import { A6QListType, options1, options2 } from "../data";
+import { A6QListType, A6QListTypeSlist, options1, options2 } from "../data";
 import { MessageFu } from "@/utils/message";
 import TextArea from "antd/es/input/TextArea";
 import { CloseCircleOutlined } from "@ant-design/icons";
 import classNames from "classnames";
+import {
+  A6Q_API_Tadds,
+  A6Q_API_Tdels2,
+  A6Q_API_Tedit,
+  A6Q_API_TgetInfo,
+} from "@/store/action/A6_1ques";
 
 const oneObj: A6QListType = {
   id: 1,
@@ -25,10 +37,44 @@ type Props = {
   moInfo: { id: number; num: number };
   closeFu: () => void;
   tableLen: number; //当前已经有的题目数量(表格)
+  upTableFu: () => void;
+  // 最外层 表格 的id
+  fatherId: number;
 };
 
-function QTadd({ moInfo, closeFu, tableLen }: Props) {
-  const getInfoFu = useCallback(async (id: number) => {}, []);
+function QTadd({ moInfo, closeFu, tableLen, upTableFu, fatherId }: Props) {
+  const sListOldIds = useRef([] as number[]);
+  const sListDelIds = useRef([] as number[]);
+
+  const getInfoFu = useCallback(async (id: number) => {
+    const res = await A6Q_API_TgetInfo(id);
+    if (res.code === 0) {
+      const data = res.data;
+      const sListArr: A6QListTypeSlist[] = [];
+      data.options.forEach((v: any) => {
+        // 编辑的时候存下 之前信息的id数组 判断 提交时选项 id是否要传null
+        sListOldIds.current.push(v.id);
+        sListArr.push({
+          id: v.id,
+          txt: v.name,
+          skip2: v.skip,
+          num2: v.skipQuestionNum,
+        });
+      });
+
+      setList([
+        {
+          id: data.id,
+          name: data.question,
+          type: data.type,
+          skip: data.skip,
+          num: data.skipQuestionNum,
+          custom: data.custom,
+          sList: sListArr,
+        },
+      ]);
+    }
+  }, []);
 
   useEffect(() => {
     if (moInfo.id > 0) getInfoFu(moInfo.id);
@@ -87,6 +133,10 @@ function QTadd({ moInfo, closeFu, tableLen }: Props) {
       if (rank === 1) {
         setList(list.filter((v) => v.id !== id));
       } else {
+        if (sListOldIds.current.includes(id)) {
+          sListDelIds.current.push(id);
+        }
+
         setList(
           list.map((v) => ({
             ...v,
@@ -193,14 +243,50 @@ function QTadd({ moInfo, closeFu, tableLen }: Props) {
   }, []);
 
   // 点击提交
-  const btnOkFu = useCallback(() => {
+  const btnOkFu = useCallback(async () => {
     setFileCheck(true);
 
     const dom = document.querySelector(".A6Qlist2SonErrBox");
     if (dom) return MessageFu.warning("请规范填写题目信息!");
 
-    console.log("------验证通过----");
-  }, []);
+    const arrTemp = list.map((v) => ({
+      custom: v.custom,
+      id: moInfo.id > 0 ? v.id : null,
+      question: v.name,
+      questionnaireId: fatherId,
+      skip: v.skip,
+      skipQuestionNum: v.num,
+      type: v.type,
+      options: v.sList.map((v2) => ({
+        id: sListOldIds.current.includes(v2.id) ? v2.id : null,
+        name: v2.txt,
+        skip: v2.skip2,
+        skipQuestionNum: v2.num2,
+      })),
+    }));
+
+    if (moInfo.id < 0) {
+      // 新增
+      const res = await A6Q_API_Tadds(arrTemp);
+      if (res.code === 0) {
+        MessageFu.success("新增成功!");
+        upTableFu();
+        closeFu();
+      }
+    } else {
+      // 编辑
+      // 删除 选项id
+      if (sListDelIds.current.length)
+        await A6Q_API_Tdels2(sListDelIds.current.join(","));
+
+      const res2 = await A6Q_API_Tedit(arrTemp[0]);
+      if (res2.code === 0) {
+        MessageFu.success("编辑成功!");
+        upTableFu();
+        closeFu();
+      }
+    }
+  }, [closeFu, fatherId, list, moInfo.id, upTableFu]);
 
   return (
     <Modal
@@ -210,15 +296,19 @@ function QTadd({ moInfo, closeFu, tableLen }: Props) {
         <div className="QTatitle">
           <div>{moInfo.id > 0 ? "编辑" : "新增"}题目</div>
           <div>
-            <span className="QTatitleS">最多支持50题</span>
-            &emsp;
-            <Button
-              type="primary"
-              onClick={() => addListFu(1)}
-              disabled={tableLen + list.length >= 50}
-            >
-              新增
-            </Button>
+            {moInfo.id < 0 ? (
+              <>
+                <span className="QTatitleS">最多支持50题</span>
+                &emsp;
+                <Button
+                  type="primary"
+                  onClick={() => addListFu(1)}
+                  disabled={tableLen + list.length >= 50}
+                >
+                  新增
+                </Button>
+              </>
+            ) : null}
           </div>
         </div>
       }

+ 22 - 0
src/pages/A6_1ques/A6Qtopic/index.module.scss

@@ -18,6 +18,28 @@
       height: calc(100% - 30px);
       margin-top: 15px;
       overflow: hidden;
+      .moveTit {
+        justify-content: center;
+        position: relative;
+        display: flex;
+
+        .inco {
+          cursor: pointer;
+          margin-left: 10px;
+          font-size: 14px;
+          color: #7e8293;
+        }
+      }
+      .ant-table-body {
+        overflow-y: auto !important;
+        overflow-y: overlay !important;
+  
+        .ant-table-row {
+          .ant-table-cell {
+            padding: 10px;
+          }
+        }
+      }
     }
   }
 }

+ 224 - 17
src/pages/A6_1ques/A6Qtopic/index.tsx

@@ -1,7 +1,42 @@
-import React, { useCallback, useEffect, useState } from "react";
+import React, {
+  useCallback,
+  useEffect,
+  useMemo,
+  useRef,
+  useState,
+} from "react";
 import styles from "./index.module.scss";
-import { Button } from "antd";
+import { Button, Table, Tooltip } from "antd";
 import QTadd from "./QTadd";
+import {
+  A6Q_API_Tdel,
+  A6Q_API_TgetList,
+  A6Q_API_Tsort,
+} from "@/store/action/A6_1ques";
+
+// 表格拖动排序-----------------
+import { ExclamationCircleFilled } from "@ant-design/icons";
+import { DndProvider, useDrag, useDrop } from "react-dnd";
+import { HTML5Backend } from "react-dnd-html5-backend";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import { MessageFu } from "@/utils/message";
+
+type A6QT_TableType = {
+  createTime: string;
+  creatorId: number;
+  creatorName: string;
+  custom: boolean;
+  id: number;
+  // options?: any;
+  // optionsCount?: any;
+  question: string;
+  questionnaireId: 1;
+  skip: string;
+  // skipQuestionNum?: any;
+  // sort?: any;
+  type: string;
+  updateTime: string;
+};
 
 type Props = {
   sId: number;
@@ -9,13 +44,168 @@ type Props = {
 };
 
 function A6Qtopic({ sId, closeFu }: Props) {
-  const getInfoFu = useCallback(async (id: number) => {
-    console.log("题目发送器拿数据");
-  }, []);
+  // 表格数组
+  const [list, setList] = useState<A6QT_TableType[]>([]);
+
+  const getInfoFu = useCallback(async () => {
+    const res = await A6Q_API_TgetList(sId);
+    if (res.code === 0) {
+      setList(res.data);
+    }
+  }, [sId]);
 
   useEffect(() => {
-    getInfoFu(sId);
-  }, [getInfoFu, sId]);
+    getInfoFu();
+  }, [getInfoFu]);
+
+  // 表格拖动排序
+  interface DraggableBodyRowProps
+    extends React.HTMLAttributes<HTMLTableRowElement> {
+    index: number;
+    moveRow: (dragIndex: number, hoverIndex: number) => void;
+  }
+
+  const type = "DraggableBodyRow";
+
+  const DraggableBodyRow = useCallback(
+    ({
+      index,
+      moveRow,
+      className,
+      style,
+      ...restProps
+    }: DraggableBodyRowProps) => {
+      // eslint-disable-next-line react-hooks/rules-of-hooks
+      const ref = useRef<HTMLTableRowElement>(null);
+      // eslint-disable-next-line react-hooks/rules-of-hooks
+      const [{ isOver, dropClassName }, drop] = useDrop({
+        accept: type,
+        collect: (monitor) => {
+          const { index: dragIndex } = monitor.getItem() || {};
+          if (dragIndex === index) {
+            return {};
+          }
+          return {
+            isOver: monitor.isOver(),
+            dropClassName:
+              dragIndex < index ? " drop-over-downward" : " drop-over-upward",
+          };
+        },
+        drop: (item: { index: number }) => {
+          if (moveRow) moveRow(item.index, index);
+        },
+      });
+      // eslint-disable-next-line react-hooks/rules-of-hooks
+      const [, drag] = useDrag({
+        type,
+        item: { index },
+        collect: (monitor) => ({
+          isDragging: monitor.isDragging(),
+        }),
+      });
+      drop(drag(ref));
+
+      return (
+        <tr
+          ref={ref}
+          className={`${className}${isOver ? dropClassName : ""}`}
+          style={{ cursor: "move", ...style }}
+          {...restProps}
+        />
+      );
+    },
+    []
+  );
+
+  const components = {
+    body: {
+      row: DraggableBodyRow,
+    },
+  };
+
+  const moveRow = useCallback(
+    async (dragIndex: number, hoverIndex: number) => {
+      if (dragIndex === hoverIndex) return;
+      // 交互位置-之前的id
+      const beforeId = list[dragIndex].id;
+      const afterId = list[hoverIndex].id;
+      // console.log("交换位置", beforeId, afterId);
+
+      const res = await A6Q_API_Tsort(beforeId, afterId);
+
+      if (res.code === 0) getInfoFu();
+    },
+    [getInfoFu, list]
+  );
+
+  // 点击删除
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A6Q_API_Tdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getInfoFu();
+      }
+    },
+    [getInfoFu]
+  );
+
+  const columns = useMemo(() => {
+    return [
+      {
+        width: 100,
+        title: (
+          <div className="moveTit">
+            序号
+            <Tooltip title="按住鼠标可拖动表格调整顺序">
+              <div className="inco" hidden={list.length < 2}>
+                <ExclamationCircleFilled />
+              </div>
+            </Tooltip>
+          </div>
+        ),
+        render: (_1: any, _2: any, index: number) => index + 1,
+      },
+      {
+        title: "类型",
+        dataIndex: "type",
+      },
+      {
+        title: "题目描述",
+        render: (item: A6QT_TableType) =>
+          item.question.length >= 50 ? (
+            <span style={{ cursor: "pointer" }} title={item.question}>
+              {item.question.substring(0, 50) + "..."}
+            </span>
+          ) : (
+            item.question
+          ),
+      },
+      {
+        title: "支持自定义回答",
+        render: (item: A6QT_TableType) => (item.custom ? "是" : "否"),
+      },
+      {
+        title: "跳题",
+        dataIndex: "skip",
+      },
+      {
+        title: "操作",
+        render: (item: A6QT_TableType, _: any, index: number) => (
+          <>
+            <Button
+              size="small"
+              type="text"
+              onClick={() => setMoInfo({ id: item.id, num: index + 1 })}
+            >
+              编辑
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu, list.length]);
 
   // 弹窗的显示和隐藏
   const [moInfo, setMoInfo] = useState({ id: 0, num: 0 });
@@ -24,25 +214,42 @@ function A6Qtopic({ sId, closeFu }: Props) {
     <div className={styles.A6Qtopic}>
       <div className="QTtop">
         <Button onClick={closeFu}>返回</Button>&emsp;
-        <Button type="primary" onClick={() => setMoInfo({ id: -1, num: 0 })}>
+        <Button
+          type="primary"
+          onClick={() => {
+            if (list.length >= 50) return MessageFu.warning("最多支持50题!");
+            setMoInfo({ id: -1, num: 0 });
+          }}
+        >
           新增
         </Button>
       </div>
       <div className="QTtable">
-        {/* <MyTable
-          yHeight={680}
-          list={tableList}
-          columnsTemp={A1tableCFu(type)}
-          pagingInfo={false}
-          lastBtn={tableLastBtn}
-        /> */}
+        <DndProvider backend={HTML5Backend}>
+          <Table
+            scroll={{ y: 688 }}
+            columns={columns}
+            dataSource={list}
+            components={components}
+            rowKey="id"
+            pagination={false}
+            onRow={(_, index) => {
+              const attr = {
+                index,
+                moveRow,
+              };
+              return attr as React.HTMLAttributes<any>;
+            }}
+          />
+        </DndProvider>
       </div>
-      {/* 待完善  tableLen*/}
       {moInfo.id ? (
         <QTadd
           moInfo={moInfo}
           closeFu={() => setMoInfo({ id: 0, num: 0 })}
-          tableLen={10}
+          tableLen={list.length}
+          upTableFu={getInfoFu}
+          fatherId={sId}
         />
       ) : null}
     </div>

+ 9 - 7
src/pages/A6_1ques/data.ts

@@ -4,6 +4,14 @@ export type A6QInfoType = {
 };
 
 // 新增里面的题目列表
+
+export type A6QListTypeSlist = {
+  id: number;
+  txt: string;
+  skip2: boolean;
+  num2: number;
+};
+
 export type A6QListType = {
   id: number;
   name: string;
@@ -11,13 +19,7 @@ export type A6QListType = {
   skip: "不需要" | "答完跳题" | "选项跳题";
   num: number;
   custom: boolean; //是否支持自定义回答
-  sList: {
-    //除了填空以外的选项数组
-    id: number;
-    txt: string;
-    skip2: boolean;
-    num2: number;
-  }[];
+  sList: A6QListTypeSlist[];
 };
 
 export const options1 = [

+ 82 - 24
src/pages/A6_1ques/index.tsx

@@ -1,12 +1,24 @@
-import React, { useCallback, useEffect, useRef, useState } from "react";
+import React, {
+  useCallback,
+  useEffect,
+  useMemo,
+  useRef,
+  useState,
+} from "react";
 import styles from "./index.module.scss";
 import { Button, Input } from "antd";
-import { useDispatch } from "react-redux";
+import { useDispatch, useSelector } from "react-redux";
 import A6Qadd from "./A6Qadd";
 import { A6QInfoType } from "./data";
 import A6QInfo from "./A6QInfo";
 import A6Qtopic from "./A6Qtopic";
-import downloadPDF2 from "@/utils/htmlToPdf2";
+import { A6Q_APIdel, A6Q_APIgetList } from "@/store/action/A6_1ques";
+import MyTable from "@/components/MyTable";
+import { RootState } from "@/store";
+import { A6QtableC } from "@/utils/tableData";
+import { A6QtableType } from "@/types";
+import MyPopconfirm from "@/components/MyPopconfirm";
+import { MessageFu } from "@/utils/message";
 
 function A6_1ques() {
   const dispatch = useDispatch();
@@ -18,9 +30,8 @@ function A6_1ques() {
   });
 
   const getListFu = useCallback(() => {
-    // dispatch(A4_APIgetList(fromData));
-    console.log(123);
-  }, []);
+    dispatch(A6Q_APIgetList(fromData));
+  }, [dispatch, fromData]);
 
   useEffect(() => {
     getListFu();
@@ -56,6 +67,55 @@ function A6_1ques() {
     txt: "",
   });
 
+  // 从仓库获取列表数据
+  const tableInfo = useSelector((state: RootState) => state.A6_1ques.tableInfo);
+
+  // 点击删除
+  const delTableFu = useCallback(
+    async (id: number) => {
+      const res = await A6Q_APIdel(id);
+      if (res.code === 0) {
+        MessageFu.success("删除成功!");
+        getListFu();
+      }
+    },
+    [getListFu]
+  );
+
+  const tableLastBtn = useMemo(() => {
+    return [
+      {
+        title: "操作",
+        render: (item: A6QtableType) => (
+          <>
+            <Button
+              size="small"
+              type="text"
+              onClick={() => setInfo({ id: item.id, txt: "查看" })}
+            >
+              查看
+            </Button>
+            <Button
+              size="small"
+              type="text"
+              onClick={() => setInfo({ id: item.id, txt: "编辑" })}
+            >
+              编辑
+            </Button>
+            <Button
+              size="small"
+              type="text"
+              onClick={() => setInfo({ id: item.id, txt: "题目管理" })}
+            >
+              题目管理
+            </Button>
+            <MyPopconfirm txtK="删除" onConfirm={() => delTableFu(item.id)} />
+          </>
+        ),
+      },
+    ];
+  }, [delTableFu]);
+
   return (
     <div className={styles.A6_1ques}>
       <div className="pageTitle">
@@ -89,23 +149,10 @@ function A6_1ques() {
 
       {/* 表格主体 */}
       <div className="A6_1tableBox">
-        <Button onClick={() => setInfo({ id: 1, txt: "编辑" })}>编辑</Button>
-        <Button onClick={() => setInfo({ id: 1, txt: "查看" })}>查看</Button>
-        <Button onClick={() => setInfo({ id: 1, txt: "题目管理" })}>
-          题目管理
-        </Button>
-        &emsp;
-        <Button
-          onClick={() =>
-            downloadPDF2(document.querySelector(".A6_1tableBox")!, "xxxx")
-          }
-        >
-          导出pdf
-        </Button>
-        {/* <MyTable
+        <MyTable
           yHeight={625}
           list={tableInfo.list}
-          columnsTemp={A4tableC}
+          columnsTemp={A6QtableC}
           lastBtn={tableLastBtn}
           pageNum={fromData.pageNum}
           pageSize={fromData.pageSize}
@@ -113,12 +160,17 @@ function A6_1ques() {
           onChange={(pageNum, pageSize) =>
             setFromData({ ...fromData, pageNum, pageSize })
           }
-        /> */}
+        />
       </div>
 
       {/* 点击新增/编辑出来的页面 */}
       {["编辑", "新增"].includes(info.txt) ? (
-        <A6Qadd sInfo={info} closeFu={() => setInfo({ id: 0, txt: "" })} />
+        <A6Qadd
+          sInfo={info}
+          closeFu={() => setInfo({ id: 0, txt: "" })}
+          addTableFu={resetSelectFu}
+          editTableFu={getListFu}
+        />
       ) : null}
 
       {/* 查看 */}
@@ -128,7 +180,13 @@ function A6_1ques() {
 
       {/* 题目管理 */}
       {info.txt === "题目管理" ? (
-        <A6Qtopic sId={info.id} closeFu={() => setInfo({ id: 0, txt: "" })} />
+        <A6Qtopic
+          sId={info.id}
+          closeFu={() => {
+            getListFu();
+            setInfo({ id: 0, txt: "" });
+          }}
+        />
       ) : null}
     </div>
   );

+ 89 - 0
src/store/action/A6_1ques.ts

@@ -0,0 +1,89 @@
+import http from "@/utils/http";
+import { AppDispatch } from "..";
+/**
+ * 获取 问卷管理列表
+ */
+export const A6Q_APIgetList = (data: any) => {
+  return async (dispatch: AppDispatch) => {
+    const res = await http.post("cms/questionnaire/pageList", data);
+    if (res.code === 0) {
+      const obj = {
+        list: res.data.records,
+        total: res.data.total,
+      };
+      dispatch({ type: "A6Q/getList", payload: obj });
+    }
+  };
+};
+
+/**
+ * 删除
+ */
+export const A6Q_APIdel = (id: number) => {
+  return http.get(`cms/questionnaire/remove/${id}`);
+};
+
+/**
+ * 新增/编辑
+ */
+export const A6Q_APIsave = (data: any) => {
+  return http.post("cms/questionnaire/save", data);
+};
+
+/**
+ * 通过id获取详情
+ */
+export const A6Q_APIgetInfo = (id: number) => {
+  return http.get(`cms/questionnaire/detail/${id}`);
+};
+
+// ------------------------题目管理-----------------------
+
+/**
+ * 获取列表
+ */
+export const A6Q_API_TgetList = (id: number) => {
+  return http.get(`cms/question/getList/${id}`);
+};
+
+/**
+ * 列表排序
+ */
+export const A6Q_API_Tsort = (id1: number, id2: number) => {
+  return http.get(`cms/question/sort/${id1}/${id2}`);
+};
+
+/**
+ * 删除
+ */
+export const A6Q_API_Tdel = (id: number) => {
+  return http.get(`cms/question/removes/${id}`);
+};
+
+/**
+ * 删除选项
+ */
+export const A6Q_API_Tdels2 = (ids: string) => {
+  return http.get(`cms/question/option/removes/${ids}`);
+};
+
+/**
+ * 批量新增
+ */
+export const A6Q_API_Tadds = (data: any) => {
+  return http.post("cms/question/addBatch", data);
+};
+
+/**
+ * 单个编辑
+ */
+export const A6Q_API_Tedit = (data: any) => {
+  return http.post("cms/question/edit", data);
+};
+
+/**
+ * 获取详情
+ */
+export const A6Q_API_TgetInfo = (id: number) => {
+  return http.get(`cms/question/detail/${id}`);
+};

+ 28 - 0
src/store/reducer/A6_1ques.ts

@@ -0,0 +1,28 @@
+import { A6QtableType } from "@/types";
+
+// 初始化状态
+const initState = {
+  // 列表数据
+  tableInfo: {
+    list: [] as A6QtableType[],
+    total: 0,
+  },
+};
+
+// 定义 action 类型
+type Props = {
+  type: "A6Q/getList";
+  payload: { list: A6QtableType[]; total: number };
+};
+
+// 频道 reducer
+export default function Reducer(state = initState, action: Props) {
+  switch (action.type) {
+    // 获取列表数据
+    case "A6Q/getList":
+      return { ...state, tableInfo: action.payload };
+
+    default:
+      return state;
+  }
+}

+ 3 - 2
src/store/reducer/index.ts

@@ -7,10 +7,10 @@ import A1video from "./A1video";
 import A2poster from "./A2poster";
 import A4exhibit from "./A4exhibit";
 import A5goods from "./A5goods";
+import A6_1ques from "./A6_1ques";
 import A7user from "./A7user";
 import A8log from "./A8log";
 
-
 // 合并 reducer
 const rootReducer = combineReducers({
   A0Layout,
@@ -18,8 +18,9 @@ const rootReducer = combineReducers({
   A2poster,
   A4exhibit,
   A5goods,
+  A6_1ques,
   A7user,
-  A8log
+  A8log,
 });
 
 // 默认导出

+ 12 - 0
src/types/api/A6_1ques.d.ts

@@ -0,0 +1,12 @@
+export type A6QtableType= {
+	createTime: string;
+	creatorName: string;
+	description: string;
+	display: number;
+	id: number;
+	name: string;
+	pcsGather: number;
+	pcsQuestion: number;
+	publishDate: string;
+	updateTime: string;
+}

+ 1 - 0
src/types/index.d.ts

@@ -2,5 +2,6 @@ export * from './api/layot'
 export * from './api/A1video'
 export * from './api/A4exhibit'
 export * from './api/A5goods'
+export * from './api/A6_1ques'
 export * from './api/A7user'
 export * from './api/A8log'

+ 2 - 2
src/utils/http.ts

@@ -7,8 +7,8 @@ import { domShowFu } from "./domShow";
 
 const envFlag = process.env.NODE_ENV === "development";
 
-const baseUrlTemp = "https://sit-chaozhoubwg.4dage.com"; // 测试环境
-// const baseUrlTemp = "http://192.168.20.61:8064"; // 线下环境
+// const baseUrlTemp = "https://sit-chaozhoubwg.4dage.com"; // 测试环境
+const baseUrlTemp = "http://192.168.20.61:8064"; // 线下环境
 
 const baseFlag = baseUrlTemp.includes("https://");
 

+ 8 - 0
src/utils/tableData.ts

@@ -47,3 +47,11 @@ export const A8tableC = [
   ["txt", "操作模块", "type"],
   ["txt", "操作事件", "description"],
 ];
+
+export const A6QtableC = [
+  ["txt", "标题", "name"],
+  ["txt", "题目数量", "pcsQuestion"],
+  ["txt", "已收集份数", "pcsGather"],
+  ["txt", "发布日期", "publishDate"],
+  ["txtChange", "问卷状态", "display",{1:'开启',0:'关闭'}],
+];

+ 42 - 0
yarn.lock

@@ -1825,6 +1825,21 @@
     rc-resize-observer "^1.3.1"
     rc-util "^5.38.0"
 
+"@react-dnd/asap@^5.0.1":
+  version "5.0.2"
+  resolved "https://registry.npmmirror.com/@react-dnd/asap/-/asap-5.0.2.tgz#1f81f124c1cd6f39511c11a881cfb0f715343488"
+  integrity sha512-WLyfoHvxhs0V9U+GTsGilGgf2QsPl6ZZ44fnv0/b8T3nQyvzxidxsg/ZltbWssbsRDlYW8UKSQMTGotuTotZ6A==
+
+"@react-dnd/invariant@^4.0.1":
+  version "4.0.2"
+  resolved "https://registry.npmmirror.com/@react-dnd/invariant/-/invariant-4.0.2.tgz#b92edffca10a26466643349fac7cdfb8799769df"
+  integrity sha512-xKCTqAK/FFauOM9Ta2pswIyT3D8AQlfrYdOi/toTPEhqCuAs1v5tcJ3Y08Izh1cJ5Jchwy9SeAXmMg6zrKs2iw==
+
+"@react-dnd/shallowequal@^4.0.1":
+  version "4.0.2"
+  resolved "https://registry.npmmirror.com/@react-dnd/shallowequal/-/shallowequal-4.0.2.tgz#d1b4befa423f692fa4abf1c79209702e7d8ae4b4"
+  integrity sha512-/RVXdLvJxLg4QKvMoM5WlwNR9ViO9z8B/qPcc+C0Sa/teJY7QG7kJ441DwzOjMYEY7GmU4dj5EcGHIkKZiQZCA==
+
 "@react-spring/animated@~9.6.1":
   version "9.6.1"
   resolved "https://registry.npmmirror.com/@react-spring/animated/-/animated-9.6.1.tgz#ccc626d847cbe346f5f8815d0928183c647eb425"
@@ -4392,6 +4407,15 @@ dlv@^1.1.3:
   resolved "https://registry.npmmirror.com/dlv/-/dlv-1.1.3.tgz#5c198a8a11453596e751494d49874bc7732f2e79"
   integrity sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==
 
+dnd-core@^16.0.1:
+  version "16.0.1"
+  resolved "https://registry.npmmirror.com/dnd-core/-/dnd-core-16.0.1.tgz#a1c213ed08961f6bd1959a28bb76f1a868360d19"
+  integrity sha512-HK294sl7tbw6F6IeuK16YSBUoorvHpY8RHO+9yFfaJyCDVb6n7PRcezrOEOa2SBCqiYpemh5Jx20ZcjKdFAVng==
+  dependencies:
+    "@react-dnd/asap" "^5.0.1"
+    "@react-dnd/invariant" "^4.0.1"
+    redux "^4.2.0"
+
 dns-packet@^5.2.2:
   version "5.6.1"
   resolved "https://registry.npmmirror.com/dns-packet/-/dns-packet-5.6.1.tgz#ae888ad425a9d1478a0674256ab866de1012cf2f"
@@ -9024,6 +9048,24 @@ react-dev-utils@^12.0.1:
     strip-ansi "^6.0.1"
     text-table "^0.2.0"
 
+react-dnd-html5-backend@^16.0.1:
+  version "16.0.1"
+  resolved "https://registry.npmmirror.com/react-dnd-html5-backend/-/react-dnd-html5-backend-16.0.1.tgz#87faef15845d512a23b3c08d29ecfd34871688b6"
+  integrity sha512-Wu3dw5aDJmOGw8WjH1I1/yTH+vlXEL4vmjk5p+MHxP8HuHJS1lAGeIdG/hze1AvNeXWo/JgULV87LyQOr+r5jw==
+  dependencies:
+    dnd-core "^16.0.1"
+
+react-dnd@^16.0.1:
+  version "16.0.1"
+  resolved "https://registry.npmmirror.com/react-dnd/-/react-dnd-16.0.1.tgz#2442a3ec67892c60d40a1559eef45498ba26fa37"
+  integrity sha512-QeoM/i73HHu2XF9aKksIUuamHPDvRglEwdHL4jsp784BgUuWcg6mzfxT0QDdQz8Wj0qyRKx2eMg8iZtWvU4E2Q==
+  dependencies:
+    "@react-dnd/invariant" "^4.0.1"
+    "@react-dnd/shallowequal" "^4.0.1"
+    dnd-core "^16.0.1"
+    fast-deep-equal "^3.1.3"
+    hoist-non-react-statics "^3.3.2"
+
 react-dom@^18.2.0:
   version "18.2.0"
   resolved "https://registry.npmmirror.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"