import React, { useEffect, useRef, useState } from 'react';
import { Form, Row, Col, Card, Modal, Input, Select, Upload, Button, message, Tag, Badge } from 'antd';
import { connect } from 'umi';
import styles from './index.less';
import {
ForkOutlined,
PlusOutlined,
ExclamationCircleFilled,
UploadOutlined,
EditOutlined,
EyeOutlined,
} from '@ant-design/icons';
import * as echarts from 'echarts';
import { recurrent, severity, bug_categories } from './const';
import { timeToString,getBase64 } from '../../utils';
import BugGuideTree from '../BugGuideTree';
import { instanceOf } from 'prop-types';
const formItemLayout = {
labelCol: {
span: 8,
},
wrapperCol: {
span: 19,
},
};
const modalFormItemLayout = {
labelCol: {
span: 5,
},
wrapperCol: {
span: 19,
},
};
const uploadButton = (
);
const Step2 = (props) => {
const [reportForm] = Form.useForm();
const [addCaseForm] = Form.useForm();
const [addBugForm] = Form.useForm();
const [editReportForm] = Form.useForm();
const {
dispatch, reportCommonInfo, osType,
testCaseList, caseBugList, categories, pathInfo,
} = props;
const [showTaskRecommendModal, setTaskRecommendModal] = useState(false);
const [showAddTestCaseModal, setAddTestCaseModal] = useState(false);
const [showAddBugModal, setAddTestBugModal] = useState(false);
const [showEditReportModal, setEditReportModal] = useState(false);
const currentTestCaseRef = useRef({});
const [isAddCaseStatus, setIsAddCaseStatus] = useState(true);
// const [currActiveTestCase, setCurrActiveTestCase] = useState({});
//上传图片廊需要的字段
const [fileList,setFileList] = useState([]);
const [previewTitle,setPreviewTitle] = useState('');
const [previewImage,setPreviewImage] = useState('');
const [previewVisible,setPreviewVisible] = useState(false);
const [page2List, setPage2List] = useState([]);
const [page3List, setPage3List] = useState([]);
const handleEditReportInfo = () => {
editReportForm.validateFields().then((res)=> {
let formData = new FormData();
formData.append('name', res.name);
formData.append('report_id', reportCommonInfo.id);
formData.append('worker_id', '2');
formData.append('case_take_id', '1718-1718');
formData.append('device_model', res.device_model);
formData.append('device_brand', res.device_brand);
formData.append('device_os', res.device_os);
dispatch({
type: 'editReport/updateReportCommonDetail',
payload: { formData }
})
})
setEditReportModal(false)
};
const handleAddOrEditTestCase = () => {
addCaseForm.validateFields().then((res) => {
let formData = new FormData();
// formData.append("id", values.reportName);
formData.append('report_id', reportCommonInfo.id);
formData.append('name', res.name);
formData.append('front', res.front);
formData.append('behind', res.behind);
formData.append('description', res.description);
if (!isAddCaseStatus) {
//处理编辑用例
formData.append('id', currentTestCaseRef.current.id);
dispatch({
type: 'editReport/updateTestCase',
payload: {
formData,
report_id: reportCommonInfo.id,
},
}).then((res) => {
if (res && res.status === 200) {
message.success('修改成功!');
}
});
} else {
//处理添加用例
dispatch({
type: 'editReport/createTestCase',
payload: {
formData,
report_id: reportCommonInfo.id,
},
}).then((res) => {
if (res && res.id) {
message.success('添加成功!');
}
});
}
setAddTestCaseModal(false);
});
};
const handleAddBug = () => {
addBugForm.validateFields().then((res) => {
let formData = new FormData();
formData.append('report_id', reportCommonInfo.id);
formData.append('title', res.title);
formData.append('description', res.description);
formData.append('bug_category', res.bug_category);
formData.append('severity', res.severity);
formData.append('recurrent', res.recurrent);
formData.append('parent', null);
formData.append('useCase', currentTestCaseRef.current.id);
formData.append('case_id', '1718');
formData.append('case_take_id', '1718-1718');
formData.append('worker_id', '2');
formData.append('page', `${res.page1}-${res.page2}-${res.page3}`);
if(fileList.length){
let str = '';
fileList.map(item=>{
str += (item.response + ',')
})
str = str.substring(0,str.length-1);
formData.append('img_url', str);
}
//新建bug
dispatch({
type: 'editReport/createCaseBug',
payload: {
formData,
useCase: currentTestCaseRef.current.id,
},
}).then(res => {
setAddTestBugModal(false);
});
});
};
const handleClickTestCase = (caseItem) => {
// setCurrActiveTestCase(caseItem);
currentTestCaseRef.current = caseItem;
dispatch({
type: 'editReport/getCaseBugList',
payload: caseItem.id,
});
};
const handleEditTestCase = (item) => {
setIsAddCaseStatus(false);
currentTestCaseRef.current = item;
addCaseForm.setFieldsValue(currentTestCaseRef.current);
setAddTestCaseModal(true);
};
const handleClickAddCase = () => {
addCaseForm.resetFields();
setAddTestCaseModal(true);
};
const handleClickAddBug = () => {
//current目前只在点击edit cease的时候会有用
addBugForm.resetFields();
setAddTestBugModal(true);
};
const handleClickRecommendBtn = () => {
dispatch({
type: 'editReport/getPathInfo',
payload: {
case_take_id: '1718-1718',
report_id: reportCommonInfo.id,
},
});
dispatch({
type: 'editReport/getBugRecommendPath',
payload: {
case_take_id: '1718-1718',
report_id: reportCommonInfo.id,
},
});
dispatch({
type: 'editReport/getBugRecommendList',
payload: {
case_take_id: '1718-1718',
report_id: reportCommonInfo.id,
},
});
setTaskRecommendModal(true);
};
const handleSelectPage1 = (val) => {
let item = categories.find(x => x.item === val);
setPage2List(item.children);
};
const handleSelectPage2 = (val) => {
let item = page2List.find(x => x.item === val);
setPage3List(item.children);
};
const handlePreview = async file => {
if (!file.url && !file.preview) {
file.preview = await getBase64(file.originFileObj);
}
setPreviewImage(file.url || file.preview);
setPreviewVisible(true);
setPreviewTitle(file.name || file.url.substring(file.url.lastIndexOf('/') + 1))
};
const handleCancel = () => setPreviewVisible(false);
const handleChange = ({ fileList }) => {
setFileList(fileList);
};
useEffect(() => {
//判断是否已经有报告
dispatch({
type: 'editReport/getReportInfo',
payload: {
case_take_id: '1718-1718',
worker_id: '2',
},
}).then((res) => {
// console.log(res)
// console.log(reportCommonInfo)
//有报告,获取对应信息。没有就直接转去了第一步
dispatch({
type: 'editReport/getTestCaseList',
payload: { report_id: reportCommonInfo.id },
}).then((res) => {
if (res && res.length) {
currentTestCaseRef.current = res[0];
dispatch({
type: 'editReport/getCaseBugList',
payload: currentTestCaseRef.current.id,
});
}
});
dispatch({
type: 'editReport/getCategories',
payload: { examId: 1718 },
});
});
}, [dispatch, reportCommonInfo.id]);
return (
setEditReportModal(true)}
/>
测试用例列表
{testCaseList && testCaseList.length ? testCaseList.map((item) => {
return (
{
handleClickTestCase(item);
}}>
{{`NO.${((item.id).substring((item.id.length) - 6)).toUpperCase()}`}}
{/**/}
{item.name}
handleEditTestCase(item)} />
);
}) :
快来创建你的第一个测试用例吧~
}
缺陷列表
{caseBugList && caseBugList.length ? caseBugList.map((item) => {
return (
标题:
{item.detail.title}
{recurrent[item.detail.recurrent]}
{severity[item.detail.severity]}
{item.detail.bug_category}
路径:
{item.detail.bug_page}
描述:
{item.detail.description}
);
}) :
当前用例暂无提交记录,快去创建第一个BUG吧~
}
确定,
]}
onCancel={() => {
setAddTestCaseModal(false);
}}
>
为了评分准确,请勿提交重复测试用例
确定,
]}
onCancel={() => {
setAddTestBugModal(false);
}}
className={styles.bugForm}
>
为了评分准确,请勿提交重复Bug
({ // data里存放的是接口的请求参数
file,
caseId:currentTestCaseRef.current.id,
work_id:'2'
})}
listType="picture-card"
fileList={fileList}
onPreview={handlePreview}
onChange={handleChange}
>
{uploadButton}
handleCancel()}
>
确定,
]}
onCancel={() => {
setEditReportModal(false);
}}>
setTaskRecommendModal(false)}
onCancel={() => {
setTaskRecommendModal(false);
}
}
className="addModal">
);
};
export default connect(({ editReport, loading }) => ({
submitting: loading.effects['editReport/submitStepForm'],
reportCommonInfo: editReport.reportCommonInfo,
testCaseList: editReport.testCaseList,
caseBugList: editReport.caseBugList,
categories: editReport.categories,
pathInfo: editReport.pathInfo,
osType: editReport.osType,
}))(Step2);