Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
suxiaoxin 2017-08-17 18:00:11 +08:00
commit b574604717
5 changed files with 66 additions and 15 deletions

View File

@ -6,9 +6,11 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux' import { connect } from 'react-redux'
@connect(state=>{ @connect(state=>{
console.log(state);
return { return {
curUid: state.user.uid, curUid: state.user.uid,
userType: state.user.type userType: state.user.type,
curRole: state.user.role
} }
},{ },{
@ -19,7 +21,8 @@ class Profile extends Component {
static propTypes = { static propTypes = {
match: PropTypes.object, match: PropTypes.object,
curUid: PropTypes.number, curUid: PropTypes.number,
userType: PropTypes.string userType: PropTypes.string,
curRole: PropTypes.string
} }
constructor(props) { constructor(props) {
@ -147,12 +150,32 @@ class Profile extends Component {
}else{ }else{
userType = false; userType = false;
} }
if (this.state.usernameEdit === false) { if (this.state.usernameEdit === false) {
let btn = "";
if(userType){
if(userinfo.uid === this.props.curUid){//本人
btn = <Button icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>;
}else{
if(this.props.curRole === "admin"){
btn = <Button icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>;
}else{
btn = "";
}
}
}else{
// if(userinfo.uid === this.props.curUid){//本人
// btn = <Button icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>;
// }else{
btn = "";
// }
}
userNameEditHtml = <div > userNameEditHtml = <div >
<span className="text">{userinfo.username}</span>&nbsp;&nbsp; <span className="text">{userinfo.username}</span>&nbsp;&nbsp;
{/*<span className="text-button" onClick={() => { this.handleEdit('usernameEdit', true) }}><Icon type="edit" />修改</span>*/} {/*<span className="text-button" onClick={() => { this.handleEdit('usernameEdit', true) }}><Icon type="edit" />修改</span>*/}
{<Button icon="edit" onClick={() => { this.handleEdit('usernameEdit', true) }}>修改</Button>} {
btn
}
</div> </div>
} else { } else {
userNameEditHtml = <div> userNameEditHtml = <div>
@ -165,10 +188,28 @@ class Profile extends Component {
} }
if (this.state.emailEdit === false) { if (this.state.emailEdit === false) {
let btn = "";
if(userType){
if(userinfo.uid === this.props.curUid){//本人
btn = <Button icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>
}else{
if(this.props.curRole === "admin"){
btn = <Button icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>
}else{
btn = "";
}
}
}else{
if(userinfo.uid === this.props.curUid){//本人
// btn = <Button icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>
}else{
btn = "";
}
}
emailEditHtml = <div > emailEditHtml = <div >
<span className="text">{userinfo.email}</span>&nbsp;&nbsp; <span className="text">{userinfo.email}</span>&nbsp;&nbsp;
{/*<span className="text-button" onClick={() => { this.handleEdit('emailEdit', true) }} ><Icon type="edit" />修改</span>*/} {/*<span className="text-button" onClick={() => { this.handleEdit('emailEdit', true) }} ><Icon type="edit" />修改</span>*/}
{userType?<Button icon="edit" onClick={() => { this.handleEdit('emailEdit', true) }}>修改</Button>:""} {btn}
</div> </div>
} else { } else {
emailEditHtml = <div> emailEditHtml = <div>
@ -181,24 +222,27 @@ class Profile extends Component {
} }
if (this.state.roleEdit === false) { if (this.state.roleEdit === false) {
let btn = "";
roleEditHtml = <div> roleEditHtml = <div>
<span className="text">{roles[userinfo.role]}</span>&nbsp;&nbsp; <span className="text">{roles[userinfo.role]}</span>&nbsp;&nbsp;
{/*<span className="text-button" onClick={() => { this.handleEdit('roleEdit', true) }} ><Icon type="edit" />修改</span>*/} {btn}
{userType?<Button icon="edit" onClick={() => { this.handleEdit('roleEdit', true) }}>修改</Button>:""}
</div> </div>
} else { } else {
roleEditHtml = <Select defaultValue={_userinfo.role} onChange={ this.changeRole} style={{ width: 150 }} > roleEditHtml = <Select defaultValue={_userinfo.role} onChange={ this.changeRole} style={{ width: 150 }} >
<Option value="admin">管理员</Option> <Option value="admin">管理员</Option>
<Option value="member">会员</Option> <Option value="member">会员</Option>
</Select> </Select>
} }
if (this.state.secureEdit === false) { if (this.state.secureEdit === false) {
secureEditHtml = <Button icon="edit" onClick={() => { this.handleEdit('secureEdit', true) }}>修改</Button> let btn = "";
if(this.props.curRole === "admin" && userType){
btn = <Button icon="edit" onClick={() => { this.handleEdit('secureEdit', true) }}>修改</Button>
}
secureEditHtml = btn;
} else { } else {
secureEditHtml = <div> secureEditHtml = <div>
<Input style={{display: this.state.userinfo.role === 'admin' ? 'none': ''}} placeholder="旧的密码" type="password" name="old_password" id="old_password" /> <Input style={{display: this.props.curRole === 'admin' ? 'none': ''}} placeholder="旧的密码" type="password" name="old_password" id="old_password" />
<Input placeholder="新的密码" type="password" name="password" id="password" /> <Input placeholder="新的密码" type="password" name="password" id="password" />
<Input placeholder="确认密码" type="password" name="verify_pass" id="verify_pass" /> <Input placeholder="确认密码" type="password" name="verify_pass" id="verify_pass" />
<ButtonGroup className="edit-buttons" > <ButtonGroup className="edit-buttons" >
@ -208,10 +252,9 @@ class Profile extends Component {
</div> </div>
} }
return <div className="user-profile"> return <div className="user-profile">
<Row className="user-item" type="flex" justify="start"> <Row className="user-item" type="flex" justify="start">
<Col span={24}><AvatarUpload uid={userinfo.uid}>点击上传头像</AvatarUpload></Col> <Col span={24}>{userinfo.uid === this.props.curUid?<AvatarUpload uid={userinfo.uid}>点击上传头像</AvatarUpload>:<img className = "avatarImg" src = {`/api/user/avatar?uid=${userinfo.uid}`} />}</Col>
<Col span={4}>用户id</Col> <Col span={4}>用户id</Col>
<Col span={12}> <Col span={12}>
{userinfo.uid} {userinfo.uid}
@ -229,7 +272,7 @@ class Profile extends Component {
{emailEditHtml} {emailEditHtml}
</Col> </Col>
</Row> </Row>
<Row className="user-item" style={{display: this.state.userinfo.role === 'admin'? '': 'none'}} type="flex" justify="start"> <Row className="user-item" style={{display: this.props.curRole === 'admin'? '': 'none'}} type="flex" justify="start">
<Col span={4}>角色</Col> <Col span={4}>角色</Col>
<Col span={12}> <Col span={12}>
{roleEditHtml} {roleEditHtml}
@ -248,7 +291,7 @@ class Profile extends Component {
</Col> </Col>
</Row> </Row>
{userType?<Row className="user-item" type="flex" justify="start"> {(this.props.curRole === "admin" && userType)?<Row className="user-item" type="flex" justify="start">
<Col span={4}>密码</Col> <Col span={4}>密码</Col>
<Col span={12}> <Col span={12}>
{secureEditHtml} {secureEditHtml}

View File

@ -121,6 +121,11 @@
} }
.avatar{ .avatar{
width: 100px; width: 100px;
// border-radius: 50px;
}
.avatarImg{
width: 100px;
border-radius: 50px;
} }
.avatar-uploader { .avatar-uploader {
display: block; display: block;

View File

@ -31,7 +31,8 @@ export default (state = initialState, action) => {
role: action.payload.data.data ? action.payload.data.data.role:null, role: action.payload.data.data ? action.payload.data.data.role:null,
loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS, loginState: (action.payload.data.errcode == 0)?MEMBER_STATUS:GUEST_STATUS,
userName: action.payload.data.data ? action.payload.data.data.username : null, userName: action.payload.data.data ? action.payload.data.data.username : null,
uid: action.payload.data.data ? action.payload.data.data._id : null uid: action.payload.data.data ? action.payload.data.data._id : null,
type: action.payload.data.data ? action.payload.data.data.type : null
}; };
} }
case LOGIN: { case LOGIN: {

View File

@ -356,6 +356,7 @@ class userController extends baseController {
username: result.username, username: result.username,
email: result.email, email: result.email,
role: result.role, role: result.role,
type: result.type,
add_time: result.add_time, add_time: result.add_time,
up_time: result.up_time up_time: result.up_time
}); });

View File

@ -730,6 +730,7 @@ var userController = function (_baseController) {
username: result.username, username: result.username,
email: result.email, email: result.email,
role: result.role, role: result.role,
type: result.type,
add_time: result.add_time, add_time: result.add_time,
up_time: result.up_time up_time: result.up_time
})); }));