-
- {question.questionTypes === '1'? (
- this.handleRadioChange(index, e.target.value)}
- >
- A
- this.handleAnswerOptionChange(index, 'A', e.target.value)}
- />
-
- ) : (
- this.handleCheckboxChange(index,'A', values,)}>
- A
- this.handleAnswerOptionChange(index, 'A', e.target.value)}
- />
-
- )}
- {question.questionTypes === '1'? (
- this.handleRadioChange(index, e.target.value)}
- style={{ marginLeft: 20 }}
- >
- B
- this.handleAnswerOptionChange(index, 'B', e.target.value)}
- />
-
- ) : (
- this.handleCheckboxChange(index,'B',values)}>
- B
- this.handleAnswerOptionChange(index, 'B', e.target.value)}
- />
-
- )}
-
-
- {question.questionTypes === '1'? (
-
this.handleRadioChange(index, e.target.value)}
- >
- C
- this.handleAnswerOptionChange(index, 'C', e.target.value)}
- />
-
- ) : (
-
this.handleCheckboxChange(index,'C', values)}>
- C
- this.handleAnswerOptionChange(index, 'C', e.target.value)}
- />
-
- )}
- {question.questionTypes === '1'? (
+
+
+
+
+
+
-
+
))}
-
+
@@ -493,13 +440,12 @@ class QuestionAdd extends Component
{
bottom: 10,
right: 10,
width: '100%',
- backgroundColor: 'white',
zIndex: 1000
}}>
-
@@ -507,4 +453,5 @@ class QuestionAdd extends Component
{
);
}
}
+
export default QuestionAdd;
\ No newline at end of file
diff --git a/packages/examination/src/views/question/questionList.tsx b/packages/examination/src/views/question/questionList.tsx
index 1564afd..87a96d7 100644
--- a/packages/examination/src/views/question/questionList.tsx
+++ b/packages/examination/src/views/question/questionList.tsx
@@ -1,7 +1,6 @@
import React, { Component } from'react';
-import {Form, Input, Button, Table, Select, message, Modal} from 'antd';
-import { TableRowSelection } from 'antd/lib/table/interface';
-import {deleteQuestion, deleteQuestionList, findIndustry, getList} from 'api/question';
+import { Form, Input, Button, Table, Select, message, Modal } from 'antd';
+import { delQuestion, findIndustry, getList } from 'api/question';
import { dictionary } from "api/dict/index";
const { Option } = Select;
@@ -9,152 +8,145 @@ const { Option } = Select;
interface States {
num: number;
page: number;
+ total: number;
listQuery: {
- industryId: string | undefined;
- serviceTypeId: string | undefined;
- questionContent: string | undefined;
+ industryId: string;
+ serviceTypeId: string;
+ questionContent: string;
};
list: any[];
- total: number;
loading: boolean;
- currentRow: object;
- title: string;
- modalText: string;
- modalWidth: number | string;
industryDict: any;
serviceTypeDict: any;
selectedRowKeys: number[];
- isAllSelected: boolean;
}
class QuestionList extends Component {
formRef: any;
+
constructor(props: any) {
super(props);
this.formRef = React.createRef();
this.state = {
num: 10,
page: 1,
+ total: 0,
listQuery: {
industryId: '',
serviceTypeId: '',
questionContent: ''
},
list: [],
- total: 0,
loading: false,
- currentRow: {
- id: 0,
- status: 0
- },
- title: '',
- modalText: '',
- modalWidth: 0,
- industryDict: undefined,
- serviceTypeDict: undefined,
+ industryDict: [],
+ serviceTypeDict: [],
selectedRowKeys: [],
- isAllSelected: false,
};
}
componentDidMount() {
this.findDict();
- this.findIndustry();
this.getList();
}
- // 监管行业
- findIndustry() {
- findIndustry().then((res: any) => {
- if (res.data) {
- this.setState({ industryDict: res.data });
- }
- });
- }
-
- // AQ服务类型
+ // 字典
findDict() {
- dictionary('serviceTypeDict').then((res) => {
- if (res.data) {
- this.setState({ serviceTypeDict: res.data });
- }
- });
+ // 监管行业
+ findIndustry()
+ .then((res: any) => {
+ if (res.data) {
+ this.setState({ industryDict: res.data });
+ }
+ })
+ .catch(() => {
+ message.error('获取监管行业字典数据失败,请稍后重试');
+ });
+ // AQ服务类型
+ dictionary('serviceTypeDict')
+ .then((res) => {
+ if (res.data) {
+ this.setState({ serviceTypeDict: res.data });
+ }
+ })
+ .catch(() => {
+ message.error('获取AQ服务类型字典数据失败,请稍后重试');
+ });
}
// 查询
getList() {
this.setState({ loading: true });
const { num, page, listQuery } = this.state;
- getList(num, page, listQuery).then((res) => {
- this.setState({
- loading: false,
- list: res.data.data,
- total: res.data.total,
- selectedRowKeys: [],
- isAllSelected: false,
+ getList(num, page, listQuery)
+ .then((res) => {
+ this.setState({
+ list: res.data.data,
+ total: res.data.total,
+ selectedRowKeys: [],
+ });
+ })
+ .catch(() => {
+ message.error('获取数据失败');
+ })
+ .finally(() => {
+ this.setState({ loading: false });
});
- this.setState({ loading: false });
- }).catch(() => {
- this.setState({ loading: false });
- });
}
// 重置
handleReset = () => {
- if (this.formRef.current) {
- // 重置表单字段
- this.formRef.current.resetFields();
- // 重置 listQuery 状态
- this.setState({
- listQuery: {
- industryId: undefined,
- serviceTypeId: undefined,
- questionContent: undefined
- },
- selectedRowKeys: [],
- isAllSelected: false,
- });
- }
+ this.formRef.current.resetFields();
+ this.setState({
+ listQuery: {
+ industryId: '',
+ serviceTypeId: '',
+ questionContent: '',
+ },
+ });
};
- // 删除(明细)
- deleteSingle = (id: number) => {
+ // 删除问题
+ handleDeleteQuestion = (id: number) => {
Modal.confirm({
title: '确认删除',
content: '你确定要删除这个问题吗?',
onOk: () => {
- deleteQuestion(id).then((res) => {
- const isSuccess = res.data;
- if (isSuccess) {
- message.success('删除成功');
- this.getList();
- } else {
- message.error('删除失败,请稍后重试');
- }
- }).catch(() => {
- message.error('删除时发生错误,请检查');
- });
+ const idList = [id];
+ delQuestion(idList)
+ .then((res) => {
+ const success = res['success'];
+ if (success) {
+ message.success('删除成功');
+ this.getList();
+ } else {
+ message.error('删除失败,请稍后重试');
+ }
+ })
+ .catch(() => {
+ message.error('删除时发生错误,请检查');
+ });
},
onCancel: () => {
},
});
};
- // 删除
- deleteMultiple = () => {
+ // 批量删除问题
+ handleBatchDeleteQuestions = () => {
const { selectedRowKeys } = this.state;
- if (selectedRowKeys.length === 0) {
- message.warning('请选择要删除的问题');
+
+ if (selectedRowKeys === null || selectedRowKeys.length === 0) {
+ message.warning('请选择要删除的问题').then();
return;
}
Modal.confirm({
title: '确认删除',
content: '你确定要删除这些选中的问题吗?',
onOk: () => {
- deleteQuestionList(selectedRowKeys)
+ delQuestion(selectedRowKeys)
.then((res) => {
- const isSuccess = res.data;
- if (isSuccess) {
+ const success = res['success'];
+ if (success) {
message.success('删除成功');
this.getList();
} else {
@@ -170,94 +162,104 @@ class QuestionList extends Component {
});
};
- // 多选
- onSelectChange = (selectedRowKeys: React.Key[]) => {
+ // 行选择
+ onChange = (selectedRowKeys: React.Key[]) => {
this.setState({
selectedRowKeys: selectedRowKeys as number[],
- isAllSelected: selectedRowKeys.length === this.state.list.length
});
};
- // 单选
- onSelect = (record: any, selected: boolean) => {
- if (selected) {
- // 单选时只保留当前选中行
- this.setState({
- selectedRowKeys: [record.id],
- isAllSelected: false
- });
- } else {
- // 取消选中时清空选中行
- this.setState({
- selectedRowKeys: [],
- isAllSelected: false
- });
- }
- };
-
render() {
const onFinish = (values: object) => {
- const _listQuery = { ...this.state.listQuery, ...values };
- this.setState({ listQuery: _listQuery });
+ const listQuery = { ...this.state.listQuery, ...values };
+ this.setState({ listQuery });
this.getList();
};
- const { industryDict, serviceTypeDict, selectedRowKeys } = this.state;
-
- // 行选择
- const rowSelection: TableRowSelection = {
- selectedRowKeys,
- onChange: this.onSelectChange,
- onSelect: this.onSelect,
- getCheckboxProps: (record) => ({
- checked: selectedRowKeys.includes(record.id),
- indeterminate: selectedRowKeys.includes(record.id),
- })
- };
-
- // 页面跳转
- const handleAddQuestion = () => {
- this.props.history.push('/questionAdd');
+ const changePage = (current: number, pageSize?: number) => {
+ setTimeout(() => {
+ this.setState({ page: current, num: pageSize || 20 });
+ this.getList();
+ }, 0);
};
+ const {
+ industryDict,
+ serviceTypeDict,
+ selectedRowKeys,
+ list,
+ loading,
+ page,
+ num
+ } = this.state;
const columns: any = [
- { title: '序号', dataIndex: 'index', key: 'index', align: 'center', width: 60,
+ {
+ title: '序号',
+ dataIndex: 'index',
+ key: 'index',
+ align: 'center',
+ width: 60,
render: (_: number, __: number, index: number) => {
- const { page, num } = this.state;
return (page - 1) * num + index + 1;
}
},
- { title: '监管行业', dataIndex: 'industryId', key: 'industryId', align: 'center', width: 150,
- render: (industryId:any) => {
- const industry = industryDict?.find((item: { industryId: string | number; industryName: string }) => String(item.industryId) === String(industryId));
+ {
+ title: '监管行业',
+ dataIndex: 'industryId',
+ key: 'industryId',
+ align: 'center',
+ width: 150,
+ render: (industryId: any) => {
+ const industry = industryDict?.find((item: any) => item.industryId === String(industryId));
return industry? industry.industryName : industryId;
}
},
- { title: 'AQ服务类型', dataIndex: 'serviceTypeId', key: 'serviceTypeId', align: 'center', width: 150,
- render: (serviceTypeId:any) => {
- const serviceType = serviceTypeDict?.find((item: { dictKey: string | number; dictValue: string }) => String(item.dictKey) === String(serviceTypeId));
+ {
+ title: 'AQ服务类型',
+ dataIndex: 'serviceTypeId',
+ key: 'serviceTypeId',
+ align: 'center',
+ width: 150,
+ render: (serviceTypeId: any) => {
+ const serviceType = serviceTypeDict?.find((item: any) => item.dictKey === serviceTypeId);
return serviceType? serviceType.dictValue : serviceTypeId;
}
},
- { title: '题型', dataIndex: 'questionTypes', key: 'questionTypes', align: 'center', width: 80,
- render: (questionTypes:any) => {
- if (questionTypes === 1) {
- return '单选题';
- } else if (questionTypes === 2) {
- return '多选题';
+ {
+ title: '题型',
+ dataIndex: 'questionTypes',
+ key: 'questionTypes',
+ align: 'center',
+ width: 80,
+ render: (questionTypes: any) => {
+ return questionTypes === 1? '单选题' : '多选题';
}
- return questionTypes;}
},
- { title: '题干', dataIndex: 'questionContent', key: 'questionContent', align: 'center', width: 450 },
- { title: '答案', dataIndex: 'answer', key: 'answer', align: 'center', width: 120 },
- { title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 120,
+ {
+ title: '题干',
+ dataIndex: 'questionContent',
+ key: 'questionContent',
+ align: 'center',
+ width: 450
+ },
+ {
+ title: '答案',
+ dataIndex: 'answer',
+ key: 'answer',
+ align: 'center',
+ width: 120
+ },
+ {
+ title: '操作',
+ key: 'operation',
+ align: 'center',
+ fixed: 'right',
+ width: 120,
render: (record: any) => [
{
- this.setState({title: '删除', modalWidth: '85%'})
- this.deleteSingle(record.id);
+ this.handleDeleteQuestion(record.id);
}}>删除,
{
- this.setState({title: '修正', modalWidth: '85%'})
sessionStorage.setItem('id', String(record.id));
this.props.history.push(`/questionEdit`);
}}>修正
@@ -265,106 +267,94 @@ class QuestionList extends Component {
},
];
- // 分页切换
- const changePage = (current: number, pageSize?: number) => {
- setTimeout(() => {
- this.setState({page: current, num: pageSize || 20});
- this.getList();
- }, 0);
- };
-
- // 多少每页
- const selectChange = (page: number, num: number) => {
- this.setState({ page, num });
- this.getList();
- };
-
- const { list, loading } = this.state;
-
return (
-
-
-
-
-
-
-
-
-
- 0?
+ (() => {
+ let rows = [];
+ for (let i = 0; i < industryDict.length; i++) {
+ const item = industryDict[i];
+ rows.push(
+
+ );
+ }
+ return rows;
+ })()
+ :
+
+ }
+
+
+
+
-
- 重置
-
-
- 查询
-
-
-
+ {
+ serviceTypeDict && serviceTypeDict.length > 0?
+ (() => {
+ let rows = [];
+ for (let i = 0; i < serviceTypeDict.length; i++) {
+ const item = serviceTypeDict[i];
+ rows.push(
+
+ );
+ }
+ return rows;
+ })()
+ :
+
+ }
+
+
+
+
+
+
+ 重置
+
+
+ 查询
+
+
- 删除
+ 删除
- 新增试题
+ {
+ this.props.history.push('/questionAdd');
+ }}>新增试题
{
columns={columns}
rowKey="id"
loading={loading}
- scroll={{ y: '400px' }}
+ rowSelection={{
+ selectedRowKeys: selectedRowKeys,
+ onChange: this.onChange,
+ getCheckboxProps: () => ({
+ disabled: false
+ })
+ }}
pagination={{
total: this.state.total,
current: this.state.page,
showQuickJumper: true,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`,
- onShowSizeChange: selectChange,
onChange: changePage
}}
- rowSelection={rowSelection}
/>
);
}
}
-
export default QuestionList;
\ No newline at end of file