diff --git a/client/containers/Group/Group.js b/client/containers/Group/Group.js
index 40af66b..00d8bc2 100644
--- a/client/containers/Group/Group.js
+++ b/client/containers/Group/Group.js
@@ -1,4 +1,4 @@
-import React, { PureComponent as Component } from 'react';
+import React, {PureComponent as Component} from 'react';
import GroupList from './GroupList/GroupList.js';
import ProjectList from './ProjectList/ProjectList.js';
import MemberList from './MemberList/MemberList.js';
@@ -16,6 +16,7 @@ import {
} from '../../reducer/modules/group';
import './Group.scss';
import axios from 'axios'
+import plugin from "../../plugin";
@connect(
state => {
@@ -67,6 +68,11 @@ export default class Group extends Component {
// // }
// }
render() {
+ let panes = []
+ plugin.emitHook('add_group_tab', panes);
+
+ let filterPanes = panes.filter(it => it.roles.indexOf(this.props.curUserRoleInGroup) > -1 ||
+ this.props.curUserRole === 'admin');
if(this.state.groupId === -1)return
const GroupContent = (
@@ -106,6 +112,14 @@ export default class Group extends Component {
) : null}
+ { filterPanes.map(it =>{
+ let Com = it.component
+ return (
+
+
+
+ )
+ }) }
diff --git a/client/plugin.js b/client/plugin.js
index 705c5a0..6a95a38 100644
--- a/client/plugin.js
+++ b/client/plugin.js
@@ -82,7 +82,7 @@ hooks = {
},
/**
* 在运行页面或单个测试也里每次发送完成后调用
- * 返回值为响应原始值 +
+ * 返回值为响应原始值 +
* {
* type: 'inter' | 'case',
* projectId: string,
@@ -104,7 +104,7 @@ hooks = {
},
/**
* 在测试集里运行每次发送请求后调用
- * 返回值为响应原始值 +
+ * 返回值为响应原始值 +
* {
* type: 'col',
* caseId: string,
@@ -204,9 +204,9 @@ hooks = {
/*
* 添加 reducer
* @param Object reducerModules
- *
+ *
* @info
- * importDataModule = {};
+ * importDataModule = {};
*/
add_reducer: {
@@ -218,7 +218,7 @@ hooks = {
/*
* 添加 subnav 钩子
* @param Object reducerModules
- *
+ *
* let routers = {
interface: { name: '接口', path: "/project/:id/interface/:action", component:Interface },
activity: { name: '动态', path: "/project/:id/activity", component: Activity},
@@ -235,7 +235,7 @@ hooks = {
/*
* 添加项目设置 nav
* @param Object routers
- *
+ *
* let routers = {
interface: { name: 'xxx', component: Xxx },
}
@@ -244,6 +244,11 @@ hooks = {
type: 'listener',
mulit: true,
listener: []
+ },
+ add_group_tab:{
+ type: 'listener',
+ mulit: true,
+ listener: []
}
};
diff --git a/exts/yapi-plugin-export-markdown-template/client.js b/exts/yapi-plugin-export-markdown-template/client.js
index 735912a..c22086c 100644
--- a/exts/yapi-plugin-export-markdown-template/client.js
+++ b/exts/yapi-plugin-export-markdown-template/client.js
@@ -31,5 +31,14 @@ module.exports = function() {
name: 'Markdown',
component: Services
}
-})
+ })
+
+ this.bindHook('add_group_tab', function (panes) {
+ panes.push({
+ key: 'Markdown',
+ title: 'Markdown设置',
+ component: mdTemplate,
+ roles: ['admin', 'owner']
+ })
+ })
};
diff --git a/exts/yapi-plugin-export-markdown-template/configModel.js b/exts/yapi-plugin-export-markdown-template/configModel.js
index 5b512d3..f78d951 100644
--- a/exts/yapi-plugin-export-markdown-template/configModel.js
+++ b/exts/yapi-plugin-export-markdown-template/configModel.js
@@ -10,13 +10,14 @@ class configModel extends baseModel {
getSchema() {
return {
uid: { type: Number},
- project_id: { type: Number, required: true },
+ project_id: { type: Number, required: false },
+ group_id: { type: Number, required: false },
//是否开启自动同步
is_export_by_interface: { type: Boolean, default: false },
// 模板
template_data: String,
add_time: Number,
- up_time: Number,
+ up_time: Number
};
}
@@ -26,6 +27,11 @@ class configModel extends baseModel {
})
}
+ getByGroupId(id) {
+ return this.model.findOne({
+ group_id: id
+ })
+ }
delByProjectId(project_id){
return this.model.remove({
project_id: project_id
diff --git a/exts/yapi-plugin-export-markdown-template/controller.js b/exts/yapi-plugin-export-markdown-template/controller.js
index 4512e64..3cf3907 100644
--- a/exts/yapi-plugin-export-markdown-template/controller.js
+++ b/exts/yapi-plugin-export-markdown-template/controller.js
@@ -3,6 +3,7 @@ const interfaceModel = require('models/interface.js');
const projectModel = require('models/project.js');
const interfaceCatModel = require('models/interfaceCat.js');
const userModel = require("models/user.js");
+const groupModel = require("models/group.js");
const yapi = require('yapi.js');
const uuid = require('uuid');
const configModel = require("./configModel");
@@ -17,6 +18,7 @@ class exportMarkdownController extends baseController {
this.projectModel = yapi.getInst(projectModel);
this.configModel = yapi.getInst(configModel);
this.userModel = yapi.getInst(userModel);
+ this.groupModel = yapi.getInst(groupModel);
}
/*
@@ -82,16 +84,19 @@ class exportMarkdownController extends baseController {
}
let templateData = await this.configModel.getByProjectId(pid);
+ let curProject = await this.projectModel.get(pid);
+ if (!templateData){
+ templateData = await this.configModel.getByGroupId(curProject.group_id);
+ }
// console.log(result);
- if (!templateData.is_export_by_interface) {
+ if (!templateData || !templateData.is_export_by_interface) {
console.log("重定向")
ctx.status = 302;
ctx.redirect(`/api/plugin/export?type=markdown&pid=${pid}`);
return;
}
- let curProject;
try {
- curProject = await this.projectModel.get(pid);
+
// ctx.set('Content-Type', 'application/json');
// ctx.set('Content-Type', 'application/octet-stream');
const list = await this.handleListClass(pid, status);
@@ -153,8 +158,9 @@ class exportMarkdownController extends baseController {
async upConfig(ctx) {
let requestBody = ctx.request.body;
let projectId = requestBody.project_id;
- if (!projectId) {
- return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
+ let groupId = requestBody.group_id;
+ if (!projectId && !groupId) {
+ return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id/组id'));
}
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
@@ -176,11 +182,17 @@ class exportMarkdownController extends baseController {
* @param {*} ctx
*/
async getConfig(ctx) {
- let projectId = ctx.query.project_id;
- if (!projectId) {
- return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
+ let projectId = ctx.query.project_id || ctx.query.projectId;
+ let groupId = ctx.query.group_id || ctx.query.groupId;
+ if (!projectId && !groupId) {
+ return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id/组id'));
+ }
+ let result = null;
+ if (projectId){
+ result = await this.configModel.getByProjectId(projectId);
+ }else {
+ result= await this.configModel.getByGroupId(groupId);
}
- let result = await this.configModel.getByProjectId(projectId);
return (ctx.body = yapi.commons.resReturn(result));
}
@@ -196,12 +208,15 @@ class exportMarkdownController extends baseController {
if (!interfaceData) {
return (ctx.body = yapi.commons.resReturn(null, 200, ''));
}
+ let project = await this.projectModel.get(interfaceData.project_id);
let templateData = await this.configModel.getByProjectId(interfaceData.project_id);
+ if (!templateData || !templateData.template_data) {
+ templateData = await this.configModel.getByGroupId(project.group_id);
+ }
if (!templateData || !templateData.template_data) {
return (ctx.body = yapi.commons.resReturn(null, 200, ''));
}
let interfaceCat = await this.catModel.get(interfaceData.catid);
- let project = await this.projectModel.get(interfaceData.project_id);
let {result, errMsg} = await this.executeJsRender(templateData.template_data, project, interfaceData, interfaceCat, userData);
if (errMsg){
ctx.body = yapi.commons.resReturn(errMsg, 502, '渲染出错');
diff --git a/exts/yapi-plugin-export-markdown-template/mdTemplate/Services.js b/exts/yapi-plugin-export-markdown-template/mdTemplate/Services.js
index 8a1dcdf..097cf90 100644
--- a/exts/yapi-plugin-export-markdown-template/mdTemplate/Services.js
+++ b/exts/yapi-plugin-export-markdown-template/mdTemplate/Services.js
@@ -69,10 +69,10 @@ class MDTemplateServices extends Component {
const extraContent = (
+ onClick={() => this.preCopy(this.state.render_data.data)}>拷贝原文