mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev
This commit is contained in:
commit
62a9683c39
@ -1,9 +1,86 @@
|
||||
import React, { Component } from 'react'
|
||||
import Routes from './routes'
|
||||
import axios from 'axios';
|
||||
import { Route, HashRouter, Redirect } from 'react-router-dom'
|
||||
import { Home, ProjectGroups, Interface, News } from './containers/index'
|
||||
import User from './containers/User/User.js'
|
||||
import Header from './components/Header/Header'
|
||||
|
||||
const LOADING_STATUS = 0;
|
||||
const GUEST_STATUS = 1;
|
||||
const MEMBER_STATUS = 2;
|
||||
|
||||
class App extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
login: LOADING_STATUS
|
||||
}
|
||||
}
|
||||
|
||||
route = (status) => {
|
||||
let r;
|
||||
if (status === LOADING_STATUS) {
|
||||
return <span>loading...</span>
|
||||
} else if (status === GUEST_STATUS) {
|
||||
r = (
|
||||
<HashRouter>
|
||||
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<Route path="/" component={Home} exact />
|
||||
<Redirect to="/" />
|
||||
</div>
|
||||
|
||||
|
||||
</HashRouter>
|
||||
)
|
||||
} else {
|
||||
r = (
|
||||
<HashRouter>
|
||||
<div className="router-main">
|
||||
<Header />
|
||||
<Route path="/" component={ProjectGroups} exact />
|
||||
<Route path="/ProjectGroups" component={ProjectGroups} />
|
||||
<Route path="/Interface" component={Interface} />
|
||||
<Route path="/user" component={User} />
|
||||
<Route path="/News" component={News} />
|
||||
</div>
|
||||
|
||||
</HashRouter>
|
||||
)
|
||||
}
|
||||
return r
|
||||
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
console.log('app.js init')
|
||||
axios.get('/user/status').then((res) => {
|
||||
if (res.data.errcode === 0 && res.data.data._id > 0) {
|
||||
this.setState({
|
||||
login: MEMBER_STATUS
|
||||
})
|
||||
} else {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
})
|
||||
}
|
||||
}, (err) => {
|
||||
this.setState({
|
||||
login: GUEST_STATUS
|
||||
})
|
||||
console.log(err.message)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
return <Routes />
|
||||
console.log(MEMBER_STATUS)
|
||||
console.log(this.route(this.state.login))
|
||||
return this.route(this.state.login)
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ const loginActions = (data) => {
|
||||
data: res
|
||||
}
|
||||
});
|
||||
location.reload()
|
||||
} else {
|
||||
console.log('登录失败,errcode不为0');
|
||||
}
|
||||
|
@ -4,19 +4,11 @@ import {
|
||||
} from '../constants/action-types.js';
|
||||
|
||||
export function fetchNewsData () {
|
||||
const data = [{
|
||||
name: 'John Brown',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '创建服务现场'
|
||||
}, {
|
||||
name: 'John Brown1',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '技术测试异常'
|
||||
}, {
|
||||
name: 'John Brown2',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '网络异常正在修复'
|
||||
}]
|
||||
const data = [
|
||||
{ key: 1, type: 'John Brown', news: '您好!亲爱的用户:您已成功申请接口:实时空气质量数据查询,请于两个月内进行应用验证,逾期接口将不能正常使用。如果您在使用的过程中遇到任何问题,欢迎前往交流社区反馈意见,谢谢!',time: '2014-12-01' },
|
||||
{ key: 2, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 3, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' }
|
||||
];
|
||||
|
||||
return {
|
||||
type: FETCH_NEWS_DATA,
|
||||
@ -25,19 +17,11 @@ export function fetchNewsData () {
|
||||
}
|
||||
|
||||
export function fetchViewedNews () {
|
||||
const data = [{
|
||||
name: 'John Brown21',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '创建服务现场'
|
||||
}, {
|
||||
name: 'John Brown12',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '技术测试异常'
|
||||
}, {
|
||||
name: 'John Brown22',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '网络异常正在修复'
|
||||
}]
|
||||
const data = [
|
||||
{ key: 1, type: 'John Brown1', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 2, type: 'John Brown2', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 3, type: 'John Brown3å', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' }
|
||||
];
|
||||
|
||||
return {
|
||||
type: FETCH_NEWS_DATA,
|
||||
@ -46,19 +30,11 @@ export function fetchViewedNews () {
|
||||
}
|
||||
|
||||
export function fetchNotVieweNews () {
|
||||
const data = [{
|
||||
name: 'John Brown22',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '创建服务现场'
|
||||
}, {
|
||||
name: 'John Brown12',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '技术测试异常'
|
||||
}, {
|
||||
name: 'John Brown22',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '网络异常正在修复'
|
||||
}]
|
||||
const data = [
|
||||
{ key: 1, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2015-11-11 13:00:15' },
|
||||
{ key: 2, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2015-11-11 13:00:15' },
|
||||
{ key: 3, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2015-11-11 13:00:15' }
|
||||
];
|
||||
|
||||
return {
|
||||
type: FETCH_NEWS_DATA,
|
||||
@ -68,19 +44,11 @@ export function fetchNotVieweNews () {
|
||||
|
||||
export function fetchMoreNews () {
|
||||
return (dispatch)=>{
|
||||
const data = [{
|
||||
name: 'John Brown2212',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '创建服务现场'
|
||||
}, {
|
||||
name: 'John Brown1132',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '技术测试异常'
|
||||
}, {
|
||||
name: 'John Brown23212',
|
||||
date: '2015-11-11 13:00:15',
|
||||
desc: '网络异常正在修复'
|
||||
}]
|
||||
const data = [
|
||||
{ key: 1, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 2, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' },
|
||||
{ key: 3, type: 'John Brown', news: 'My name is John Brown, I am 32 years old, living in New York No. 1 Lake Park.',time: '2014-12-01' }
|
||||
];
|
||||
|
||||
dispatch({
|
||||
type: FETCH_MORE_NEWS,
|
||||
|
@ -1,6 +1,7 @@
|
||||
import './Home.scss'
|
||||
import React, { Component } from 'react'
|
||||
import { connect } from 'react-redux'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Row, Col, Button } from 'antd'
|
||||
import PropTypes from "prop-types"
|
||||
import Login from '../Login/login-wrap'
|
||||
@ -66,12 +67,18 @@ class Home extends Component {
|
||||
<div className="home-main">
|
||||
{login?
|
||||
(
|
||||
<div className="main-one">
|
||||
<div>
|
||||
登录以后的首页
|
||||
<div className="user-home">
|
||||
<div className="user-des">
|
||||
<p className="title">YAPI</p>
|
||||
<p className="des">一个高效,易用,功能强大的api管理系统</p>
|
||||
<div className="btn">
|
||||
<Button type="primary" size="large">
|
||||
<Link to="/ProjectGroups" onClick={this.toStart}>开始</Link>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<Button type="primary" size="large">开始</Button>
|
||||
</div>)
|
||||
</div>
|
||||
)
|
||||
: <HomeGuest introList={this.props.introList}/>}
|
||||
<Footer/>
|
||||
</div>
|
||||
|
@ -43,6 +43,31 @@ $color-black-lighter: #404040;
|
||||
padding-left: .15rem;
|
||||
}
|
||||
}
|
||||
.user-home{
|
||||
height:calc(100% - .64rem);
|
||||
padding: .5rem .5rem 0 .5rem;
|
||||
.user-des{
|
||||
max-width: 11rem;
|
||||
margin: 0 auto .5rem;
|
||||
text-align: center;
|
||||
.title{
|
||||
font-size: .8rem;
|
||||
margin-bottom: .2rem;
|
||||
}
|
||||
.des{
|
||||
font-size: .25rem;
|
||||
margin-bottom: .3rem;
|
||||
}
|
||||
.btn{
|
||||
button{
|
||||
font-size: .2rem;
|
||||
line-height: .2rem;
|
||||
height: .5rem;
|
||||
padding: .15rem .5rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.main-part{
|
||||
padding: .9rem .5rem;
|
||||
&:nth-child(odd){
|
||||
|
@ -4,7 +4,7 @@ import NewsTimeline from './NewsTimeline/NewsTimeline'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
import NewsList from './NewsList/NewsList.js'
|
||||
import { fetchNewsData } from '../../actions/news.js'
|
||||
import { fetchNotVieweNews } from '../../actions/news.js'
|
||||
|
||||
|
||||
@connect(
|
||||
@ -14,7 +14,7 @@ import { fetchNewsData } from '../../actions/news.js'
|
||||
}
|
||||
},
|
||||
{
|
||||
fetchNewsData: fetchNewsData
|
||||
fetchNotVieweNews: fetchNotVieweNews
|
||||
}
|
||||
)
|
||||
|
||||
@ -24,10 +24,10 @@ class News extends Component {
|
||||
}
|
||||
static propTypes = {
|
||||
newsData: PropTypes.array,
|
||||
fetchNewsData: PropTypes.func
|
||||
fetchNotVieweNews: PropTypes.func
|
||||
}
|
||||
componentWillMount(){
|
||||
this.props.fetchNewsData()
|
||||
this.props.fetchNotVieweNews()
|
||||
}
|
||||
render () {
|
||||
const data = this.props.newsData
|
||||
|
@ -29,6 +29,50 @@
|
||||
.news-timeline{
|
||||
margin-left: 30px;
|
||||
margin-top: 30px;
|
||||
.removeAllNews{
|
||||
background-color: #f7f7f7;
|
||||
padding: 7px;
|
||||
display: inline-block;
|
||||
overflow: hidden;
|
||||
margin-bottom: 5px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
color: #a09f9f;
|
||||
|
||||
&:hover,&:active{
|
||||
background-color: #333;
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
.ant-table-wrapper{
|
||||
width: 822px;
|
||||
}
|
||||
.ant-table-row{
|
||||
max-width: 80%;
|
||||
}
|
||||
.newsDesc{
|
||||
padding-right: 15px;
|
||||
|
||||
p{
|
||||
text-indent: 2em;
|
||||
color: #333;
|
||||
font-size: 14px;
|
||||
line-height: 30px;;
|
||||
}
|
||||
span{
|
||||
font-size: 14px;
|
||||
margin-top: 15px;
|
||||
display: inline-block;
|
||||
color: #999;
|
||||
cursor: pointer;
|
||||
i{
|
||||
margin-right: 5px;
|
||||
}
|
||||
&:hover, &.active {
|
||||
color: #333;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ant-timeline-item-content{
|
||||
|
@ -66,9 +66,9 @@ class NewsList extends Component {
|
||||
render () {
|
||||
return (
|
||||
<ul onClick = {this.fetchData.bind(this)} className="news-list">
|
||||
<li className="active allnews">全部消息</li>
|
||||
{/*<li className="allnews">全部消息</li>*/}
|
||||
<li className='active notview'>未读消息</li>
|
||||
<li className='viewednews'>已读消息</li>
|
||||
<li className='notview'>未读消息</li>
|
||||
</ul>
|
||||
)
|
||||
}
|
||||
|
@ -1,8 +1,13 @@
|
||||
import React, { Component } from 'react'
|
||||
import { Timeline } from 'antd'
|
||||
import { Table, Icon, Popconfirm } from 'antd'
|
||||
import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import { fetchMoreNews } from '../../../actions/news.js'
|
||||
|
||||
const removeConfirm = function(e){
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
@connect(
|
||||
state=>{
|
||||
return state;
|
||||
@ -11,35 +16,41 @@ import { fetchMoreNews } from '../../../actions/news.js'
|
||||
fetchMoreNews: fetchMoreNews
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class NewsTimeline extends Component {
|
||||
static propTypes = {
|
||||
newsData: PropTypes.array,
|
||||
fetchMoreNews: PropTypes.func
|
||||
}
|
||||
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
removeOneNews(id){
|
||||
return ()=>{
|
||||
console.log(id);
|
||||
}
|
||||
}
|
||||
render () {
|
||||
const columns = [
|
||||
{ title: '类型',width:100, dataIndex: 'type', key: 'type' },
|
||||
{ title: '消息', dataIndex: 'news', key: 'news' },
|
||||
{ title: '发布时间',width:150, dataIndex: 'time', key: 'time' }
|
||||
];
|
||||
const data = this.props.newsData;
|
||||
return (
|
||||
<section className="news-timeline">
|
||||
<Timeline pending={<a onClick = {this.props.fetchMoreNews}>See more</a>}>
|
||||
{
|
||||
data.map(function(item,i){
|
||||
return (
|
||||
<Timeline.Item color = 'green' key = {i} >
|
||||
<div>
|
||||
<span className='timelineDate'>{item.date}</span>
|
||||
<span className='timelineName'>{item.name}</span>
|
||||
</div>
|
||||
<p>{item.desc}</p>
|
||||
</Timeline.Item>
|
||||
)
|
||||
})
|
||||
}
|
||||
</Timeline>
|
||||
<span className='removeAllNews'>
|
||||
<Popconfirm title="你确定要清空所有消息吗?" onConfirm={removeConfirm} okText="删除" cancelText="取消">
|
||||
清空消息
|
||||
</Popconfirm>
|
||||
</span>
|
||||
<Table
|
||||
columns={columns}
|
||||
expandedRowRender={record => <div className='newsDesc'><p>{record.news}</p><span onClick = {this.removeOneNews(record.key)} ><Icon type="delete" />删除</span></div>}
|
||||
dataSource={data}
|
||||
/>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
@ -6,12 +6,13 @@ import { autobind } from 'core-decorators';
|
||||
import axios from 'axios';
|
||||
|
||||
const Search = Input.Search;
|
||||
const confirm = Modal.confirm;
|
||||
const TYPE_EDIT = 'edit';
|
||||
|
||||
import {
|
||||
fetchGroupList,
|
||||
setCurrGroup,
|
||||
addGroup,
|
||||
fetchProjectList
|
||||
setGroupList
|
||||
} from '../../../actions/group.js'
|
||||
|
||||
import './GroupList.scss'
|
||||
@ -24,8 +25,7 @@ import './GroupList.scss'
|
||||
{
|
||||
fetchGroupList,
|
||||
setCurrGroup,
|
||||
addGroup,
|
||||
fetchProjectList
|
||||
setGroupList
|
||||
}
|
||||
)
|
||||
export default class GroupList extends Component {
|
||||
@ -35,13 +35,17 @@ export default class GroupList extends Component {
|
||||
currGroup: PropTypes.object,
|
||||
fetchGroupList: PropTypes.func,
|
||||
setCurrGroup: PropTypes.func,
|
||||
fetchProjectList: PropTypes.func
|
||||
setGroupList: PropTypes.func
|
||||
}
|
||||
|
||||
state = {
|
||||
addGroupModalVisible: false,
|
||||
editGroupModalVisible: false,
|
||||
newGroupName: '',
|
||||
newGroupDesc: ''
|
||||
newGroupDesc: '',
|
||||
currGroupName: '',
|
||||
currGroupDesc: '',
|
||||
groupList: []
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
@ -51,15 +55,37 @@ export default class GroupList extends Component {
|
||||
componentWillMount() {
|
||||
this.props.fetchGroupList().then(() => {
|
||||
const currGroup = this.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
this.setState({groupList: this.props.groupList});
|
||||
this.props.setCurrGroup(currGroup)
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
showModal() {
|
||||
this.setState({
|
||||
addGroupModalVisible: true
|
||||
});
|
||||
showModal(type) {
|
||||
if (type === 'edit') {
|
||||
const { currGroup } = this.props;
|
||||
this.setState({
|
||||
currGroupName: currGroup.group_name,
|
||||
currGroupDesc: currGroup.group_desc,
|
||||
editGroupModalVisible: true
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
addGroupModalVisible: true
|
||||
});
|
||||
}
|
||||
}
|
||||
@autobind
|
||||
hideModal(type) {
|
||||
if (type === TYPE_EDIT) {
|
||||
this.setState({
|
||||
editGroupModalVisible: false
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
addGroupModalVisible: false
|
||||
});
|
||||
}
|
||||
}
|
||||
@autobind
|
||||
addGroup() {
|
||||
@ -71,24 +97,43 @@ export default class GroupList extends Component {
|
||||
this.setState({
|
||||
addGroupModalVisible: false
|
||||
});
|
||||
this.props.fetchGroupList()
|
||||
this.props.fetchGroupList().then(() => {
|
||||
this.setState({groupList: this.props.groupList});
|
||||
})
|
||||
this.props.setCurrGroup(res.data.data)
|
||||
}
|
||||
});
|
||||
}
|
||||
@autobind
|
||||
handleCancel(e) {
|
||||
console.log(e);
|
||||
this.setState({
|
||||
addGroupModalVisible: false
|
||||
editGroup() {
|
||||
const { currGroupName: group_name, currGroupDesc: group_desc } = this.state;
|
||||
const id = this.props.currGroup._id;
|
||||
axios.post('/group/up', { group_name, group_desc, id }).then(res => {
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
this.setState({
|
||||
editGroupModalVisible: false
|
||||
});
|
||||
this.props.setCurrGroup({ group_name, group_desc, _id: id });
|
||||
}
|
||||
});
|
||||
}
|
||||
@autobind
|
||||
inputNewGroupName(e) {
|
||||
this.setState({newGroupName: e.target.value});
|
||||
inputNewGroupName(e, type) {
|
||||
if (type === TYPE_EDIT) {
|
||||
this.setState({ currGroupName: e.target.value})
|
||||
} else {
|
||||
this.setState({newGroupName: e.target.value});
|
||||
}
|
||||
}
|
||||
@autobind
|
||||
inputNewGroupDesc(e) {
|
||||
this.setState({newGroupDesc: e.target.value});
|
||||
inputNewGroupDesc(e, type) {
|
||||
if (type === TYPE_EDIT) {
|
||||
this.setState({ currGroupDesc: e.target.value})
|
||||
} else {
|
||||
this.setState({newGroupDesc: e.target.value});
|
||||
}
|
||||
}
|
||||
|
||||
@autobind
|
||||
@ -96,25 +141,60 @@ export default class GroupList extends Component {
|
||||
const groupId = e.key;
|
||||
const currGroup = this.props.groupList.find((group) => { return +group._id === +groupId });
|
||||
this.props.setCurrGroup(currGroup);
|
||||
// this.props.fetchProjectList(groupId);
|
||||
}
|
||||
|
||||
@autobind
|
||||
deleteGroup() {
|
||||
const self = this;
|
||||
const { currGroup } = self.props;
|
||||
confirm({
|
||||
title: `你确定要删除分组 ${currGroup.group_name}?`,
|
||||
content: `分组简介:${currGroup.group_desc}`,
|
||||
onOk() {
|
||||
axios.post('/group/del', {id: currGroup._id}).then(res => {
|
||||
if (res.data.errcode) {
|
||||
message.error(res.data.errmsg);
|
||||
} else {
|
||||
message.success('删除成功');
|
||||
self.props.fetchGroupList().then(() => {
|
||||
const currGroup = self.props.groupList[0] || { group_name: '', group_desc: '' };
|
||||
self.setState({groupList: self.props.groupList});
|
||||
self.props.setCurrGroup(currGroup)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@autobind
|
||||
searchGroup(e, value) {
|
||||
const v = value || e.target.value;
|
||||
const { groupList } = this.props;
|
||||
if (v === '') {
|
||||
this.setState({groupList})
|
||||
} else {
|
||||
this.setState({groupList: groupList.filter(group => new RegExp(v, 'i').test(group.group_name))})
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
const { groupList, currGroup } = this.props;
|
||||
const { currGroup } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="group-bar">
|
||||
<div className="curr-group">
|
||||
<div className="curr-group-name">{currGroup.group_name}<Icon className="edit-group" type="edit"/></div>
|
||||
<div className="curr-group-name">
|
||||
{currGroup.group_name}
|
||||
<Icon className="edit-group" type="edit" title="编辑分组" onClick={() => this.showModal(TYPE_EDIT)}/>
|
||||
<Icon className="delete-group" type="delete" title="删除分组" onClick={this.deleteGroup}/>
|
||||
</div>
|
||||
<div className="curr-group-desc">简介:{currGroup.group_desc}</div>
|
||||
</div>
|
||||
<div className="group-operate">
|
||||
<div className="search">
|
||||
<Search
|
||||
placeholder="input search text"
|
||||
onSearch={value => console.log(value)}
|
||||
/>
|
||||
<Search onChange={this.searchGroup} onSearch={(v) => this.searchGroup(null, v)}/>
|
||||
</div>
|
||||
<Button type="primary" onClick={this.showModal}>添加分组</Button>
|
||||
</div>
|
||||
@ -125,7 +205,7 @@ export default class GroupList extends Component {
|
||||
selectedKeys={[`${currGroup._id}`]}
|
||||
>
|
||||
{
|
||||
groupList.map((group) => (
|
||||
this.state.groupList.map((group) => (
|
||||
<Menu.Item key={`${group._id}`} className="group-item">
|
||||
<Icon type="folder-open" />{group.group_name}
|
||||
</Menu.Item>
|
||||
@ -137,7 +217,7 @@ export default class GroupList extends Component {
|
||||
title="添加分组"
|
||||
visible={this.state.addGroupModalVisible}
|
||||
onOk={this.addGroup}
|
||||
onCancel={this.handleCancel}
|
||||
onCancel={this.hideModal}
|
||||
className="add-group-modal"
|
||||
>
|
||||
<Row gutter={6} className="modal-input">
|
||||
@ -153,6 +233,26 @@ export default class GroupList extends Component {
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
<Modal
|
||||
title="编辑分组"
|
||||
visible={this.state.editGroupModalVisible}
|
||||
onOk={this.editGroup}
|
||||
onCancel={() => this.hideModal(TYPE_EDIT)}
|
||||
className="add-group-modal"
|
||||
>
|
||||
<Row gutter={6} className="modal-input">
|
||||
<Col span="5"><div className="label">分组名:</div></Col>
|
||||
<Col span="15">
|
||||
<Input placeholder="请输入分组名称" value={this.state.currGroupName} onChange={(e) => this.inputNewGroupName(e, TYPE_EDIT)}></Input>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row gutter={6} className="modal-input">
|
||||
<Col span="5"><div className="label">简介:</div></Col>
|
||||
<Col span="15">
|
||||
<Input placeholder="请输入分组描述" value={this.state.currGroupDesc} onChange={(e) => this.inputNewGroupDesc(e, TYPE_EDIT)}></Input>
|
||||
</Col>
|
||||
</Row>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -12,11 +12,12 @@
|
||||
color: #fff;
|
||||
font-size: 12px;
|
||||
}
|
||||
.edit-group {
|
||||
.delete-group, .edit-group {
|
||||
font-size: 18px;
|
||||
margin-left: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.edit-group:hover {
|
||||
.delete-group:hover, .edit-group:hover {
|
||||
color: #ccc;
|
||||
}
|
||||
}
|
||||
@ -30,7 +31,8 @@
|
||||
}
|
||||
}
|
||||
.group-list {
|
||||
// background: #fff;
|
||||
max-height: 650px;
|
||||
overflow: scroll;
|
||||
border-bottom: 1px solid #e9e9e9;
|
||||
padding-bottom: 24px;
|
||||
border-radius: 0 0 6px 6px;
|
||||
|
@ -2,6 +2,7 @@ import {
|
||||
FETCH_GROUP_LIST,
|
||||
SET_CURR_GROUP
|
||||
} from '../../constants/action-types';
|
||||
import { message } from 'antd'
|
||||
|
||||
const initialState = {
|
||||
groupList: [],
|
||||
@ -11,7 +12,9 @@ const initialState = {
|
||||
export default (state = initialState, action) => {
|
||||
switch (action.type) {
|
||||
case FETCH_GROUP_LIST: {
|
||||
if (!action.payload.data.errcode) {
|
||||
if (action.payload.data.errcode) {
|
||||
message.error(action.payload.data.errmsg);
|
||||
} else {
|
||||
return {
|
||||
...state,
|
||||
groupList: action.payload.data.data
|
||||
|
@ -1,5 +1,6 @@
|
||||
import React from 'react'
|
||||
|
||||
|
||||
import { Route, HashRouter } from 'react-router-dom'
|
||||
import { Home, ProjectGroups, Interface, News } from './containers/index'
|
||||
import User from './containers/User/User.js'
|
||||
|
@ -23,6 +23,9 @@ class groupController extends baseController{
|
||||
*/
|
||||
async add(ctx) {
|
||||
let params = ctx.request.body;
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
if(!params.group_name){
|
||||
return ctx.body = yapi.commons.resReturn(null, 400, '项目分组名不能为空');
|
||||
}
|
||||
@ -80,7 +83,10 @@ class groupController extends baseController{
|
||||
* @example ./api/group/del.json
|
||||
*/
|
||||
|
||||
async del(ctx){
|
||||
async del(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
var projectInst = yapi.getInst(projectModel);
|
||||
@ -88,7 +94,7 @@ class groupController extends baseController{
|
||||
if(!id){
|
||||
return ctx.body = yapi.commons.resReturn(null, 402, 'id不能为空');
|
||||
}
|
||||
let count = projectInst.countByGroupId(id);
|
||||
let count = await projectInst.countByGroupId(id);
|
||||
if(count > 0){
|
||||
return ctx.body = yapi.commons.resReturn(null, 403, '请先删除该分组下的项目');
|
||||
}
|
||||
@ -114,13 +120,16 @@ class groupController extends baseController{
|
||||
*/
|
||||
|
||||
async up(ctx){
|
||||
if(this.getRole() !== 'admin'){
|
||||
return ctx.body = yapi.commons.resReturn(null,401,'没有权限');
|
||||
}
|
||||
try{
|
||||
var groupInst = yapi.getInst(groupModel);
|
||||
let id = ctx.request.body.id;
|
||||
let data = {};
|
||||
ctx.request.body.group_name && (data.group_name = ctx.request.body.group_name)
|
||||
ctx.request.body.group_desc && (data.group_desc = ctx.request.body.group_desc)
|
||||
if(Object.keys(data).length ===0){
|
||||
if(Object.keys(data).length === 0 ){
|
||||
ctx.body = yapi.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
let result = await groupInst.up(id, data);
|
||||
|
@ -229,7 +229,7 @@ class projectController extends baseController {
|
||||
let result = await this.Model.listWithPaging(group_id, page, limit);
|
||||
let count = await this.Model.listCount();
|
||||
ctx.body = yapi.commons.resReturn({
|
||||
total: count,
|
||||
total: Math.ceil(count / limit),
|
||||
list: result
|
||||
})
|
||||
}catch(err){
|
||||
|
@ -305,7 +305,7 @@ class userController extends baseController {
|
||||
let user = await userInst.listWithPaging(page, limit);
|
||||
let count = await userInst.listCount();
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
total: count,
|
||||
total: Math.ceil(count / limit),
|
||||
list: user
|
||||
});
|
||||
} catch(e) {
|
||||
|
@ -83,29 +83,37 @@ var groupController = function (_baseController) {
|
||||
case 0:
|
||||
params = ctx.request.body;
|
||||
|
||||
if (params.group_name) {
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context.next = 3;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 3:
|
||||
if (params.group_name) {
|
||||
_context.next = 5;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组名不能为空'));
|
||||
|
||||
case 3:
|
||||
case 5:
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
_context.next = 6;
|
||||
_context.next = 8;
|
||||
return groupInst.checkRepeat(params.group_name);
|
||||
|
||||
case 6:
|
||||
case 8:
|
||||
checkRepeat = _context.sent;
|
||||
|
||||
if (!(checkRepeat > 0)) {
|
||||
_context.next = 9;
|
||||
_context.next = 11;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目分组名已存在'));
|
||||
|
||||
case 9:
|
||||
case 11:
|
||||
data = {
|
||||
group_name: params.group_name,
|
||||
group_desc: params.group_desc,
|
||||
@ -113,30 +121,30 @@ var groupController = function (_baseController) {
|
||||
add_time: _yapi2.default.commons.time(),
|
||||
up_time: _yapi2.default.commons.time()
|
||||
};
|
||||
_context.prev = 10;
|
||||
_context.next = 13;
|
||||
_context.prev = 12;
|
||||
_context.next = 15;
|
||||
return groupInst.save(data);
|
||||
|
||||
case 13:
|
||||
case 15:
|
||||
result = _context.sent;
|
||||
|
||||
result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']);
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context.next = 21;
|
||||
_context.next = 23;
|
||||
break;
|
||||
|
||||
case 18:
|
||||
_context.prev = 18;
|
||||
_context.t0 = _context['catch'](10);
|
||||
case 20:
|
||||
_context.prev = 20;
|
||||
_context.t0 = _context['catch'](12);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message);
|
||||
|
||||
case 21:
|
||||
case 23:
|
||||
case 'end':
|
||||
return _context.stop();
|
||||
}
|
||||
}
|
||||
}, _callee, this, [[10, 18]]);
|
||||
}, _callee, this, [[12, 20]]);
|
||||
}));
|
||||
|
||||
function add(_x) {
|
||||
@ -218,51 +226,63 @@ var groupController = function (_baseController) {
|
||||
while (1) {
|
||||
switch (_context3.prev = _context3.next) {
|
||||
case 0:
|
||||
_context3.prev = 0;
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context3.next = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 2:
|
||||
_context3.prev = 2;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
projectInst = _yapi2.default.getInst(_project2.default);
|
||||
id = ctx.request.body.id;
|
||||
|
||||
if (id) {
|
||||
_context3.next = 6;
|
||||
_context3.next = 8;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 402, 'id不能为空'));
|
||||
|
||||
case 6:
|
||||
count = projectInst.countByGroupId(id);
|
||||
case 8:
|
||||
_context3.next = 10;
|
||||
return projectInst.countByGroupId(id);
|
||||
|
||||
case 10:
|
||||
count = _context3.sent;
|
||||
|
||||
if (!(count > 0)) {
|
||||
_context3.next = 9;
|
||||
_context3.next = 13;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 403, '请先删除该分组下的项目'));
|
||||
|
||||
case 9:
|
||||
_context3.next = 11;
|
||||
case 13:
|
||||
_context3.next = 15;
|
||||
return groupInst.del(id);
|
||||
|
||||
case 11:
|
||||
case 15:
|
||||
result = _context3.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context3.next = 18;
|
||||
_context3.next = 22;
|
||||
break;
|
||||
|
||||
case 15:
|
||||
_context3.prev = 15;
|
||||
_context3.t0 = _context3['catch'](0);
|
||||
case 19:
|
||||
_context3.prev = 19;
|
||||
_context3.t0 = _context3['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 18:
|
||||
case 22:
|
||||
case 'end':
|
||||
return _context3.stop();
|
||||
}
|
||||
}
|
||||
}, _callee3, this, [[0, 15]]);
|
||||
}, _callee3, this, [[2, 19]]);
|
||||
}));
|
||||
|
||||
function del(_x3) {
|
||||
@ -294,7 +314,15 @@ var groupController = function (_baseController) {
|
||||
while (1) {
|
||||
switch (_context4.prev = _context4.next) {
|
||||
case 0:
|
||||
_context4.prev = 0;
|
||||
if (!(this.getRole() !== 'admin')) {
|
||||
_context4.next = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限'));
|
||||
|
||||
case 2:
|
||||
_context4.prev = 2;
|
||||
groupInst = _yapi2.default.getInst(_group2.default);
|
||||
id = ctx.request.body.id;
|
||||
data = {};
|
||||
@ -304,28 +332,28 @@ var groupController = function (_baseController) {
|
||||
if ((0, _keys2.default)(data).length === 0) {
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空');
|
||||
}
|
||||
_context4.next = 9;
|
||||
_context4.next = 11;
|
||||
return groupInst.up(id, data);
|
||||
|
||||
case 9:
|
||||
case 11:
|
||||
result = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 16;
|
||||
_context4.next = 18;
|
||||
break;
|
||||
|
||||
case 13:
|
||||
_context4.prev = 13;
|
||||
_context4.t0 = _context4['catch'](0);
|
||||
case 15:
|
||||
_context4.prev = 15;
|
||||
_context4.t0 = _context4['catch'](2);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message);
|
||||
|
||||
case 16:
|
||||
case 18:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[0, 13]]);
|
||||
}, _callee4, this, [[2, 15]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
|
@ -608,7 +608,7 @@ var projectController = function (_baseController) {
|
||||
count = _context6.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn({
|
||||
total: count,
|
||||
total: Math.ceil(count / limit),
|
||||
list: result
|
||||
});
|
||||
_context6.next = 16;
|
||||
|
@ -666,7 +666,7 @@ var userController = function (_baseController) {
|
||||
case 8:
|
||||
count = _context9.sent;
|
||||
return _context9.abrupt('return', ctx.body = _yapi2.default.commons.resReturn({
|
||||
total: count,
|
||||
total: Math.ceil(count / limit),
|
||||
list: user
|
||||
}));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user