|
|
@@ -25,6 +25,7 @@ import { QuestionTableType } from "@/types";
|
|
|
import { MessageFu } from "@/utils/message";
|
|
|
import encodeStr from "@/utils/pass";
|
|
|
import { Base64 } from "js-base64";
|
|
|
+import { v4 } from "uuid";
|
|
|
type Props = {
|
|
|
closeFu: () => void;
|
|
|
};
|
|
|
@@ -40,13 +41,10 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
endTime: "",
|
|
|
});
|
|
|
|
|
|
- // 页码变化
|
|
|
- const paginationChange = (pageNum: number, pageSize: number) => {
|
|
|
- pageNumRef.current = pageNum;
|
|
|
- pagePageRef.current = pageSize;
|
|
|
- setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
- };
|
|
|
-
|
|
|
+ // 用于表格展示分页的数据
|
|
|
+ const [tableShowData, setTableShowData] = useState<any>(
|
|
|
+ [] as QuestionTableType[]
|
|
|
+ );
|
|
|
// 编辑前数据保存
|
|
|
const [editBeforeData, setEditBeforeData] = useState<any>(
|
|
|
[] as QuestionTableType[]
|
|
|
@@ -59,61 +57,146 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
[] as QuestionTableType[]
|
|
|
);
|
|
|
|
|
|
+ // 页码变化
|
|
|
+ const paginationChange = (pageNum: number, pageSize: number) => {
|
|
|
+ pageNumRef.current = pageNum;
|
|
|
+ pagePageRef.current = pageSize;
|
|
|
+ setTableSelect({ ...tableSelect, pageNum, pageSize });
|
|
|
+ };
|
|
|
+
|
|
|
const [form] = Form.useForm();
|
|
|
const [curEdit, setCurEdit] = useState<any>();
|
|
|
const onFinish = useCallback(
|
|
|
async (values: any) => {
|
|
|
let newList = editShowData;
|
|
|
- console.log(curEdit, newList[curEdit.index], values.numberVal);
|
|
|
+ // console.log(curEdit, newList[curEdit.index + (Number(pageNumRef) * Number(pagePageRef))], values.numberVal);
|
|
|
+ console.log(curEdit, editShowData);
|
|
|
if (curEdit) {
|
|
|
switch (curEdit.project) {
|
|
|
case "题目描述":
|
|
|
- newList[curEdit.index].question = values.numberVal;
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].question = values.numberVal;
|
|
|
break;
|
|
|
case "选项1":
|
|
|
- newList[curEdit.index].answer.answer[0]
|
|
|
- ? (newList[curEdit.index].answer.answer[0].name =
|
|
|
- values.numberVal)
|
|
|
- : newList[curEdit.index].answer.answer.push({
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer[0]
|
|
|
+ ? (newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer[0].name = values.numberVal)
|
|
|
+ : newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer.push({
|
|
|
name: values.numberVal,
|
|
|
val: encodeStr(Base64.encode("A")),
|
|
|
});
|
|
|
break;
|
|
|
case "选项2":
|
|
|
- newList[curEdit.index].answer.answer[1]
|
|
|
- ? (newList[curEdit.index].answer.answer[1].name =
|
|
|
- values.numberVal)
|
|
|
- : newList[curEdit.index].answer.answer.push({
|
|
|
- name: values.numberVal,
|
|
|
- val: encodeStr(Base64.encode("B")),
|
|
|
- });
|
|
|
+ if (
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer.length <= 0
|
|
|
+ ) {
|
|
|
+ MessageFu.warning("请先填写前面选项!");
|
|
|
+ } else {
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer[1]
|
|
|
+ ? (newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer[1].name = values.numberVal)
|
|
|
+ : newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer.push({
|
|
|
+ name: values.numberVal,
|
|
|
+ val: encodeStr(Base64.encode("B")),
|
|
|
+ });
|
|
|
+ }
|
|
|
break;
|
|
|
case "选项3":
|
|
|
- newList[curEdit.index].answer.answer[2]
|
|
|
- ? (newList[curEdit.index].answer.answer[2].name =
|
|
|
- values.numberVal)
|
|
|
- : newList[curEdit.index].answer.answer.push({
|
|
|
- name: values.numberVal,
|
|
|
- val: encodeStr(Base64.encode("C")),
|
|
|
- });
|
|
|
+ if (
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer.length <= 1
|
|
|
+ ) {
|
|
|
+ MessageFu.warning("请先填写前面选项!");
|
|
|
+ } else {
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer[2]
|
|
|
+ ? (newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer[2].name = values.numberVal)
|
|
|
+ : newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer.push({
|
|
|
+ name: values.numberVal,
|
|
|
+ val: encodeStr(Base64.encode("C")),
|
|
|
+ });
|
|
|
+ }
|
|
|
break;
|
|
|
case "选项4":
|
|
|
- newList[curEdit.index].answer.answer[3]
|
|
|
- ? (newList[curEdit.index].answer.answer[3].name =
|
|
|
- values.numberVal)
|
|
|
- : newList[curEdit.index].answer.answer.push({
|
|
|
- name: values.numberVal,
|
|
|
- val: encodeStr(Base64.encode("D")),
|
|
|
- });
|
|
|
+ if (
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer.length <= 2
|
|
|
+ ) {
|
|
|
+ MessageFu.warning("请先填写前面选项!");
|
|
|
+ } else {
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.answer[3]
|
|
|
+ ? (newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer[3].name = values.numberVal)
|
|
|
+ : newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) *
|
|
|
+ Number(pagePageRef.current)
|
|
|
+ ].answer.answer.push({
|
|
|
+ name: values.numberVal,
|
|
|
+ val: encodeStr(Base64.encode("D")),
|
|
|
+ });
|
|
|
+ }
|
|
|
break;
|
|
|
case "答案解析":
|
|
|
- newList[curEdit.index].description = values.numberVal;
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].description = values.numberVal;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
setEditShowData([...newList]);
|
|
|
setEditShow(false);
|
|
|
- console.log(curEdit, editShowData[curEdit.index], values.numberVal);
|
|
|
+ console.log(
|
|
|
+ "修改的单元",
|
|
|
+ newList[
|
|
|
+ curEdit.index +
|
|
|
+ Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ]
|
|
|
+ );
|
|
|
},
|
|
|
[curEdit, editShowData]
|
|
|
);
|
|
|
@@ -127,12 +210,15 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
});
|
|
|
});
|
|
|
setEditShowData(newList);
|
|
|
+ // setTableShowData(newList.splice(0, pagePageRef.current));
|
|
|
}, []);
|
|
|
|
|
|
const handleCorrectChange = useCallback(
|
|
|
(value: string, index: number) => {
|
|
|
let newList = editShowData;
|
|
|
- newList[index].answer.correct = value;
|
|
|
+ newList[
|
|
|
+ index + Number(pageNumRef.current - 1) * Number(pagePageRef.current)
|
|
|
+ ].answer.correct = value;
|
|
|
setEditShowData([...newList]);
|
|
|
console.log(editShowData);
|
|
|
},
|
|
|
@@ -177,6 +263,7 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
title: "序号",
|
|
|
render: (text: any, record: any, index: any) =>
|
|
|
index + 1 + (pageNumRef.current - 1) * pagePageRef.current,
|
|
|
+ // index,
|
|
|
},
|
|
|
{
|
|
|
title: "题目描述",
|
|
|
@@ -188,6 +275,7 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
setEditShow(true);
|
|
|
setCurEdit({
|
|
|
index: index,
|
|
|
+ id: item.id,
|
|
|
project: "题目描述",
|
|
|
value: item.question,
|
|
|
});
|
|
|
@@ -339,6 +427,7 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
setEditShow(true);
|
|
|
setCurEdit({
|
|
|
index: index,
|
|
|
+ id: item.id,
|
|
|
project: "答案解析",
|
|
|
value: item.description ? item.description : "",
|
|
|
});
|
|
|
@@ -383,7 +472,8 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
setEditShowData([
|
|
|
...editShowData,
|
|
|
{
|
|
|
- id: null,
|
|
|
+ id: v4(),
|
|
|
+ type: "add",
|
|
|
answer: {
|
|
|
answer: [],
|
|
|
},
|
|
|
@@ -409,7 +499,7 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
}
|
|
|
// 执行数据提交 新增不用传id 编辑要传id
|
|
|
let data = editShowData.map((item: any) => {
|
|
|
- return item.id == null
|
|
|
+ return item.type && item.type === "add"
|
|
|
? {
|
|
|
answer: JSON.stringify(item.answer),
|
|
|
description: item.description,
|
|
|
@@ -435,20 +525,21 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
MessageFu.warning("至少提交一道题目");
|
|
|
return;
|
|
|
}
|
|
|
+ console.log(editShowData);
|
|
|
|
|
|
editShowData.forEach((element: any) => {
|
|
|
// 题目描述为空
|
|
|
if (element.question === "" || !element.question) {
|
|
|
MessageFu.warning("题目描述不能为空");
|
|
|
- return;
|
|
|
+ throw new Error("");
|
|
|
}
|
|
|
if (element.answer.answer.length < 2) {
|
|
|
MessageFu.warning("每道题目至少填入两个选项");
|
|
|
- return;
|
|
|
+ throw new Error("");
|
|
|
}
|
|
|
if (!element.answer.correct || element.answer.correct === "") {
|
|
|
MessageFu.warning("需设置正确答案且正确答案不能为空");
|
|
|
- return;
|
|
|
+ throw new Error("");
|
|
|
}
|
|
|
});
|
|
|
submitFinish();
|
|
|
@@ -537,7 +628,12 @@ function TopicSetting({ closeFu }: Props) {
|
|
|
style={{ marginTop: "40px" }}
|
|
|
hide-required-asterisk={true}
|
|
|
>
|
|
|
- <Input placeholder="请输入" />
|
|
|
+ <Input
|
|
|
+ placeholder="请输入"
|
|
|
+ maxLength={
|
|
|
+ curEdit ? (curEdit.project === "题目描述" ? 200 : 20) : 20
|
|
|
+ }
|
|
|
+ />
|
|
|
</Form.Item>
|
|
|
{/* 确定和取消按钮 */}
|
|
|
<br />
|