Browse Source

Merge branch 'master' of http://git.ycjcjy.com/civilized_city/pc-admin

Yansen 2 years ago
parent
commit
d59cff4550
2 changed files with 213 additions and 0 deletions
  1. 202
    0
      src/pages/question/list/index.jsx
  2. 11
    0
      src/routes/routes.jsx

+ 202
- 0
src/pages/question/list/index.jsx View File

@@ -0,0 +1,202 @@
1
+import React from 'react';
2
+import { Button, Form, Row, Col, Card, List } from 'antd';
3
+import {
4
+  ProForm,
5
+  ProFormText,
6
+  ProFormSelect,
7
+  ProFormList,
8
+  PageContainer
9
+} from '@ant-design/pro-components';
10
+import { postTdLocQuestion, getTdLocQuestion, deleteTdLocQuestion, getTdLocQuestionById } from '@/service/tdlocquestion';
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
+}
60
+
61
+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 postTdLocQuestion(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;
92
+  }
93
+
94
+  const onEditQu = (qu) => {
95
+    setQuInfo(qu);
96
+    setOpen(true);
97
+  }
98
+
99
+  const onDeleteQu = (qu) => {
100
+    if (qu?.quId) {
101
+      deleteTdLocQuestion(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
+    }
107
+  }
108
+
109
+  React.useEffect(() => {
110
+    if (quInfo) {
111
+      form.setFieldsValue(quInfo);
112
+    }
113
+  }, [quInfo]);
114
+
115
+  // React.useEffect(() => {
116
+  //   if (itemId) {
117
+  //     getTdLocQuestion({ pageSize: 500, itemId }).then((res) => {
118
+  //       setList(res.records);
119
+  //     });
120
+  //   }
121
+  // }, [itemId]);
122
+
123
+  React.useEffect(() => {
124
+    if (itemId) {
125
+      getTdLocQuestionById({ 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
+  return (
136
+    <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)} />}
198
+      />
199
+
200
+    </div>
201
+  )
202
+});

+ 11
- 0
src/routes/routes.jsx View File

@@ -30,6 +30,7 @@ import LocTypeList from "@/pages/locType/list";
30 30
 import LocTypeEdit from "@/pages/locType/edit";
31 31
 import IssueTypeList from "@/pages/issueType/list";
32 32
 import IssueTypeEdit from "@/pages/issueType/edit";
33
+import QuestionList from "@/pages/question/list";
33 34
 
34 35
 /**
35 36
  * meta 用来扩展自定义数据数据
@@ -153,6 +154,16 @@ export const authRoutes = [
153 154
           // permission: 'form',
154 155
         },
155 156
       },
157
+      {
158
+        path: "question/list",
159
+        element: <QuestionList />,
160
+        meta: {
161
+          title: '点位问题',
162
+          // icon: <AppstoreOutlined />,
163
+          // permission: 'form',
164
+        },
165
+      },
166
+
156 167
     ]
157 168
   },
158 169
   {