opti: 把项目成员和项目数据管理两个功能提取出来

This commit is contained in:
suxiaoxin 2017-09-14 21:57:11 +08:00
parent 3ad41fd4bb
commit c02ec86d36
5 changed files with 52 additions and 37 deletions

View File

@ -9,7 +9,8 @@ import { getProject } from '../../reducer/modules/project';
import Interface from './Interface/Interface.js' import Interface from './Interface/Interface.js'
import Activity from './Activity/Activity.js' import Activity from './Activity/Activity.js'
import Setting from './Setting/Setting.js' import Setting from './Setting/Setting.js'
import ProjectMember from './Setting/ProjectMember/ProjectMember.js';
import ProjectData from './Setting/ProjectData/ProjectData.js';
@connect( @connect(
state => { state => {
@ -55,7 +56,9 @@ export default class Project extends Component {
const routers = { const routers = {
activity: { name: '动态', path: "/project/:id/activity" }, activity: { name: '动态', path: "/project/:id/activity" },
interface: { name: '接口', path: "/project/:id/interface/:action" }, interface: { name: '接口', path: "/project/:id/interface/:action" },
setting: { name: '设置', path: "/project/:id/setting" } setting: { name: '设置', path: "/project/:id/setting" },
members: { name: '成员管理', path: "/project/:id/members" },
data: { name: '数据管理', path: "/project/:id/data" }
} }
let key, defaultName; let key, defaultName;
@ -81,12 +84,20 @@ export default class Project extends Component {
}, { }, {
name: routers.activity.name, name: routers.activity.name,
path: `/project/${match.params.id}/activity` path: `/project/${match.params.id}/activity`
}, {
name: routers.members.name,
path: `/project/${match.params.id}/members`
}, {
name: routers.data.name,
path: `/project/${match.params.id}/data`
}]} /> }]} />
<Switch> <Switch>
<Redirect exact from="/project/:id" to={`/project/${match.params.id}/interface/api`} /> <Redirect exact from="/project/:id" to={`/project/${match.params.id}/interface/api`} />
<Route path={routers.activity.path} component={Activity} /> <Route path={routers.activity.path} component={Activity} />
<Route path={routers.interface.path} component={Interface} /> <Route path={routers.interface.path} component={Interface} />
<Route path={routers.setting.path} component={Setting} /> <Route path={routers.setting.path} component={Setting} />
<Route path={routers.members.path} component={ProjectMember} />
<Route path={routers.data.path} component={ProjectData} />
</Switch> </Switch>
</div> </div>
) )

View File

@ -35,7 +35,7 @@ class ProjectData extends Component {
} }
componentWillMount(){ componentWillMount(){
axios.get(`/api/interface/getCatMenu?project_id=${this.props.projectId}`).then((data)=>{ axios.get(`/api/interface/getCatMenu?project_id=${this.props.match.params.id}`).then((data)=>{
let menuList = data.data.data; let menuList = data.data.data;
this.setState({ this.setState({
menuList: menuList menuList: menuList
@ -269,7 +269,7 @@ class ProjectData extends Component {
onChange: this.uploadChnange.bind(this) onChange: this.uploadChnange.bind(this)
} }
return ( return (
<div className="m-panel"> <div className="m-panel g-row" style={{paddingTop: '15px'}}>
<div className="postman-dataImport"> <div className="postman-dataImport">
<div className="dataImportCon"> <div className="dataImportCon">

View File

@ -6,7 +6,7 @@ import { fetchGroupMsg } from '../../../../reducer/modules/group';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ErrMsg from '../../../../components/ErrMsg/ErrMsg.js'; import ErrMsg from '../../../../components/ErrMsg/ErrMsg.js';
import { fetchGroupMemberList } from '../../../../reducer/modules/group.js'; import { fetchGroupMemberList } from '../../../../reducer/modules/group.js';
import { getProjectMsg, getProjectMemberList, addMember, delMember, changeMemberRole } from '../../../../reducer/modules/project.js'; import { getProjectMsg, getProjectMemberList,getProject, addMember, delMember, changeMemberRole } from '../../../../reducer/modules/project.js';
import UsernameAutoComplete from '../../../../components/UsernameAutoComplete/UsernameAutoComplete.js'; import UsernameAutoComplete from '../../../../components/UsernameAutoComplete/UsernameAutoComplete.js';
import '../Setting.scss'; import '../Setting.scss';
@ -24,7 +24,7 @@ const arrayAddKey = (arr) => {
@connect( @connect(
state => { state => {
return { return {
projectMsg: state.project.projectMsg, projectMsg: state.project.currProject,
uid: state.user.uid uid: state.user.uid
} }
}, },
@ -35,7 +35,8 @@ const arrayAddKey = (arr) => {
addMember, addMember,
delMember, delMember,
fetchGroupMsg, fetchGroupMsg,
changeMemberRole changeMemberRole,
getProject
} }
) )
class ProjectMember extends Component { class ProjectMember extends Component {
@ -53,12 +54,14 @@ class ProjectMember extends Component {
} }
} }
static propTypes = { static propTypes = {
match: PropTypes.object,
projectId: PropTypes.number, projectId: PropTypes.number,
projectMsg: PropTypes.object, projectMsg: PropTypes.object,
uid: PropTypes.number, uid: PropTypes.number,
addMember: PropTypes.func, addMember: PropTypes.func,
delMember: PropTypes.func, delMember: PropTypes.func,
changeMemberRole: PropTypes.func, changeMemberRole: PropTypes.func,
getProject: PropTypes.func,
fetchGroupMemberList: PropTypes.func, fetchGroupMemberList: PropTypes.func,
getProjectMsg: PropTypes.func, getProjectMsg: PropTypes.func,
fetchGroupMsg: PropTypes.func, fetchGroupMsg: PropTypes.func,
@ -74,7 +77,7 @@ class ProjectMember extends Component {
// 重新获取列表 // 重新获取列表
@autobind @autobind
reFetchList() { reFetchList() {
this.props.getProjectMemberList(this.props.projectId).then((res) => { this.props.getProjectMemberList(this.props.match.params.id).then((res) => {
this.setState({ this.setState({
projectMemberList: arrayAddKey(res.payload.data.data), projectMemberList: arrayAddKey(res.payload.data.data),
visible: false visible: false
@ -86,7 +89,7 @@ class ProjectMember extends Component {
@autobind @autobind
handleOk() { handleOk() {
this.props.addMember({ this.props.addMember({
id: this.props.projectId, id: this.props.match.params.id,
member_uid: this.state.inputUid, member_uid: this.state.inputUid,
role: this.state.inputRole role: this.state.inputRole
}).then((res) => { }).then((res) => {
@ -108,7 +111,7 @@ class ProjectMember extends Component {
@autobind @autobind
deleteConfirm(member_uid) { deleteConfirm(member_uid) {
return () => { return () => {
const id = this.props.projectId; const id = this.props.match.params.id;
this.props.delMember({ id, member_uid }).then((res) => { this.props.delMember({ id, member_uid }).then((res) => {
if (!res.payload.data.errcode) { if (!res.payload.data.errcode) {
message.success(res.payload.data.errmsg); message.success(res.payload.data.errmsg);
@ -121,7 +124,7 @@ class ProjectMember extends Component {
// 改 - 修改成员权限 // 改 - 修改成员权限
@autobind @autobind
changeUserRole(e) { changeUserRole(e) {
const id = this.props.projectId; const id = this.props.match.params.id;
const role = e.split('-')[0]; const role = e.split('-')[0];
const member_uid = e.split('-')[1]; const member_uid = e.split('-')[1];
this.props.changeMemberRole({ id, member_uid, role }).then((res) => { this.props.changeMemberRole({ id, member_uid, role }).then((res) => {
@ -148,10 +151,11 @@ class ProjectMember extends Component {
} }
async componentWillMount() { async componentWillMount() {
await this.props.getProject(this.props.match.params.id)
const groupMemberList = await this.props.fetchGroupMemberList(this.props.projectMsg.group_id); const groupMemberList = await this.props.fetchGroupMemberList(this.props.projectMsg.group_id);
const groupMsg = await this.props.fetchGroupMsg(this.props.projectMsg.group_id); const groupMsg = await this.props.fetchGroupMsg(this.props.projectMsg.group_id);
const rojectMsg = await this.props.getProjectMsg(this.props.projectId); const rojectMsg = await this.props.getProjectMsg(this.props.match.params.id);
const projectMemberList = await this.props.getProjectMemberList(this.props.projectId); const projectMemberList = await this.props.getProjectMemberList(this.props.match.params.id);
this.setState({ this.setState({
groupMemberList: groupMemberList.payload.data.data, groupMemberList: groupMemberList.payload.data.data,
groupName: groupMsg.payload.data.data.group_name, groupName: groupMsg.payload.data.data.group_name,
@ -201,7 +205,7 @@ class ProjectMember extends Component {
} }
}]; }];
return ( return (
<div className="m-panel"> <div className="m-panel g-row" style={{paddingTop: '15px'}}>
<Modal <Modal
title="添加成员" title="添加成员"
visible={this.state.visible} visible={this.state.visible}

View File

@ -3,8 +3,7 @@ import { Tabs } from 'antd';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const TabPane = Tabs.TabPane; const TabPane = Tabs.TabPane;
import ProjectMessage from './ProjectMessage/ProjectMessage.js'; import ProjectMessage from './ProjectMessage/ProjectMessage.js';
import ProjectMember from './ProjectMember/ProjectMember.js';
import ProjectData from './ProjectData/ProjectData.js';
import './Setting.scss'; import './Setting.scss';
class Setting extends Component { class Setting extends Component {
@ -17,8 +16,7 @@ class Setting extends Component {
<div className="g-row"> <div className="g-row">
<Tabs type="card" className="m-tab"> <Tabs type="card" className="m-tab">
<TabPane tab="项目信息" key="1"><ProjectMessage projectId={+id}/></TabPane> <TabPane tab="项目信息" key="1"><ProjectMessage projectId={+id}/></TabPane>
<TabPane tab="成员列表" key="2"><ProjectMember projectId={+id}/></TabPane>
<TabPane tab="数据管理" key="3"><ProjectData projectId={+id}/></TabPane>
</Tabs> </Tabs>
</div> </div>
) )

View File

@ -666,16 +666,18 @@ class interfaceController extends baseController {
async getCatMenu(ctx) { async getCatMenu(ctx) {
let project_id = ctx.request.query.project_id; let project_id = ctx.request.query.project_id;
if (!project_id) {
if (!project_id || !isNaN(project_id)) {
return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'); return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空');
} }
try {
let project = await this.projectModel.getBaseInfo(project_id); let project = await this.projectModel.getBaseInfo(project_id);
if (project.project_type === 'private') { if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) { if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限'); return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
} }
} }
try {
let res = await this.catModel.list(project_id); let res = await this.catModel.list(project_id);
return ctx.body = yapi.commons.resReturn(res); return ctx.body = yapi.commons.resReturn(res);
} catch (e) { } catch (e) {