2017-08-10 16:00:52 +08:00
|
|
|
import React, { Component } from 'react'
|
2017-08-11 17:24:50 +08:00
|
|
|
import { connect } from 'react-redux';
|
2017-08-10 16:00:52 +08:00
|
|
|
import PropTypes from 'prop-types'
|
2017-08-21 10:18:56 +08:00
|
|
|
import { Route, Switch, Redirect, matchPath } from 'react-router-dom';
|
2017-08-28 18:12:13 +08:00
|
|
|
import { Subnav } from '../../components/index';
|
|
|
|
import { fetchGroupMsg } from '../../reducer/modules/group';
|
|
|
|
import { setBreadcrumb } from '../../reducer/modules/user';
|
2017-08-21 10:18:56 +08:00
|
|
|
import { getProject } from '../../reducer/modules/project';
|
2017-08-11 17:29:37 +08:00
|
|
|
import Interface from './Interface/Interface.js'
|
2017-08-14 15:17:05 +08:00
|
|
|
import Activity from './Activity/Activity.js'
|
2017-08-17 12:09:08 +08:00
|
|
|
import Setting from './Setting/Setting.js'
|
2017-09-14 21:57:11 +08:00
|
|
|
import ProjectMember from './Setting/ProjectMember/ProjectMember.js';
|
|
|
|
import ProjectData from './Setting/ProjectData/ProjectData.js';
|
2017-08-10 16:00:52 +08:00
|
|
|
|
2017-08-11 17:24:50 +08:00
|
|
|
@connect(
|
|
|
|
state => {
|
|
|
|
return {
|
2017-08-15 11:12:39 +08:00
|
|
|
curProject: state.project.currProject
|
2017-08-11 17:24:50 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2017-08-28 18:12:13 +08:00
|
|
|
getProject,
|
|
|
|
fetchGroupMsg,
|
|
|
|
setBreadcrumb
|
2017-08-10 16:00:52 +08:00
|
|
|
}
|
2017-08-11 17:24:50 +08:00
|
|
|
)
|
2017-08-21 10:18:56 +08:00
|
|
|
|
2017-08-11 17:24:50 +08:00
|
|
|
export default class Project extends Component {
|
2017-08-10 16:00:52 +08:00
|
|
|
|
2017-08-11 17:24:50 +08:00
|
|
|
static propTypes = {
|
|
|
|
match: PropTypes.object,
|
|
|
|
curProject: PropTypes.object,
|
2017-08-21 10:18:56 +08:00
|
|
|
getProject: PropTypes.func,
|
2017-08-28 18:12:13 +08:00
|
|
|
location: PropTypes.object,
|
|
|
|
fetchGroupMsg: PropTypes.func,
|
|
|
|
setBreadcrumb: PropTypes.func
|
2017-08-10 16:00:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
2017-08-28 18:12:13 +08:00
|
|
|
async componentWillMount() {
|
|
|
|
await this.props.getProject(this.props.match.params.id);
|
|
|
|
const groupMsg = await this.props.fetchGroupMsg(this.props.curProject.group_id);
|
|
|
|
this.props.setBreadcrumb([{
|
|
|
|
name: groupMsg.payload.data.data.group_name,
|
|
|
|
href: '/group/'+groupMsg.payload.data.data._id
|
|
|
|
}, {
|
|
|
|
name: this.props.curProject.name
|
|
|
|
}]);
|
2017-08-10 16:00:52 +08:00
|
|
|
}
|
|
|
|
|
2017-08-21 10:18:56 +08:00
|
|
|
render() {
|
|
|
|
const { match, location } = this.props;
|
|
|
|
const routers = {
|
|
|
|
activity: { name: '动态', path: "/project/:id/activity" },
|
|
|
|
interface: { name: '接口', path: "/project/:id/interface/:action" },
|
2017-09-14 21:57:11 +08:00
|
|
|
setting: { name: '设置', path: "/project/:id/setting" },
|
|
|
|
members: { name: '成员管理', path: "/project/:id/members" },
|
|
|
|
data: { name: '数据管理', path: "/project/:id/data" }
|
2017-08-21 10:18:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
let key, defaultName;
|
|
|
|
for (key in routers) {
|
|
|
|
if (matchPath(location.pathname, {
|
|
|
|
path: routers[key].path
|
|
|
|
}) !== null) {
|
|
|
|
defaultName = routers[key].name;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 16:00:52 +08:00
|
|
|
return (
|
|
|
|
<div>
|
2017-08-10 20:56:08 +08:00
|
|
|
<Subnav
|
2017-08-21 10:18:56 +08:00
|
|
|
default={defaultName}
|
2017-08-10 20:56:08 +08:00
|
|
|
data={[{
|
2017-08-21 10:18:56 +08:00
|
|
|
name: routers.interface.name,
|
2017-08-16 18:04:16 +08:00
|
|
|
path: `/project/${match.params.id}/interface/api`
|
2017-08-10 20:56:08 +08:00
|
|
|
}, {
|
2017-08-21 10:18:56 +08:00
|
|
|
name: routers.activity.name,
|
2017-08-11 10:44:33 +08:00
|
|
|
path: `/project/${match.params.id}/activity`
|
2017-09-14 21:57:11 +08:00
|
|
|
}, {
|
2017-09-19 14:15:08 +08:00
|
|
|
name: routers.data.name,
|
|
|
|
path: `/project/${match.params.id}/data`
|
|
|
|
},{
|
2017-09-14 21:57:11 +08:00
|
|
|
name: routers.members.name,
|
|
|
|
path: `/project/${match.params.id}/members`
|
|
|
|
}, {
|
2017-09-19 14:15:08 +08:00
|
|
|
name: routers.setting.name,
|
|
|
|
path: `/project/${match.params.id}/setting`
|
2017-08-21 10:18:56 +08:00
|
|
|
}]} />
|
2017-08-10 20:08:23 +08:00
|
|
|
<Switch>
|
2017-08-21 10:18:56 +08:00
|
|
|
<Redirect exact from="/project/:id" to={`/project/${match.params.id}/interface/api`} />
|
|
|
|
<Route path={routers.activity.path} component={Activity} />
|
|
|
|
<Route path={routers.interface.path} component={Interface} />
|
|
|
|
<Route path={routers.setting.path} component={Setting} />
|
2017-09-14 21:57:11 +08:00
|
|
|
<Route path={routers.members.path} component={ProjectMember} />
|
|
|
|
<Route path={routers.data.path} component={ProjectData} />
|
2017-08-10 20:08:23 +08:00
|
|
|
</Switch>
|
2017-08-10 16:00:52 +08:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|