From b4b3a2af4215258066664e2b37493eaca50b2e21 Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Thu, 17 Feb 2022 09:40:25 +0800 Subject: [PATCH] fix del bug --- admin/src/pages/examination/option/index.tsx | 8 +- admin/src/pages/examination/service.ts | 5 +- .../examinationrules/attestation/index.tsx | 18 +- .../pages/examinationrules/normal/index.tsx | 181 ++---------------- .../pages/examinationrules/normal/service.ts | 13 +- admin/src/pages/examinationrules/service.ts | 11 ++ 6 files changed, 54 insertions(+), 182 deletions(-) diff --git a/admin/src/pages/examination/option/index.tsx b/admin/src/pages/examination/option/index.tsx index 87b19ea..68d63cb 100644 --- a/admin/src/pages/examination/option/index.tsx +++ b/admin/src/pages/examination/option/index.tsx @@ -16,6 +16,7 @@ import UpdateForm from './components/UpdateForm'; import { querySubjectList, updateExamination, removeExamination, queryExaminationList, queryRulesList } from '../service'; import type { TableListItem, TableListPagination } from './data'; import type { DataItem } from '@antv/data-set/lib/transform/tag-cloud'; +import { ConsoleMessage } from 'puppeteer-core'; @@ -48,14 +49,15 @@ const handleUpdate = async (fields: FormValueType) => { * * @param selectedRows */ -const handleRemove = async (selectedRows: TableListItem[]) => { +const handleRemove = async (selectedRows: TableListItem[], currentRow) => { + console.log('selectedRows', selectedRows) const hide = message.loading('正在删除'); if (!selectedRows) return true; try { await removeExamination({ key: selectedRows.map((row) => row.key), - }); + },currentRow); hide(); message.success('删除成功,即将刷新'); return true; @@ -320,7 +322,7 @@ const ExaminationList: React.FC = () => { { - handleRemove([{ key: record?.examination_id }]); // 调用批量删除函数(如果接口不支持批量需要在service中处理) + handleRemove([{ key: record?.examination_id }], record); // 调用批量删除函数(如果接口不支持批量需要在service中处理) setSelectedRows([]); actionRef.current?.reloadAndRest?.(); }}> diff --git a/admin/src/pages/examination/service.ts b/admin/src/pages/examination/service.ts index e6577bf..a93e010 100644 --- a/admin/src/pages/examination/service.ts +++ b/admin/src/pages/examination/service.ts @@ -82,13 +82,12 @@ export async function updateExamination(data: Record, options?: Rec } /** 删除考试 */ -export async function removeExamination(data: { key: number[] }, options?: Record) { +export async function removeExamination(data: { key: number[]}, options?: Record) { console.log('data:::', data); return request>('/dsideal_yy/zygh/training/examination/delExamination', { - data: { examination_id: data?.key[0] }, // 当前接口不支持批量操作 + data: { examination_id: data?.key[0], rules_id: options?.rules_id}, // 当前接口不支持批量操作 method: 'POST', requestType: 'form', - ...(options || {}), }); } diff --git a/admin/src/pages/examinationrules/attestation/index.tsx b/admin/src/pages/examinationrules/attestation/index.tsx index 67a96b6..7b2b23c 100644 --- a/admin/src/pages/examinationrules/attestation/index.tsx +++ b/admin/src/pages/examinationrules/attestation/index.tsx @@ -10,7 +10,7 @@ import { BetaSchemaForm, ModalForm, ProFormText, ProFormTextArea } from '@ant-de import type { ProDescriptionsItemProps } from '@ant-design/pro-descriptions'; import ProDescriptions from '@ant-design/pro-descriptions'; import type { FormValueType } from './components/UpdateForm'; -import { querySubjectList, saveExamination, removeExamination, queryRulesList } from '../service'; +import { querySubjectList, saveExamination, removeExamination, queryRulesList, removeRules } from '../service'; import type { TableListItem, TableListPagination } from './data'; import type { DataItem } from '@antv/data-set/lib/transform/tag-cloud'; @@ -60,18 +60,18 @@ const handleUpdate = async (fields: FormValueType, currentRow?: TableListItem) = }; /** - * 删除考试 + * 删除考试规则 * * @param selectedRows */ -const handleRemove = async (selectedRows: TableListItem[]) => { + const handleRemove = async (selectedRows: TableListItem[], currentRow) => { const hide = message.loading('正在删除'); if (!selectedRows) return true; try { - await removeExamination({ + await removeRules({ key: selectedRows.map((row) => row.key), - }); + }, currentRow); hide(); message.success('删除成功,即将刷新'); return true; @@ -213,7 +213,13 @@ const ExaminationRules: React.FC = () => { > 编辑 , - + { + handleRemove([{ key: record?.id }], record); // 调用批量删除函数(如果接口不支持批量需要在service中处理) + setSelectedRows([]); + actionRef.current?.reloadAndRest?.(); + }}> 删除 , { - const hide = message.loading('正在添加'); - - try { - await saveExamination({ ...fields }); - hide(); - message.success('添加成功'); - return true; - } catch (error) { - hide(); - message.error('添加失败请重试!'); - return false; - } -}; - -/** - * 更新考试 - * - * @param fields - */ - -const handleUpdate = async (fields: FormValueType, currentRow?: TableListItem) => { - const hide = message.loading('正在配置'); - - try { - await saveExamination({ - ...currentRow, - ...fields, - }); - hide(); - message.success('操作成功'); - return true; - } catch (error) { - hide(); - message.error('操作失败请重试!'); - return false; - } -}; - -/** - * 删除考试 + * 删除考试规则 * * @param selectedRows */ -const handleRemove = async (selectedRows: TableListItem[]) => { +const handleRemove = async (selectedRows: TableListItem[], currentRow) => { const hide = message.loading('正在删除'); if (!selectedRows) return true; try { - await removeExamination({ + await removeRules({ key: selectedRows.map((row) => row.key), - }); + }, currentRow); hide(); message.success('删除成功,即将刷新'); return true; @@ -84,12 +39,7 @@ const handleRemove = async (selectedRows: TableListItem[]) => { }; const ExaminationRules: React.FC = () => { - /** 更新窗口的弹窗 */ - const [createModalVisible, handleCreateModalVisible] = useState(false); - const [detailModalVisible, handleDetailModalVisible] = useState(false); - const [updateModalVisible, handleUpdateModalVisible] = useState(false); //const [registrationModalVisible, handleRegistrationModalVisible] = useState(false); - const actionRef = useRef(); const [currentRow, setCurrentRow] = useState(); const [selectedRowsState, setSelectedRows] = useState([]); @@ -209,12 +159,17 @@ const ExaminationRules: React.FC = () => { key="update" onClick={() => { history.push('/examinationrules/normal/step/' + record.id) - }} > 编辑 , - + { + handleRemove([{ key: record?.id }], record); // 调用批量删除函数(如果接口不支持批量需要在service中处理) + setSelectedRows([]); + actionRef.current?.reloadAndRest?.(); + }}> 删除 , { )} - { - setCurrentRow(undefined); // 设置当前行 - handleDetailModalVisible(false); - }} - footer={null} - centered - >{console.log('currentRow', currentRow)} - {currentRow?.name && ( - - column={2} - /* title={currentRow?.name} */ - dataSource={currentRow} - /* - request={async () => ({ - data: currentRow || {}, - })}*/ - params={{ - id: currentRow?.examination_id, - }} - columns={ - columns - //columns.slice(0, columns.length - 1) as ProDescriptionsItemProps[] - } - /> - )} - - - { - handleCreateModalVisible(false); - }} - footer={null} - > - - layout="horizontal" - layoutType="Form" - labelCol={{ span: 8 }} - wrapperCol={{ span: 12 }} - onFinish={async (values: any) => { - // 表单处理 - console.log('columns:', columns); - console.log('values:', values); - - }} - submitter={{ - render: (props, doms) => ( - - - {doms} - - - ), - }} - // action = '' - title="新建" - columns={columns} - /> - - - { - handleUpdateModalVisible(false); - }} - footer={null} - > - {currentRow?.name && ( - - layout="horizontal" - layoutType="Form" - labelCol={{ span: 8 }} - wrapperCol={{ span: 12 }} - onFinish={async (values) => { - console.log('currentRow', currentRow) - //const url = values?.upload[0]?.url?.replace('/dsideal_yy/html/','') || values?.upload[0]?.response?.url; - //console.log('url', url) - await handleUpdate({ - ...values, - examination_id: currentRow?.examination_id, - }); - handleUpdateModalVisible(false); // 隐藏编辑窗口 - actionRef.current?.reloadAndRest?.(); - console.log(values); - }} - submitter={{ - render: (props, doms) => ( - - - {doms} - - - ), - }} - // action = '' - title="编辑" - columns={getInitialValues(columns, currentRow)} - /> - )} - - ); }; diff --git a/admin/src/pages/examinationrules/normal/service.ts b/admin/src/pages/examinationrules/normal/service.ts index c8c4457..6dcc064 100644 --- a/admin/src/pages/examinationrules/normal/service.ts +++ b/admin/src/pages/examinationrules/normal/service.ts @@ -28,7 +28,7 @@ export async function querySubjectList(params: { }); } - +/dsideal_yy/zygh/training/rules/delRules @@ -67,3 +67,14 @@ export async function updateFakeList( }, }); } + +/** 删除考试规则 */ +export async function removeRules(data: { key: number[] }, options?: Record) { + console.log('data:::', data); + return request>('/dsideal_yy/zygh/training/rules/delRules', { + data: { id: data?.key[0], rules_type: options?.rules_type, subject_id: options?.subject_id}, // 当前接口不支持批量操作 + method: 'POST', + requestType: 'form', + ...(options || {}), + }); +} \ No newline at end of file diff --git a/admin/src/pages/examinationrules/service.ts b/admin/src/pages/examinationrules/service.ts index b630720..d4f6bbb 100644 --- a/admin/src/pages/examinationrules/service.ts +++ b/admin/src/pages/examinationrules/service.ts @@ -130,4 +130,15 @@ export async function queryRegistrationList( }, ...(options || {}), }); +} + +/** 删除考试规则 */ +export async function removeRules(data: { key: number[] }, options?: Record) { + console.log('data:::', data); + return request>('/dsideal_yy/zygh/training/rules/delRules', { + data: { id: data?.key[0], rules_type: options?.rules_type, subject_id: options?.subject_id}, // 当前接口不支持批量操作 + method: 'POST', + requestType: 'form', + ...(options || {}), + }); } \ No newline at end of file