fangmingyue 2 years ago
parent
commit
53118a40f7
2 changed files with 122 additions and 183 deletions
  1. 121
    182
      src/pages/question/list/index.jsx
  2. 1
    1
      src/routes/routes.jsx

+ 121
- 182
src/pages/question/list/index.jsx View File

@@ -1,202 +1,141 @@
1 1
 import React from 'react';
2
-import { Button, Form, Row, Col, Card, List } from 'antd';
2
+import { Row, Col } from 'antd';
3 3
 import {
4
-  ProForm,
5 4
   ProFormText,
6 5
   ProFormSelect,
7 6
   ProFormList,
8
-  PageContainer
9 7
 } from '@ant-design/pro-components';
10
-import { postTdQuestion, getTdQuestion, deleteTdQuestion, getTdQuestionById } from '@/service/tdquestion';
11
-
12
-const QuItem = (props) => {
13
-  const { qu, onEdit, onDelete } = props;
14
-
15
-  const quTitle = `${qu?.quType == 'fill' ? '填空' : '选择'} ${qu?.title}`
16
-
17
-  return (
18
-    <Card title={quTitle}
19
-      extra={(
20
-        <>
21
-          <Button type='link' onClick={onEdit}>修改</Button>
22
-          <Popconfirm
23
-            title="确认进行删除操作?"
24
-            onConfirm={onDelete}
25
-          >
26
-            <Button type='link' danger >删除</Button>
27
-          </Popconfirm>
28
-        </>
29
-      )}
30
-      style={{ marginTop: '24px' }}>
31
-      <Card.Meta
32
-        title={
33
-          qu?.quType != 'fill' ?
34
-            (
35
-              <Row gutter={24}>
36
-                {
37
-                  (qu || []).map((item) => {
38
-                    const anStr = `${item.answerCode} ${item.answer}`;
39
-
40
-                    return (
41
-                      <Col span={12} key={item.quId} style={{ height: '32px', lineHeight: '32px', fontWeight: 400 }}>
42
-                        {anStr}
43
-                      </Col>
44
-                    );
45
-                  })
46
-                }
47
-              </Row>
48
-            ) : null
49
-        }
50
-        description={(
51
-          <>
52
-            <h3>验收标准</h3>
53
-            <div dangerouslySetInnerHTML={{ __html: qu?.stand }} />
54
-          </>
55
-        )}
56
-      />
57
-    </Card>
58
-  );
59
-}
8
+import { postTdQuestion, getTdQuestion, deleteTdQuestion, putTdQuestion } from '@/service/tdquestion';
9
+import Curd from '@/components/Page/Curd';
60 10
 
61 11
 export default React.forwardRef((props, ref) => {
62
-
63
-  const { itemId, onChange } = props;
64
-
65
-  const [open, setOpen] = React.useState(false);
66
-  const [quInfo, setQuInfo] = React.useState(false);
67
-  const [list, setList] = React.useState([]);
68
-  // const [and, setAnd] = React.useState([]);
69
-  const [form] = Form.useForm();
70
-
71
-  const onFinish = async (values) => {
72
-    const data = { ...(quInfo || {}), ...values, itemId };
73
-    const res = await postTdQuestion(data).then(x => x);
74
-    let found = false;
75
-    const newList = list.map(item => {
76
-      if (item.quId === res.quId) {
77
-        found = true;
78
-        return res;
79
-      } else {
80
-        return item
81
-      }
82
-    });
83
-
84
-    if (!found) {
85
-      newList.push(res);
86
-    }
87
-
88
-    setList(list);
89
-    onChange(res);
90
-
91
-    return true;
12
+  const actionRef = React.useRef();
13
+
14
+  const columns = [
15
+    {
16
+      title: "问题类型",
17
+      dataIndex: "quType",
18
+      valueEnum: {
19
+        1: {
20
+          text: "单选",
21
+          status: "radio",
22
+        },
23
+        0: {
24
+          text: "填空题",
25
+          status: "fill",
26
+        },
27
+      },
28
+    },
29
+    {
30
+      title: "问题描述",
31
+      dataIndex: "title",
32
+    },
33
+    {
34
+      title: "正确答案",
35
+      dataIndex: "rightAnswers",
36
+    },
37
+    {
38
+      title: "状态",
39
+      dataIndex: "status",
40
+      valueEnum: {
41
+        1: {
42
+          text: "正常",
43
+          status: "Processing",
44
+        },
45
+        0: {
46
+          text: "禁用",
47
+          status: "Error",
48
+        },
49
+      },
50
+    },
51
+  ]
52
+
53
+  const Add = (data) => {
54
+    postTdQuestion(data).then((res) => {
55
+      actionRef.current.reload();
56
+    })
92 57
   }
93 58
 
94
-  const onEditQu = (qu) => {
95
-    setQuInfo(qu);
96
-    setOpen(true);
59
+  const Edit = (row, data) => {
60
+    console.log('fff', data);
61
+    putTdQuestion(row, data).then((res) => {
62
+      actionRef.current.reload();
63
+    })
97 64
   }
98 65
 
99
-  const onDeleteQu = (qu) => {
100
-    if (qu?.quId) {
101
-      deleteTdQuestion(qu.quId).then(() => {
102
-        setList(list.filter(x => x.quId !== qu.quId));
103
-      })
104
-    } else {
105
-      setList(list.filter(x => x.quId !== qu.quId));
106
-    }
66
+  const Delete = (row) => {
67
+    deleteTdQuestion(row).then(() => {
68
+      actionRef.current.reload();
69
+    })
107 70
   }
108 71
 
109
-  React.useEffect(() => {
110
-    if (quInfo) {
111
-      form.setFieldsValue(quInfo);
112
-    }
113
-  }, [quInfo]);
114
-
115
-  // React.useEffect(() => {
116
-  //   if (itemId) {
117
-  //     getTdQuestion({ pageSize: 500, itemId }).then((res) => {
118
-  //       setList(res.records);
119
-  //     });
120
-  //   }
121
-  // }, [itemId]);
122
-
123
-  React.useEffect(() => {
124
-    if (itemId) {
125
-      getTdQuestionById({ pageSize: 500, itemId }).then((res) => {
126
-        setList(res.records);
127
-      });
128
-    }
129
-  }, [itemId]);
130
-
131
-  React.useImperativeHandle(ref, () => ({
132
-    add: () => setOpen(true),
133
-  }), []);
134
-
135 72
   return (
136 73
     <div>
137
-      <Card>
138
-        <ProForm style={{ width: '800px' }} form={form} onFinish={onFinish} itemId={itemId} quInfo={quInfo} open={open}>
139
-          <ProFormText
140
-            name="title"
141
-            label="问题描述"
142
-            placeholder="请填写"
143
-            rules={[
144
-              {
145
-                required: true,
146
-                message: '请填写题干',
147
-              },
148
-            ]}
149
-          />
150
-          <ProFormSelect
151
-            name="quType"
152
-            label="问题类型"
153
-            fieldProps={{
154
-              style: { width: '100%' }
155
-            }}
156
-            valueEnum={{
157
-              radio: '单选',
158
-              fill: '填空'
159
-            }}
160
-            rules={[
161
-              {
162
-                required: true,
163
-                message: '请选择问题类型',
164
-              },
165
-            ]}
166
-          />
167
-          <ProFormList
168
-            label="选项列表"
169
-            copyIconProps={false}
170
-            name="quAnswerList"
171
-          >
172
-            <Row gutter={24} style={{ width: '730px' }}>
173
-              <Col span={6}>
174
-                <ProFormText
175
-                  name="answerCode"
176
-                  label="答案选项"
177
-                  help="类似 A, B, C, D"
178
-                />
179
-              </Col>
180
-              <Col span={6}>
181
-                <ProFormText
182
-                  name="answer"
183
-                  label="答案"
184
-                  placeholder="具体选项内容"
185
-                />
186
-              </Col>
187
-            </Row>
188
-          </ProFormList>
189
-        </ProForm>
190
-
191
-      </Card>
192
-      <List
193
-        itemLayout="horizontal"
194
-        itemId={itemId}
195
-        quInfo={quInfo}
196
-        dataSource={list}
197
-        renderItem={(item) => <QuItem qu={item} onEdit={() => onEditQu(item)} onDelete={() => onDeleteQu(item)} />}
74
+      <Curd
75
+        rowKey="quId"
76
+        columns={columns}
77
+        search={false}
78
+        request={{
79
+          list: getTdQuestion,
80
+          save: Add,
81
+          update: Edit,
82
+          del: Delete,
83
+        }}
84
+        renderFormItems={() => (
85
+          <>
86
+            <ProFormText
87
+              name="title"
88
+              label="问题描述"
89
+              placeholder="请填写"
90
+              rules={[
91
+                {
92
+                  required: true,
93
+                  message: '请填写题干',
94
+                },
95
+              ]}
96
+            />
97
+            <ProFormSelect
98
+              name="quType"
99
+              label="问题类型"
100
+              fieldProps={{
101
+                style: { width: '100%' }
102
+              }}
103
+              valueEnum={{
104
+                radio: '单选',
105
+                fill: '填空'
106
+              }}
107
+              rules={[
108
+                {
109
+                  required: true,
110
+                  message: '请选择问题类型',
111
+                },
112
+              ]}
113
+            />
114
+            <ProFormList
115
+              label="选项列表"
116
+              copyIconProps={false}
117
+              name="quAnswerList"
118
+            >
119
+              <Row gutter={24} style={{ width: '730px' }}>
120
+                <Col span={6}>
121
+                  <ProFormText
122
+                    name="answerCode"
123
+                    label="答案选项"
124
+                    help="类似 A, B, C, D"
125
+                  />
126
+                </Col>
127
+                <Col span={6}>
128
+                  <ProFormText
129
+                    name="answer"
130
+                    label="答案"
131
+                    placeholder="具体选项内容"
132
+                  />
133
+                </Col>
134
+              </Row>
135
+            </ProFormList>
136
+          </>
137
+        )}
198 138
       />
199
-
200 139
     </div>
201 140
   )
202 141
 });

+ 1
- 1
src/routes/routes.jsx View File

@@ -79,7 +79,7 @@ export const authRoutes = [
79 79
         element: <CheckEdit />,
80 80
         meta: {
81 81
           hideInMenu: true,
82
-          title: '模拟测评',
82
+          title: '模拟测评维护',
83 83
           icon: <ProjectOutlined />,
84 84
         }
85 85
       },