From 5b92f8a8c2b06c125d92174260ce6a068bec2ec8 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Tue, 22 Mar 2022 14:48:35 +0800 Subject: [PATCH] fix --- .../components/QuestionSelector.tsx | 34 +++++++++++++++---- .../examinationrules/normal/step/index.tsx | 6 ++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/admin/src/pages/examinationrules/components/QuestionSelector.tsx b/admin/src/pages/examinationrules/components/QuestionSelector.tsx index fc77826..2ec96b8 100644 --- a/admin/src/pages/examinationrules/components/QuestionSelector.tsx +++ b/admin/src/pages/examinationrules/components/QuestionSelector.tsx @@ -9,7 +9,7 @@ import { Button, message } from 'antd'; //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 { forwardRef, Key, 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 { queryCourseListByTag, queryCourseView, queryTagList } from '@/pages/course/option/service'; @@ -17,6 +17,8 @@ import { queryQuestionList, queryQuestionType } from '@/pages/questionbank/servi //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 { FooterToolbar } from '@ant-design/pro-layout'; +import { constant } from 'lodash'; export type TableListItem = { id: string; @@ -120,10 +122,12 @@ const QuestionSelector = (props: any, ref: any) => { 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 [selectedRowsState, setSelectedRows] = useState([]); + const [selectedRowKeys, setSelectedRowKeys] = useState([]); + + //const [addType, setAddType] = useState({name: '', value: 0}); - const labels = ['A','B','C','D','E','F','G','H','I'] + //const labels = ['A','B','C','D','E','F','G','H','I'] /** 获取题型 */ const { data } = useRequest(() => { @@ -143,6 +147,9 @@ const QuestionSelector = (props: any, ref: any) => { // 暴露组件的方法 接受外部获取的ref useImperativeHandle(ref, () => ({ // 构造ref的获取数据方法 + getSelectedRowKeys: () => { + return selectedRowKeys; + }, getSelectedRows: () => { return selectedRowsState; }, @@ -151,6 +158,7 @@ const QuestionSelector = (props: any, ref: any) => { return ( <> + { page_number: value?.current || 1, page_size: value?.pageSize, }); - // 课程名称及课程标签 + // const data = [] for(let i=0; i { }; }} rowSelection={{ - onChange: (_, selectedRows) => { - setSelectedRows(selectedRows); + selectedRowKeys: selectedRowKeys, + onChange: (selectedKeys, _) => { + const res = selectedRowsState?.filter(item=>(item.page === actionRef.current?.pageInfo?.current)).length + let rows = []; + rows = selectedRowsState?.map(item=>(item?.page === actionRef.current?.pageInfo?.current ? {page: actionRef.current?.pageInfo?.current, selected: selectedKeys} : item)) + if(res === 0){ + rows.push({page: actionRef.current?.pageInfo?.current, selected: selectedKeys}) + } + const _data: any = [] + rows?.forEach((item)=>{ + _data.push(...item?.selected) + }) + setSelectedRowKeys(_data) + setSelectedRows(rows); // selectedRowsState }, }} columns={columns} diff --git a/admin/src/pages/examinationrules/normal/step/index.tsx b/admin/src/pages/examinationrules/normal/step/index.tsx index a2cb01c..0fe1992 100644 --- a/admin/src/pages/examinationrules/normal/step/index.tsx +++ b/admin/src/pages/examinationrules/normal/step/index.tsx @@ -34,8 +34,8 @@ 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 }) + rows?.forEach((key) => { + questions.push({ question_id: key }) }) const _data = await manualPaper({ question_count: questions?.length || 0, @@ -655,7 +655,7 @@ export default () => { onVisibleChange={handleSelectorModalVisible} onFinish={async (values) => { console.log('v::::', values.name); - const rows = selectorRef?.current?.getSelectedRows() + const rows = selectorRef?.current?.getSelectedRowKeys() console.log('rows::::', rows); const { code, data: paper, msg } = await handleAppend(Number(params?.id || rulesId), rows) console.log('paper', paper)