From 209fe92e5c92f4b99b2a6a19ef724e1ee5302679 Mon Sep 17 00:00:00 2001 From: xialiang <1818147@qq.com> Date: Fri, 18 Mar 2022 18:47:45 +0800 Subject: [PATCH] bug --- admin/src/pages/course/subject/step/index.tsx | 4 +- .../pages/examinationrules/normal/index.tsx | 22 +- admin/src/pages/questionbank/index.tsx | 320 +++++++++--------- 3 files changed, 181 insertions(+), 165 deletions(-) diff --git a/admin/src/pages/course/subject/step/index.tsx b/admin/src/pages/course/subject/step/index.tsx index ffbcdaf..73c8c62 100644 --- a/admin/src/pages/course/subject/step/index.tsx +++ b/admin/src/pages/course/subject/step/index.tsx @@ -397,7 +397,7 @@ export default () => { }}*/ onFinish={async (value: any) => { - console.log(subjectId, 'subjectId') + console.log(value, 'subjectId') const url = value?.upload[0]?.url?.replace('/dsideal_yy/html/', '') || value?.upload[0]?.response?.url; const info = await saveSubject({ @@ -435,7 +435,7 @@ export default () => { width="xl" // tooltip="最长为 6 位汉字,需要与考生身份证一致" placeholder="请输入介绍" - rules={[{ required: true }]} + // rules={[{ required: true }]} // value="锦书" // disabled diff --git a/admin/src/pages/examinationrules/normal/index.tsx b/admin/src/pages/examinationrules/normal/index.tsx index cd16686..a19e290 100644 --- a/admin/src/pages/examinationrules/normal/index.tsx +++ b/admin/src/pages/examinationrules/normal/index.tsx @@ -2,7 +2,7 @@ import React, { useState, useRef } from 'react'; import { useRequest, history } from 'umi'; import { PlusOutlined, TagsOutlined, UploadOutlined } from '@ant-design/icons'; -import { Button, message, Input, Drawer, Modal, Col, Row, Space, Upload, Typography } from 'antd'; +import { Button, message, Input, Drawer, Modal, Col, Row, Space, Upload, Typography, Popconfirm } from 'antd'; import { PageContainer, FooterToolbar } from '@ant-design/pro-layout'; import type { ProColumns, ActionType } from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table'; @@ -128,7 +128,7 @@ const ExaminationRules: React.FC = () => { sinfo.push({ label: Items.list[i].subject_name, value: Items.list[i].subject_id }) } console.log(sinfo, 'sinfo'); - const info = sinfo?.filter((item, idx, self)=>{ + const info = sinfo?.filter((item, idx, self) => { return item?.b_use === 1 }); return info; @@ -192,18 +192,22 @@ const ExaminationRules: React.FC = () => { > 编辑 , - , + + + + + + + , { diff --git a/admin/src/pages/questionbank/index.tsx b/admin/src/pages/questionbank/index.tsx index f918b9f..f3e15da 100644 --- a/admin/src/pages/questionbank/index.tsx +++ b/admin/src/pages/questionbank/index.tsx @@ -9,21 +9,22 @@ 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 type { ReactText } from 'react'; +import { useEffect, useRef, useState } from 'react'; import { PlusOutlined, DeleteOutlined, DownloadOutlined, UploadOutlined, EditOutlined, EyeOutlined, EyeInvisibleOutlined, DownOutlined, UserOutlined } from '@ant-design/icons'; import { exportQuestionTemplate, queryQuestionById, queryQuestionList, queryQuestionType, removeQuestion, saveQuestion } from './service'; import { useParams, useRequest, history, useRouteMatch } from 'umi'; import { queryCourseListByTag, queryCourseView, queryTagList } from '@/pages/course/option/service'; import ProForm, { BetaSchemaForm, ProFormCheckbox, ProFormList, ProFormRadio, ProFormSelect, ProFormText } from '@ant-design/pro-form'; -import { DataItem } from '../dashboard/analysis/data'; -import { ActionType, ProColumns } from '@ant-design/pro-table'; +import type { DataItem } from '../dashboard/analysis/data'; +import type { ActionType, ProColumns } from '@ant-design/pro-table'; import ProFormRichEdit from '../course/subject/components/ProFormRichEdit'; -import { TableListItem } from '../course/option/data'; +import type { 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 labels = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']; const parsingMap = new Map() console.log('first'); @@ -32,10 +33,10 @@ console.log('first'); * * @param fields */ - const handleAdd = async (fields: TableListItem) => { +const handleAdd = async (fields: TableListItem) => { const hide = message.loading('正在添加'); try { - await saveQuestion({ ...fields}); + await saveQuestion({ ...fields }); hide(); message.success('添加成功'); return true; @@ -51,10 +52,10 @@ console.log('first'); * * @param fields */ - const handleUpdate = async (fields: TableListItem) => { +const handleUpdate = async (fields: TableListItem) => { const hide = message.loading('正在保存'); try { - await saveQuestion({ ...fields}); + await saveQuestion({ ...fields }); hide(); message.success('保存成功'); return true; @@ -76,13 +77,13 @@ const handleRemove = async (selectedRows: TableListItem[]) => { if (!selectedRows) return true; try { - const {code, msg} = await removeQuestion({ + const { code, msg } = await removeQuestion({ key: selectedRows.map((row) => row.key), }); hide(); - if(code === 2000 ){ + if (code === 2000) { message.success('删除成功,即将刷新'); - }else{ + } else { message.warning(msg); } return true; @@ -97,26 +98,26 @@ const QuestionBank = () => { const match = useRouteMatch(); console.log('match', match); - const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0 ; // 题库类型 + const type = history.location.pathname === '/questionbank/attestation' ? 1 : 0; // 题库类型 const actionRef = useRef(); const formRef = useRef(); - + const [questionType, setQuestionType] = useState([]); - + const [parsing, setParsing] = useState(); - + const [createModalVisible, handleCreateModalVisible] = useState(false); const [updateModalVisible, handleUpdateModalVisible] = useState(false); - + const [selectedRowsState, setSelectedRows] = useState([]); const [currentRow, setCurrentRow] = useState(); const [expandedDescRowKeys, setExpandedDescRowKeys] = useState([]); // 展开解析设置 - const [addType, setAddType] = useState({name: '', value: ''}); - + const [addType, setAddType] = useState({ name: '', value: '' }); + const [pageNumber, setPageNumber] = useState(1) //const [answertrueValues, setAnswertrueValues] = useState(); // 编辑试题答案项值 //const [options, setOptions] = useState([]); // 设置当前选项, 用于删除选项时判断 - + /** 表单项定义 */ const columns: ProColumns[] = [ { @@ -176,8 +177,8 @@ const QuestionBank = () => { renderText: (val: string) => `${val}`, dependencies: ['tag_ids'], request: async (params) => { - const {tag_ids} = params; - const { data: Items } = await queryCourseListByTag({tag_ids: tag_ids?.toString()}); + const { tag_ids } = params; + const { data: Items } = await queryCourseListByTag({ tag_ids: tag_ids?.toString() }); console.log('queryCourseListByTag...') const courses = [] for (let i = 0; i < Items?.length; i++) { @@ -198,7 +199,7 @@ const QuestionBank = () => { fieldProps: { maxLength: 50 }, - formItemProps: { + formItemProps: { rules: [ { required: true, @@ -235,42 +236,42 @@ const QuestionBank = () => { hideInTable: false, hideInForm: false, hideInSearch: true, - dependencies:['answers'], + dependencies: ['answers'], renderFormItem: (item, { defaultRender, ...rest }, form) => { console.log('正确答案...', form.getFieldValue('answers')) // 关联长度变化及编辑回显 console.log('edit answertrue11', item) - console.log('form::::::',form.getFieldValue('answertrue')) + console.log('form::::::', form.getFieldValue('answertrue')) console.log('rest', rest) console.log('question_type:::', form.getFieldValue('question_type')) // 获取选项长度 const len = form.getFieldValue('answers')?.length || 2; const opts = [] - for(let i=0; i - : - + return ((addType?.value === 0 || addType?.value === 2) || (Number(form.getFieldValue('question_type')) === 0) || Number(form.getFieldValue('question_type')) === 2) ? + + : + }, formItemProps: { @@ -295,43 +296,52 @@ const QuestionBank = () => { { required: true, message: '请填写试题解析', - }, + }, { + validator: (rule, value) => { + console.log("表单:", value, value.replace(/(^\s*)|(\s*$)/g, ""), "|") + if (value.replace(/(^\s*)|(\s*$)/g, "") === "") { + return Promise.reject('请填写试题解析') + } else { + return Promise.resolve() + } + } + } ] }, - renderText: (val: string) => (
), - renderFormItem: (item, { defaultRender, ...rest }, form) => ( - - ), + renderText: (val: string) => (
), + // renderFormItem: (item, { defaultRender, ...rest }, form) => ( + // + // ), }, - + ] /** 获取题型 */ const { data } = useRequest(() => { return queryQuestionType(); - },{ + }, { formatResult: (result) => { return result.list; } }); -/* - const { data: template } = useRequest(() => { - return exportQuestionTemplate(); - }); - */ + /* + const { data: template } = useRequest(() => { + return exportQuestionTemplate(); + }); + */ useEffect(() => { setQuestionType(data || []); - return ()=>{ + return () => { /** 退出当前页面清空Map */ parsingMap.clear(); } @@ -340,7 +350,7 @@ const QuestionBank = () => { return ( - style={{minWidth:1180}} + style={{ minWidth: 1180 }} rowKey='id' itemLayout="vertical" actionRef={actionRef} @@ -356,34 +366,34 @@ const QuestionBank = () => { toolBarRender={() => { const menuItems = []; console.log('toolBarRender', questionType); - if(questionType?.length > 0){ + if (questionType?.length > 0) { console.log('push'); - questionType.forEach((item: {code: number, name: string})=>{ + questionType.forEach((item: { code: number, name: string }) => { menuItems.push({item?.name}) }) } - const menu = ( - { + const menu = ( + { console.log('menu11', value); console.log('menu11', value.key); - console.log('menuquestionType', ); - setAddType({ name: questionType[Number(value?.key)]?.name, value: Number(value?.key)}); + console.log('menuquestionType',); + setAddType({ name: questionType[Number(value?.key)]?.name, value: Number(value?.key) }); handleCreateModalVisible(true); - }}> + }}> {menuItems} - + ); return [ , - , - , { type: type, } } - onChange={({file, fileList, event })=>{ + onChange={({ file, fileList, event }) => { console.log('file status', file?.status) - console.log('file event',event) - if(file?.status === 'done' && file?.response?.success === true){ - message.success(file?.response?.info); + console.log('file event', event) + if (file?.status === 'done' && file?.response?.success === true) { + message.success(file?.response?.info); actionRef.current?.reload(); // 上传完成刷新 } - if(file?.status === 'done' && file?.response?.success === false){ - message.error( file?.response?.error_list?.toString() ); + if (file?.status === 'done' && file?.response?.success === false) { + message.error(file?.response?.error_list?.toString()); //actionRef.current?.reload(); // 上传完成刷新 } - if(file?.status === 'error'){ + if (file?.status === 'error') { message.error('批量上传失败'); } }} @@ -463,13 +473,13 @@ const QuestionBank = () => { page_size: value?.pageSize, }); // 课程名称及课程标签 - console.log('data',questions); + console.log('data', questions); const data = [] - for(let i=0; i { title: '题干', search: false, dataIndex: 'question_stem', - render: (text: React.ReactNode, record: T, index: number) => ({record?.id} {text}), + render: (text: React.ReactNode, record: T, index: number) => ({record?.id} {text}), }, avatar: { title: '题型', @@ -504,15 +514,15 @@ const QuestionBank = () => { dataIndex: 'question_type', valueType: 'text', render: (text: React.ReactNode, record: T, index: number) => { - const type = questionType?.filter((item, idx, self)=>{ + const type = questionType?.filter((item, idx, self) => { console.log('FFFF', item, idx, self); return item?.code === record.question_type }); console.log('type', type?.name); console.log('type', type?.name); - console.log('questionType::::',questionType); - return `${(pageNumber - 1) * actionRef.current?.pageInfo?.pageSize + index +1}. [${type[0]?.name}]` + console.log('questionType::::', questionType); + return `${(pageNumber - 1) * actionRef.current?.pageInfo?.pageSize + index + 1}. [${type[0]?.name}]` }, }, description: { @@ -528,51 +538,51 @@ const QuestionBank = () => { bordered={false} dataSource={record.answers || []} rowKey='id' - renderItem={ (item, key) => { + renderItem={(item, key) => { console.log('item', item); return ( - {`${(record?.question_type === 2) ? ['A','B'][key] : labels[key]}. ${item?.answer}`} + {`${(record?.question_type === 2) ? ['A', 'B'][key] : labels[key]}. ${item?.answer}`} ) }} /> ); }, }, - subTitle: { + subTitle: { search: false }, - content: { + content: { search: false, render: (text: React.ReactNode, record: T, index: number) => { let answer = ''; const answertrue = record?.answertrue?.split(','); console.log('answertrue', answertrue) /** 题型 */ - switch(record?.question_type){ + switch (record?.question_type) { case 0: // 单选 case 1: // 多选 - answer = labels?.filter((x, idx, self)=>`${answertrue[idx]}` === `1`).toString() + answer = labels?.filter((x, idx, self) => `${answertrue[idx]}` === `1`).toString() break; case 2: // 判断 - answer = ['A', 'B']?.filter((x, idx, self)=>`${answertrue[idx]}` === `1`).toString() + answer = ['A', 'B']?.filter((x, idx, self) => `${answertrue[idx]}` === `1`).toString() break; - } + } console.log('expandedDescRowKeys', expandedDescRowKeys) - if(expandedDescRowKeys?.indexOf(record.id) > -1){ + if (expandedDescRowKeys?.indexOf(record.id) > -1) { return ( - + 正确答案: - {answer} + {answer} - 【解析】:
+ 【解析】:
); - }else{ + } else { return ( - + 正确答案: - {answer} + {answer} ) @@ -585,24 +595,24 @@ const QuestionBank = () => { cardActionProps: 'extra', render: (text: React.ReactNode, record: T, _index: number) => { let eye - if(expandedDescRowKeys?.indexOf(record.id) > -1){ + if (expandedDescRowKeys?.indexOf(record.id) > -1) { eye = <> 隐藏解析 - }else{ + } else { eye = <> 查看解析 } - return( - - + return ( + + 创建时间:{record?.create_time} 标签:{record?.tag_name} 课程:{record?.course_name} - + - { - console.log('record',record) + { + console.log('record', record) setCurrentRow(record); handleUpdateModalVisible(true) return false; @@ -626,35 +636,35 @@ const QuestionBank = () => { { - if(expandedDescRowKeys?.indexOf(record.id) > -1){ - const descRowKeys = expandedDescRowKeys?.filter((item, idx, self)=>{ + onClick={async () => { + if (expandedDescRowKeys?.indexOf(record.id) > -1) { + const descRowKeys = expandedDescRowKeys?.filter((item, idx, self) => { console.log('FFFF', item, idx, self); return item !== record.id }); setExpandedDescRowKeys([...descRowKeys]); - }else{ - const { bean } = await queryQuestionById({id: record.id}) + } else { + const { bean } = await queryQuestionById({ id: record.id }) parsingMap.set(bean.id, bean.parsing) setParsing(parsingMap); console.log('parsing', parsing); setExpandedDescRowKeys([...expandedDescRowKeys, record.id]); } - + console.log('record id:', record.id); console.log('expandedDescRowKeys......', expandedDescRowKeys) - }} + }} > {eye} - + ) } }, /** 搜索定义 */ - question_type:{ + question_type: { title: '题型', valueType: 'select', search: true, @@ -670,7 +680,7 @@ const QuestionBank = () => { return types; }, }, - tags: { + tags: { title: '标签', search: true, valueType: 'select', @@ -699,8 +709,8 @@ const QuestionBank = () => { }, dependencies: ['tag_ids'], request: async (params) => { - const {tag_ids} = params; - const { data: Items } = await queryCourseListByTag({tag_ids: tag_ids?.toString()}); + const { tag_ids } = params; + const { data: Items } = await queryCourseListByTag({ tag_ids: tag_ids?.toString() }); console.log('queryCourseListByTag...') const courses = [] for (let i = 0; i < Items?.length; i++) { @@ -716,7 +726,7 @@ const QuestionBank = () => { dataIndex: 'question_stem', valueType: 'text', fieldProps: { - placeholder:'请输入关键字' + placeholder: '请输入关键字' }, }, create_time: { @@ -725,19 +735,19 @@ const QuestionBank = () => { dataIndex: 'create_time', valueType: 'dateRange', fieldProps: { - placeholder:['开始时间','结束时间'] - }, + placeholder: ['开始时间', '结束时间'] + }, }, }} /> { - setAddType({name: '', value: ''}); // 还原题型选择 + setAddType({ name: '', value: '' }); // 还原题型选择 handleCreateModalVisible(false); }} footer={null} @@ -748,7 +758,7 @@ const QuestionBank = () => { layoutType="Form" labelCol={{ span: 8 }} wrapperCol={{ span: 12 }} - onValuesChange={()=>{ + onValuesChange={() => { //console.log('formRef', formRef.current.getFieldInstance('answertrue')) //console.log('formRef.current', formRef.current.getFieldsValue(['answertrue'])) //console.log('v', value) @@ -756,11 +766,11 @@ const QuestionBank = () => { const answerTrue = formRef?.current?.getFieldValue('answertrue'); let fixed_answertrue; // 如果正确答案为字符串(单选 / 判断) - if(typeof answerTrue === 'string'){ + if (typeof answerTrue === 'string') { console.log('string.....') fixed_answertrue = labels.indexOf(answerTrue) < (formRef?.current?.getFieldValue('answers')?.length || 0) ? answerTrue : undefined; - }else if(answerTrue?.length > 0){ - fixed_answertrue = answerTrue?.filter((item, key)=>{ + } else if (answerTrue?.length > 0) { + fixed_answertrue = answerTrue?.filter((item, key) => { return labels.indexOf(item) < (formRef?.current?.getFieldValue('answers')?.length || 0) }) } @@ -768,19 +778,21 @@ const QuestionBank = () => { /* const */ //console.log('fixed', fixed_answertrue) - formRef?.current?.setFieldsValue({answertrue: fixed_answertrue}) + formRef?.current?.setFieldsValue({ answertrue: fixed_answertrue }) }} onFinish={async (values: any) => { //console.log('formRef.current', formRef.current.getFieldsValue(['answertrue'])) - + console.log(values); + return + // 表单处理 console.log('columns:', columns); - console.log('values:', values); + console.log('values:', values); const opts = []; - values?.answers?.forEach((item, key)=>{ + values?.answers?.forEach((item, key) => { // const isTrue = (values?.answertrue.toString().indexOf(labels[key]) !== -1) ? 1 : 0; // 判断是否为正确答案 - opts.push({answer:item, is_true:isTrue}) + opts.push({ answer: item, is_true: isTrue }) }) const success = await handleAdd({ ...values, @@ -790,7 +802,7 @@ const QuestionBank = () => { // subject_id: params?.id || 0, }); console.log('123') - if(success){ + if (success) { handleCreateModalVisible(false); actionRef.current?.reload(); } @@ -810,13 +822,13 @@ const QuestionBank = () => { /> { - setAddType({name: '', value: ''}); // 还原题型选择 + setAddType({ name: '', value: '' }); // 还原题型选择 handleUpdateModalVisible(false); }} footer={null} @@ -826,29 +838,29 @@ const QuestionBank = () => { layoutType="Form" labelCol={{ span: 8 }} wrapperCol={{ span: 12 }} - request={()=>{ + request={() => { // 编辑数据初始化 - console.log('currentRow##',currentRow) + console.log('currentRow##', currentRow) //answers:currentRow?.answers.map((item)=>(item.answer)) const answertrue = currentRow?.answertrue?.split(','); - console.log('answertrue,,,',answertrue) - const answerTrueData = labels?.filter((x, idx, self)=>(`${answertrue[idx]}` === '1')) + console.log('answertrue,,,', answertrue) + const answerTrueData = labels?.filter((x, idx, self) => (`${answertrue[idx]}` === '1')) console.log('$$$', answerTrueData) const trueData = Number(currentRow?.question_type) === 1 ? answerTrueData : answerTrueData[0] // 处理单选和判断 const tag_ids = currentRow?.tag_ids.split(',') - return {...currentRow, answers: currentRow?.answers.map((item)=>(item.answer)), answertrue: trueData, tag_ids: tag_ids.map(item=>Number(item)) } + return { ...currentRow, answers: currentRow?.answers.map((item) => (item.answer)), answertrue: trueData, tag_ids: tag_ids.map(item => Number(item)) } }} onFinish={async (values: any) => { // 表单处理 - console.log('columns:', columns); + console.log('columns:', columns); console.log('values:', values); const opts = []; - 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}) // 循环选项 + 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 handleUpdate({ ...currentRow, ...values, @@ -858,7 +870,7 @@ const QuestionBank = () => { //question_type: currentRow?.question_type, // 题型 // subject_id: params?.id || 0, }); - if(success){ + if (success) { handleUpdateModalVisible(false); actionRef.current?.reloadAndRest?.(); }