From b50b6f206e1d77243d8f58df84db87d8ba462f8b Mon Sep 17 00:00:00 2001 From: zhengpengju Date: Mon, 7 Mar 2022 09:47:56 +0800 Subject: [PATCH] fix bug --- admin/src/pages/questionbank/index.tsx | 37 ++++++++++++++++++----- admin/src/pages/training/option/index.tsx | 8 ++--- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/admin/src/pages/questionbank/index.tsx b/admin/src/pages/questionbank/index.tsx index 2e2b2e1..d36c96c 100644 --- a/admin/src/pages/questionbank/index.tsx +++ b/admin/src/pages/questionbank/index.tsx @@ -46,6 +46,25 @@ console.log('first'); } }; +/** + * 编辑试题 + * + * @param fields + */ + const handleUpdate = async (fields: TableListItem) => { + const hide = message.loading('正在保存'); + try { + await saveQuestion({ ...fields}); + hide(); + message.success('保存成功'); + return true; + } catch (error) { + hide(); + message.error('保存失败请重试!'); + return false; + } +}; + /** * 删除试题 * @@ -642,22 +661,26 @@ const QuestionBank = () => { }} onFinish={async (values: any) => { // 表单处理 - console.log('columns:', columns); + console.log('columns:', columns); console.log('values:', values); const opts = []; - values?.answers?.forEach((item)=>{ - opts.push({answer:item, is_true:0}) + values?.answers?.forEach((item,key)=>{ + const is_true = values?.answertrue.indexOf(labels[key]) >-1 ? 1 : 0; + opts.push({answer:item, is_true: is_true||0}) // 循环选项 + }) - const success = await handleAdd({ + + const success = await handleUpdate({ + ...currentRow, ...values, type: type, // 必填,0-常规题,1-资质考试题 answers: JSON.stringify(opts), - question_type: addType.value, + //question_type: currentRow?.question_type, // 题型 // subject_id: params?.id || 0, }); - console.log('123') + console.log('123', success) if(success){ - handleCreateModalVisible(false); + handleUpdateModalVisible(false); actionRef.current?.reloadAndRest?.(); } }} diff --git a/admin/src/pages/training/option/index.tsx b/admin/src/pages/training/option/index.tsx index 91986e6..2d38a84 100644 --- a/admin/src/pages/training/option/index.tsx +++ b/admin/src/pages/training/option/index.tsx @@ -218,12 +218,12 @@ const TableList: React.FC = () => { }, request: async () => { const { data: Items } = await querySubjectList(); - // console.log(Items, ')))'); + console.log('Items:::', 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 }) + for (let i = 0; i < Items.length; i++) { + console.log(Items[i], ">>>") + sinfo.push({ label: Items[i].subject_name, value: Items[i].subject_id }) } console.log(sinfo, 'sinfo');