feat: 拖拽接口和用例

This commit is contained in:
zwjamnsss 2017-10-12 20:45:34 +08:00
parent daf431613e
commit 49fc89985c
3 changed files with 34 additions and 5 deletions

View File

@ -243,6 +243,19 @@ export default class InterfaceColMenu extends Component {
this.setState({filterValue: value})
}
onDrop = async (e) => {
const projectId = this.props.match.params.id;
const dropColIndex = e.node.props.pos.split('-')[1];
const dropColId = this.props.interfaceColList[dropColIndex]._id;
const id = e.dragNode.props.eventKey;
const dragColIndex = e.dragNode.props.pos.split('-')[1];
const dragColId = this.props.interfaceColList[dragColIndex]._id;
if (id.indexOf('col') === -1 && dropColId !== dragColId) {
await axios.post('/api/col/up_case', {id: id.split('_')[1], col_id: dropColId});
this.props.fetchInterfaceColList(projectId);
}
}
render() {
const { currColId, currCaseId, isShowCol } = this.props;
const { colModalType, colModalVisible, filterValue, importInterVisible } = this.state;
@ -282,6 +295,8 @@ export default class InterfaceColMenu extends Component {
onSelect={this.onSelect}
autoExpandParent
onExpand={this.onExpand}
draggable
onDrop={this.onDrop}
>
{
this.props.interfaceColList.filter(col =>{

View File

@ -248,6 +248,18 @@ class InterfaceMenu extends Component {
})
}
onDrop = async (e) => {
const dropCatIndex = e.node.props.pos.split('-')[1] - 1;
const dropCatId = this.props.list[dropCatIndex]._id;
const id = e.dragNode.props.eventKey;
const dragCatIndex = e.dragNode.props.pos.split('-')[1] - 1;
const dragCatId = this.props.list[dragCatIndex]._id;
if (id.indexOf('cat') === -1 && dragCatIndex > -1 && dropCatId !== dragCatId) {
await axios.post('/api/interface/up', {id, catid: dropCatId});
this.props.fetchInterfaceList(this.props.projectId);
}
}
render() {
const matchParams = this.props.match.params;
let menuList = this.state.list;
@ -421,6 +433,8 @@ class InterfaceMenu extends Component {
selectedKeys={currentKes.selects}
onSelect={this.onSelect}
onExpand={this.onExpand}
draggable
onDrop={this.onDrop}
>
<TreeNode className="item-all-interface" title={<Link style={{ fontSize: '14px' }} to={"/project/" + matchParams.id + "/interface/api"}><Icon type="folder" style={{ marginRight: 5 }} />全部接口</Link>} key="root" />
{menuList.map((item) => {

View File

@ -328,9 +328,9 @@ class interfaceColController extends baseController{
return ctx.body = yapi.commons.resReturn(null, 400, '用例id不能为空');
}
if(!params.casename){
return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
}
// if(!params.casename){
// return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
// }
let caseData = await this.caseModel.get(params.id);
let auth = await this.checkAuth(caseData.project_id, 'project', 'edit');
@ -342,13 +342,13 @@ class interfaceColController extends baseController{
delete params.interface_id;
delete params.project_id;
delete params.col_id;
// delete params.col_id;
let result = await this.caseModel.up(params.id, params);
let username = this.getUsername();
this.colModel.get(caseData.col_id).then((col)=>{
yapi.commons.saveLog({
content: `用户 "${username}" 在接口集 "${col.name}" 更新了接口用例 "${params.casename}"`,
content: `用户 "${username}" 在接口集 "${col.name}" 更新了接口用例 "${params.casename || caseData.casename}"`,
type: 'project',
uid: this.getUid(),
username: username,