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

This commit is contained in:
suxiaoxin 2017-09-14 21:57:11 +08:00
parent 4a989aaf49
commit 20de8e6784
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 Activity from './Activity/Activity.js'
import Setting from './Setting/Setting.js'
import ProjectMember from './Setting/ProjectMember/ProjectMember.js';
import ProjectData from './Setting/ProjectData/ProjectData.js';
@connect(
state => {
@ -55,7 +56,9 @@ export default class Project extends Component {
const routers = {
activity: { name: '动态', path: "/project/:id/activity" },
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;
@ -81,12 +84,20 @@ export default class Project extends Component {
}, {
name: routers.activity.name,
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>
<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} />
<Route path={routers.members.path} component={ProjectMember} />
<Route path={routers.data.path} component={ProjectData} />
</Switch>
</div>
)

View File

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

View File

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

View File

@ -3,8 +3,7 @@ import { Tabs } from 'antd';
import PropTypes from 'prop-types';
const TabPane = Tabs.TabPane;
import ProjectMessage from './ProjectMessage/ProjectMessage.js';
import ProjectMember from './ProjectMember/ProjectMember.js';
import ProjectData from './ProjectData/ProjectData.js';
import './Setting.scss';
class Setting extends Component {
@ -17,8 +16,7 @@ class Setting extends Component {
<div className="g-row">
<Tabs type="card" className="m-tab">
<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>
</div>
)

View File

@ -654,28 +654,30 @@ class interfaceController extends baseController {
/**
* 获取分类列表
* @interface /interface/getCatMenu
* @method GET
* @category interface
* @foldnumber 10
* @param {Number} project_id 项目id不能为空
* @returns {Object}
* @example ./api/interface/getCatMenu
*/
* 获取分类列表
* @interface /interface/getCatMenu
* @method GET
* @category interface
* @foldnumber 10
* @param {Number} project_id 项目id不能为空
* @returns {Object}
* @example ./api/interface/getCatMenu
*/
async getCatMenu(ctx) {
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不能为空');
}
let project = await this.projectModel.getBaseInfo(project_id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
try {
let project = await this.projectModel.getBaseInfo(project_id);
if (project.project_type === 'private') {
if (await this.checkAuth(project._id, 'project', 'edit') !== true) {
return ctx.body = yapi.commons.resReturn(null, 406, '没有权限');
}
}
let res = await this.catModel.list(project_id);
return ctx.body = yapi.commons.resReturn(res);
} catch (e) {