添加文件生成功能,支持自定义文件模板

This commit is contained in:
2024-07-07 21:10:05 +08:00
parent 37cdf271dc
commit 34a98ab47e
16 changed files with 1250 additions and 2 deletions

View File

@@ -1 +1 @@
module.exports = {"import-postman" : {module: require('exts/yapi-plugin-import-postman/client.js'),options: null},"import-har" : {module: require('exts/yapi-plugin-import-har/client.js'),options: null},"advanced-mock" : {module: require('exts/yapi-plugin-advanced-mock/client.js'),options: null},"import-swagger" : {module: require('exts/yapi-plugin-import-swagger/client.js'),options: null},"statistics" : {module: require('exts/yapi-plugin-statistics/client.js'),options: null},"export-data" : {module: require('exts/yapi-plugin-export-data/client.js'),options: null},"gen-services" : {module: require('exts/yapi-plugin-gen-services/client.js'),options: null},"export-swagger2-data" : {module: require('exts/yapi-plugin-export-swagger2-data/client.js'),options: null},"import-yapi-json" : {module: require('exts/yapi-plugin-import-yapi-json/client.js'),options: null},"wiki" : {module: require('exts/yapi-plugin-wiki/client.js'),options: null},"swagger-auto-sync" : {module: require('exts/yapi-plugin-swagger-auto-sync/client.js'),options: null},"export-postman" : {module: require('exts/yapi-plugin-export-postman/client.js'),options: null},"export-markdown-template" : {module: require('exts/yapi-plugin-export-markdown-template/client.js'),options: null}}
module.exports = {"import-postman" : {module: require('exts/yapi-plugin-import-postman/client.js'),options: null},"import-har" : {module: require('exts/yapi-plugin-import-har/client.js'),options: null},"advanced-mock" : {module: require('exts/yapi-plugin-advanced-mock/client.js'),options: null},"import-swagger" : {module: require('exts/yapi-plugin-import-swagger/client.js'),options: null},"statistics" : {module: require('exts/yapi-plugin-statistics/client.js'),options: null},"export-data" : {module: require('exts/yapi-plugin-export-data/client.js'),options: null},"gen-java-services" : {module: require('exts/yapi-plugin-gen-java-services/client.js'),options: null},"export-swagger2-data" : {module: require('exts/yapi-plugin-export-swagger2-data/client.js'),options: null},"import-yapi-json" : {module: require('exts/yapi-plugin-import-yapi-json/client.js'),options: null},"wiki" : {module: require('exts/yapi-plugin-wiki/client.js'),options: null},"swagger-auto-sync" : {module: require('exts/yapi-plugin-swagger-auto-sync/client.js'),options: null},"export-postman" : {module: require('exts/yapi-plugin-export-postman/client.js'),options: null},"export-markdown-template" : {module: require('exts/yapi-plugin-export-markdown-template/client.js'),options: null}}

View File

@@ -12,7 +12,7 @@ module.exports = {
},{
name: 'export-data'
},{
name: 'gen-services'
name: 'gen-java-services'
},{
name: 'export-swagger2-data'
},{

View File

@@ -0,0 +1,76 @@
import React, {PureComponent as Component} from 'react'
import PropTypes from 'prop-types'
import {connect} from 'react-redux';
import {getToken} from '../../../client/reducer/modules/project.js'
import './Services.scss';
import {withRouter} from "react-router-dom";
import axios from "axios";
import {message} from "antd";
@connect(
state => {
return {
token: state.project.token
}
},
{
getToken
}
)
class Services extends Component {
static propTypes = {
projectId: PropTypes.number,
token: PropTypes.string,
getToken: PropTypes.func,
match: PropTypes.object
}
constructor(props, context) {
super(props, context);
this.state = {
render_data: {}
}
}
componentDidMount() {
this.getSyncData();
}
async getSyncData() {
let projectId = this.props.match.params.id;
let interfaceId = this.props.match.params.actionId;
let result = await axios.get(`/api/plugin/codeGen?projectId=${projectId}&interfaceId=${interfaceId}`);
if (result.data) {
this.setState({
render_data: result.data
});
}
}
async preCopy(code) {
await navigator.clipboard.writeText(code)
message.success("复制成功")
}
render() {
let render_vide = [];
if (this.state.render_data) {
Object.keys(this.state.render_data)
Object.keys(this.state.render_data).forEach((tag) => {
render_vide.push(<h5 key={tag + "_desc"}>{tag}</h5>)
render_vide.push(<pre key={tag + "_code"}><span className='btn-pre-copy' onClick={()=>this.preCopy(this.state.render_data[tag])}>复制代码</span>{this.state.render_data[tag] + "\n"}</pre>)
});
}
console.log(render_vide)
return (
<div className="project-services">
<section className="news-box m-panel">
<div className="token">
{render_vide}
</div>
</section>
</div>
);
}
}
module.exports = withRouter(Services);

View File

@@ -0,0 +1,30 @@
.project-services {
margin: 0;
pre {
background: #efefef;
}
}
pre{
position: relative;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 4px;
padding: 10px;
}
pre .btn-pre-copy{
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-khtml-user-select: none;
user-select: none;
position: absolute;
top: 10px;
right: 12px;
font-size: 12px;
line-height: 1;
cursor: pointer;
color: hsla(0,0%,54.9%,.8);
transition: color .1s;
}

View File

@@ -0,0 +1,145 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {Form, Button, message} from 'antd';
import {handleSwaggerUrlData} from 'client/reducer/modules/project';
const FormItem = Form.Item;
import axios from 'axios';
import AceEditor from "../../../client/components/AceEditor/AceEditor";
// layout
const formItemLayout = {
labelCol: {
lg: {span: 5},
xs: {span: 24},
sm: {span: 10}
},
wrapperCol: {
lg: {span: 16},
xs: {span: 24},
sm: {span: 12}
},
className: 'form-item'
};
const tailFormItemLayout = {
wrapperCol: {
sm: {
span: 16,
offset: 11
}
}
};
@connect(
state => {
return {
projectMsg: state.project.currProject
};
},
{
handleSwaggerUrlData
}
)
@Form.create()
export default class CodeGenTemplate extends Component {
static propTypes = {
form: PropTypes.object,
match: PropTypes.object,
projectId: PropTypes.number,
projectMsg: PropTypes.object,
handleSwaggerUrlData: PropTypes.func
};
constructor(props) {
super(props);
this.state = {
config_data: {template_data: "", _id: null}
};
}
handleSubmit = async () => {
const {form, projectId} = this.props;
let params = {
project_id: projectId,
template_data: this.state.config_data.template_data,
uid: this.props.projectMsg.uid
};
if (this.state.config_data._id) {
params.id = this.state.config_data._id;
}
form.validateFields(async (err, values) => {
if (!err) {
let assignValue = Object.assign(params, values);
await axios.post('/api/plugin/template/save', assignValue).then(res => {
if (res.data.errcode === 0) {
message.success('保存成功');
} else {
message.error(res.data.errmsg);
}
});
}
});
};
UNSAFE_componentWillMount() {
//查询同步任务
this.setState({
config_data: {}
});
this.getSyncData();
}
async getSyncData() {
let projectId = this.props.projectMsg._id;
let result = await axios.get('/api/plugin/template/get?projectId=' + projectId);
if (result.data.errcode === 0) {
if (result.data.data) {
let templateData = result.data.data.find(it => it.tag === "default")
if (templateData == null) {
templateData = result.data.data[0]
}
this.setState({
config_data: templateData
});
}
}
}
handleTemplateInput = e => {
let config_data = this.state.config_data;
config_data.template_data = e.text;
this.setState({
config_data: config_data
});
};
render() {
const templateEditor = (
<FormItem {...formItemLayout} label="默认模板">
<AceEditor
data={this.state.config_data.template_data}
onChange={this.handleTemplateInput}
style={{minHeight: '300px'}}
/>
</FormItem>
)
return (
<div className="m-panel">
<Form>
<div>
{templateEditor}
</div>
<FormItem {...tailFormItemLayout}>
<Button type="primary" htmlType="submit" icon="save" size="large" onClick={this.handleSubmit}>
保存
</Button>
</FormItem>
</Form>
</div>
);
}
}

View File

@@ -0,0 +1,21 @@
import Services from './Services/Services.js';
import CodeGenTemplate from "./Services/codeTemplate";
module.exports = function () {
this.bindHook('interface_tab', function (tabs) {
tabs.javaGen = {
name: '代码生成',
component: Services
}
})
this.bindHook('sub_setting_nav', function (route) {
route.codeGen = {
name: '代码生成模板配置',
component: CodeGenTemplate
};
})
}

View File

@@ -0,0 +1,140 @@
const baseController = require('controllers/base.js');
const interfaceModel = require('models/interface.js');
const projectModel = require('models/project.js');
// const wikiModel = require('../yapi-plugin-wiki/wikiModel.js');
const interfaceCatModel = require('models/interfaceCat.js');
const groupModel = require("models/group.js");
const userModel = require("models/user.js");
const genCodeModel = require("./genCodeModel");
const yapi = require('yapi.js');
const {default: Safeify} = require("safeify");
// const htmlToPdf = require("html-pdf");
class exportController extends baseController {
constructor(ctx) {
super(ctx);
// 分类
this.catModel = yapi.getInst(interfaceCatModel);
this.interModel = yapi.getInst(interfaceModel);
this.projectModel = yapi.getInst(projectModel);
this.groupModel = yapi.getInst(groupModel);
this.userModel = yapi.getInst(userModel);
this.genCodeModel = yapi.getInst(genCodeModel);
}
async genCode(ctx) {
let projectId = ctx.request.query.projectId;
let interfaceId = ctx.request.query.interfaceId;
try {
let curProject = await this.projectModel.get(projectId);
let interfaceData = await this.interModel.get(interfaceId);
let userData = await this.userModel.findById(this.getUid());
let errMsg = [];
let templateList = await this.genCodeModel.listByProjectId(projectId);
let retData = {};
console.log(templateList)
if (templateList == null || templateList.length === 0) {
ctx.body = yapi.commons.resReturn(errMsg, 502, '请先设置生成模板');
return;
}
for (const template of templateList) {
const safeVm = new Safeify({
timeout: 3000, //超时时间
asyncTimeout: 10000, //包含异步操作的超时时间
unrestricted: true,
quantity: 4, //沙箱进程数量,默认同 CPU 核数
memoryQuota: 500, //沙箱最大能使用的内存(单位 m默认 500m
cpuQuota: 0.5 //沙箱的 cpu 资源配额(百分比),默认 50%
});
// console.log("curProject", curProject)
const vmContext = {
projectTmp: JSON.stringify(curProject),
interfaceTmp: JSON.stringify(interfaceData),
userTemp: JSON.stringify(userData)
};
try {
safeVm.preset("const project = JSON.parse(projectTmp);const interface = JSON.parse(interfaceTmp);const user=JSON.parse(userTemp)")
let model = await safeVm.run(template.template_data, vmContext);
safeVm.destroy();
retData[template.tag] = model
} catch (e) {
errMsg.push({
error: e.toString(),
context: vmContext
});
}
}
ctx.body = retData;
if (errMsg.length) {
ctx.body = yapi.commons.resReturn(errMsg, 502, '渲染出错');
}
} catch (error) {
yapi.commons.log(error, 'error');
ctx.body = yapi.commons.resReturn(null, 502, '渲染出错');
}
}
async saveTemplate(ctx) {
let requestBody = ctx.request.body;
let projectId = requestBody.project_id;
if (!projectId) {
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
}
if ((await this.checkAuth(projectId, 'project', 'edit')) !== true) {
return (ctx.body = yapi.commons.resReturn(null, 405, '没有权限'));
}
let existData = await this.genCodeModel.listByProjectId(projectId);
if (existData.find(templ => templ.tag === requestBody.tag)){
return (ctx.body = yapi.commons.resReturn(null, 502, 'tag已存在'));
}
let result;
if (requestBody.id) {
result = await this.genCodeModel.up(requestBody);
} else {
result = await this.genCodeModel.save(requestBody);
}
return (ctx.body = yapi.commons.resReturn(result));
}
/**
* 查询配置信息
* @param {*} ctx
*/
async getTemplate(ctx) {
let projectId = ctx.params.projectId;
if (!projectId) {
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少项目Id'));
}
console.log(this.genCodeModel)
let result = await this.genCodeModel.listByProjectId(projectId);
return (ctx.body = yapi.commons.resReturn(result));
}
/**
* 删除模板
* @param {*} ctx
*/
async deleteTemplate(ctx) {
let templateId = ctx.params.templateId;
if (!templateId) {
return (ctx.body = yapi.commons.resReturn(null, 408, '缺少模板Id'));
}
let result = await this.genCodeModel.del(templateId);
return (ctx.body = yapi.commons.resReturn(result));
}
}
module.exports = exportController;

View File

@@ -0,0 +1,351 @@
@charset "UTF-8";
html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
width: 6px;
}
/* 外层轨道 */
::-webkit-scrollbar-track {
-webkit-box-shadow: inset006pxrgba(255, 0, 0, 0.3);
background: rgba(0, 0, 0, 0.1);
}
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
border-radius: 4px;
background: rgba(0, 0, 0, 0.2);
-webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(0, 0, 0, 0.2);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif;
font-size: 13px;
line-height: 25px;
color: #393838;
position: relative;
}
table {
margin: 10px 0 15px 0;
border-collapse: collapse;
}
td,
th {
border: 1px solid #ddd;
padding: 3px 10px;
}
th {
padding: 5px 10px;
}
a, a:link, a:visited {
color: #34495e;
text-decoration: none;
}
a:hover, a:focus {
color: #59d69d;
text-decoration: none;
}
a img {
border: none;
}
p {
padding-left: 10px;
margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #404040;
line-height: 36px;
}
h1 {
color: #2c3e50;
font-weight: 600;
margin-bottom: 16px;
font-size: 32px;
padding-bottom: 16px;
border-bottom: 1px solid #ddd;
line-height: 50px;
}
h2 {
font-size: 28px;
padding-top: 10px;
padding-bottom: 10px;
}
h3 {
clear: both;
font-weight: 400;
margin-top: 20px;
margin-bottom: 20px;
border-left: 3px solid #59d69d;
padding-left: 8px;
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 13px;
}
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
blockquote {
padding: 13px 13px 21px 15px;
margin-bottom: 18px;
font-family: georgia, serif;
font-style: italic;
}
blockquote:before {
font-size: 40px;
margin-left: -10px;
font-family: georgia, serif;
color: #eee;
}
blockquote p {
font-size: 14px;
font-weight: 300;
line-height: 18px;
margin-bottom: 0;
font-style: italic;
}
code,
pre {
font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
background-color: #fee9cc;
color: rgba(0, 0, 0, 0.75);
padding: 1px 3px;
font-size: 12px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
pre {
display: block;
padding: 14px;
margin: 0 0 18px;
line-height: 16px;
font-size: 11px;
border: 1px solid #d9d9d9;
white-space: pre-wrap;
word-wrap: break-word;
background: #f6f6f6;
}
pre code {
background-color: #f6f6f6;
color: #737373;
font-size: 11px;
padding: 0;
}
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media print {
body,
code,
pre code,
h1,
h2,
h3,
h4,
h5,
h6 {
color: black;
}
table,
pre {
page-break-inside: avoid;
}
}
html,
body {
height: 100%;
}
.table-of-contents {
position: fixed;
top: 61px;
left: 0;
bottom: 0;
overflow-x: hidden;
overflow-y: auto;
width: 260px;
}
.table-of-contents > ul > li > a {
font-size: 20px;
margin-bottom: 16px;
margin-top: 16px;
}
.table-of-contents ul {
overflow: auto;
margin: 0px;
height: 100%;
padding: 0px 0px;
box-sizing: border-box;
list-style-type: none;
}
.table-of-contents ul li {
padding-left: 20px;
}
.table-of-contents a {
padding: 2px 0px;
display: block;
text-decoration: none;
}
.content-right {
max-width: 700px;
margin-left: 290px;
padding-left: 70px;
flex-grow: 1;
}
.content-right h2:target {
padding-top: 80px;
}
body > p {
margin-left: 30px;
}
body > table {
margin-left: 30px;
}
body > pre {
margin-left: 30px;
}
.curProject {
position: fixed;
top: 20px;
font-size: 25px;
color: black;
margin-left: -240px;
width: 240px;
padding: 5px;
line-height: 25px;
box-sizing: border-box;
}
.g-doc {
margin-top: 56px;
padding-top: 24px;
display: flex;
}
.curproject-name {
font-size: 42px;
}
.m-header {
background: #32363a;
height: 56px;
line-height: 56px;
padding-left: 60px;
display: flex;
align-items: center;
position: fixed;
z-index: 9;
top: 0;
left: 0;
right: 0;
}
.m-header .title {
font-size: 22px;
color: #fff;
font-weight: normal;
-webkit-font-smoothing: antialiased;
margin: 0;
margin-left: 16px;
padding: 0;
line-height: 56px;
border: none;
}
.m-header .nav {
color: #fff;
font-size: 16px;
position: absolute;
right: 32px;
top: 0;
}
.m-header .nav a {
color: #fff;
margin-left: 16px;
padding: 8px;
transition: color .2s;
}
.m-header .nav a:hover {
color: #59d69d;
}
.m-footer {
border-top: 1px solid #ddd;
padding-top: 16px;
padding-bottom: 16px;
}
/*# sourceMappingURL=defaultTheme.css.map */

View File

@@ -0,0 +1,7 @@
{
"version": 3,
"mappings": ";AAAA;;;;;;;;;UASW;EACP,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,WAAW,EAAE,MAAM;EACnB,sBAAsB,EAAE,WAAW;;;AAEvC,cAAc;AACd,mBAAoB;EAChB,KAAK,EAAE,GAAG;;;AAEd,UAAU;AACV,yBAA0B;EACtB,kBAAkB,EAAE,8BAA8B;EAClD,UAAU,EAAE,kBAAkB;;;AAElC,WAAW;AACX,yBAA0B;EACtB,aAAa,EAAE,GAAG;EAClB,UAAU,EAAE,kBAAkB;EAC9B,kBAAkB,EAAE,4BAA4B;;;AAEpD,yCAA0C;EACtC,U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ACnB,MAAM,EAAE,IAAI;EACZ,WAAW,EAAE,IAAI;EACjB,YAAY,EAAE,IAAI;EAClB,OAAO,EAAE,IAAI;EACb,WAAW,EAAE,MAAM;EACnB,QAAQ,EAAE,KAAK;EACf,OAAO,EAAE,CAAC;EACV,GAAG,EAAE,CAAC;EACN,IAAI,EAAE,CAAC;EACP,KAAK,EAAE,CAAC;;AACR,gBAAO;EACH,SAAS,EAAE,IAAI;EACf,KAAK,EAAE,IAAI;EACX,WAAW,EAAE,MAAM;EACnB,sBAAsB,EAAE,WAAW;EACnC,MAAM,EAAE,CAAC;EACT,WAAW,EAAE,IAAI;EACjB,OAAO,EAAE,CAAC;EACV,WAAW,EAAE,IAAI;EACjB,MAAM,EAAE,IAAI;;AAEhB,cAAK;EACD,KAAK,EAAE,IAAI;EACX,SAAS,EAAE,IAAI;EACf,QAAQ,EAAE,QAAQ;EAClB,KAAK,EAAE,IAAI;EACX,GAAG,EAAE,CAAC;;AACN,gBAAE;EACE,KAAK,EAAE,IAAI;EACX,WAAW,EAAE,IAAI;EACjB,OAAO,EAAE,GAAG;EACZ,UAAU,EAAE,SAAS;;AAEzB,sBAAQ;EACJ,KAAK,EAAE,OAAO;;;AAK1B,SAAU;EACN,UAAU,EAAE,cAAc;EAC1B,WAAW,EAAE,IAAI;EACjB,cAAc,EAAE,IAAI",
"sources": ["defaultTheme.scss"],
"names": [],
"file": "defaultTheme.css"
}

View File

@@ -0,0 +1,4 @@
const fs = require('fs');
const sysPath = require('path');
const css = fs.readFileSync(sysPath.join(__dirname, './defaultTheme.css'));
module.exports = '<style>' + css + '</style>';

View File

@@ -0,0 +1,355 @@
html,
body,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote {
margin: 0;
padding: 0;
font-weight: normal;
-webkit-font-smoothing: antialiased;
}
/* 设置滚动条的样式 */
::-webkit-scrollbar {
width: 6px;
}
/* 外层轨道 */
::-webkit-scrollbar-track {
-webkit-box-shadow: inset006pxrgba(255, 0, 0, 0.3);
background: rgba(0, 0, 0, 0.1);
}
/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
border-radius: 4px;
background: rgba(0, 0, 0, 0.2);
-webkit-box-shadow: inset006pxrgba(0, 0, 0, 0.5);
}
::-webkit-scrollbar-thumb:window-inactive {
background: rgba(0, 0, 0, 0.2);
}
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", SimSun, sans-serif;
font-size: 13px;
line-height: 25px;
color: #393838;
position: relative;
// overflow-x: hidden;
}
table {
margin: 10px 0 15px 0;
border-collapse: collapse;
}
td,
th {
border: 1px solid #ddd;
padding: 3px 10px;
}
th {
padding: 5px 10px;
}
a, a:link, a:visited {
color: #34495e;
text-decoration: none;
}
a:hover, a:focus {
color: #59d69d;
text-decoration: none;
}
a img {
border: none;
}
p {
padding-left: 10px;
margin-bottom: 9px;
}
h1,
h2,
h3,
h4,
h5,
h6 {
color: #404040;
line-height: 36px;
}
h1 {
color: #2c3e50;
font-weight: 600;
// margin-top: 35px;
margin-bottom: 16px;
font-size: 32px;
padding-bottom: 16px;
border-bottom: 1px solid #ddd;
line-height: 50px;
}
h2 {
font-size: 28px;
padding-top: 10px;
padding-bottom: 10px;
}
h3 {
clear: both;
font-weight: 400;
margin-top: 20px;
margin-bottom: 20px;
border-left: 3px solid #59d69d;
padding-left: 8px;
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
font-size: 13px;
}
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
blockquote {
padding: 13px 13px 21px 15px;
margin-bottom: 18px;
font-family: georgia, serif;
font-style: italic;
}
blockquote:before {
font-size: 40px;
margin-left: -10px;
font-family: georgia, serif;
color: #eee;
}
blockquote p {
font-size: 14px;
font-weight: 300;
line-height: 18px;
margin-bottom: 0;
font-style: italic;
}
code,
pre {
font-family: Monaco, Andale Mono, Courier New, monospace;
}
code {
background-color: #fee9cc;
color: rgba(0, 0, 0, 0.75);
padding: 1px 3px;
font-size: 12px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;
}
pre {
display: block;
padding: 14px;
margin: 0 0 18px;
line-height: 16px;
font-size: 11px;
border: 1px solid #d9d9d9;
white-space: pre-wrap;
word-wrap: break-word;
background: #f6f6f6;
}
pre code {
background-color: #f6f6f6;
color: #737373;
font-size: 11px;
padding: 0;
}
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media print {
body,
code,
pre code,
h1,
h2,
h3,
h4,
h5,
h6 {
color: black;
}
table,
pre {
page-break-inside: avoid;
}
}
html,
body {
height: 100%;
}
.table-of-contents {
position: fixed;
top: 61px;
left: 0;
bottom: 0;
overflow-x: hidden;
overflow-y: auto;
width: 260px;
}
.table-of-contents>ul>li>a {
font-size: 20px;
margin-bottom: 16px;
margin-top: 16px;
}
.table-of-contents ul {
// position: fixed;
// top: 80px;
// left: 40px;
overflow: auto;
margin: 0px;
height: 100%;
padding: 0px 0px;
box-sizing: border-box;
list-style-type: none;
}
.table-of-contents ul li {
padding-left: 20px;
}
.table-of-contents a {
padding: 2px 0px;
display: block;
text-decoration: none;
}
.content-right {
// position: relative;
// top: -20px;
max-width: 700px;
margin-left: 290px;
padding-left: 70px;
flex-grow: 1;
h2:target{
padding-top: 80px;
}
}
body>p {
margin-left: 30px;
}
body>table {
margin-left: 30px;
}
body>pre {
margin-left: 30px;
}
.curProject {
position: fixed;
top: 20px;
font-size: 25px;
color: black;
margin-left: -240px;
width: 240px;
padding: 5px;
line-height: 25px;
box-sizing: border-box;
}
.g-doc {
margin-top: 56px;
padding-top: 24px;
display: flex;
}
.curproject-name{
font-size: 42px;
}
.m-header {
background: #32363a;
height: 56px;
line-height: 56px;
padding-left: 60px;
display: flex;
align-items: center;
position: fixed;
z-index: 9;
top: 0;
left: 0;
right: 0;
.title {
font-size: 22px;
color: #fff;
font-weight: normal;
-webkit-font-smoothing: antialiased;
margin: 0;
margin-left: 16px;
padding: 0;
line-height: 56px;
border: none;
}
.nav {
color: #fff;
font-size: 16px;
position: absolute;
right: 32px;
top: 0;
a {
color: #fff;
margin-left: 16px;
padding: 8px;
transition: color .2s;
}
a:hover {
color: #59d69d;
}
}
}
.m-footer {
border-top: 1px solid #ddd;
padding-top: 16px;
padding-bottom: 16px;
}

View File

@@ -0,0 +1,83 @@
const yapi = require('yapi.js');
const baseModel = require('models/base.js');
class genCodeModel extends baseModel {
getName() {
return 'gencode_template_config';
}
getSchema() {
return {
uid: { type: Number},
project_id: { type: Number, required: true },
//是否开启自动同步
tag: { type: String, default: "default" },
tag_desc: { type: String, default: "默认" },
// 模板
template_data: String,
add_time: Number,
up_time: Number
};
}
getByProjectId(id) {
return this.model.findOne({
project_id: id,
tag: 'default'
})
}
listByProjectId(id) {
return this.model.find({
project_id: id
})
}
delByProjectId(project_id){
return this.model.remove({
project_id: project_id
})
}
save(data) {
data.up_time = yapi.commons.time();
let m = new this.model(data);
return m.save();
}
listAll() {
return this.model
.find({})
.select(
'_id uid project_id add_time up_time is_sync_open sync_cron sync_json_url sync_mode old_swagger_content last_sync_time'
)
.sort({ _id: -1 })
.exec();
}
up(data) {
console.log(data)
let id = data.id;
delete data.id;
data.up_time = yapi.commons.time();
return this.model.update({
_id: id
}, data)
}
upById(id, data) {
delete data.id;
data.up_time = yapi.commons.time();
return this.model.update({
_id: id
}, data)
}
del(id){
return this.model.remove({
_id: id
})
}
}
module.exports = genCodeModel;

View File

@@ -0,0 +1,4 @@
module.exports = {
server: true,
client: true
}

View File

@@ -0,0 +1,32 @@
const controller = require('./controller');
module.exports = function(){
this.bindHook('add_router', function(addRouter){
addRouter({
controller: controller,
method: 'get',
path: 'codeGen',
action: "genCode"
});
addRouter({
controller: controller,
method: 'get',
path: 'template/get',
action: "getTemplate"
});
addRouter({
controller: controller,
method: 'post',
path: 'template/save',
action: "saveTemplate"
});
addRouter({
controller: controller,
method: 'delete',
path: 'template/:templateId',
action: "deleteTemplate"
});
})
}