diff --git a/admin/src/pages/examinationrules/attestation/step/index.tsx b/admin/src/pages/examinationrules/attestation/step/index.tsx index 241cb84..76bacaf 100644 --- a/admin/src/pages/examinationrules/attestation/step/index.tsx +++ b/admin/src/pages/examinationrules/attestation/step/index.tsx @@ -1,4 +1,4 @@ -import React, { useRef } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { history, useParams, useRequest } from 'umi'; import type { ProFormInstance } from '@ant-design/pro-form'; import { ProFormRadio } from '@ant-design/pro-form'; @@ -16,8 +16,15 @@ import { Button, Checkbox, Col, Divider, List, Menu, message, Radio, Row, Space, import { PageContainer } from '@ant-design/pro-layout'; import ProDescriptions from '@ant-design/pro-descriptions'; import styles from './index.less' -import { saveRules, querySubjectList, queryRulesView } from '../../service'; +import { saveRules, querySubjectList, queryRulesView, queryRulesList, queryRulesPaper } from '../../service'; +import { queryQuestionType } from '@/pages/questionbank/service'; +import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table'; +import { TableListPagination } from '@/pages/ListTableList2/data'; +import { PlusOutlined } from '@ant-design/icons'; +import { TableListItem } from '../../components/QuestionSelector'; +/** 题型序号 */ +const numberType = ['一','二','三','四','五','六','七','八','九','十']; const waitTime = (time: number = 100) => { return new Promise((resolve) => { @@ -30,12 +37,119 @@ const numbers = []; for (let i = 0; i < 50; i++) { numbers.push({ id: `${i}` }) } + export default () => { + /** 列表项定义 */ + const columns: ProColumns[] = [ + { + title: '序号', + key: 'index', + valueType: 'indexBorder', + width: 48, + }, + { + title: '考试名称', + dataIndex: 'rules_name', + valueType: 'text', + hideInTable: false, + hideInForm: false, + hideInSearch: true, + }, + { + title: '试卷', + dataIndex: 'examination_time', + valueType: 'text', + sorter: false, + hideInTable: false, + hideInForm: false, + hideInSearch: true, + renderText: (val: string) => `${val}`, + }, + { + title: '关联主题', + dataIndex: 'subject_name', + valueType: 'text', + hideInTable: false, + hideInForm: false, + hideInSearch: true, + }, + { + title: '题型设置', + dataIndex: 'subject_id', + valueType: 'text', + hideInTable: true, + hideInForm: false, + hideInSearch: false, + request: async () => { + /* + const { data: Items } = await querySubjectList({}); + // console.log(Items, ')))'); + + const sinfo = [] + for (let i = 0; i < Items.list.length; i++) { + // console.log(Items.list[i], ">>>") + sinfo.push({ label: Items.list[i].subject_name, value: Items.list[i].subject_id }) + } + console.log(sinfo, 'sinfo'); + */ + return []; + }, + }, + { + title: '总分', + dataIndex: 'sum_score', + sorter: false, + valueType: 'text', + hideInSearch: true, + hideInForm: false, + renderText: (val: string) => `${val}分`, + }, + { + title: '通过线', + dataIndex: 'pass_score', + sorter: false, + valueType: 'text', + hideInSearch: true, + hideInForm: false, + renderText: (val: string) => `${val}`, + }, + { + title: '操作', + dataIndex: 'option', + valueType: 'option', + render: (_dom: any, record: React.SetStateAction) => { + console.log(record, 'record') + return [ + { + //console.log('entity', entity); + //setCurrentRow(record); + //handleDetailModalVisible(true); + }} + > + 查看 + , + { + //history.push(`/examination/option/registration/${record.examination_id}`); + //setCurrentRow(record); + }} + > + 重新生成 + , + ] + }, + }, + ]; const formRef = useRef(); const params = useParams(); + const actionRef = useRef(); + console.log(params, 'params'); let ruleData = {} - if (params.id) { + if (params?.id) { console.log(JSON.stringify(params), "878"); const { data } = useRequest(async () => { @@ -46,7 +160,24 @@ export default () => { } console.log(ruleData, 'ruleData'); + const [questionType, setQuestionType] = useState([]); // 题型 + /** 获取题型 */ + const { data: questionTypeData } = useRequest(() => { + return queryQuestionType(); + },{ + formatResult: (result) => { + return result.list; + } + }); + useEffect(() => { + setQuestionType(questionTypeData || []); + return ()=>{ + /** 退出当前页面清空Map */ + //parsingMap.clear(); + } + }, [questionTypeData]); + return ( @@ -162,78 +293,51 @@ export default () => { }} >
- 生涯规划师初级认证考试 - {/** 一旦录入另一项将禁用,清空组卷后可选另一项 */} - { }} style={{ marginBottom: 16 }}> - 手动组卷 - 系统组卷 - - - - - - - - - 4. 以下哪些是符合法律规定的 ? - - { return true }} value={0} size="large"> - - A. 单位在试用期辞退员工 - B. 社会中介收取中介费 - C. 单位不缴纳五险一金 - D. 要求员工支付押金 - - - - - 5. 以下哪些是不符合法律规定的(多选) ? - - { return true }}> - - A. 单位在试用期辞退员工 - B. 社会中介收取中介费 - C. 单位不缴纳五险一金 - D. 要求员工支付押金 - - - - - 6. 单位在试用期辞退员工是符合法律规定的 ? - - { return true }} value={0} size="large"> - - 正确 - 错误 - - - - - - -
- - 试卷信息与设置 - 共 { } 题 { } 分 - - - 单选题 共 { } 题 { } 分 - 多选题 共 { } 题 { } 分 - 判断题 共 { } 题 { } 分 - - - - - -
- -
+ + headerTitle={false} + actionRef={actionRef} + rowKey="examination_id" + options={false} + search={false} + toolBarRender={() => [ + , + + ]} + request={async (value) => { + const _data = await queryRulesPaper( + { + rules_id: params?.id, + page_number: value.current, + page_size: value.pageSize + } + ); + return { + current: _data?.pageNumber, + data: _data?.table_List, + pageSize: _data?.pageSize, + total: _data?.totalRow || 0, + }; + }} + // dataSource={list} + columns={columns} + rowSelection={false} + />
diff --git a/admin/src/pages/examinationrules/normal/components/OperationModal.tsx b/admin/src/pages/examinationrules/components/OperationModal.tsx similarity index 100% rename from admin/src/pages/examinationrules/normal/components/OperationModal.tsx rename to admin/src/pages/examinationrules/components/OperationModal.tsx diff --git a/admin/src/pages/examinationrules/normal/components/QuestionSelector.tsx b/admin/src/pages/examinationrules/components/QuestionSelector.tsx similarity index 68% rename from admin/src/pages/examinationrules/normal/components/QuestionSelector.tsx rename to admin/src/pages/examinationrules/components/QuestionSelector.tsx index d9042df..c97cea0 100644 --- a/admin/src/pages/examinationrules/normal/components/QuestionSelector.tsx +++ b/admin/src/pages/examinationrules/components/QuestionSelector.tsx @@ -1,21 +1,22 @@ -/** 资质考试 */ +/** 模拟考试 | 资质考试选题 */ //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; -import { Switch, Button, Card, Col, List, Menu, Progress, Row, Typography, Space, Divider, Radio, Checkbox, Tag, Dropdown, Upload, Modal, Form } from 'antd'; -import { PageContainer } from '@ant-design/pro-layout'; +import { Button, message } from 'antd'; +//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; //import { useRequest } from 'umi'; //import { queryFakeList } from './service'; //import type { CardListItemDataType } from './data'; import styles from '../style.less'; //import SubMenu from 'antd/lib/menu/SubMenu'; //import ProCard from '@ant-design/pro-card'; -import ProList from '@ant-design/pro-list'; -import { ReactText, useEffect, useRef, useState } from 'react'; -import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons'; +//import ProList from '@ant-design/pro-list'; +import { forwardRef, ReactText, useEffect, useImperativeHandle, useRef, useState } from 'react'; +//import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons'; import { useParams, useRequest, history, useRouteMatch } from 'umi'; import { queryCourseView } from '@/pages/course/option/service'; -import { queryQuestionById, queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; -import ProForm, { ProFormSelect } from '@ant-design/pro-form'; -import ProTable, { ActionType, ProColumns } from '@ant-design/pro-table'; +import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; +//import ProForm, { ProFormSelect } from '@ant-design/pro-form'; +import type { ActionType, ProColumns } from '@ant-design/pro-table'; +import ProTable from '@ant-design/pro-table'; export type TableListItem = { id: string; @@ -29,10 +30,9 @@ export type TableListItem = { memo: string; }; -//const { Paragraph } = Typography; +// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 +const QuestionSelector = (props: any, ref: any) => { -console.log('first'); -const QuestionSelector = () => { const actionRef = useRef(); /** 列表项定义 */ const columns: ProColumns[] | ProColumns[] = [ @@ -57,6 +57,19 @@ const QuestionSelector = () => { hideInTable: false, hideInForm: true, hideInSearch: false, + width: 100, + request: async () => { + const { list: Items } = await queryQuestionType(); + const types = [] + for (let i = 0; i < Items.length; i++) { + types.push({text: Items[i]?.name, label: Items[i]?.name, value: Items[i]?.code }) + } + return types; + }, + render: (text: React.ReactNode, _: any, index: number) => { + return text; + }, + }, { title: '题干', @@ -71,13 +84,8 @@ const QuestionSelector = () => { console.log('match', match); const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 - const [questionType, setQuestionType] = useState([]); - - - const [createModalVisible, handleCreateModalVisible] = useState(false); const [selectedRowsState, setSelectedRows] = useState([]); - const [expandedDescRowKeys, setExpandedDescRowKeys] = useState([]); // 展开解析设置 const [addType, setAddType] = useState({name: '', value: 0}); const labels = ['A','B','C','D','E'] @@ -90,20 +98,22 @@ const QuestionSelector = () => { return result.list; } }); -/* - const { data: template } = useRequest(() => { - return exportQuestionTemplate(); - }); - */ + useEffect(() => { setQuestionType(data || []); return ()=>{ - /** 退出当前页面清空Map */ - //parsingMap.clear(); } }, [data]); - + + // 暴露组件的方法 接受外部获取的ref + useImperativeHandle(ref, () => ({ + // 构造ref的获取数据方法 + getSelectedRows: () => { + return selectedRowsState; + }, + })); return ( + <> { }} columns={columns} // grid={{ gutter: 16, column: 1 }} - metas={{ title: { dataIndex: 'question_stem', @@ -161,20 +170,19 @@ const QuestionSelector = () => { avatar: { dataIndex: 'question_type', valueType: 'text', - render: (text: React.ReactNode, record: T, index: number) => { - const type = questionType?.filter((item, idx, self)=>{ + render: (text: React.ReactNode, record: T, _: number) => { + const _type = questionType?.filter((item, idx, self)=>{ return item?.code === record.question_type }); - return `[${type[0]?.name}]` + return `[${_type[0]?.name}]` }, }, description: { }, - }} - /> - + /> + ); }; - -export default QuestionSelector; +// forwardRef这个组件能够将其接受的 ref 属性转发到其组件树下 +export default forwardRef( QuestionSelector ); diff --git a/admin/src/pages/examinationrules/normal/_components/OperationModal.tsx b/admin/src/pages/examinationrules/normal/_components/OperationModal.tsx new file mode 100644 index 0000000..a92023c --- /dev/null +++ b/admin/src/pages/examinationrules/normal/_components/OperationModal.tsx @@ -0,0 +1,105 @@ +import type { FC } from 'react'; +import { + ModalForm, + ProFormSelect, + ProFormDateTimePicker, + ProFormText, + ProFormTextArea, +} from '@ant-design/pro-form'; +import type { BasicListItemDataType } from '../data'; +import styles from '../style.less'; +import { Button, Result } from 'antd'; + +type OperationModalProps = { + done: boolean; + visible: boolean; + current: Partial | undefined; + onDone: () => void; + onSubmit: (values: BasicListItemDataType) => void; +}; + +const OperationModal: FC = (props) => { + const { done, visible, current, onDone, onSubmit, children } = props; + if (!visible) { + return null; + } + return ( + + visible={visible} + title={done ? null : `任务${current ? '编辑' : '添加'}`} + className={styles.standardListForm} + width={640} + onFinish={async (values) => { + onSubmit(values); + }} + initialValues={current} + submitter={{ + render: (_, dom) => (done ? null : dom), + }} + trigger={<>{children}} + modalProps={{ + onCancel: () => onDone(), + destroyOnClose: true, + bodyStyle: done ? { padding: '72px 0' } : {}, + }} + > + {!done ? ( + <> + + + + + + ) : ( + + 知道了 + + } + className={styles.formResult} + /> + )} + + ); +}; + +export default OperationModal; diff --git a/admin/src/pages/examinationrules/normal/_components/QuestionSelector.tsx b/admin/src/pages/examinationrules/normal/_components/QuestionSelector.tsx new file mode 100644 index 0000000..05d2abf --- /dev/null +++ b/admin/src/pages/examinationrules/normal/_components/QuestionSelector.tsx @@ -0,0 +1,189 @@ +/** 模拟考试 */ +//import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; +import { Button, message } from 'antd'; +//import { FooterToolbar, PageContainer } from '@ant-design/pro-layout'; +//import { useRequest } from 'umi'; +//import { queryFakeList } from './service'; +//import type { CardListItemDataType } from './data'; +import styles from '../style.less'; +//import SubMenu from 'antd/lib/menu/SubMenu'; +//import ProCard from '@ant-design/pro-card'; +//import ProList from '@ant-design/pro-list'; +import { forwardRef, ReactText, useEffect, useImperativeHandle, useRef, useState } from 'react'; +//import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined } from '@ant-design/icons'; +import { useParams, useRequest, history, useRouteMatch } from 'umi'; +import { queryCourseView } from '@/pages/course/option/service'; +import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/service'; +//import ProForm, { ProFormSelect } from '@ant-design/pro-form'; +import type { ActionType, ProColumns } from '@ant-design/pro-table'; +import ProTable from '@ant-design/pro-table'; +import { manualPaper } from '../service'; + +export type TableListItem = { + id: string; + code: number; + name: string; + creator: string; + status: string; + createdAt: number; + progress: number; + money: number; + memo: string; +}; + +// React.forwardRef 接受渲染函数作为参数。React 将使用 props 和 ref 作为参数来调用此函数。此函数应返回 React 节点。 +const QuestionSelector = (props: any, ref: any) => { + + const actionRef = useRef(); + /** 列表项定义 */ + const columns: ProColumns[] | ProColumns[] = [ + { + title: '序号', + key: 'index', + valueType: 'indexBorder', + render: (text: React.ReactNode, _: any, index: number) => { + if (actionRef && actionRef?.current && actionRef?.current?.pageInfo) { + return `${(actionRef?.current?.pageInfo?.current - 1) * actionRef.current.pageInfo?.pageSize + (index + 1) + }`; + } else { + return ''; + } + }, + width: 48, + }, + { + title: '类型', + dataIndex: 'question_type', + valueType: 'select', + hideInTable: false, + hideInForm: true, + hideInSearch: false, + width: 100, + request: async () => { + const { list: Items } = await queryQuestionType(); + const types = [] + for (let i = 0; i < Items.length; i++) { + types.push({text: Items[i]?.name, label: Items[i]?.name, value: Items[i]?.code }) + } + return types; + }, + render: (text: React.ReactNode, _: any, index: number) => { + return text; + }, + + }, + { + title: '题干', + dataIndex: 'question_stem', + valueType: 'text', + hideInTable: false, + hideInForm: true, + hideInSearch: false, + }, + ]; + const match = useRouteMatch(); + console.log('match', match); + + const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 + const [questionType, setQuestionType] = useState([]); + const [selectedRowsState, setSelectedRows] = useState([]); + const [addType, setAddType] = useState({name: '', value: 0}); + + const labels = ['A','B','C','D','E'] + + /** 获取题型 */ + const { data } = useRequest(() => { + return queryQuestionType(); + },{ + formatResult: (result) => { + return result.list; + } + }); + + useEffect(() => { + setQuestionType(data || []); + return ()=>{ + } + }, [data]); + + // 暴露组件的方法 接受外部获取的ref + useImperativeHandle(ref, () => ({ + // 构造ref的获取数据方法 + getSelectedRows: () => { + return selectedRowsState; + }, + })); + return ( + <> + { + console.log('value', value) + /* + const { create_time } = value; + if (create_time) { + value.begin_time = create_time[0] + value.end_time = create_time[1] + }*/ + const questions = await queryQuestionList({ + ...value, + type: type, + page_number: value?.current || 1, + page_size: value?.pageSize, + }); + // 课程名称及课程标签 + const data = [] + for(let i=0; i { + setSelectedRows(selectedRows); + }, + }} + columns={columns} + // grid={{ gutter: 16, column: 1 }} + metas={{ + title: { + dataIndex: 'question_stem', + render: (text: React.ReactNode, record: T, index: number) => `1. ${text}`, + }, + avatar: { + dataIndex: 'question_type', + valueType: 'text', + render: (text: React.ReactNode, record: T, _: number) => { + const _type = questionType?.filter((item, idx, self)=>{ + return item?.code === record.question_type + }); + return `[${_type[0]?.name}]` + }, + }, + description: { + }, + }} + /> + + ); +}; +// forwardRef这个组件能够将其接受的 ref 属性转发到其组件树下 +export default forwardRef( QuestionSelector ); diff --git a/admin/src/pages/examinationrules/normal/index.tsx b/admin/src/pages/examinationrules/normal/index.tsx index 3cdd2be..acbfa5a 100644 --- a/admin/src/pages/examinationrules/normal/index.tsx +++ b/admin/src/pages/examinationrules/normal/index.tsx @@ -9,11 +9,12 @@ import ProTable from '@ant-design/pro-table'; import { BetaSchemaForm, ModalForm, ProFormText, ProFormTextArea } from '@ant-design/pro-form'; import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions'; -import type { FormValueType } from './components/UpdateForm'; -import UpdateForm from './components/UpdateForm'; +import type { FormValueType } from './_components/UpdateForm'; +import UpdateForm from './_components/UpdateForm'; import { querySubjectList, queryRulesList, removeRules } from '../service'; import type { TableListItem, TableListPagination } from './data'; import type { DataItem } from '@antv/data-set/lib/transform/tag-cloud'; +import { updateRules } from './service'; /** * 删除考试规则 @@ -38,6 +39,29 @@ const handleRemove = async (selectedRows: TableListItem[], currentRow) => { } }; +/** + * 更新考试规则 + * + * @param fields + */ + const handleUpdate = async (fields: FormValueType, currentRow?: TableListItem) => { + const hide = message.loading('正在配置'); + console.log('fields',fields) + try { + await updateRules({ + ...currentRow, + ...fields, + }); + hide(); + message.success('配置成功'); + return true; + } catch (error) { + hide(); + message.error('配置失败请重试!'); + return false; + } +}; + const ExaminationRules: React.FC = () => { //const [registrationModalVisible, handleRegistrationModalVisible] = useState(false); const actionRef = useRef(); @@ -173,10 +197,13 @@ const ExaminationRules: React.FC = () => { 删除 , { - history.push(`/examination/option/registration/${record.examination_id}`); + key="b_use" + onClick={async () => { + //history.push(`/examination/option/registration/${record.examination_id}`); //setCurrentRow(record); + console.log('record', {...record, b_use: !record.b_use}) + await handleUpdate({b_use: record?.b_use === 0 ? 1 : 0}, record); + actionRef.current?.reloadAndRest?.(); }} > {record.b_use == 0 ? "未发布" : "已发布"} diff --git a/admin/src/pages/examinationrules/normal/service.ts b/admin/src/pages/examinationrules/normal/service.ts index 6dcc064..bdbf12f 100644 --- a/admin/src/pages/examinationrules/normal/service.ts +++ b/admin/src/pages/examinationrules/normal/service.ts @@ -5,6 +5,7 @@ type ParamsType = { count?: number; } & Partial; + export async function queryFakeList( params: ParamsType, ): Promise<{ data: { list: BasicListItemDataType[] } }> { @@ -13,6 +14,7 @@ export async function queryFakeList( }); } + /** * 获取主题列表 * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426 @@ -28,10 +30,6 @@ export async function querySubjectList(params: { }); } -/dsideal_yy/zygh/training/rules/delRules - - - export async function removeFakeList( params: ParamsType, ): Promise<{ data: { list: BasicListItemDataType[] } }> { @@ -44,6 +42,7 @@ export async function removeFakeList( }); } + export async function addFakeList( params: ParamsType, ): Promise<{ data: { list: BasicListItemDataType[] } }> { @@ -77,4 +76,66 @@ export async function removeRules(data: { key: number[] }, options?: Record { + return request('/dsideal_yy/zygh/training/rules/updateRules', { + method: 'POST', + requestType: 'form', + data: { + ...params, + }, + }); +} + +/** + * 获取组卷,查询试题临时表(当前选题列表) + * http://10.10.14.252:8080/workspace/myWorkspace.do?projectId=382#6426 + * @param params + * @returns + */ + export async function queryTempQuestionList(params: { + page_size: number; + //count: number; +}): Promise<{ data: { list: CardListItemDataType[] } }> { + return request('/dsideal_yy/zygh/training/rules/getTempQuestionList', { + params, + }); +} + +/** + * 15 组卷,手动组卷保存临时表 + * @param params + * @returns + */ +export async function manualPaper( + params: ParamsType, +): Promise<{ data: { list: BasicListItemDataType[] } }> { + return request('/dsideal_yy/zygh/training/rules/manualPaper', { + method: 'POST', + requestType: 'form', + data: { + ...params, + }, + }); +} + +/** + * 20 组卷,提交保存试卷 + * @param params + * @returns + */ + export async function updatePaper( + params: ParamsType, +): Promise<{ data: { list: BasicListItemDataType[] } }> { + return request('/dsideal_yy/zygh/training/rules/updatePaper', { + method: 'POST', + requestType: 'form', + data: { + ...params, + }, + }); +} diff --git a/admin/src/pages/examinationrules/normal/step/index.tsx b/admin/src/pages/examinationrules/normal/step/index.tsx index 49336ae..3a38f94 100644 --- a/admin/src/pages/examinationrules/normal/step/index.tsx +++ b/admin/src/pages/examinationrules/normal/step/index.tsx @@ -1,6 +1,6 @@ -import React, { useRef, useState } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; import { history, useParams, useRequest } from 'umi'; -import type { ProFormInstance } from '@ant-design/pro-form'; +import { ModalForm, ProFormInstance } from '@ant-design/pro-form'; import { ProFormRadio } from '@ant-design/pro-form'; import ProForm, { StepsForm, @@ -16,13 +16,67 @@ import { Button, Checkbox, Col, Divider, Dropdown, List, Menu, message, Modal, R import { PageContainer } from '@ant-design/pro-layout'; import ProDescriptions from '@ant-design/pro-descriptions'; import styles from './index.less' -import { saveRules, querySubjectList, queryRulesView } from '../../service'; +import { saveRules, querySubjectList, queryRulesView, queryTempQuestionList } from '../../service'; import { queryCourseView } from '@/pages/course/option/service'; -import { queryQuestionList, queryQuestionById } from '@/pages/questionbank/service'; +import { queryQuestionList, queryQuestionById, queryQuestionType } from '@/pages/questionbank/service'; import { PlusOutlined, DownOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EyeInvisibleOutlined, EyeOutlined, EditOutlined } from '@ant-design/icons'; import ProList from '@ant-design/pro-list'; -import QuestionSelector from '../components/QuestionSelector'; +import QuestionSelector from '../../components/QuestionSelector'; +import { manualPaper, updatePaper } from '../service'; +/** + * 保存选题 + * + * @param values + */ +const handleAppend = async (rules_id: number, rows: any[]) => { + const hide = message.loading('正在添加'); + try { + const questions: { question_id: any; }[] = []; + rows?.forEach((item)=>{ + questions.push({question_id: item?.id}) + }) + const _data = await manualPaper({ + question_count: questions?.length || 0, + questions: JSON.stringify(questions), + rules_id: Number(rules_id) + }); + hide(); + message.success('添加成功'); + return _data; + } catch (error) { + hide(); + message.error('添加失败请重试!'); + return false; + } +}; + +/** + * 保存选题试卷 + * + * @param values + */ + const handleUpdatePaper = async ( rules_id: number, paper_uuid: number, paper_id: number) => { + const hide = message.loading('正在保存'); + try { + const _data = { + rules_id: Number(rules_id), + paper_uuid: paper_uuid, + paper_id: paper_id + } + if(paper_id === 0){ + delete _data.paper_id; + } + await updatePaper(_data); + hide(); + message.success('保存成功'); + return true; + } catch (error) { + hide(); + message.error('保存失败请重试!'); + return false; + } +}; const waitTime = (time: number = 100) => { return new Promise((resolve) => { @@ -31,25 +85,56 @@ const waitTime = (time: number = 100) => { }, time); }); }; -const numbers = []; -for (let i = 0; i < 50; i++) { - numbers.push({ id: `${i}` }) -} + export default () => { const [selectorModalVisible, handleSelectorModalVisible] = useState(false); + const [uuidPaper, setUuidPaper] = useState(0); const formRef = useRef(); + const childRef = useRef(); + + const params = useParams(); + + const [questionType, setQuestionType] = useState([]); // 题型 + /** 获取题型 */ + const { data: questionTypeData } = useRequest(() => { + return queryQuestionType(); + },{ + formatResult: (result) => { + return result.list; + } + }); + + useEffect(() => { + setQuestionType(questionTypeData || []); + return ()=>{ + /** 退出当前页面清空Map */ + //parsingMap.clear(); + } + }, [questionTypeData]); + + /** 组卷,查询试题临时表(当前选题列表) */ + const { data: questions, run } = useRequest(async () => { + return queryTempQuestionList(params); + },{ + manual: true, + formatResult: (result) => { + return result?.bean; + }}); + console.log(params, 'params'); + let ruleData = {} if (params?.id) { - console.log(JSON.stringify(params), "878"); - + //console.log(JSON.stringify(params), "878"); const { data } = useRequest(async () => { - const { bean } = await queryRulesView(params); - return { data: bean } - }); + return queryRulesView(params); + },{ + formatResult: (result) => { + return result?.bean; + }}); ruleData = data } console.log(ruleData, 'ruleData'); @@ -99,7 +184,7 @@ export default () => { b_use: 0, rules_type: 0, }); - + run({paper_uuid:1}); // 获取当前选题列表 // await waitTime(2000); return true; @@ -141,7 +226,8 @@ export default () => { label="关联主题" /> @@ -234,7 +320,12 @@ export default () => { - + @@ -274,7 +365,7 @@ export default () => { - + @@ -286,19 +377,29 @@ export default () => {
- { - handleSelectorModalVisible(false); - }} + onVisibleChange={handleSelectorModalVisible} footer={null} + onFinish={async (values) => { + + console.log('v::::', values.name); + const rows = childRef?.current?.getSelectedRows() + console.log('rows::::', rows); + const {code, data: paper, msg} = await handleAppend(Number(params?.id), rows) + console.log('paper', paper) + setUuidPaper(paper?.paper_uuid) + // message.success('提交成功'); + handleSelectorModalVisible(false) + return true; + }} > - - + +
); diff --git a/admin/src/pages/examinationrules/service.ts b/admin/src/pages/examinationrules/service.ts index d4f6bbb..60d3ce7 100644 --- a/admin/src/pages/examinationrules/service.ts +++ b/admin/src/pages/examinationrules/service.ts @@ -141,4 +141,52 @@ export async function removeRules(data: { key: number[] }, options?: Record, +) { + return request<{ + data: TableListItem[]; + /** 列表的内容总数 */ + total?: number; + success?: boolean; + }>('/dsideal_yy/zygh/training/rules/getTempQuestionList', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} + +/** 组卷详情查询 */ +export async function queryRulesPaper( + params: { + /** 当前的页码 */ + current?: number; + /** 页面的容量 */ + pageSize?: number; + }, + options?: Record, +) { + return request<{ + data: TableListItem[]; + /** 列表的内容总数 */ + total?: number; + success?: boolean; + }>('/dsideal_yy/zygh/training/rules/getRulesPaper', { + method: 'GET', + params: { + ...params, + }, + ...(options || {}), + }); +} diff --git a/admin/src/pages/questionbank/components/AnswersEditor.tsx b/admin/src/pages/questionbank/components/AnswersEditor.tsx index 73e7558..29f44cc 100644 --- a/admin/src/pages/questionbank/components/AnswersEditor.tsx +++ b/admin/src/pages/questionbank/components/AnswersEditor.tsx @@ -42,7 +42,7 @@ const AnswersSelector = () => { return ( { diff --git a/admin/src/pages/questionbank/index.tsx b/admin/src/pages/questionbank/index.tsx index 9f049bb..f836dc6 100644 --- a/admin/src/pages/questionbank/index.tsx +++ b/admin/src/pages/questionbank/index.tsx @@ -1,6 +1,6 @@ /** 资质考试 */ //import { AlignLeftOutlined, PlusOutlined } from '@ant-design/icons'; -import { Switch, Button, Card, Col, List, Menu, Progress, Row, Typography, Space, Divider, Radio, Checkbox, Tag, Dropdown, Upload, Modal, Form, Input } from 'antd'; +import { Switch, Button, Card, Col, List, Menu, Progress, Row, Typography, Space, Divider, Radio, Checkbox, Tag, Dropdown, Upload, Modal, Form, Input, message } from 'antd'; import { PageContainer } from '@ant-design/pro-layout'; //import { useRequest } from 'umi'; //import { queryFakeList } from './service'; @@ -11,7 +11,7 @@ import styles from './style.less'; import ProList from '@ant-design/pro-list'; import { ReactText, useEffect, useRef, useState } from 'react'; import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined, UserOutlined } from '@ant-design/icons'; -import { exportQuestionTemplate, queryQuestionById, queryQuestionList, queryQuestionType } from './service'; +import { exportQuestionTemplate, queryQuestionById, queryQuestionList, queryQuestionType, saveQuestion } from './service'; import { useParams, useRequest, history, useRouteMatch } from 'umi'; import { queryCourseListByTag, queryCourseView, queryTagList } from '@/pages/course/option/service'; import ProForm, { BetaSchemaForm, ProFormList, ProFormSelect, ProFormText } from '@ant-design/pro-form'; @@ -21,10 +21,31 @@ import ProFormRichEdit from '../course/subject/components/ProFormRichEdit'; import { TableListItem } from '../course/option/data'; import AnswersSelector from './components/AnswersEditor'; //const { Paragraph } = Typography; +const { Text, Link } = Typography; const labels = ['A','B','C','D','E','F','G','H','I','J','K']; const parsingMap = new Map() console.log('first'); + +/** + * 添加试题 + * + * @param fields + */ + const handleAdd = async (fields: TableListItem) => { + const hide = message.loading('正在添加'); + try { + await saveQuestion({ ...fields}); + hide(); + message.success('添加成功'); + return true; + } catch (error) { + hide(); + message.error('添加失败请重试!'); + return false; + } +}; + const QuestionBank = () => { const match = useRouteMatch(); console.log('match', match); @@ -60,13 +81,13 @@ const QuestionBank = () => { { title: '课程', valueType: 'select', - dataIndex: 'course_ids', + dataIndex: 'course_id', sorter: false, hideInTable: false, hideInForm: false, hideInSearch: true, fieldProps: { - mode: "multiple" + //mode: "multiple" }, formItemProps: { rules: [ @@ -158,7 +179,7 @@ const QuestionBank = () => { }, { title: '解析', - dataIndex: 'chapter_describe', + dataIndex: 'parsing', valueType: 'textarea', sorter: false, hideInTable: false, @@ -175,7 +196,7 @@ const QuestionBank = () => { renderText: (val: string) => (
), renderFormItem: (item, { defaultRender, ...rest }, form) => ( { parsingMap.clear(); } }, [data]); - + //saveQuestion return ( @@ -337,7 +358,7 @@ const QuestionBank = () => { metas={{ title: { dataIndex: 'question_stem', - render: (text: React.ReactNode, record: T, index: number) => `1. ${text}`, + render: (text: React.ReactNode, record: T, index: number) => (<>{record?.id} {text}), }, avatar: { dataIndex: 'question_type', @@ -491,10 +512,18 @@ const QuestionBank = () => { // 表单处理 console.log('columns:', columns); console.log('values:', values); - const success = await handleAddChapter({ + const opts = []; + values?.answers?.forEach((item)=>{ + opts.push({answer:item, is_true:0}) + }) + const success = await handleAdd({ ...values, - subject_id: params?.id || 0, + type: type, // 必填,0-常规题,1-资质考试题 + answers: JSON.stringify(opts), + question_type: addType.value, + // subject_id: params?.id || 0, }); + console.log('123') if(success){ handleCreateModalVisible(false); actionRef.current?.reloadAndRest?.();