新增分组的hook模板配置
This commit is contained in:
@@ -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 GroupList from './GroupList/GroupList.js';
|
||||||
import ProjectList from './ProjectList/ProjectList.js';
|
import ProjectList from './ProjectList/ProjectList.js';
|
||||||
import MemberList from './MemberList/MemberList.js';
|
import MemberList from './MemberList/MemberList.js';
|
||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
} from '../../reducer/modules/group';
|
} from '../../reducer/modules/group';
|
||||||
import './Group.scss';
|
import './Group.scss';
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import plugin from "../../plugin";
|
||||||
|
|
||||||
@connect(
|
@connect(
|
||||||
state => {
|
state => {
|
||||||
@@ -67,6 +68,11 @@ export default class Group extends Component {
|
|||||||
// // }
|
// // }
|
||||||
// }
|
// }
|
||||||
render() {
|
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 <Spin />
|
if(this.state.groupId === -1)return <Spin />
|
||||||
const GroupContent = (
|
const GroupContent = (
|
||||||
<Layout style={{ minHeight: 'calc(100vh - 100px)', marginLeft: '24px', marginTop: '24px' }}>
|
<Layout style={{ minHeight: 'calc(100vh - 100px)', marginLeft: '24px', marginTop: '24px' }}>
|
||||||
@@ -106,6 +112,14 @@ export default class Group extends Component {
|
|||||||
<GroupSetting />
|
<GroupSetting />
|
||||||
</TabPane>
|
</TabPane>
|
||||||
) : null}
|
) : null}
|
||||||
|
{ filterPanes.map(it =>{
|
||||||
|
let Com = it.component
|
||||||
|
return (
|
||||||
|
<TabPane tab={it.title} key={it.key}>
|
||||||
|
<Com groupId={this.props.curGroupId}/>
|
||||||
|
</TabPane>
|
||||||
|
)
|
||||||
|
}) }
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</Content>
|
</Content>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ hooks = {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 在运行页面或单个测试也里每次发送完成后调用
|
* 在运行页面或单个测试也里每次发送完成后调用
|
||||||
* 返回值为响应原始值 +
|
* 返回值为响应原始值 +
|
||||||
* {
|
* {
|
||||||
* type: 'inter' | 'case',
|
* type: 'inter' | 'case',
|
||||||
* projectId: string,
|
* projectId: string,
|
||||||
@@ -104,7 +104,7 @@ hooks = {
|
|||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 在测试集里运行每次发送请求后调用
|
* 在测试集里运行每次发送请求后调用
|
||||||
* 返回值为响应原始值 +
|
* 返回值为响应原始值 +
|
||||||
* {
|
* {
|
||||||
* type: 'col',
|
* type: 'col',
|
||||||
* caseId: string,
|
* caseId: string,
|
||||||
@@ -204,9 +204,9 @@ hooks = {
|
|||||||
/*
|
/*
|
||||||
* 添加 reducer
|
* 添加 reducer
|
||||||
* @param Object reducerModules
|
* @param Object reducerModules
|
||||||
*
|
*
|
||||||
* @info
|
* @info
|
||||||
* importDataModule = {};
|
* importDataModule = {};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
add_reducer: {
|
add_reducer: {
|
||||||
@@ -218,7 +218,7 @@ hooks = {
|
|||||||
/*
|
/*
|
||||||
* 添加 subnav 钩子
|
* 添加 subnav 钩子
|
||||||
* @param Object reducerModules
|
* @param Object reducerModules
|
||||||
*
|
*
|
||||||
* let routers = {
|
* let routers = {
|
||||||
interface: { name: '接口', path: "/project/:id/interface/:action", component:Interface },
|
interface: { name: '接口', path: "/project/:id/interface/:action", component:Interface },
|
||||||
activity: { name: '动态', path: "/project/:id/activity", component: Activity},
|
activity: { name: '动态', path: "/project/:id/activity", component: Activity},
|
||||||
@@ -235,7 +235,7 @@ hooks = {
|
|||||||
/*
|
/*
|
||||||
* 添加项目设置 nav
|
* 添加项目设置 nav
|
||||||
* @param Object routers
|
* @param Object routers
|
||||||
*
|
*
|
||||||
* let routers = {
|
* let routers = {
|
||||||
interface: { name: 'xxx', component: Xxx },
|
interface: { name: 'xxx', component: Xxx },
|
||||||
}
|
}
|
||||||
@@ -244,6 +244,11 @@ hooks = {
|
|||||||
type: 'listener',
|
type: 'listener',
|
||||||
mulit: true,
|
mulit: true,
|
||||||
listener: []
|
listener: []
|
||||||
|
},
|
||||||
|
add_group_tab:{
|
||||||
|
type: 'listener',
|
||||||
|
mulit: true,
|
||||||
|
listener: []
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -31,5 +31,14 @@ module.exports = function() {
|
|||||||
name: 'Markdown',
|
name: 'Markdown',
|
||||||
component: Services
|
component: Services
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.bindHook('add_group_tab', function (panes) {
|
||||||
|
panes.push({
|
||||||
|
key: 'Markdown',
|
||||||
|
title: 'Markdown设置',
|
||||||
|
component: mdTemplate,
|
||||||
|
roles: ['admin', 'owner']
|
||||||
|
})
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ class configModel extends baseModel {
|
|||||||
getSchema() {
|
getSchema() {
|
||||||
return {
|
return {
|
||||||
uid: { type: Number},
|
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 },
|
is_export_by_interface: { type: Boolean, default: false },
|
||||||
// 模板
|
// 模板
|
||||||
template_data: String,
|
template_data: String,
|
||||||
add_time: Number,
|
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){
|
delByProjectId(project_id){
|
||||||
return this.model.remove({
|
return this.model.remove({
|
||||||
project_id: project_id
|
project_id: project_id
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ const interfaceModel = require('models/interface.js');
|
|||||||
const projectModel = require('models/project.js');
|
const projectModel = require('models/project.js');
|
||||||
const interfaceCatModel = require('models/interfaceCat.js');
|
const interfaceCatModel = require('models/interfaceCat.js');
|
||||||
const userModel = require("models/user.js");
|
const userModel = require("models/user.js");
|
||||||
|
const groupModel = require("models/group.js");
|
||||||
const yapi = require('yapi.js');
|
const yapi = require('yapi.js');
|
||||||
const uuid = require('uuid');
|
const uuid = require('uuid');
|
||||||
const configModel = require("./configModel");
|
const configModel = require("./configModel");
|
||||||
@@ -17,6 +18,7 @@ class exportMarkdownController extends baseController {
|
|||||||
this.projectModel = yapi.getInst(projectModel);
|
this.projectModel = yapi.getInst(projectModel);
|
||||||
this.configModel = yapi.getInst(configModel);
|
this.configModel = yapi.getInst(configModel);
|
||||||
this.userModel = yapi.getInst(userModel);
|
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 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);
|
// console.log(result);
|
||||||
if (!templateData.is_export_by_interface) {
|
if (!templateData || !templateData.is_export_by_interface) {
|
||||||
console.log("重定向")
|
console.log("重定向")
|
||||||
ctx.status = 302;
|
ctx.status = 302;
|
||||||
ctx.redirect(`/api/plugin/export?type=markdown&pid=${pid}`);
|
ctx.redirect(`/api/plugin/export?type=markdown&pid=${pid}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let curProject;
|
|
||||||
try {
|
try {
|
||||||
curProject = await this.projectModel.get(pid);
|
|
||||||
// ctx.set('Content-Type', 'application/json');
|
// ctx.set('Content-Type', 'application/json');
|
||||||
// ctx.set('Content-Type', 'application/octet-stream');
|
// ctx.set('Content-Type', 'application/octet-stream');
|
||||||
const list = await this.handleListClass(pid, status);
|
const list = await this.handleListClass(pid, status);
|
||||||
@@ -153,8 +158,9 @@ class exportMarkdownController extends baseController {
|
|||||||
async upConfig(ctx) {
|
async upConfig(ctx) {
|
||||||
let requestBody = ctx.request.body;
|
let requestBody = ctx.request.body;
|
||||||
let projectId = requestBody.project_id;
|
let projectId = requestBody.project_id;
|
||||||
if (!projectId) {
|
let groupId = requestBody.group_id;
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
|
if (!projectId && !groupId) {
|
||||||
|
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id/组id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
|
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
|
||||||
@@ -176,11 +182,17 @@ class exportMarkdownController extends baseController {
|
|||||||
* @param {*} ctx
|
* @param {*} ctx
|
||||||
*/
|
*/
|
||||||
async getConfig(ctx) {
|
async getConfig(ctx) {
|
||||||
let projectId = ctx.query.project_id;
|
let projectId = ctx.query.project_id || ctx.query.projectId;
|
||||||
if (!projectId) {
|
let groupId = ctx.query.group_id || ctx.query.groupId;
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
|
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));
|
return (ctx.body = yapi.commons.resReturn(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,12 +208,15 @@ class exportMarkdownController extends baseController {
|
|||||||
if (!interfaceData) {
|
if (!interfaceData) {
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 200, ''));
|
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);
|
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) {
|
if (!templateData || !templateData.template_data) {
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 200, ''));
|
return (ctx.body = yapi.commons.resReturn(null, 200, ''));
|
||||||
}
|
}
|
||||||
let interfaceCat = await this.catModel.get(interfaceData.catid);
|
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);
|
let {result, errMsg} = await this.executeJsRender(templateData.template_data, project, interfaceData, interfaceCat, userData);
|
||||||
if (errMsg){
|
if (errMsg){
|
||||||
ctx.body = yapi.commons.resReturn(errMsg, 502, '渲染出错');
|
ctx.body = yapi.commons.resReturn(errMsg, 502, '渲染出错');
|
||||||
|
|||||||
@@ -69,10 +69,10 @@ class MDTemplateServices extends Component {
|
|||||||
const extraContent = (
|
const extraContent = (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<Button size={"small"} type={"link"} icon="copy"
|
<Button size={"small"} type={"link"} icon="copy"
|
||||||
onClick={(e) => this.preCopy(this.state.render_data.data)}>拷贝原文</Button>
|
onClick={() => this.preCopy(this.state.render_data.data)}>拷贝原文</Button>
|
||||||
|
|
||||||
<Button size={"small"} type={"link"} icon="table"
|
<Button size={"small"} type={"link"} icon="table"
|
||||||
onClick={(e) => {
|
onClick={() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
isHtml: !this.state.isHtml
|
isHtml: !this.state.isHtml
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export default class ProjectInterfaceSync extends Component {
|
|||||||
static propTypes = {
|
static propTypes = {
|
||||||
form: PropTypes.object,
|
form: PropTypes.object,
|
||||||
match: PropTypes.object,
|
match: PropTypes.object,
|
||||||
|
groupId: PropTypes.number,
|
||||||
projectId: PropTypes.number,
|
projectId: PropTypes.number,
|
||||||
projectMsg: PropTypes.object,
|
projectMsg: PropTypes.object,
|
||||||
handleSwaggerUrlData: PropTypes.func
|
handleSwaggerUrlData: PropTypes.func
|
||||||
@@ -55,11 +56,14 @@ export default class ProjectInterfaceSync extends Component {
|
|||||||
config_data: { is_export_by_interface: false, template_data:"",_id:null }
|
config_data: { is_export_by_interface: false, template_data:"",_id:null }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
componentDidMount() {
|
||||||
|
this.getSyncData();
|
||||||
|
}
|
||||||
handleSubmit = async () => {
|
handleSubmit = async () => {
|
||||||
const { form, projectId } = this.props;
|
const { form, projectId, groupId } = this.props;
|
||||||
let params = {
|
let params = {
|
||||||
project_id: projectId,
|
project_id: projectId,
|
||||||
|
group_id: groupId,
|
||||||
is_export_by_interface: this.state.config_data.is_export_by_interface,
|
is_export_by_interface: this.state.config_data.is_export_by_interface,
|
||||||
template_data: this.state.config_data.template_data,
|
template_data: this.state.config_data.template_data,
|
||||||
uid: this.props.projectMsg.uid
|
uid: this.props.projectMsg.uid
|
||||||
@@ -97,12 +101,10 @@ export default class ProjectInterfaceSync extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
config_data: {}
|
config_data: {}
|
||||||
});
|
});
|
||||||
this.getSyncData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSyncData() {
|
async getSyncData() {
|
||||||
let projectId = this.props.projectMsg._id;
|
let result = await axios.get('/api/plugin/mdConfig/get' + (this.props.projectId ? `?project_id=${this.props.projectId}` : `?groupId=${this.props.groupId}`));
|
||||||
let result = await axios.get('/api/plugin/mdConfig/get?project_id=' + projectId);
|
|
||||||
if (result.data.errcode === 0) {
|
if (result.data.errcode === 0) {
|
||||||
if (result.data.data) {
|
if (result.data.data) {
|
||||||
this.setState({
|
this.setState({
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ export default class CodeGenTemplate extends Component {
|
|||||||
form: PropTypes.object,
|
form: PropTypes.object,
|
||||||
match: PropTypes.object,
|
match: PropTypes.object,
|
||||||
projectId: PropTypes.number,
|
projectId: PropTypes.number,
|
||||||
|
groupId: PropTypes.number,
|
||||||
projectMsg: PropTypes.object,
|
projectMsg: PropTypes.object,
|
||||||
handleSwaggerUrlData: PropTypes.func
|
handleSwaggerUrlData: PropTypes.func
|
||||||
};
|
};
|
||||||
@@ -73,9 +74,10 @@ export default class CodeGenTemplate extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit = async (data) => {
|
handleSubmit = async (data) => {
|
||||||
const {form, projectId} = this.props;
|
const {form, projectId, groupId} = this.props;
|
||||||
let params = {
|
let params = {
|
||||||
project_id: projectId,
|
project_id: projectId,
|
||||||
|
group_id: groupId,
|
||||||
tag: data.tag_t || data.tag,
|
tag: data.tag_t || data.tag,
|
||||||
tag_desc: data.tag_desc_t || data.tag_desc,
|
tag_desc: data.tag_desc_t || data.tag_desc,
|
||||||
template_data: data.template_data,
|
template_data: data.template_data,
|
||||||
@@ -99,7 +101,9 @@ export default class CodeGenTemplate extends Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
componentDidMount() {
|
||||||
|
this.getSyncData();
|
||||||
|
}
|
||||||
|
|
||||||
UNSAFE_componentWillMount() {
|
UNSAFE_componentWillMount() {
|
||||||
//查询同步任务
|
//查询同步任务
|
||||||
@@ -107,12 +111,11 @@ export default class CodeGenTemplate extends Component {
|
|||||||
config_data: {template_data: "", _id: null},
|
config_data: {template_data: "", _id: null},
|
||||||
templateList: []
|
templateList: []
|
||||||
});
|
});
|
||||||
this.getSyncData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getSyncData() {
|
async getSyncData() {
|
||||||
let projectId = this.props.projectMsg._id;
|
const {projectId, groupId} = this.props;
|
||||||
let result = await axios.get('/api/plugin/template/get?projectId=' + projectId);
|
let result = await axios.get('/api/plugin/template/get?' + (projectId ? `projectId=${projectId}` : `groupId=${groupId}`));
|
||||||
if (result.data.errcode === 0) {
|
if (result.data.errcode === 0) {
|
||||||
if (result.data.data && result.data.data.length) {
|
if (result.data.data && result.data.data.length) {
|
||||||
let defaultTemplate = result.data.data.find(it => it.tag === "default")
|
let defaultTemplate = result.data.data.find(it => it.tag === "default")
|
||||||
|
|||||||
@@ -10,6 +10,15 @@ module.exports = function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
this.bindHook('add_group_tab', function (panes) {
|
||||||
|
panes.push({
|
||||||
|
key: 'codeGen',
|
||||||
|
title: '代码生成模板配置',
|
||||||
|
component: CodeGenTemplate,
|
||||||
|
roles: ['admin', 'owner']
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
this.bindHook('sub_setting_nav', function (route) {
|
this.bindHook('sub_setting_nav', function (route) {
|
||||||
route.codeGen = {
|
route.codeGen = {
|
||||||
name: '代码生成模板配置',
|
name: '代码生成模板配置',
|
||||||
|
|||||||
@@ -26,16 +26,22 @@ class exportController extends baseController {
|
|||||||
|
|
||||||
|
|
||||||
async genCode(ctx) {
|
async genCode(ctx) {
|
||||||
let projectId = ctx.request.query.projectId;
|
|
||||||
let interfaceId = ctx.request.query.interfaceId;
|
let interfaceId = ctx.request.query.interfaceId;
|
||||||
try {
|
try {
|
||||||
let curProject = await this.projectModel.get(projectId);
|
|
||||||
let interfaceData = await this.interModel.get(interfaceId);
|
let interfaceData = await this.interModel.get(interfaceId);
|
||||||
|
if (!interfaceData) {
|
||||||
|
ctx.body = yapi.commons.resReturn(null, 502, '接口不存在');
|
||||||
|
return
|
||||||
|
}
|
||||||
|
let curProject = await this.projectModel.get(interfaceData.project_id);
|
||||||
let userData = await this.userModel.findById(this.getUid());
|
let userData = await this.userModel.findById(this.getUid());
|
||||||
let errMsg = [];
|
let errMsg = [];
|
||||||
|
|
||||||
let templateList = await this.genCodeModel.listByProjectId(projectId);
|
let templateList = await this.genCodeModel.listByProjectId(interfaceData.project_id);
|
||||||
let retData = {};
|
let retData = {};
|
||||||
|
if (templateList == null || templateList.length === 0) {
|
||||||
|
templateList = await this.genCodeModel.listByGroupId(curProject.group_id);
|
||||||
|
}
|
||||||
console.log(templateList)
|
console.log(templateList)
|
||||||
if (templateList == null || templateList.length === 0) {
|
if (templateList == null || templateList.length === 0) {
|
||||||
ctx.body = yapi.commons.resReturn(errMsg, 502, '请先设置生成模板');
|
ctx.body = yapi.commons.resReturn(errMsg, 502, '请先设置生成模板');
|
||||||
@@ -82,9 +88,10 @@ class exportController extends baseController {
|
|||||||
|
|
||||||
async saveTemplate(ctx) {
|
async saveTemplate(ctx) {
|
||||||
let requestBody = ctx.request.body;
|
let requestBody = ctx.request.body;
|
||||||
let projectId = requestBody.project_id;
|
let projectId = requestBody.project_id || requestBody.projectId
|
||||||
if (!projectId) {
|
let groupId = requestBody.group_id || requestBody.groupId
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
|
if (!projectId && !groupId) {
|
||||||
|
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id/组id'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
|
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
|
||||||
@@ -96,7 +103,7 @@ class exportController extends baseController {
|
|||||||
} else {
|
} else {
|
||||||
let existData = await this.genCodeModel.listByProjectId(projectId);
|
let existData = await this.genCodeModel.listByProjectId(projectId);
|
||||||
|
|
||||||
if (existData.find(templ => templ.tag === requestBody.tag)){
|
if (existData.find(templ => templ.tag === requestBody.tag)) {
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 502, 'tag已存在'));
|
return (ctx.body = yapi.commons.resReturn(null, 502, 'tag已存在'));
|
||||||
}
|
}
|
||||||
result = await this.genCodeModel.save(requestBody);
|
result = await this.genCodeModel.save(requestBody);
|
||||||
@@ -110,12 +117,18 @@ class exportController extends baseController {
|
|||||||
* @param {*} ctx
|
* @param {*} ctx
|
||||||
*/
|
*/
|
||||||
async getTemplate(ctx) {
|
async getTemplate(ctx) {
|
||||||
let projectId = ctx.params.projectId;
|
let projectId = ctx.params.projectId || ctx.params.project_id;
|
||||||
if (!projectId) {
|
let groupId = ctx.params.groupId || ctx.params.group_id;
|
||||||
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
|
if (!projectId && !groupId) {
|
||||||
|
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id/组id'));
|
||||||
}
|
}
|
||||||
console.log(this.genCodeModel)
|
console.log(this.genCodeModel)
|
||||||
let result = await this.genCodeModel.listByProjectId(projectId);
|
let result = null;
|
||||||
|
if (projectId) {
|
||||||
|
result = await this.genCodeModel.listByProjectId(projectId);
|
||||||
|
} else {
|
||||||
|
result = await this.genCodeModel.listByGroupId(groupId);
|
||||||
|
}
|
||||||
return (ctx.body = yapi.commons.resReturn(result));
|
return (ctx.body = yapi.commons.resReturn(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ class genCodeModel extends baseModel {
|
|||||||
getSchema() {
|
getSchema() {
|
||||||
return {
|
return {
|
||||||
uid: { type: Number},
|
uid: { type: Number},
|
||||||
project_id: { type: Number, required: true },
|
project_id: { type: Number, required: false },
|
||||||
|
group_id: { type: Number, required: false },
|
||||||
//是否开启自动同步
|
//是否开启自动同步
|
||||||
tag: { type: String, default: "default" },
|
tag: { type: String, default: "default" },
|
||||||
tag_desc: { type: String, default: "默认" },
|
tag_desc: { type: String, default: "默认" },
|
||||||
@@ -33,6 +34,13 @@ class genCodeModel extends baseModel {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
listByGroupId(id) {
|
||||||
|
return this.model.find({
|
||||||
|
group_id: id
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
delByProjectId(project_id){
|
delByProjectId(project_id){
|
||||||
return this.model.remove({
|
return this.model.remove({
|
||||||
project_id: project_id
|
project_id: project_id
|
||||||
|
|||||||
Reference in New Issue
Block a user