|
|
|
@ -4,11 +4,11 @@
|
|
|
|
|
* @Github:
|
|
|
|
|
* @Date: 2019-11-21 09:19:38
|
|
|
|
|
* @LastEditors: tangjiang
|
|
|
|
|
* @LastEditTime: 2019-12-19 17:54:28
|
|
|
|
|
* @LastEditTime: 2019-12-20 09:23:07
|
|
|
|
|
*/
|
|
|
|
|
import './index.scss';
|
|
|
|
|
import React, { useState } from 'react';
|
|
|
|
|
import { Collapse, Icon, Input, Form, Button } from 'antd';
|
|
|
|
|
import { Collapse, Icon, Input, Form } from 'antd';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import actions from '../../../../../redux/actions';
|
|
|
|
|
import { CNotificationHOC} from 'educoder';
|
|
|
|
@ -18,14 +18,14 @@ const FormItem = Form.Item;
|
|
|
|
|
const AddTestDemo = (props) => {
|
|
|
|
|
const {
|
|
|
|
|
key,
|
|
|
|
|
onSubmitTest,
|
|
|
|
|
// onSubmitTest,
|
|
|
|
|
onDeleteTest,
|
|
|
|
|
testCase,
|
|
|
|
|
testCaseValidate,
|
|
|
|
|
isOpen
|
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
|
|
const [isEditor, setIsEditor] = useState(false); // 是否是编辑
|
|
|
|
|
// const [isEditor, setIsEditor] = useState(false); // 是否是编辑
|
|
|
|
|
|
|
|
|
|
// 删除操作
|
|
|
|
|
const handleDeletePanel = (e) => {
|
|
|
|
@ -73,54 +73,54 @@ const AddTestDemo = (props) => {
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// 取消操作
|
|
|
|
|
const handleReset = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
props.form.resetFields();
|
|
|
|
|
}
|
|
|
|
|
// const handleReset = (e) => {
|
|
|
|
|
// e.preventDefault();
|
|
|
|
|
// props.form.resetFields();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 保存
|
|
|
|
|
const handleSubmit = (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
props.form.validateFields((err, values) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log('提交表单: ', values);
|
|
|
|
|
onSubmitTest(values);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// const handleSubmit = (e) => {
|
|
|
|
|
// e.preventDefault();
|
|
|
|
|
// props.form.validateFields((err, values) => {
|
|
|
|
|
// if (err) {
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
// console.log('提交表单: ', values);
|
|
|
|
|
// onSubmitTest(values);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
|
|
|
|
// 编辑后保存
|
|
|
|
|
const handleEditorOrSave = (e) => {
|
|
|
|
|
if (!isEditor) {
|
|
|
|
|
setIsEditor(true);
|
|
|
|
|
} else {
|
|
|
|
|
// TODO 调用修改测试用例接口
|
|
|
|
|
setIsEditor(false); // 保存后 设置 false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// const handleEditorOrSave = (e) => {
|
|
|
|
|
// if (!isEditor) {
|
|
|
|
|
// setIsEditor(true);
|
|
|
|
|
// } else {
|
|
|
|
|
// // TODO 调用修改测试用例接口
|
|
|
|
|
// setIsEditor(false); // 保存后 设置 false
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// 渲染提交按钮
|
|
|
|
|
const renderSubmitBtn = () => {
|
|
|
|
|
const { identifier, testCase, loading } = props;
|
|
|
|
|
// console.log('========', identifier);
|
|
|
|
|
// 1. 新增时,不显示按钮
|
|
|
|
|
if (identifier) {
|
|
|
|
|
if (testCase.isAdd) {
|
|
|
|
|
return (
|
|
|
|
|
<FormItem style={{ textAlign: 'right' }}>
|
|
|
|
|
<Button style={{ marginRight: '20px' }} onClick={handleReset}>取消</Button>
|
|
|
|
|
<Button type="primary" onClick={handleSubmit}>保存</Button>
|
|
|
|
|
</FormItem>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<FormItem style={{ textAlign: 'right' }}>
|
|
|
|
|
<Button onClick={handleEditorOrSave} loading={loading}>{isEditor ? '保存' : (loading ? '保存' : '编辑')}</Button>
|
|
|
|
|
</FormItem>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// const renderSubmitBtn = () => {
|
|
|
|
|
// const { identifier, testCase, loading } = props;
|
|
|
|
|
// // console.log('========', identifier);
|
|
|
|
|
// // 1. 新增时,不显示按钮
|
|
|
|
|
// if (identifier) {
|
|
|
|
|
// if (testCase.isAdd) {
|
|
|
|
|
// return (
|
|
|
|
|
// <FormItem style={{ textAlign: 'right' }}>
|
|
|
|
|
// <Button style={{ marginRight: '20px' }} onClick={handleReset}>取消</Button>
|
|
|
|
|
// <Button type="primary" onClick={handleSubmit}>保存</Button>
|
|
|
|
|
// </FormItem>
|
|
|
|
|
// );
|
|
|
|
|
// } else {
|
|
|
|
|
// return (
|
|
|
|
|
// <FormItem style={{ textAlign: 'right' }}>
|
|
|
|
|
// <Button onClick={handleEditorOrSave} loading={loading}>{isEditor ? '保存' : (loading ? '保存' : '编辑')}</Button>
|
|
|
|
|
// </FormItem>
|
|
|
|
|
// );
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 文本输入框可编辑的情况
|
|
|
|
@ -128,9 +128,9 @@ const AddTestDemo = (props) => {
|
|
|
|
|
* 2. isAdd 为 false 且 isEditor 为true 时
|
|
|
|
|
* @param {*} testCase
|
|
|
|
|
*/
|
|
|
|
|
const isDisabled = (testCase) => {
|
|
|
|
|
return !testCase.isAdd && !isEditor;
|
|
|
|
|
};
|
|
|
|
|
// const isDisabled = (testCase) => {
|
|
|
|
|
// return !testCase.isAdd && !isEditor;
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
// const {input = {}, output = {}} = (testCasesValidate[index] = {});
|
|
|
|
|
const activePane = {
|
|
|
|
@ -158,7 +158,8 @@ const AddTestDemo = (props) => {
|
|
|
|
|
rows={5}
|
|
|
|
|
value={testCase.input}
|
|
|
|
|
onChange={handleInputChange}
|
|
|
|
|
disabled={isDisabled(testCase)}/>
|
|
|
|
|
// disabled={isDisabled(testCase)}
|
|
|
|
|
/>
|
|
|
|
|
</FormItem>
|
|
|
|
|
<FormItem
|
|
|
|
|
label={<span className={'label_text'}>输出</span>}
|
|
|
|
@ -170,9 +171,10 @@ const AddTestDemo = (props) => {
|
|
|
|
|
rows={5}
|
|
|
|
|
value={testCase.output}
|
|
|
|
|
onChange={handleOutputChange}
|
|
|
|
|
disabled={isDisabled(testCase)}/>
|
|
|
|
|
// disabled={isDisabled(testCase)}
|
|
|
|
|
/>
|
|
|
|
|
</FormItem>
|
|
|
|
|
{renderSubmitBtn()}
|
|
|
|
|
{/* {renderSubmitBtn()} */}
|
|
|
|
|
</Form>
|
|
|
|
|
</Panel>
|
|
|
|
|
</Collapse>
|
|
|
|
|