mirror of
https://github.com/YMFE/yapi.git
synced 2025-04-12 15:10:23 +08:00
fix: modify
This commit is contained in:
commit
400974f4bd
@ -22,8 +22,5 @@ module.exports = {
|
||||
"comma-dangle": ["error", "never"],
|
||||
"no-console": ["off"],
|
||||
"import/no-unresolved": ["error"]
|
||||
},
|
||||
"globals": {
|
||||
"ENV_PARAMS": true
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ exports.formatTime = (timestamp) => {
|
||||
return moment.unix(timestamp).format("YYYY-MM-DD HH:mm:ss")
|
||||
}
|
||||
|
||||
// 获取 YAPI LOGO 的 SVG
|
||||
// 参数 length 为 svg 的直径。
|
||||
exports.logoSVG = (length) => (<svg className="svg" width={length} height={length} viewBox="0 0 64 64" version="1.1">
|
||||
<title>Icon</title>
|
||||
<desc>Created with Sketch.</desc>
|
||||
@ -38,6 +40,10 @@ exports.logoSVG = (length) => (<svg className="svg" width={length} height={lengt
|
||||
</g>
|
||||
</svg>);
|
||||
|
||||
// 防抖函数,减少高频触发的函数执行的频率
|
||||
// 请在 constructor 里使用:
|
||||
// import { debounce } from '$/common';
|
||||
// this.func = debounce(this.func, 400);
|
||||
exports.debounce = (func, wait) => {
|
||||
let timeout;
|
||||
return function() {
|
||||
@ -45,3 +51,12 @@ exports.debounce = (func, wait) => {
|
||||
timeout = setTimeout(func, wait);
|
||||
};
|
||||
};
|
||||
|
||||
// 从 Javascript 对象中选取随机属性
|
||||
exports.pickRandomProperty = (obj) => {
|
||||
let result;
|
||||
let count = 0;
|
||||
for (let prop in obj)
|
||||
if (Math.random() < 1/++count) result = prop;
|
||||
return result;
|
||||
}
|
||||
|
@ -46,6 +46,16 @@ class ErrMsg extends Component {
|
||||
title = '你还没有关注项目呢';
|
||||
desc = <span>先去 <a onClick={() => this.props.history.push('/group')}>“项目广场”</a> 逛逛吧, 那里可以添加关注。</span>;
|
||||
break;
|
||||
case 'noInterface':
|
||||
title = '该项目还没有接口呢';
|
||||
desc = '在左侧 “接口列表” 中添加接口';
|
||||
break;
|
||||
case 'noMemberInProject':
|
||||
title = '该项目还没有成员呢';
|
||||
break;
|
||||
case 'noMemberInGroup':
|
||||
title = '该分组还没有成员呢';
|
||||
break;
|
||||
case 'noProject':
|
||||
title = '该分组还没有项目呢';
|
||||
desc = <span>请点击右上角 “<Icon type="plus-circle" />” 按钮新建项目</span>;
|
||||
|
@ -3,6 +3,7 @@
|
||||
font-size: .14rem;
|
||||
line-height: 2;
|
||||
margin-bottom: .24rem;
|
||||
color: rgba(13, 27, 62, 0.43);
|
||||
.icon {
|
||||
font-size: .6rem;
|
||||
margin-bottom: .08rem;
|
||||
|
@ -22,7 +22,7 @@
|
||||
margin-bottom: .08rem;
|
||||
}
|
||||
.link {
|
||||
font-size: .15rem;
|
||||
font-size: .14rem;
|
||||
font-weight: 200;
|
||||
color: #8898aa;
|
||||
line-height: .3rem;
|
||||
|
@ -13,7 +13,8 @@
|
||||
.logo {
|
||||
position: relative;
|
||||
float: left;
|
||||
line-height: .54rem;
|
||||
line-height: .56rem;
|
||||
height: .56rem;
|
||||
.href {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
@ -25,7 +25,11 @@ export default class Run extends Component {
|
||||
|
||||
static propTypes = {
|
||||
data: PropTypes.object,
|
||||
save:PropTypes.func
|
||||
save: PropTypes.oneOfType([
|
||||
PropTypes.bool,
|
||||
PropTypes.func
|
||||
]),
|
||||
saveTip: PropTypes.string
|
||||
}
|
||||
|
||||
state = {
|
||||
@ -50,7 +54,9 @@ export default class Run extends Component {
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
this.getInterfaceState(nextProps)
|
||||
if (nextProps.data._id !== this.props.data._id) {
|
||||
this.getInterfaceState(nextProps)
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -85,7 +91,7 @@ export default class Run extends Component {
|
||||
}
|
||||
const domains = env.concat();
|
||||
if (domain && !env.find(item => item.domain === domain)) {
|
||||
domains.push([{name: 'default', domain}])
|
||||
domains.push({name: 'default', domain})
|
||||
}
|
||||
|
||||
this.setState({
|
||||
@ -97,7 +103,7 @@ export default class Run extends Component {
|
||||
bodyForm: req_body_form.concat(),
|
||||
headers: req_headers.concat(),
|
||||
bodyOther: req_body_other,
|
||||
currDomain: domain || env[0].domain,
|
||||
currDomain: domain || (env[0] && env[0].domain),
|
||||
bodyType: req_body_type || 'form',
|
||||
loading: false
|
||||
});
|
||||
@ -397,11 +403,11 @@ export default class Run extends Component {
|
||||
loading={this.state.loading}
|
||||
>发送</Button>
|
||||
</Tooltip>
|
||||
<Tooltip placement="bottom" title="保存到集合">
|
||||
<Tooltip placement="bottom" title={this.props.saveTip}>
|
||||
<Button
|
||||
onClick={this.props.save}
|
||||
type="primary"
|
||||
style={{marginLeft: 10}}
|
||||
style={{marginLeft: 10, display: this.props.save === false ? 'none' : ''}}
|
||||
>保存</Button>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
@ -7,6 +7,7 @@ import { delFollow, addFollow } from '../../reducer/modules/follow';
|
||||
import PropTypes from 'prop-types';
|
||||
import { withRouter } from 'react-router';
|
||||
import { debounce } from '../../common';
|
||||
import constants from '../../constants/variable.js';
|
||||
|
||||
@connect(
|
||||
state => {
|
||||
@ -53,11 +54,10 @@ class ProjectCard extends Component {
|
||||
uid,
|
||||
projectid: projectData._id,
|
||||
projectname: projectData.name,
|
||||
icon: projectData.icon,
|
||||
color: projectData.color
|
||||
icon: projectData.icon || constants.PROJECT_ICON[0],
|
||||
color: projectData.color || constants.PROJECT_COLOR.blue
|
||||
}
|
||||
this.props.addFollow(param).then((res) => {
|
||||
console.log(res);
|
||||
if (res.payload.data.errcode === 0) {
|
||||
this.props.callbackResult();
|
||||
// message.success('已添加关注!'); // 星号已做出反馈 无需重复提醒用户
|
||||
@ -70,7 +70,7 @@ class ProjectCard extends Component {
|
||||
return (
|
||||
<div className="card-container">
|
||||
<Card bordered={false} className="m-card" onClick={() => this.props.history.push('/project/' + projectData._id)}>
|
||||
<Icon type={projectData.icon || 'star-o'} className="ui-logo" style={{backgroundColor: projectData.color || '#2395f1'}} />
|
||||
<Icon type={projectData.icon || 'star-o'} className="ui-logo" style={{ backgroundColor: constants.PROJECT_COLOR[projectData.color] || constants.PROJECT_COLOR.blue }} />
|
||||
<h4 className="ui-title">{projectData.name || projectData.projectname}</h4>
|
||||
</Card>
|
||||
<div className="card-btns" onClick={projectData.follow || inFollowPage ? this.del : this.add}>
|
||||
|
@ -45,7 +45,7 @@
|
||||
.ant-card-body {
|
||||
background-color: $color-bg-gray;
|
||||
border-radius: 4px;
|
||||
padding-top: .9rem;
|
||||
padding-top: .24rem + .16rem + 1rem;
|
||||
box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);
|
||||
}
|
||||
.ui-logo {
|
||||
@ -55,8 +55,8 @@
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 0;
|
||||
transform: translate(-50%, -20%);
|
||||
font-size: .4rem;
|
||||
transform: translate(-50%, .24rem);
|
||||
font-size: .5rem;
|
||||
color: #fff;
|
||||
background-color: #2395f1;
|
||||
line-height: 1rem;
|
||||
@ -64,7 +64,6 @@
|
||||
}
|
||||
.ui-title {
|
||||
font-size: .19rem;
|
||||
margin-bottom: .08rem;
|
||||
font-weight: normal;
|
||||
overflow: hidden;
|
||||
text-overflow:ellipsis;
|
||||
@ -82,18 +81,45 @@
|
||||
|
||||
}
|
||||
|
||||
.card-panel-s {
|
||||
// .card-panel-s {
|
||||
// .m-card {
|
||||
// .ant-card-body {
|
||||
// padding-top: .6rem;
|
||||
// }
|
||||
// .ui-logo {
|
||||
// width: .6rem;
|
||||
// height: .6rem;
|
||||
// line-height: .6rem;
|
||||
// transform: translate(-50%, -20%);
|
||||
// font-size: .24rem;
|
||||
// background-color: #2395f1;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@media (max-width: 768px) {
|
||||
.m-card {
|
||||
.ant-card-body {
|
||||
padding-top: .6rem;
|
||||
padding-top: .24rem + .16rem + .6rem;
|
||||
}
|
||||
.ui-logo {
|
||||
width: .6rem;
|
||||
height: .6rem;
|
||||
line-height: .6rem;
|
||||
transform: translate(-50%, -20%);
|
||||
font-size: .24rem;
|
||||
background-color: #2395f1;
|
||||
font-size: .3rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 768px) and (max-width: 992px) {
|
||||
.m-card {
|
||||
.ant-card-body {
|
||||
padding-top: .24rem + .16rem + .8rem;
|
||||
}
|
||||
.ui-logo {
|
||||
width: .8rem;
|
||||
height: .8rem;
|
||||
line-height: .8rem;
|
||||
font-size: .4rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,10 @@ class Subnav extends Component {
|
||||
className="g-row m-subnav-menu"
|
||||
>
|
||||
{this.props.data.map((item, index) => {
|
||||
// 若导航标题为两个字,则自动在中间加个空格
|
||||
if (item.name.length === 2) {
|
||||
item.name = item.name[0] + ' ' + item.name[1];
|
||||
}
|
||||
return (
|
||||
<Menu.Item className="item" key={item.name}>
|
||||
<Link to={item.path}>{this.props.data[index].name}</Link>
|
||||
|
@ -8,6 +8,7 @@
|
||||
border: none;
|
||||
.m-subnav-menu {
|
||||
border: none;
|
||||
padding: 0 .24rem;
|
||||
.item {
|
||||
line-height: .54rem;
|
||||
padding: 0 .36rem;
|
||||
|
@ -22,7 +22,59 @@ export default {
|
||||
'PATCH': {
|
||||
request_body: true
|
||||
}
|
||||
}
|
||||
},
|
||||
PROJECT_COLOR: {
|
||||
blue: '#2395f1',
|
||||
green: '#00a854',
|
||||
yellow: '#ffbf00',
|
||||
red: '#f56a00',
|
||||
pink: '#f5317f',
|
||||
cyan: '#00a2ae',
|
||||
gray: '#bfbfbf',
|
||||
purple: '#7265e6'
|
||||
},
|
||||
PROJECT_ICON: [
|
||||
'code-o',
|
||||
'swap',
|
||||
'clock-circle-o',
|
||||
'unlock',
|
||||
'calendar',
|
||||
'play-circle-o',
|
||||
'file-text',
|
||||
'desktop',
|
||||
'hdd',
|
||||
'appstore-o',
|
||||
'line-chart',
|
||||
'mail',
|
||||
'mobile',
|
||||
'notification',
|
||||
'picture',
|
||||
'poweroff',
|
||||
'search',
|
||||
'setting',
|
||||
'share-alt',
|
||||
'shopping-cart',
|
||||
'tag-o',
|
||||
'video-camera',
|
||||
'cloud-o',
|
||||
'star-o',
|
||||
'environment-o',
|
||||
'camera-o',
|
||||
'team',
|
||||
'customer-service',
|
||||
'pay-circle-o',
|
||||
'rocket',
|
||||
'database',
|
||||
'tool',
|
||||
'wifi',
|
||||
'idcard',
|
||||
'medicine-box',
|
||||
'coffee',
|
||||
'safety',
|
||||
'global',
|
||||
'api',
|
||||
'fork',
|
||||
'android-o',
|
||||
'apple-o'
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
|
@ -9,6 +9,8 @@ const { TextArea } = Input;
|
||||
const FormItem = Form.Item;
|
||||
const Option = Select.Option;
|
||||
const RadioGroup = Radio.Group;
|
||||
import { pickRandomProperty } from '../../common';
|
||||
import constants from '../../constants/variable.js';
|
||||
import { withRouter } from 'react-router';
|
||||
import './Addproject.scss';
|
||||
|
||||
@ -62,6 +64,8 @@ class ProjectList extends Component {
|
||||
if (!err) {
|
||||
values.group_id = values.group.split(':')[0];
|
||||
values.group_name = values.group.split(':')[1];
|
||||
values.icon = constants.PROJECT_ICON[0];
|
||||
values.color = pickRandomProperty(constants.PROJECT_COLOR);
|
||||
delete values.group;
|
||||
addProject(values).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
|
@ -3,7 +3,8 @@ import { createDevTools } from 'redux-devtools';
|
||||
import LogMonitor from 'redux-devtools-log-monitor';
|
||||
import DockMonitor from 'redux-devtools-dock-monitor';
|
||||
|
||||
export default createDevTools(
|
||||
|
||||
module.exports = createDevTools(
|
||||
<DockMonitor
|
||||
toggleVisibilityKey="ctrl-h"
|
||||
changePositionKey="ctrl-q"
|
||||
@ -11,4 +12,4 @@ export default createDevTools(
|
||||
>
|
||||
<LogMonitor />
|
||||
</DockMonitor>
|
||||
);
|
||||
);
|
@ -60,18 +60,18 @@ export default class GroupList extends Component {
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
const groupName = this.props.match.params.groupName;
|
||||
const groupId = !isNaN(this.props.match.params.groupId) ? parseInt(this.props.match.params.groupId) : 0;
|
||||
await this.props.fetchGroupList();
|
||||
let currGroup = this.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
if(this.props.groupList.length && groupName){
|
||||
if(this.props.groupList.length && groupId){
|
||||
for(let i = 0;i<this.props.groupList.length;i++){
|
||||
if(this.props.groupList[i].group_name === groupName){
|
||||
if(this.props.groupList[i]._id === groupId){
|
||||
currGroup = this.props.groupList[i];
|
||||
}else{
|
||||
this.props.history.replace(`${currGroup._id}`);
|
||||
}
|
||||
}
|
||||
}else if(!groupName && this.props.groupList.length){
|
||||
}else if(!groupId && this.props.groupList.length){
|
||||
this.props.history.push(`/group/${this.props.groupList[0]._id}`);
|
||||
}
|
||||
this.setState({groupList: this.props.groupList});
|
||||
|
@ -5,6 +5,7 @@ import { Table, Select, Button, Modal, Row, Col, message, Popconfirm } from 'ant
|
||||
import './MemberList.scss';
|
||||
import { autobind } from 'core-decorators';
|
||||
import { fetchGroupMemberList, fetchGroupMsg, addMember, delMember, changeMemberRole } from '../../../reducer/modules/group.js'
|
||||
import ErrMsg from '../../../components/ErrMsg/ErrMsg.js';
|
||||
import UsernameAutoComplete from '../../../components/UsernameAutoComplete/UsernameAutoComplete.js';
|
||||
const Option = Select.Option;
|
||||
|
||||
@ -230,7 +231,7 @@ class MemberList extends Component {
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
<Table columns={columns} dataSource={this.state.userInfo} pagination={false} />
|
||||
<Table columns={columns} dataSource={this.state.userInfo} pagination={false} locale={{emptyText: <ErrMsg type="noMemberInGroup"/>}} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
@ -77,14 +77,49 @@ export default class InterfaceCaseContent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
// updateCase = () => {
|
||||
// const project_id = this.props.match.params.id;
|
||||
// const {
|
||||
// currDomain: domain,
|
||||
// pathname: path,
|
||||
// method,
|
||||
// pathParam: req_params,
|
||||
// query: req_query,
|
||||
// headers: req_headers,
|
||||
// bodyType: req_body_type,
|
||||
// bodyForm: req_body_form,
|
||||
// bodyOther: req_body_other
|
||||
// } = this.postman.state;
|
||||
// const res = await axios.post('/api/col/add_case', {
|
||||
// casename: caseName,
|
||||
// col_id: colId,
|
||||
// project_id,
|
||||
// domain,
|
||||
// path,
|
||||
// method,
|
||||
// req_params,
|
||||
// req_query,
|
||||
// req_headers,
|
||||
// req_body_type,
|
||||
// req_body_form,
|
||||
// req_body_other
|
||||
// });
|
||||
// if (res.data.errcode) {
|
||||
// message.error(res.data.errmsg)
|
||||
// } else {
|
||||
// message.success('添加成功')
|
||||
// this.setState({saveCaseModalVisible: false})
|
||||
// }
|
||||
// }
|
||||
|
||||
render() {
|
||||
const { currCase, currProject } = this.props;
|
||||
const data = Object.assign({}, currCase, currProject);
|
||||
const data = Object.assign({}, currCase, currProject, {_id: currCase._id});
|
||||
return (
|
||||
<div>
|
||||
<h1 style={{marginLeft: 8}}>{currCase.casename}</h1>
|
||||
<div>
|
||||
<Postman data={data} />
|
||||
<Postman data={data} saveTip="更新保存用例" save={false} />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
@ -82,11 +82,11 @@ export default class Run extends Component {
|
||||
|
||||
render () {
|
||||
const { currInterface, currProject } = this.props;
|
||||
const data = Object.assign({}, currInterface, currProject)
|
||||
const data = Object.assign({}, currInterface, currProject, {_id: currInterface._id})
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Postman data={data} save={() => this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} />
|
||||
<Postman data={data} saveTip="保存到集合" save={() => this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} />
|
||||
<AddColModal
|
||||
visible={this.state.saveCaseModalVisible}
|
||||
onCancel={() => this.setState({saveCaseModalVisible: false})}
|
||||
|
@ -3,6 +3,7 @@ import { Table, Card, Badge, Select, Button, Modal, Row, Col, message, Popconfir
|
||||
import PropTypes from 'prop-types';
|
||||
import { autobind } from 'core-decorators';
|
||||
import { connect } from 'react-redux';
|
||||
import ErrMsg from '../../../../components/ErrMsg/ErrMsg.js';
|
||||
import { fetchGroupMemberList } from '../../../../reducer/modules/group.js';
|
||||
import { getProjectMsg, getProjectMemberList, addMember, delMember, changeMemberRole } from '../../../../reducer/modules/project.js';
|
||||
import UsernameAutoComplete from '../../../../components/UsernameAutoComplete/UsernameAutoComplete.js';
|
||||
@ -214,9 +215,9 @@ class ProjectMember extends Component {
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
<Table columns={columns} dataSource={this.state.projectMemberList} pagination={false} />
|
||||
<Table columns={columns} dataSource={this.state.projectMemberList} pagination={false} locale={{emptyText: <ErrMsg type="noMemberInProject"/>}} className="setting-project-member"/>
|
||||
<Card title={this.state.groupName + ' 分组成员 ' + '(' + this.state.groupMemberList.length + ') 人'} noHovering className="setting-group">
|
||||
{this.state.groupMemberList.map((item, index) => {
|
||||
{this.state.groupMemberList.length ? this.state.groupMemberList.map((item, index) => {
|
||||
return (<div key={index} className="card-item">
|
||||
<img src={location.protocol + '//' + location.host + '/api/user/avatar?uid=' + item.uid} className="item-img" />
|
||||
<p className="item-name">{item.username}</p>
|
||||
@ -224,7 +225,7 @@ class ProjectMember extends Component {
|
||||
{item.role === 'owner' ? <p className="item-role">组长</p> : null}
|
||||
{item.role === 'dev' ? <p className="item-role">开发者</p> : null}
|
||||
</div>);
|
||||
})}
|
||||
}): <ErrMsg type="noMemberInGroup"/>}
|
||||
</Card>
|
||||
</div>
|
||||
)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Form, Input, Icon, Tooltip, Select, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover } from 'antd';
|
||||
import { Form, Input, Icon, Tooltip, Select, Button, Row, Col, message, Card, Radio, Alert, Modal, Popover, Affix } from 'antd';
|
||||
import PropTypes from 'prop-types';
|
||||
import { updateProject, delProject, getProjectMsg } from '../../../../reducer/modules/project';
|
||||
import { updateProject, delProject, getProjectMsg, upsetProject } from '../../../../reducer/modules/project';
|
||||
import { fetchGroupMsg } from '../../../../reducer/modules/group';
|
||||
import { connect } from 'react-redux';
|
||||
const { TextArea } = Input;
|
||||
@ -9,9 +9,10 @@ import { withRouter } from 'react-router';
|
||||
const FormItem = Form.Item;
|
||||
const Option = Select.Option;
|
||||
const RadioGroup = Radio.Group;
|
||||
const RadioButton = Radio.Button;
|
||||
import constants from '../../../../constants/variable.js';
|
||||
const confirm = Modal.confirm;
|
||||
import '../Setting.scss';
|
||||
|
||||
// layout
|
||||
const formItemLayout = {
|
||||
labelCol: {
|
||||
@ -39,7 +40,8 @@ let uuid = 0; // 环境配置的计数
|
||||
updateProject,
|
||||
delProject,
|
||||
getProjectMsg,
|
||||
fetchGroupMsg
|
||||
fetchGroupMsg,
|
||||
upsetProject
|
||||
}
|
||||
)
|
||||
@withRouter
|
||||
@ -60,6 +62,7 @@ class ProjectMessage extends Component {
|
||||
getProjectMsg: PropTypes.func,
|
||||
history: PropTypes.object,
|
||||
fetchGroupMsg: PropTypes.func,
|
||||
upsetProject: PropTypes.func,
|
||||
projectList: PropTypes.array,
|
||||
projectMsg: PropTypes.object
|
||||
}
|
||||
@ -90,6 +93,7 @@ class ProjectMessage extends Component {
|
||||
updateProject(assignValue).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('修改成功! ');
|
||||
// this.props.history.push('/group');
|
||||
} else {
|
||||
message.error(res.payload.data.errmsg);
|
||||
}
|
||||
@ -136,22 +140,22 @@ class ProjectMessage extends Component {
|
||||
showConfirm = () => {
|
||||
let that = this;
|
||||
confirm({
|
||||
title: "确认删除 "+that.props.projectMsg.name+" 分组吗?",
|
||||
content: <div style={{marginTop:'10px', fontSize: '12px', lineHeight: '25px'}}>
|
||||
<Alert message="警告:此操作非常危险,会删除该分组下面所有项目和接口,并且无法恢复!" type="warning" banner/>
|
||||
<div style={{marginTop: '15px'}}>
|
||||
<p style={{marginBottom: '8px'}}><b>请输入项目名称确认此操作:</b></p>
|
||||
title: "确认删除 " + that.props.projectMsg.name + " 分组吗?",
|
||||
content: <div style={{ marginTop: '10px', fontSize: '12px', lineHeight: '25px' }}>
|
||||
<Alert message="警告:此操作非常危险,会删除该分组下面所有项目和接口,并且无法恢复!" type="warning" banner />
|
||||
<div style={{ marginTop: '15px' }}>
|
||||
<p style={{ marginBottom: '8px' }}><b>请输入项目名称确认此操作:</b></p>
|
||||
<Input id="project_name" size="large" />
|
||||
</div>
|
||||
</div>,
|
||||
onOk() {
|
||||
let groupName = document.getElementById('project_name').value;
|
||||
if(that.props.projectMsg.name !== groupName){
|
||||
if (that.props.projectMsg.name !== groupName) {
|
||||
message.error('分组名称有误')
|
||||
return new Promise((resolve, reject)=>{
|
||||
return new Promise((resolve, reject) => {
|
||||
reject('error')
|
||||
})
|
||||
}else{
|
||||
} else {
|
||||
that.props.delProject(that.props.projectId).then((res) => {
|
||||
if (res.payload.data.errcode == 0) {
|
||||
message.success('删除成功!');
|
||||
@ -166,6 +170,25 @@ class ProjectMessage extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
// 修改项目头像的背景颜色
|
||||
changeProjectColor = (e) => {
|
||||
const { _id, color, icon } = this.props.projectMsg;
|
||||
this.props.upsetProject({ id: _id, color: e.target.value || color, icon }).then((res) => {
|
||||
if (res.payload.data.errcode === 0) {
|
||||
this.props.getProjectMsg(this.props.projectId);
|
||||
}
|
||||
});
|
||||
}
|
||||
// 修改项目头像的图标
|
||||
changeProjectIcon = (e) => {
|
||||
const { _id, color, icon } = this.props.projectMsg;
|
||||
this.props.upsetProject({ id: _id, color, icon: e.target.value || icon }).then((res) => {
|
||||
if (res.payload.data.errcode === 0) {
|
||||
this.props.getProjectMsg(this.props.projectId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
await this.props.getProjectMsg(this.props.projectId);
|
||||
const groupMsg = await this.props.fetchGroupMsg(this.props.projectMsg.group_id);
|
||||
@ -174,10 +197,10 @@ class ProjectMessage extends Component {
|
||||
});
|
||||
}
|
||||
|
||||
render () {
|
||||
render() {
|
||||
const { getFieldDecorator, getFieldValue } = this.props.form;
|
||||
const { projectMsg } = this.props;
|
||||
console.log(projectMsg);
|
||||
const mockUrl = location.protocol + '//' + location.hostname + (location.port !== "" ? ":" + location.port : "") + `/mock/${projectMsg._id}${projectMsg.basepath}+$接口请求路径`
|
||||
let initFormValues = {};
|
||||
let envMessage = [];
|
||||
const { name, basepath, desc, env, project_type } = projectMsg;
|
||||
@ -192,7 +215,7 @@ class ProjectMessage extends Component {
|
||||
const secondIndex = 'next' + index; // 为保证key的唯一性
|
||||
return (
|
||||
<Row key={index} type="flex" justify="space-between" align={index === 0 ? 'middle' : 'top'}>
|
||||
<Col span={10} offset={2}>
|
||||
<Col span={11}>
|
||||
<FormItem
|
||||
label={index === 0 ? (
|
||||
<span>环境名称</span>) : ''}
|
||||
@ -226,7 +249,7 @@ class ProjectMessage extends Component {
|
||||
)}
|
||||
</FormItem>
|
||||
</Col>
|
||||
<Col span={10}>
|
||||
<Col span={11}>
|
||||
<FormItem
|
||||
label={index === 0 ? (
|
||||
<span>环境域名</span>) : ''}
|
||||
@ -239,13 +262,14 @@ class ProjectMessage extends Component {
|
||||
rules: [{
|
||||
required: false,
|
||||
whitespace: true,
|
||||
message: "请输入环境域名",
|
||||
validator(rule, value, callback) {
|
||||
if (value) {
|
||||
if (value.length === 0) {
|
||||
callback('请输入环境域名');
|
||||
} else if (!/\S/.test(value)) {
|
||||
callback('请输入环境域名');
|
||||
} else if (!/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}$/.test(value)) {
|
||||
callback('域名格式错误');
|
||||
} else {
|
||||
return callback();
|
||||
}
|
||||
@ -285,19 +309,23 @@ class ProjectMessage extends Component {
|
||||
</Row>
|
||||
);
|
||||
});
|
||||
|
||||
const colorSelector = (<RadioGroup onChange={this.onChange} value={1}>
|
||||
<Radio value={1} style={{color: 'red'}}></Radio>
|
||||
<Radio value={2}></Radio>
|
||||
<Radio value={3}></Radio>
|
||||
<Radio value={4}></Radio>
|
||||
const colorArr = Object.entries(constants.PROJECT_COLOR);
|
||||
const colorSelector = (<RadioGroup onChange={this.changeProjectColor} value={projectMsg.color} className="color">
|
||||
{colorArr.map((item, index) => {
|
||||
return (<RadioButton key={index} value={item[0]} style={{ backgroundColor: item[1], color: '#fff', fontWeight: 'bold' }}>{item[0] === projectMsg.color ? <Icon type="check" /> : null}</RadioButton>);
|
||||
})}
|
||||
</RadioGroup>);
|
||||
const iconSelector = (<RadioGroup onChange={this.changeProjectIcon} value={projectMsg.icon} className="icon">
|
||||
{constants.PROJECT_ICON.map((item) => {
|
||||
return (<RadioButton key={item} value={item} style={{ fontWeight: 'bold' }}><Icon type={item} /></RadioButton>);
|
||||
})}
|
||||
</RadioGroup>);
|
||||
return (
|
||||
<div className="m-panel">
|
||||
<Row className="project-setting">
|
||||
<Col sm={6} lg={3} className="setting-logo">
|
||||
<Popover placement="bottom" title={colorSelector} content={'content'} trigger="click">
|
||||
<Icon type={projectMsg.icon || 'star-o'} className="ui-logo" style={{backgroundColor: projectMsg.color || '#2395f1'}} />
|
||||
<Popover placement="bottom" title={colorSelector} content={iconSelector} trigger="click" overlayClassName="change-project-container">
|
||||
<Icon type={projectMsg.icon || 'star-o'} className="ui-logo" style={{ backgroundColor: constants.PROJECT_COLOR[projectMsg.color] || constants.PROJECT_COLOR.blue }} />
|
||||
</Popover>
|
||||
</Col>
|
||||
<Col sm={18} lg={21} className="setting-intro">
|
||||
@ -307,6 +335,13 @@ class ProjectMessage extends Component {
|
||||
</Row>
|
||||
<hr className="breakline" />
|
||||
<Form>
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="项目ID"
|
||||
>
|
||||
<span >{this.props.projectMsg._id}</span>
|
||||
|
||||
</FormItem>
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="项目名称"
|
||||
@ -332,7 +367,7 @@ class ProjectMessage extends Component {
|
||||
{...formItemLayout}
|
||||
label={(
|
||||
<span>
|
||||
基本路径
|
||||
接口基本路径
|
||||
<Tooltip title="基本路径为空表示根路径">
|
||||
<Icon type="question-circle-o" />
|
||||
</Tooltip>
|
||||
@ -342,13 +377,29 @@ class ProjectMessage extends Component {
|
||||
{getFieldDecorator('basepath', {
|
||||
initialValue: initFormValues.basepath,
|
||||
rules: [{
|
||||
required: false, message: '请输入项目基本路径! '
|
||||
required: false, message: '请输入基本路径! '
|
||||
}]
|
||||
})(
|
||||
<Input />
|
||||
)}
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label={(
|
||||
<span>
|
||||
MOCK地址
|
||||
<Tooltip title="具体使用方法请查看文档">
|
||||
<Icon type="question-circle-o" />
|
||||
</Tooltip>
|
||||
</span>
|
||||
)}
|
||||
>
|
||||
|
||||
<Input disabled value={mockUrl} onChange={()=>{}} />
|
||||
|
||||
</FormItem>
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="描述"
|
||||
@ -368,10 +419,7 @@ class ProjectMessage extends Component {
|
||||
label="环境配置"
|
||||
>
|
||||
{envSettingItems}
|
||||
</FormItem>
|
||||
|
||||
<FormItem {...formItemLayout}>
|
||||
<Button type="dashed" onClick={this.add} style={{ width: '60%' }}>
|
||||
<Button type="default" onClick={this.add} style={{ width: '50%' }}>
|
||||
<Icon type="plus" /> 添加环境配置
|
||||
</Button>
|
||||
</FormItem>
|
||||
@ -395,22 +443,19 @@ class ProjectMessage extends Component {
|
||||
<Icon type="unlock" />公开<br /><span className="radio-desc">任何人都可以索引并查看项目信息</span>
|
||||
</Radio>
|
||||
</RadioGroup>
|
||||
)}
|
||||
)}
|
||||
</FormItem>
|
||||
</Form>
|
||||
<Row>
|
||||
<Col sm={{ offset: 6 }} lg={{ offset: 3 }}>
|
||||
<Button className="m-btn" icon="plus" type="primary"
|
||||
onClick={this.handleOk}
|
||||
>修改项目</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<hr className="breakline" />
|
||||
<Affix offsetBottom={0}>
|
||||
<div className="btnwrap-changeproject">
|
||||
<Button className="m-btn btn-save" icon="save" type="primary" onClick={this.handleOk} >保 存</Button>
|
||||
</div>
|
||||
</Affix>
|
||||
|
||||
<FormItem
|
||||
{...formItemLayout}
|
||||
label="危险操作"
|
||||
className="danger-container"
|
||||
>
|
||||
<Card noHovering={true} className="card-danger">
|
||||
<div className="card-danger-content">
|
||||
|
@ -14,6 +14,7 @@
|
||||
.ant-card-body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: .24rem !important;
|
||||
}
|
||||
.card-danger-content {
|
||||
flex: 1;
|
||||
@ -24,7 +25,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
.setting-project-member {
|
||||
border: 1px solid #e9e9e9;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.setting-group {
|
||||
margin-top: .48rem;
|
||||
border-radius: 2px;
|
||||
.ant-card-head {
|
||||
background-color: #eee;
|
||||
}
|
||||
@ -83,10 +91,107 @@
|
||||
width: 1rem;
|
||||
height: 1rem;
|
||||
border-radius: 50%;
|
||||
font-size: .6rem;
|
||||
font-size: .5rem;
|
||||
color: #fff;
|
||||
background-color: #2395f1;
|
||||
line-height: 1rem;
|
||||
box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);
|
||||
position: relative;
|
||||
&:after {
|
||||
opacity: 0;
|
||||
content: '点击修改';
|
||||
display: block;
|
||||
transition: all .4s;
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
border-radius: 50%;
|
||||
font-size: .14rem;
|
||||
color: #fff;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgba(0,0,0, .25);
|
||||
}
|
||||
&:hover:after {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.change-project-container {
|
||||
max-width: 320px;
|
||||
.ant-popover-inner {
|
||||
text-align: center;
|
||||
}
|
||||
.ant-popover-title {
|
||||
padding: 8px .16rem;
|
||||
height: auto;
|
||||
}
|
||||
.ant-radio-button-wrapper {
|
||||
font-size: 16px;
|
||||
border: none;
|
||||
&:first-child {
|
||||
border: none;
|
||||
}
|
||||
&:not(:first-child)::before {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
.ant-radio-button-wrapper-checked {
|
||||
box-shadow: none;
|
||||
color: #fff;
|
||||
background-color: #2395f1;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.color {
|
||||
// .ant-radio-button-wrapper {
|
||||
// &:first-child {
|
||||
// border: none;
|
||||
// }
|
||||
// }
|
||||
.ant-radio-button-wrapper-checked {
|
||||
border-radius: 0;
|
||||
&:hover {
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.danger-container {
|
||||
margin-top: .48rem;
|
||||
}
|
||||
.btnwrap-changeproject {
|
||||
text-align: center;
|
||||
padding: .24rem 0;
|
||||
margin: 0 -.24rem;
|
||||
background: #fff;
|
||||
background-image: linear-gradient(45deg, #d9d9d9 25%, transparent 0),linear-gradient(45deg, transparent 75%, #d9d9d9 0);
|
||||
background-size: 4px 4px;
|
||||
.btn-save {
|
||||
background-color: #32325d;
|
||||
font-size: .15rem;
|
||||
font-weight: 200;
|
||||
letter-spacing: 1px;
|
||||
border: none;
|
||||
line-height: .4rem;
|
||||
height: .4rem;
|
||||
padding: 0 .24rem;
|
||||
margin-right: .24rem;
|
||||
box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
|
||||
transform: translateY(0);
|
||||
transition: all .2s;
|
||||
&:focus {
|
||||
background-color: #43458b;
|
||||
}
|
||||
&:hover {
|
||||
transform: translateY(-1px);
|
||||
background-color: #43458b;
|
||||
}
|
||||
&:active {
|
||||
transform: translateY(1px);
|
||||
background-color: #32325d;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,120 +0,0 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Row, Col, Menu, AutoComplete, Input, Icon } from 'antd'
|
||||
import axios from 'axios'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import Avatar from './Avatar.js'
|
||||
|
||||
const Option = AutoComplete.Option;
|
||||
@connect(
|
||||
state => {
|
||||
console.log(state);
|
||||
return {
|
||||
curUid: state.user.uid + '',
|
||||
curUserName: state.user.userName,
|
||||
curUserRole: state.user.role
|
||||
}
|
||||
}
|
||||
)
|
||||
class LeftMenu extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
dataSource: []
|
||||
}
|
||||
this.searchSign = 0;
|
||||
this._searchSign = 0;
|
||||
this.interval = null;
|
||||
}
|
||||
|
||||
static propTypes = {
|
||||
curUid: PropTypes.string,
|
||||
curUserName: PropTypes.string,
|
||||
curUserRole: PropTypes.string
|
||||
}
|
||||
|
||||
//延迟搜索
|
||||
handleSearch = (value) => {
|
||||
if(!value || value.length < 1) return ;
|
||||
this.searchSign = this.searchSign + 1;
|
||||
this.interval && clearInterval(this.interval)
|
||||
this.interval = setInterval(() => {
|
||||
if (this.searchSign === this._searchSign) {
|
||||
this.interval = clearInterval(this.interval)
|
||||
axios.get('/api/user/search?q=' + value).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
this.setState({
|
||||
dataSource: res.data.data
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
} else {
|
||||
this._searchSign = this.searchSign;
|
||||
}
|
||||
}, 60)
|
||||
|
||||
}
|
||||
|
||||
renderOption = (item) => {
|
||||
return (
|
||||
<Option key={item.uid} text={item.username} >
|
||||
<Link to={"/user/profile/" + item.uid} > {item.username} </Link>
|
||||
</Option>
|
||||
)
|
||||
}
|
||||
|
||||
render() {
|
||||
const menus = [{
|
||||
title: '个人资料',
|
||||
path: `/user/profile/${this.props.curUid}`
|
||||
}
|
||||
]
|
||||
if(this.props.curUserRole === 'admin'){
|
||||
menus.push({
|
||||
title: '用户管理',
|
||||
path: '/user/list'
|
||||
})
|
||||
}
|
||||
let content = menus.map((menu) => {
|
||||
return (
|
||||
<Menu.Item key={'#' + menu.path} >
|
||||
<Link to={menu.path} >{menu.title}</Link>
|
||||
</Menu.Item>
|
||||
)
|
||||
})
|
||||
|
||||
const { dataSource } = this.state;
|
||||
return (<div className="user-list">
|
||||
<div className='cur-user'>
|
||||
<Avatar />
|
||||
<div className='user-name'><span>用户名 :</span>{`${this.props.curUserName}`}</div>
|
||||
</div>
|
||||
<Row type="flex" justify="start" className="search">
|
||||
<Col span="24">
|
||||
<div className="certain-category-search-wrapper" style={{ width: "100%" }}>
|
||||
<AutoComplete
|
||||
className="certain-category-search"
|
||||
dropdownClassName="certain-category-search-dropdown"
|
||||
size="large"
|
||||
style={{ width: '100%' }}
|
||||
dataSource={dataSource.map(this.renderOption)}
|
||||
onSearch={this.handleSearch}
|
||||
placeholder="搜索用户"
|
||||
optionLabelProp="text"
|
||||
>
|
||||
<Input suffix={<Icon type="search" className="certain-category-icon" />} />
|
||||
</AutoComplete>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
<Menu mode='inline' defaultSelectedKeys={[location.hash]} className="user-nav">
|
||||
{content}
|
||||
</Menu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default LeftMenu
|
@ -2,7 +2,6 @@ import './index.scss'
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { Route } from 'react-router-dom'
|
||||
// import LeftMenu from './LeftMenu.js'
|
||||
import List from './List.js'
|
||||
import PropTypes from 'prop-types'
|
||||
import Profile from './Profile.js'
|
||||
|
@ -1,55 +0,0 @@
|
||||
import './index.scss'
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import Header from '../../components/Header/Header.js'
|
||||
|
||||
|
||||
@connect(
|
||||
state => {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
// fetchInterfaceData,
|
||||
// projectMember,
|
||||
// closeProjectMember
|
||||
}
|
||||
)
|
||||
|
||||
class user extends Component {
|
||||
static propTypes = {
|
||||
fetchInterfaceData: PropTypes.func,
|
||||
interfaceData: PropTypes.array,
|
||||
projectMember: PropTypes.func,
|
||||
closeProjectMember: PropTypes.func,
|
||||
modalVisible: PropTypes.bool
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
}
|
||||
|
||||
componentWillMount () {
|
||||
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Header />
|
||||
|
||||
<section className="user-box">
|
||||
<InterfaceList projectMember={projectMember} />
|
||||
<InterfaceMode modalVisible={modalVisible} closeProjectMember={this.props.closeProjectMember} />
|
||||
<InterfaceTable data={interfaceData} />
|
||||
</section>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default Interface
|
@ -2,11 +2,7 @@ import Header from '../components/Header/Header.js'
|
||||
import Home from './Home/Home.js'
|
||||
import Login from './Login/LoginContainer.js'
|
||||
import Group from './Group/Group.js'
|
||||
import Interface from './Interface/Interface.js'
|
||||
import Project from './Project/Project.js'
|
||||
import News from './News/News.js'
|
||||
import AddInterface from './AddInterface/AddInterface.js'
|
||||
import DevTools from './DevTools/DevTools.js'
|
||||
import Follows from './Follows/Follows.js'
|
||||
import AddProject from './AddProject/AddProject.js'
|
||||
|
||||
@ -15,11 +11,7 @@ export {
|
||||
Home,
|
||||
Login,
|
||||
Group,
|
||||
Interface,
|
||||
Project,
|
||||
AddInterface,
|
||||
News,
|
||||
DevTools,
|
||||
Follows,
|
||||
AddProject
|
||||
}
|
||||
|
@ -3,17 +3,28 @@ import ReactDOM from 'react-dom'
|
||||
import App from './Application'
|
||||
import { Provider } from 'react-redux'
|
||||
import createStore from './reducer/create';
|
||||
import { DevTools } from './containers';
|
||||
import './styles/theme.less'
|
||||
|
||||
const store = createStore();
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<div>
|
||||
<App />
|
||||
</div>
|
||||
</Provider>,
|
||||
document.getElementById('yapi')
|
||||
)
|
||||
} else {
|
||||
const DevTools = require('./containers/DevTools/DevTools.js')
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<div>
|
||||
<App />
|
||||
<DevTools />
|
||||
</div>
|
||||
</Provider>,
|
||||
document.getElementById('yapi')
|
||||
)
|
||||
}
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store}>
|
||||
<div>
|
||||
<App />
|
||||
<DevTools />
|
||||
</div>
|
||||
</Provider>,
|
||||
document.getElementById('yapi')
|
||||
)
|
||||
|
@ -8,15 +8,13 @@ export default function createStore(initialState = {}) {
|
||||
const middleware = [thunkMiddleware, promiseMiddleware, messageMiddleware];
|
||||
|
||||
let finalCreateStore;
|
||||
if (ENV_PARAMS.development) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
finalCreateStore = applyMiddleware(...middleware)(_createStore);
|
||||
} else {
|
||||
finalCreateStore = compose(
|
||||
applyMiddleware(...middleware),
|
||||
|
||||
window.devToolsExtension ? window.devToolsExtension() : require('../containers/DevTools/DevTools').default.instrument()
|
||||
window.devToolsExtension ? window.devToolsExtension() : require('../containers/DevTools/DevTools').instrument()
|
||||
)(_createStore);
|
||||
|
||||
} else {
|
||||
finalCreateStore = applyMiddleware(...middleware)(_createStore);
|
||||
}
|
||||
|
||||
const store = finalCreateStore(reducer, initialState);
|
||||
|
@ -8,6 +8,7 @@ const PROJECT_ADD = 'yapi/project/PROJECT_ADD';
|
||||
const PROJECT_DEL = 'yapi/project/PROJECT_DEL';
|
||||
// const CHANGE_TABLE_LOADING = 'yapi/project/CHANGE_TABLE_LOADING';
|
||||
const PROJECT_UPDATE = 'yapi/project/PROJECT_UPDATE';
|
||||
const PROJECT_UPSET = 'yapi/project/PROJECT_UPSET';
|
||||
const GET_CURR_PROJECT = 'yapi/project/GET_CURR_PROJECT'
|
||||
const GET_PEOJECT_MEMBER = 'yapi/project/GET_PEOJECT_MEMBER';
|
||||
const ADD_PROJECT_MEMBER = 'yapi/project/ADD_PROJECT_MEMBER';
|
||||
@ -139,7 +140,7 @@ export function getProjectMemberList(id) {
|
||||
// }
|
||||
|
||||
export function addProject(data) {
|
||||
const { name, prd_host, basepath, desc, group_id, group_name, protocol } = data;
|
||||
const { name, prd_host, basepath, desc, group_id, group_name, protocol, icon, color } = data;
|
||||
const param = {
|
||||
name,
|
||||
prd_host,
|
||||
@ -147,7 +148,9 @@ export function addProject(data) {
|
||||
basepath,
|
||||
desc,
|
||||
group_id,
|
||||
group_name
|
||||
group_name,
|
||||
icon,
|
||||
color
|
||||
};
|
||||
return {
|
||||
type: PROJECT_ADD,
|
||||
@ -155,6 +158,7 @@ export function addProject(data) {
|
||||
};
|
||||
}
|
||||
|
||||
// 修改项目
|
||||
export function updateProject(data) {
|
||||
const { name, project_type, basepath, desc, _id, env } = data;
|
||||
const param = {
|
||||
@ -171,6 +175,15 @@ export function updateProject(data) {
|
||||
};
|
||||
}
|
||||
|
||||
// 修改项目头像
|
||||
export function upsetProject(param) {
|
||||
return {
|
||||
type: PROJECT_UPSET,
|
||||
payload: axios.post('/api/project/upset', param)
|
||||
};
|
||||
}
|
||||
|
||||
// 删除项目
|
||||
export function delProject(id) {
|
||||
const param = { id };
|
||||
return {
|
||||
|
@ -174,6 +174,10 @@
|
||||
@label-required-color : @highlight-color;
|
||||
@label-color : @heading-color;
|
||||
@form-item-margin-bottom : 24px;
|
||||
// 处理添加环境配置下边距重合的 bug
|
||||
.ant-form-item > .ant-form-item, .ant-form-item :not(.ant-form) > .ant-form-item {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
@form-item-trailing-colon : true;
|
||||
|
||||
// Input
|
||||
@ -250,11 +254,11 @@
|
||||
|
||||
// Table
|
||||
// --
|
||||
@table-header-bg: @background-color-base;
|
||||
@table-header-bg: #eee;
|
||||
@table-header-sort-bg: @background-color-active;
|
||||
@table-row-hover-bg: @primary-1;
|
||||
@table-selected-row-bg: #fafafa;
|
||||
@table-padding-vertical: 16px + 2px;
|
||||
@table-padding-vertical: 16px;
|
||||
@table-padding-horizontal: 8px + 2px;
|
||||
|
||||
// Tag
|
||||
|
@ -3,6 +3,8 @@
|
||||
<p style='text-indent:2em;line-height:1.8em'>yapi的Mock功能可以根据用户的输入接口信息如协议、URL、接口名、请求头、请求参数、mock规则([点击到Mock规则](#mock))生成Mock接口,这些接口会自动生成模拟数据,创建者可以自由构造需要的数据。而且与常见的Mock方式如将Mock写在代码里和JS拦截等相比yapi的Mock在使用场景和效率和复杂度上是相差甚远的,正是由于yapi的Mock是一个第三方平台,那么在团队开发时任何人都可以权限许可下创建、修改接口信息等操作,这对于团队开发是很有好处的。
|
||||
|
||||
**mock地址解析**:yapi平台网址+mock+**您的项目id**+**接口实际请求path**
|
||||
|
||||
注:项目id可以在项目设置里查看到
|
||||
|
||||
</p>
|
||||
<img src="./images/mock.jpg" style="width: 50%" />
|
||||
@ -27,11 +29,14 @@ $.post(prefix+'/baseapi/path', {username: 'xxx'}, function(res){
|
||||
```` nginx
|
||||
location /baseapi
|
||||
{
|
||||
proxy_pass http://http://yapi.local.qunar.com:3000/mock/2817/;
|
||||
proxy_pass http://yapi.local.qunar.com:3000/mock/2817/baseapi; #baseapi后面没有"/"
|
||||
}
|
||||
````
|
||||
|
||||
#### 1.2.2 基于ykit Jerry代理
|
||||
|
||||
假设您本地服务器访问地址是: http://xxx.com
|
||||
|
||||
<img src="./images/ykit.jpg" />
|
||||
|
||||
|
||||
|
9668
npm-shrinkwrap.json
generated
Normal file
9668
npm-shrinkwrap.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
3476
package-lock.json
generated
3476
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -46,7 +46,7 @@
|
||||
"eslint-plugin-import": "^2.2.0",
|
||||
"eslint-plugin-react": "^7.1.0",
|
||||
"express": "^4.15.3",
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
"extract-text-webpack-plugin": "2.0.0",
|
||||
"fast-sass-loader": "^1.2.5",
|
||||
"fs-extra": "^3.0.1",
|
||||
"gulp": "^3.9.1",
|
||||
@ -58,6 +58,7 @@
|
||||
"jsonwebtoken": "^7.4.1",
|
||||
"koa": "^2.0.0",
|
||||
"koa-bodyparser": "^3.2.0",
|
||||
"koa-compress": "^2.0.0",
|
||||
"koa-logger": "^3.0.0",
|
||||
"koa-mysql-session": "0.0.2",
|
||||
"koa-router": "^7.0.1",
|
||||
@ -83,10 +84,8 @@
|
||||
"rc-scroll-anim": "^1.0.7",
|
||||
"react": "^15.6.1",
|
||||
"react-dom": "^15.6.1",
|
||||
"react-monaco-editor": "^0.8.1",
|
||||
"react-redux": "^5.0.5",
|
||||
"react-router-dom": "^4.1.1",
|
||||
"react-router-redux": "^4.0.8",
|
||||
"react-scripts": "1.0.10",
|
||||
"redux": "^3.7.1",
|
||||
"redux-promise": "^0.5.3",
|
||||
@ -101,9 +100,7 @@
|
||||
"universal-cookie": "^2.0.8",
|
||||
"url": "^0.11.0",
|
||||
"validate-commit-msg": "^2.12.2",
|
||||
"wangeditor": "^3.0.4",
|
||||
"ykit-config-antd": "^0.1.3",
|
||||
"ykit-config-react": "^0.4.4"
|
||||
"ykit-config-antd": "^0.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-plugin-import": "^1.3.1",
|
||||
|
@ -10,6 +10,7 @@ import router from './router.js';
|
||||
import websockify from 'koa-websocket';
|
||||
import websocket from './websocket.js'
|
||||
|
||||
var compress = require('koa-compress')
|
||||
|
||||
yapi.connect = dbModule.connect();
|
||||
const app = websockify(new Koa());
|
||||
@ -23,6 +24,11 @@ app.use(router.allowedMethods());
|
||||
|
||||
websocket(app);
|
||||
|
||||
app.use(compress({
|
||||
threshold: 50480,
|
||||
flush: require('zlib').Z_SYNC_FLUSH
|
||||
}))
|
||||
|
||||
app.use( async (ctx, next) => {
|
||||
if( /^\/(?!api)[a-zA-Z0-9\/\-_]*$/.test(ctx.path) ){
|
||||
ctx.path = "/"
|
||||
@ -34,7 +40,7 @@ app.use( async (ctx, next) => {
|
||||
})
|
||||
app.use(koaStatic(
|
||||
yapi.path.join(yapi.WEBROOT, 'static'),
|
||||
{index: indexFile}
|
||||
{index: indexFile, gzip: true}
|
||||
));
|
||||
|
||||
app.listen(yapi.WEBCONFIG.port);
|
||||
|
@ -158,6 +158,56 @@ class interfaceColController extends baseController{
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加一个接口用例
|
||||
* @interface /col/up_case
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {number} id
|
||||
* @param {String} casename
|
||||
* @param {String} domain
|
||||
* @param {String} path
|
||||
* @param {String} method
|
||||
* @param {Object} req_query
|
||||
* @param {Object} req_headers
|
||||
* @param {String} req_body_type
|
||||
* @param {Array} req_body_form
|
||||
* @param {String} req_body_other
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
async upCase(ctx){
|
||||
try{
|
||||
let params = ctx.request.body;
|
||||
params = yapi.commons.handleParams(params, {
|
||||
id: 'number',
|
||||
casename: 'string',
|
||||
domain: 'string',
|
||||
method: 'string'
|
||||
});
|
||||
|
||||
if (!params.id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例id不能为空');
|
||||
}
|
||||
|
||||
|
||||
if(!params.casename){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '用例名称不能为空');
|
||||
}
|
||||
|
||||
params.uid = this.getUid();
|
||||
|
||||
let result = await this.caseModel.up(params);
|
||||
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个接口用例详情
|
||||
* @interface /col/case
|
||||
|
@ -106,11 +106,32 @@ class projectController extends baseController {
|
||||
icon: params.icon,
|
||||
color: params.color,
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
up_time: yapi.commons.time(),
|
||||
env: [{ name: 'local', domain: 'http://127.0.0.1' }]
|
||||
};
|
||||
|
||||
try {
|
||||
let result = await this.Model.save(data);
|
||||
let colInst = yapi.getInst(interfaceColModel);
|
||||
let catInst = yapi.getInst(interfaceCatModel);
|
||||
if (result._id) {
|
||||
await colInst.save({
|
||||
name: '公共测试集',
|
||||
project_id: result._id,
|
||||
desc: '公共测试集',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
await catInst.save({
|
||||
name: '公共分类',
|
||||
project_id: result._id,
|
||||
desc: '公共分类',
|
||||
uid: this.getUid(),
|
||||
add_time: yapi.commons.time(),
|
||||
up_time: yapi.commons.time()
|
||||
})
|
||||
}
|
||||
let username = this.getUsername();
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 添加了项目 "${params.name}"`,
|
||||
@ -158,7 +179,7 @@ class projectController extends baseController {
|
||||
params.role = params.role === 'owner' ? 'owner' : 'dev';
|
||||
|
||||
let userdata = await this.getUserdata(params.member_uid, params.role);
|
||||
if(userdata === null){
|
||||
if (userdata === null) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '成员uid不存在')
|
||||
}
|
||||
|
||||
@ -212,7 +233,7 @@ class projectController extends baseController {
|
||||
let result = await this.Model.delMember(params.id, params.member_uid);
|
||||
let username = this.getUsername();
|
||||
let project = await this.Model.get(params.id);
|
||||
let member = await yapi.getInst(userModel).findById(params.member_uid);
|
||||
let member = await yapi.getInst(userModel).findById(params.member_uid);
|
||||
yapi.commons.saveLog({
|
||||
content: `用户 "${username}" 删除了项目 "${project.name}" 中的成员 "${member.username}"`,
|
||||
type: 'project',
|
||||
@ -227,11 +248,11 @@ class projectController extends baseController {
|
||||
}
|
||||
|
||||
|
||||
async getUserdata(uid, role){
|
||||
async getUserdata(uid, role) {
|
||||
role = role || 'dev';
|
||||
let userInst = yapi.getInst(userModel);
|
||||
let userData = await userInst.findById(uid);
|
||||
if(!userData){
|
||||
if (!userData) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
@ -285,7 +306,7 @@ class projectController extends baseController {
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.getBaseInfo(params.id);
|
||||
if(!result){
|
||||
if (!result) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '不存在的项目');
|
||||
}
|
||||
result = result.toObject();
|
||||
@ -317,19 +338,19 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空');
|
||||
}
|
||||
|
||||
let auth =await this.checkAuth(group_id, 'group', 'edit')
|
||||
let auth = await this.checkAuth(group_id, 'group', 'edit')
|
||||
try {
|
||||
let result = await this.Model.list(group_id, auth);
|
||||
let follow = await this.followModel.list(this.getUid());
|
||||
let uids = [];
|
||||
result.forEach((item, index) => {
|
||||
result[index] = item.toObject();
|
||||
let f = _.find(follow, (fol)=>{
|
||||
let f = _.find(follow, (fol) => {
|
||||
return fol.projectid === item._id
|
||||
})
|
||||
if(f){
|
||||
if (f) {
|
||||
result[index].follow = true;
|
||||
}else{
|
||||
} else {
|
||||
result[index].follow = false;
|
||||
}
|
||||
if (uids.indexOf(item.uid) === -1) {
|
||||
@ -397,7 +418,7 @@ class projectController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
async changeMemberRole(ctx){
|
||||
async changeMemberRole(ctx) {
|
||||
let params = ctx.request.body;
|
||||
let projectInst = yapi.getInst(projectModel);
|
||||
if (!params.member_uid) {
|
||||
@ -447,23 +468,23 @@ class projectController extends baseController {
|
||||
* @returns {Object}
|
||||
* @example ./api/project/upset
|
||||
*/
|
||||
async upSet(ctx){
|
||||
async upSet(ctx) {
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if(!id){
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
try{
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
try{
|
||||
this.followModel.updateById(this.getUid(),id,data).then();
|
||||
}catch(e){
|
||||
try {
|
||||
this.followModel.updateById(this.getUid(), id, data).then();
|
||||
} catch (e) {
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
@ -528,12 +549,12 @@ class projectController extends baseController {
|
||||
|
||||
if (params.name) data.name = params.name;
|
||||
if (params.desc) data.desc = params.desc;
|
||||
if (params.basepath ) {
|
||||
if (params.basepath) {
|
||||
data.basepath = params.basepath;
|
||||
}
|
||||
if (params.env) data.env = params.env;
|
||||
if(params.color) data.color = params.color;
|
||||
if(params.icon) data.icon = params.icon;
|
||||
if (params.color) data.color = params.color;
|
||||
if (params.icon) data.icon = params.icon;
|
||||
let result = await this.Model.up(id, data);
|
||||
let username = this.getUsername();
|
||||
yapi.commons.saveLog({
|
||||
@ -549,37 +570,37 @@ class projectController extends baseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改项目头像
|
||||
* @interface /project/upset
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id
|
||||
* @param {String} color
|
||||
* @param {String} icon
|
||||
* @return {Object}
|
||||
*/
|
||||
async upSet(ctx){
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
try{
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
}catch(e){
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
try{
|
||||
this.followModel.updateById(this.getUid(),id,data).then();
|
||||
}catch(e){
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 修改项目头像
|
||||
* @interface /project/upset
|
||||
* @method POST
|
||||
* @category project
|
||||
* @foldnumber 10
|
||||
* @param {Number} id
|
||||
* @param {String} color
|
||||
* @param {String} icon
|
||||
* @return {Object}
|
||||
*/
|
||||
async upSet(ctx) {
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
data.color = ctx.request.body.color;
|
||||
data.icon = ctx.request.body.icon;
|
||||
if (!id) {
|
||||
return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空');
|
||||
}
|
||||
try {
|
||||
let result = await this.Model.up(id, data);
|
||||
ctx.body = yapi.commons.resReturn(result);
|
||||
} catch (e) {
|
||||
ctx.body = yapi.commons.resReturn(null, 402, e.message);
|
||||
}
|
||||
try {
|
||||
this.followModel.updateById(this.getUid(), id, data).then();
|
||||
} catch (e) {
|
||||
yapi.commons.log(e, 'error'); // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 模糊搜索项目名称或者组名称
|
||||
@ -656,7 +677,7 @@ class projectController extends baseController {
|
||||
return ctx.body = yapi.commons.resReturn(null, 401, '项目id不存在');
|
||||
}
|
||||
|
||||
const arr = JSON.stringify(count.map(function(item) {
|
||||
const arr = JSON.stringify(count.map(function (item) {
|
||||
// 返回的json模板数据: item.res_body
|
||||
const mockData = Mock.mock(
|
||||
yapi.commons.json_parse(item.res_body)
|
||||
@ -697,7 +718,7 @@ class projectController extends baseController {
|
||||
});
|
||||
}
|
||||
module.exports = run;`
|
||||
.trim();
|
||||
.trim();
|
||||
return ctx.body = res;
|
||||
}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ import yapi from './yapi.js';
|
||||
import commons from './utils/commons';
|
||||
import dbModule from './utils/db.js';
|
||||
import userModel from './models/user.js';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
yapi.commons = commons;
|
||||
yapi.connect = dbModule.connect();
|
||||
|
||||
|
||||
function install() {
|
||||
let exist = yapi.commons.fileExist(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'));
|
||||
|
||||
@ -31,14 +33,109 @@ function setupSql() {
|
||||
up_time: yapi.commons.time()
|
||||
});
|
||||
|
||||
result.then(function () {
|
||||
fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'));
|
||||
console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 成功`); // eslint-disable-line
|
||||
process.exit(0);
|
||||
}, function (err) {
|
||||
console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line
|
||||
process.exit(0);
|
||||
});
|
||||
yapi.connect.then(function () {
|
||||
let userCol = mongoose.connection.db.collection('user')
|
||||
userCol.ensureIndex({
|
||||
username: 1
|
||||
})
|
||||
userCol.ensureIndex({
|
||||
email: 1
|
||||
}, {
|
||||
unique: true
|
||||
})
|
||||
|
||||
let projectCol = mongoose.connection.db.collection('project')
|
||||
projectCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
projectCol.ensureIndex({
|
||||
name: 1
|
||||
})
|
||||
projectCol.ensureIndex({
|
||||
group_id: 1
|
||||
})
|
||||
|
||||
let logCol = mongoose.connection.db.collection('log')
|
||||
logCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
|
||||
logCol.ensureIndex({
|
||||
typeid: 1,
|
||||
type: 1
|
||||
})
|
||||
|
||||
let interfaceColCol = mongoose.connection.db.collection('interface_col')
|
||||
interfaceColCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
interfaceColCol.ensureIndex({
|
||||
project_id: 1
|
||||
})
|
||||
|
||||
let interfaceCatCol = mongoose.connection.db.collection('interface_cat')
|
||||
interfaceCatCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
interfaceCatCol.ensureIndex({
|
||||
project_id: 1
|
||||
})
|
||||
|
||||
let interfaceCaseCol = mongoose.connection.db.collection('interface_case')
|
||||
interfaceCaseCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
interfaceCaseCol.ensureIndex({
|
||||
col_id: 1
|
||||
})
|
||||
interfaceCaseCol.ensureIndex({
|
||||
project_id: 1
|
||||
})
|
||||
|
||||
let interfaceCol = mongoose.connection.db.collection('interface')
|
||||
interfaceCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
interfaceCol.ensureIndex({
|
||||
path: 1,
|
||||
method: 1
|
||||
})
|
||||
interfaceCol.ensureIndex({
|
||||
project_id: 1
|
||||
})
|
||||
|
||||
let groupCol = mongoose.connection.db.collection('group')
|
||||
groupCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
groupCol.ensureIndex({
|
||||
group_name: 1
|
||||
})
|
||||
|
||||
let avatarCol = mongoose.connection.db.collection('avatar')
|
||||
avatarCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
|
||||
let followCol = mongoose.connection.db.collection('follow')
|
||||
followCol.ensureIndex({
|
||||
uid: 1
|
||||
})
|
||||
followCol.ensureIndex({
|
||||
project_id: 1
|
||||
})
|
||||
|
||||
result.then(function () {
|
||||
fs.ensureFileSync(yapi.path.join(yapi.WEBROOT_RUNTIME, 'init.lock'));
|
||||
console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 成功`); // eslint-disable-line
|
||||
process.exit(0);
|
||||
}, function (err) {
|
||||
console.log(`初始化管理员账号 "${yapi.WEBCONFIG.adminAccount}" 失败, ${err.message}`); // eslint-disable-line
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
install();
|
@ -15,7 +15,7 @@ class baseModel{
|
||||
this.schema.plugin(autoIncrement.plugin, {
|
||||
model: this.name,
|
||||
field: this.getPrimaryKey(),
|
||||
startAt: 101,
|
||||
startAt: 11,
|
||||
incrementBy: yapi.commons.rand(1, 10)
|
||||
});
|
||||
}
|
||||
|
@ -312,6 +312,10 @@ const routerConfig = {
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
},{
|
||||
action: "upCase",
|
||||
path: "up_case",
|
||||
method: "post"
|
||||
},{
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
|
@ -12,7 +12,7 @@ function model(model, schema) {
|
||||
return yapi.connect.model(model, schema, model);
|
||||
}
|
||||
|
||||
function connect() {
|
||||
function connect(callback) {
|
||||
mongoose.Promise = global.Promise;
|
||||
|
||||
let config = yapi.WEBCONFIG;
|
||||
@ -28,6 +28,9 @@ function connect() {
|
||||
|
||||
db.then(function () {
|
||||
yapi.commons.log('mongodb load success...');
|
||||
if(typeof callback === 'function'){
|
||||
callback.call(db)
|
||||
}
|
||||
}, function (err) {
|
||||
yapi.commons.log(err, 'Mongo connect error');
|
||||
});
|
||||
@ -38,6 +41,7 @@ function connect() {
|
||||
|
||||
yapi.db = model;
|
||||
|
||||
|
||||
module.exports = {
|
||||
model: model,
|
||||
connect: connect
|
||||
|
@ -53,6 +53,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
||||
_yapi2.default.commons = _commons2.default;
|
||||
|
||||
|
||||
var compress = require('koa-compress');
|
||||
|
||||
_yapi2.default.connect = _db2.default.connect();
|
||||
var app = (0, _koaWebsocket2.default)(new _koa2.default());
|
||||
var indexFile = process.argv[2] === 'dev' ? 'dev.html' : 'index.html';
|
||||
@ -64,6 +66,11 @@ app.use(_router2.default.allowedMethods());
|
||||
|
||||
(0, _websocket2.default)(app);
|
||||
|
||||
app.use(compress({
|
||||
threshold: 50480,
|
||||
flush: require('zlib').Z_SYNC_FLUSH
|
||||
}));
|
||||
|
||||
app.use(function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx, next) {
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
@ -99,7 +106,7 @@ app.use(function () {
|
||||
return _ref.apply(this, arguments);
|
||||
};
|
||||
}());
|
||||
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static'), { index: indexFile }));
|
||||
app.use((0, _koaStatic2.default)(_yapi2.default.path.join(_yapi2.default.WEBROOT, 'static'), { index: indexFile, gzip: true }));
|
||||
|
||||
app.listen(_yapi2.default.WEBCONFIG.port);
|
||||
_commons2.default.log('the server is start at port ' + _yapi2.default.WEBCONFIG.port);
|
@ -376,6 +376,97 @@ var interfaceColController = function (_baseController) {
|
||||
return addCase;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 增加一个接口用例
|
||||
* @interface /col/up_case
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {number} id
|
||||
* @param {String} casename
|
||||
* @param {String} domain
|
||||
* @param {String} path
|
||||
* @param {String} method
|
||||
* @param {Object} req_query
|
||||
* @param {Object} req_headers
|
||||
* @param {String} req_body_type
|
||||
* @param {Array} req_body_form
|
||||
* @param {String} req_body_other
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upCase',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var params, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
case 0:
|
||||
_context5.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
params = _yapi2.default.commons.handleParams(params, {
|
||||
id: 'number',
|
||||
casename: 'string',
|
||||
domain: 'string',
|
||||
method: 'string'
|
||||
});
|
||||
|
||||
if (params.id) {
|
||||
_context5.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例id不能为空'));
|
||||
|
||||
case 5:
|
||||
if (params.casename) {
|
||||
_context5.next = 7;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context5.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例名称不能为空'));
|
||||
|
||||
case 7:
|
||||
|
||||
params.uid = this.getUid();
|
||||
|
||||
_context5.next = 10;
|
||||
return this.caseModel.up(params);
|
||||
|
||||
case 10:
|
||||
result = _context5.sent;
|
||||
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
|
||||
_context5.next = 17;
|
||||
break;
|
||||
|
||||
case 14:
|
||||
_context5.prev = 14;
|
||||
_context5.t0 = _context5['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context5.t0.message);
|
||||
|
||||
case 17:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[0, 14]]);
|
||||
}));
|
||||
|
||||
function upCase(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCase;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 获取一个接口用例详情
|
||||
* @interface /col/case
|
||||
@ -389,75 +480,17 @@ var interfaceColController = function (_baseController) {
|
||||
|
||||
}, {
|
||||
key: 'getCase',
|
||||
value: function () {
|
||||
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
|
||||
var id, result;
|
||||
return _regenerator2.default.wrap(function _callee5$(_context5) {
|
||||
while (1) {
|
||||
switch (_context5.prev = _context5.next) {
|
||||
case 0:
|
||||
_context5.prev = 0;
|
||||
id = ctx.query.caseid;
|
||||
_context5.next = 4;
|
||||
return this.caseModel.get(id);
|
||||
|
||||
case 4:
|
||||
result = _context5.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context5.next = 11;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
_context5.prev = 8;
|
||||
_context5.t0 = _context5['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context5.t0.message);
|
||||
|
||||
case 11:
|
||||
case 'end':
|
||||
return _context5.stop();
|
||||
}
|
||||
}
|
||||
}, _callee5, this, [[0, 8]]);
|
||||
}));
|
||||
|
||||
function getCase(_x5) {
|
||||
return _ref5.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getCase;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
* @param {String} desc
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upCol',
|
||||
value: function () {
|
||||
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
|
||||
var params, result;
|
||||
var id, result;
|
||||
return _regenerator2.default.wrap(function _callee6$(_context6) {
|
||||
while (1) {
|
||||
switch (_context6.prev = _context6.next) {
|
||||
case 0:
|
||||
_context6.prev = 0;
|
||||
params = ctx.request.body;
|
||||
id = ctx.query.caseid;
|
||||
_context6.next = 4;
|
||||
return this.colModel.up(params.col_id, {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
return this.caseModel.get(id);
|
||||
|
||||
case 4:
|
||||
result = _context6.sent;
|
||||
@ -480,10 +513,68 @@ var interfaceColController = function (_baseController) {
|
||||
}, _callee6, this, [[0, 8]]);
|
||||
}));
|
||||
|
||||
function upCol(_x6) {
|
||||
function getCase(_x6) {
|
||||
return _ref6.apply(this, arguments);
|
||||
}
|
||||
|
||||
return getCase;
|
||||
}()
|
||||
|
||||
/**
|
||||
* 更新一个接口集name或描述
|
||||
* @interface /col/up_col
|
||||
* @method POST
|
||||
* @category col
|
||||
* @foldnumber 10
|
||||
* @param {String} name
|
||||
* @param {String} desc
|
||||
* @returns {Object}
|
||||
* @example
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'upCol',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var params, result;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
case 0:
|
||||
_context7.prev = 0;
|
||||
params = ctx.request.body;
|
||||
_context7.next = 4;
|
||||
return this.colModel.up(params.col_id, {
|
||||
name: params.name,
|
||||
desc: params.desc,
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
case 4:
|
||||
result = _context7.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context7.next = 11;
|
||||
break;
|
||||
|
||||
case 8:
|
||||
_context7.prev = 8;
|
||||
_context7.t0 = _context7['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context7.t0.message);
|
||||
|
||||
case 11:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 8]]);
|
||||
}));
|
||||
|
||||
function upCol(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCol;
|
||||
}()
|
||||
|
||||
@ -501,15 +592,15 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'upCaseIndex',
|
||||
value: function () {
|
||||
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var _this2 = this;
|
||||
|
||||
var params;
|
||||
return _regenerator2.default.wrap(function _callee7$(_context7) {
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
while (1) {
|
||||
switch (_context7.prev = _context7.next) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
case 0:
|
||||
_context7.prev = 0;
|
||||
_context8.prev = 0;
|
||||
params = ctx.request.body;
|
||||
|
||||
if (!params || !Array.isArray(params)) {
|
||||
@ -523,24 +614,24 @@ var interfaceColController = function (_baseController) {
|
||||
}
|
||||
});
|
||||
|
||||
return _context7.abrupt('return', ctx.body = _yapi2.default.commons.resReturn('success'));
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn('success'));
|
||||
|
||||
case 7:
|
||||
_context7.prev = 7;
|
||||
_context7.t0 = _context7['catch'](0);
|
||||
_context8.prev = 7;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context7.t0.message);
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, _context8.t0.message);
|
||||
|
||||
case 10:
|
||||
case 'end':
|
||||
return _context7.stop();
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee7, this, [[0, 7]]);
|
||||
}, _callee8, this, [[0, 7]]);
|
||||
}));
|
||||
|
||||
function upCaseIndex(_x7) {
|
||||
return _ref7.apply(this, arguments);
|
||||
function upCaseIndex(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return upCaseIndex;
|
||||
@ -560,108 +651,31 @@ var interfaceColController = function (_baseController) {
|
||||
}, {
|
||||
key: 'delCol',
|
||||
value: function () {
|
||||
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var id, colData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee8$(_context8) {
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context8.prev = _context8.next) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context8.prev = 0;
|
||||
_context9.prev = 0;
|
||||
id = ctx.query.col_id;
|
||||
_context8.next = 4;
|
||||
_context9.next = 4;
|
||||
return this.colModel.get(id);
|
||||
|
||||
case 4:
|
||||
colData = _context8.sent;
|
||||
colData = _context9.sent;
|
||||
|
||||
if (!colData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的id");
|
||||
}
|
||||
|
||||
if (!(colData.uid !== this.getUid())) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context8.next = 9;
|
||||
return this.checkAuth(colData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context8.sent;
|
||||
|
||||
if (auth) {
|
||||
_context8.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context8.next = 14;
|
||||
return this.colModel.del(id);
|
||||
|
||||
case 14:
|
||||
result = _context8.sent;
|
||||
_context8.next = 17;
|
||||
return this.caseModel.delByCol(id);
|
||||
|
||||
case 17:
|
||||
return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 20:
|
||||
_context8.prev = 20;
|
||||
_context8.t0 = _context8['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context8.t0.message);
|
||||
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context8.stop();
|
||||
}
|
||||
}
|
||||
}, _callee8, this, [[0, 20]]);
|
||||
}));
|
||||
|
||||
function delCol(_x8) {
|
||||
return _ref8.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCol;
|
||||
}()
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} ctx
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'delCase',
|
||||
value: function () {
|
||||
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
|
||||
var caseid, caseData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee9$(_context9) {
|
||||
while (1) {
|
||||
switch (_context9.prev = _context9.next) {
|
||||
case 0:
|
||||
_context9.prev = 0;
|
||||
caseid = ctx.query.caseid;
|
||||
_context9.next = 4;
|
||||
return this.caseModel.get(caseid);
|
||||
|
||||
case 4:
|
||||
caseData = _context9.sent;
|
||||
|
||||
if (!caseData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的caseid");
|
||||
}
|
||||
|
||||
if (!(caseData.uid !== this.getUid())) {
|
||||
_context9.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context9.next = 9;
|
||||
return this.checkAuth(caseData.project_id, 'project', 'danger');
|
||||
return this.checkAuth(colData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context9.sent;
|
||||
@ -675,30 +689,107 @@ var interfaceColController = function (_baseController) {
|
||||
|
||||
case 12:
|
||||
_context9.next = 14;
|
||||
return this.caseModel.del(caseid);
|
||||
return this.colModel.del(id);
|
||||
|
||||
case 14:
|
||||
result = _context9.sent;
|
||||
_context9.next = 17;
|
||||
return this.caseModel.delByCol(id);
|
||||
|
||||
case 17:
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context9.prev = 18;
|
||||
case 20:
|
||||
_context9.prev = 20;
|
||||
_context9.t0 = _context9['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context9.t0.message);
|
||||
|
||||
case 21:
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context9.stop();
|
||||
}
|
||||
}
|
||||
}, _callee9, this, [[0, 18]]);
|
||||
}, _callee9, this, [[0, 20]]);
|
||||
}));
|
||||
|
||||
function delCase(_x9) {
|
||||
function delCol(_x9) {
|
||||
return _ref9.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCol;
|
||||
}()
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} ctx
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'delCase',
|
||||
value: function () {
|
||||
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
|
||||
var caseid, caseData, auth, result;
|
||||
return _regenerator2.default.wrap(function _callee10$(_context10) {
|
||||
while (1) {
|
||||
switch (_context10.prev = _context10.next) {
|
||||
case 0:
|
||||
_context10.prev = 0;
|
||||
caseid = ctx.query.caseid;
|
||||
_context10.next = 4;
|
||||
return this.caseModel.get(caseid);
|
||||
|
||||
case 4:
|
||||
caseData = _context10.sent;
|
||||
|
||||
if (!caseData) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 400, "不存在的caseid");
|
||||
}
|
||||
|
||||
if (!(caseData.uid !== this.getUid())) {
|
||||
_context10.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
_context10.next = 9;
|
||||
return this.checkAuth(caseData.project_id, 'project', 'danger');
|
||||
|
||||
case 9:
|
||||
auth = _context10.sent;
|
||||
|
||||
if (auth) {
|
||||
_context10.next = 12;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '没有权限'));
|
||||
|
||||
case 12:
|
||||
_context10.next = 14;
|
||||
return this.caseModel.del(caseid);
|
||||
|
||||
case 14:
|
||||
result = _context10.sent;
|
||||
return _context10.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result));
|
||||
|
||||
case 18:
|
||||
_context10.prev = 18;
|
||||
_context10.t0 = _context10['catch'](0);
|
||||
|
||||
_yapi2.default.commons.resReturn(null, 400, _context10.t0.message);
|
||||
|
||||
case 21:
|
||||
case 'end':
|
||||
return _context10.stop();
|
||||
}
|
||||
}
|
||||
}, _callee10, this, [[0, 18]]);
|
||||
}));
|
||||
|
||||
function delCase(_x10) {
|
||||
return _ref10.apply(this, arguments);
|
||||
}
|
||||
|
||||
return delCase;
|
||||
}()
|
||||
}]);
|
||||
|
@ -149,7 +149,7 @@ var projectController = function (_baseController) {
|
||||
key: 'add',
|
||||
value: function () {
|
||||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
|
||||
var params, checkRepeat, data, result, username;
|
||||
var params, checkRepeat, data, result, colInst, catInst, username;
|
||||
return _regenerator2.default.wrap(function _callee$(_context) {
|
||||
while (1) {
|
||||
switch (_context.prev = _context.next) {
|
||||
@ -233,7 +233,8 @@ var projectController = function (_baseController) {
|
||||
icon: params.icon,
|
||||
color: params.color,
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
up_time: _yapi2.default.commons.time(),
|
||||
env: [{ name: 'local', domain: 'http://127.0.0.1' }]
|
||||
};
|
||||
_context.prev = 20;
|
||||
_context.next = 23;
|
||||
@ -241,6 +242,36 @@ var projectController = function (_baseController) {
|
||||
|
||||
case 23:
|
||||
result = _context.sent;
|
||||
colInst = _yapi2.default.getInst(_interfaceCol2.default);
|
||||
catInst = _yapi2.default.getInst(_interfaceCat2.default);
|
||||
|
||||
if (!result._id) {
|
||||
_context.next = 31;
|
||||
break;
|
||||
}
|
||||
|
||||
_context.next = 29;
|
||||
return colInst.save({
|
||||
name: '公共测试集',
|
||||
project_id: result._id,
|
||||
desc: '公共测试集',
|
||||
uid: this.getUid(),
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
case 29:
|
||||
_context.next = 31;
|
||||
return catInst.save({
|
||||
name: '公共分类',
|
||||
project_id: result._id,
|
||||
desc: '公共分类',
|
||||
uid: this.getUid(),
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
case 31:
|
||||
username = this.getUsername();
|
||||
|
||||
_yapi2.default.commons.saveLog({
|
||||
@ -252,21 +283,21 @@ var projectController = function (_baseController) {
|
||||
typename: params.group_name
|
||||
});
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 32;
|
||||
_context.next = 39;
|
||||
break;
|
||||
|
||||
case 29:
|
||||
_context.prev = 29;
|
||||
case 36:
|
||||
_context.prev = 36;
|
||||
_context.t1 = _context['catch'](20);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t1.message);
|
||||
|
||||
case 32:
|
||||
case 39:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[20, 29]]);
|
||||
}, _callee, this, [[20, 36]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
|
@ -20,6 +20,10 @@ var _user = require('./models/user.js');
|
||||
|
||||
var _user2 = _interopRequireDefault(_user);
|
||||
|
||||
var _mongoose = require('mongoose');
|
||||
|
||||
var _mongoose2 = _interopRequireDefault(_mongoose);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
_yapi2.default.commons = _commons2.default;
|
||||
@ -49,13 +53,106 @@ function setupSql() {
|
||||
up_time: _yapi2.default.commons.time()
|
||||
});
|
||||
|
||||
result.then(function () {
|
||||
_fsExtra2.default.ensureFileSync(_yapi2.default.path.join(_yapi2.default.WEBROOT_RUNTIME, 'init.lock'));
|
||||
console.log('\u521D\u59CB\u5316\u7BA1\u7406\u5458\u8D26\u53F7 "' + _yapi2.default.WEBCONFIG.adminAccount + '" \u6210\u529F'); // eslint-disable-line
|
||||
process.exit(0);
|
||||
}, function (err) {
|
||||
console.log('\u521D\u59CB\u5316\u7BA1\u7406\u5458\u8D26\u53F7 "' + _yapi2.default.WEBCONFIG.adminAccount + '" \u5931\u8D25, ' + err.message); // eslint-disable-line
|
||||
process.exit(0);
|
||||
_yapi2.default.connect.then(function () {
|
||||
var userCol = _mongoose2.default.connection.db.collection('user');
|
||||
userCol.ensureIndex({
|
||||
username: 1
|
||||
});
|
||||
userCol.ensureIndex({
|
||||
email: 1
|
||||
}, {
|
||||
unique: true
|
||||
});
|
||||
|
||||
var projectCol = _mongoose2.default.connection.db.collection('project');
|
||||
projectCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
projectCol.ensureIndex({
|
||||
name: 1
|
||||
});
|
||||
projectCol.ensureIndex({
|
||||
group_id: 1
|
||||
});
|
||||
|
||||
var logCol = _mongoose2.default.connection.db.collection('log');
|
||||
logCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
|
||||
logCol.ensureIndex({
|
||||
typeid: 1,
|
||||
type: 1
|
||||
});
|
||||
|
||||
var interfaceColCol = _mongoose2.default.connection.db.collection('interface_col');
|
||||
interfaceColCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
interfaceColCol.ensureIndex({
|
||||
project_id: 1
|
||||
});
|
||||
|
||||
var interfaceCatCol = _mongoose2.default.connection.db.collection('interface_cat');
|
||||
interfaceCatCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
interfaceCatCol.ensureIndex({
|
||||
project_id: 1
|
||||
});
|
||||
|
||||
var interfaceCaseCol = _mongoose2.default.connection.db.collection('interface_case');
|
||||
interfaceCaseCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
interfaceCaseCol.ensureIndex({
|
||||
col_id: 1
|
||||
});
|
||||
interfaceCaseCol.ensureIndex({
|
||||
project_id: 1
|
||||
});
|
||||
|
||||
var interfaceCol = _mongoose2.default.connection.db.collection('interface');
|
||||
interfaceCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
interfaceCol.ensureIndex({
|
||||
path: 1,
|
||||
method: 1
|
||||
});
|
||||
interfaceCol.ensureIndex({
|
||||
project_id: 1
|
||||
});
|
||||
|
||||
var groupCol = _mongoose2.default.connection.db.collection('group');
|
||||
groupCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
groupCol.ensureIndex({
|
||||
group_name: 1
|
||||
});
|
||||
|
||||
var avatarCol = _mongoose2.default.connection.db.collection('avatar');
|
||||
avatarCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
|
||||
var followCol = _mongoose2.default.connection.db.collection('follow');
|
||||
followCol.ensureIndex({
|
||||
uid: 1
|
||||
});
|
||||
followCol.ensureIndex({
|
||||
project_id: 1
|
||||
});
|
||||
|
||||
result.then(function () {
|
||||
_fsExtra2.default.ensureFileSync(_yapi2.default.path.join(_yapi2.default.WEBROOT_RUNTIME, 'init.lock'));
|
||||
console.log('\u521D\u59CB\u5316\u7BA1\u7406\u5458\u8D26\u53F7 "' + _yapi2.default.WEBCONFIG.adminAccount + '" \u6210\u529F'); // eslint-disable-line
|
||||
process.exit(0);
|
||||
}, function (err) {
|
||||
console.log('\u521D\u59CB\u5316\u7BA1\u7406\u5458\u8D26\u53F7 "' + _yapi2.default.WEBCONFIG.adminAccount + '" \u5931\u8D25, ' + err.message); // eslint-disable-line
|
||||
process.exit(0);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,7 @@ var baseModel = function () {
|
||||
this.schema.plugin(_mongooseAutoIncrement2.default.plugin, {
|
||||
model: this.name,
|
||||
field: this.getPrimaryKey(),
|
||||
startAt: 101,
|
||||
startAt: 11,
|
||||
incrementBy: _yapi2.default.commons.rand(1, 10)
|
||||
});
|
||||
}
|
||||
|
@ -306,6 +306,10 @@ var routerConfig = {
|
||||
action: "addCase",
|
||||
path: "add_case",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "upCase",
|
||||
path: "up_case",
|
||||
method: "post"
|
||||
}, {
|
||||
action: "getCase",
|
||||
path: "case",
|
||||
|
@ -24,7 +24,7 @@ function model(model, schema) {
|
||||
return _yapi2.default.connect.model(model, schema, model);
|
||||
}
|
||||
|
||||
function connect() {
|
||||
function connect(callback) {
|
||||
_mongoose2.default.Promise = global.Promise;
|
||||
|
||||
var config = _yapi2.default.WEBCONFIG;
|
||||
@ -39,6 +39,9 @@ function connect() {
|
||||
|
||||
db.then(function () {
|
||||
_yapi2.default.commons.log('mongodb load success...');
|
||||
if (typeof callback === 'function') {
|
||||
callback.call(db);
|
||||
}
|
||||
}, function (err) {
|
||||
_yapi2.default.commons.log(err, 'Mongo connect error');
|
||||
});
|
||||
|
@ -4,6 +4,7 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>YAPI-高效、易用、功能强大的api管理平台</title>
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/image/favicon.png">
|
||||
<link rel="stylesheet" href="http://127.0.0.1:4000/yapi/prd/index@dev.css">
|
||||
</head>
|
||||
<body>
|
||||
|
BIN
static/image/favicon.png
Normal file
BIN
static/image/favicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -4,8 +4,9 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title>YAPI-高效、易用、功能强大的api管理平台</title>
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="/image/favicon.png">
|
||||
<script>
|
||||
document.write('<script src="prd/assets.js?v=' + Math.random() + '"><\/script>');
|
||||
document.write('<script src="/prd/assets.js?v=' + Math.random() + '"><\/script>');
|
||||
</script>
|
||||
|
||||
|
||||
|
23
ykit.js
23
ykit.js
@ -9,19 +9,22 @@ var assetsPluginInstance = new AssetsPlugin({
|
||||
|
||||
function handleCommonsChunk(webpackConfig) {
|
||||
var commonsChunk = {
|
||||
//filename: 'scripts/[name]@[chunkhash][ext]',
|
||||
vendors: {
|
||||
lib: ['react', 'redux',
|
||||
'redux-thunk',
|
||||
'react-dom',
|
||||
'redux-promise',
|
||||
'react-router',
|
||||
'react-router-dom',
|
||||
'prop-types'
|
||||
|
||||
],
|
||||
lib2: [
|
||||
'prop-types',
|
||||
'axios',
|
||||
'moment'
|
||||
|
||||
],
|
||||
lib2: [
|
||||
'brace',
|
||||
'mockjs',
|
||||
'json5'
|
||||
]
|
||||
}
|
||||
},
|
||||
@ -78,7 +81,7 @@ module.exports = {
|
||||
"regenerator": true
|
||||
}]);
|
||||
defaultQuery.plugins.push('transform-decorators-legacy');
|
||||
// defaultQuery.plugins.push(["import", { libraryName: "antd", style: "css" }])
|
||||
defaultQuery.plugins.push(["import", { libraryName: "antd"}])
|
||||
return defaultQuery;
|
||||
}
|
||||
}
|
||||
@ -93,19 +96,19 @@ module.exports = {
|
||||
var ENV_PARAMS = {};
|
||||
switch (this.env) {
|
||||
case 'local':
|
||||
ENV_PARAMS = { development: true };
|
||||
ENV_PARAMS = 'dev';
|
||||
break;
|
||||
case 'dev':
|
||||
ENV_PARAMS = { development: true };
|
||||
ENV_PARAMS = 'dev';
|
||||
break;
|
||||
case 'prd':
|
||||
ENV_PARAMS = { development: false };
|
||||
ENV_PARAMS = 'production';
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
baseConfig.plugins.push(new this.webpack.DefinePlugin({
|
||||
ENV_PARAMS: JSON.stringify(ENV_PARAMS)
|
||||
'process.env.NODE_ENV': JSON.stringify(ENV_PARAMS)
|
||||
}))
|
||||
|
||||
//初始化配置
|
||||
|
Loading…
x
Reference in New Issue
Block a user