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

This commit is contained in:
suxiaoxin 2017-07-24 11:24:13 +08:00
commit 9724b605a2
11 changed files with 106 additions and 165 deletions

View File

@ -2,7 +2,8 @@ import {
LOGIN,
LOGIN_OUT,
LOGIN_TYPE,
GET_LOGIN_STATE
GET_LOGIN_STATE,
REGISTER
} from '../constants/action-types.js';
import axios from 'axios';
@ -22,52 +23,29 @@ const checkLoginState = () => {
}
const loginActions = (data) => {
return (dispatch) => {
axios.post('/user/login', data).then((res) => {
if (res.data.errcode === 0) {
dispatch({
type: LOGIN,
payload: {
data: res
}
});
} else {
console.log('登录失败,errcode不为0');
}
}).catch((err) => {
console.log(err);
});
}
}
return {
type: LOGIN,
payload: axios.post('/user/login', data)
};
};
const regActions = (data) => {
console.log(data);
const { email, password, userName } = data;
const param = {
email: data.email,
password: data.password,
username: data.userName
}
return () => {
axios.post('/user/login', param).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});
}
}
email,
password,
username: userName
};
return {
type: REGISTER,
payload: axios.post('/user/reg', param)
};
};
const logoutActions = () => {
return(dispatch)=>{
axios.get('./user/logout').then((res) => {
console.log(res);
if(res.data.errcode === 0){
dispatch({
type: LOGIN_OUT
})
}
}).catch((err) => {
console.log(err);
})
return {
type: LOGIN_OUT,
payload: axios.get('./user/logout')
}
}

View File

@ -15,7 +15,7 @@ const fetchProjectList = (id, pageNum) => {
payload: axios.get('/project/list', {
params: {
group_id: id,
page: pageNum,
page: pageNum || 1,
limit: variable.PAGE_LIMIT
}
})
@ -54,14 +54,15 @@ const addProject = (data) => {
};
const updateProject = (data) => {
const { name, prd_host, basepath, desc, _id, protocol } = data;
const { name, prd_host, basepath, desc, _id, protocol, env } = data;
const param = {
name,
prd_host,
protocol,
basepath,
desc,
id: _id
id: _id,
env
};
return {
type: PROJECT_UPDATE,

View File

@ -1,82 +0,0 @@
import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import { Route, HashRouter, Redirect, Switch } from 'react-router-dom'
import { Home, ProjectGroups, Interface, News, AddInterface } from './containers/index'
import User from './containers/User/User.js'
import Header from './components/Header/Header'
import { checkLoginState } from './actions/login'
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
}
}
static propTypes = {
checkLoginState:PropTypes.func,
loginState:PropTypes.number
}
route = (status) => {
let r;
if (status === LOADING_STATUS) {
return <span>loading...</span>
} else if (status === GUEST_STATUS) {
r = (
<HashRouter>
<div className="router-main">
<Header />
<Switch>
<Route
path="/"
component={Home}/>
<Redirect from="(/:str)" to="/" />
</Switch>
</div>
</HashRouter>
)
} else {
r = (
<HashRouter>
<div className="router-main">
<Header />
<Route path="/" component={Home} exact />
<Route path="/ProjectGroups" component={ProjectGroups} />
<Route path="/Interface" component={Interface} />
<Route path="/user" component={User} />
<Route path="/News" component={News} />
<Route path="/AddInterface" component={ AddInterface } />
</div>
</HashRouter>
)
}
return r
}
componentDidMount() {
this.props.checkLoginState();
}
render() {
return this.route(this.props.loginState)
}
}
export default connect(
state => {
return{
loginState:state.login.loginState
}
},
{
checkLoginState
}
)(App)

View File

@ -3,7 +3,7 @@ import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Link } from 'react-router-dom'
import { Icon, Layout, Menu, Dropdown } from 'antd'
import { Icon, Layout, Menu, Dropdown, message } from 'antd'
import { checkLoginState, logoutActions, loginTypeAction} from '../../actions/login'
import { changeMenuItem } from '../../actions/menu'
import { withRouter } from 'react-router';
@ -98,12 +98,17 @@ class HeaderCom extends Component {
}
logout = (e) => {
e.preventDefault();
this.props.logoutActions();
this.props.history.push('/');
this.props.changeMenuItem("/");
// this.setState({
// current : "/"
// })
this.props.logoutActions().then((res) => {
if (res.payload.data.errcode == 0) {
this.props.history.push('/');
this.props.changeMenuItem("/");
message.success('退出成功! ');
} else {
message.error(res.payload.data.errmsg);
}
}).catch((err) => {
message.error(err);
});
}
handleLogin = (e) => {
e.preventDefault();
@ -114,7 +119,7 @@ class HeaderCom extends Component {
this.props.loginTypeAction("2");
}
checkLoginState = () => {
this.props.checkLoginState().then((res) => {
this.props.checkLoginState.then((res) => {
if (res.payload.data.errcode !== 0) {
this.props.history.push('/');
}

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Form, Button, Input, Icon } from 'antd';
import { Form, Button, Input, Icon, message } from 'antd';
import { loginActions } from '../../actions/login';
const FormItem = Form.Item;
@connect(
@ -30,7 +30,15 @@ class Login extends Component {
const form = this.props.form;
form.validateFields((err, values) => {
if (!err) {
this.props.loginActions(values);
this.props.loginActions(values).then((res) => {
if (res.payload.data.errcode == 0) {
message.success('登录成功! ');
} else {
message.error(res.payload.data.errmsg);
}
}).catch((err) => {
message.error(err);
});
}
});
}

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Form, Button, Input, Icon } from 'antd';
import { Form, Button, Input, Icon, message } from 'antd';
import { regActions } from '../../actions/login';
const FormItem = Form.Item;
@ -34,7 +34,15 @@ class Reg extends Component {
const form = this.props.form;
form.validateFieldsAndScroll((err, values) => {
if (!err) {
this.props.regActions(values);
this.props.regActions(values).then((res) => {
if (res.payload.data.errcode == 0) {
message.success('注册成功! ');
} else {
message.error(res.payload.data.errmsg);
}
}).catch((err) => {
message.error(err);
});
}
});
}

View File

@ -80,9 +80,11 @@ class UpDateModal extends Component {
// 确认修改
handleOk = (e) => {
console.log('in');
e.preventDefault();
const { form, updateProject, changeUpdateModal, currGroup, projectList, handleUpdateIndex, fetchProjectList, changeTableLoading } = this.props;
form.validateFields((err, values) => {
console.log(err);
if (!err) {
console.log(projectList[handleUpdateIndex]);
let assignValue = Object.assign(projectList[handleUpdateIndex], values);
@ -90,7 +92,7 @@ class UpDateModal extends Component {
assignValue.env = assignValue.envs.map((item, index) => {
return {
name: values['envs-name-'+index],
host: values['envs-host-'+index]
domain: values['envs-domain-'+index]
}
});
console.log(assignValue);
@ -117,21 +119,26 @@ class UpDateModal extends Component {
});
}
remove = (k) => {
// 项目的修改操作 - 删除一项环境配置
remove = (id) => {
const { form } = this.props;
// can use data-binding to get
const envs = form.getFieldValue('envs');
// We need at least one passenger
if (envs.length === 1) {
if (envs.length === 0) {
return;
}
// can use data-binding to set
form.setFieldsValue({
envs: envs.filter(key => key !== k)
envs: envs.filter(key => {
console.log(key);
return key._id !== id;
})
});
}
// 项目的修改操作 - 添加一项环境配置
add = () => {
uuid++;
const { form } = this.props;
@ -145,15 +152,6 @@ class UpDateModal extends Component {
});
}
handleSubmit = (e) => {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
console.log('Received values of form: ', values);
}
});
}
render() {
const { getFieldDecorator, getFieldValue } = this.props.form;
// const that = this;
@ -176,7 +174,7 @@ class UpDateModal extends Component {
getFieldDecorator('envs', { initialValue: envMessage });
const envs = getFieldValue('envs');
const formItems = envs.map((k, index) => {
// console.log(k);
console.log(k);
const secondIndex = 'next' + index; // 为保证key的唯一性
return (
<Row key={index} type="flex" justify="space-between" align={index === 0 ? 'middle' : 'top'}>
@ -193,7 +191,20 @@ class UpDateModal extends Component {
rules: [{
required: false,
whitespace: true,
message: "请输入环境名称"
message: "请输入环境名称",
validator(rule, value, callback) {
if (value) {
if (value.length === 0) {
callback('请输入环境域名');
} else if (!/\S/.test(value)) {
callback('请输入环境域名');
} else {
return callback();
}
} else {
callback('请输入环境域名');
}
}
}]
})(
<Input placeholder="请输入环境名称" style={{ width: '90%', marginRight: 8 }} />
@ -207,13 +218,26 @@ class UpDateModal extends Component {
required={false}
key={secondIndex}
>
{getFieldDecorator(`envs-host-${index}`, {
{getFieldDecorator(`envs-domain-${index}`, {
validateTrigger: ['onChange', 'onBlur'],
initialValue: envMessage.length !== 0 ? k.host : '',
initialValue: envMessage.length !== 0 ? k.domain : '',
rules: [{
required: false,
whitespace: true,
message: "请输入环境域名"
message: "请输入环境域名",
validator(rule, value, callback) {
if (value) {
if (value.length === 0) {
callback('请输入环境域名');
} else if (!/\S/.test(value)) {
callback('请输入环境域名');
} else {
return callback();
}
} else {
callback('请输入环境域名');
}
}
}]
})(
<Input placeholder="请输入环境域名" style={{ width: '90%', marginRight: 8 }} />
@ -221,12 +245,11 @@ class UpDateModal extends Component {
</FormItem>
</Col>
<Col span={2}>
{envs.length > 1 ? (
{envs.length > 0 ? (
<Icon
className="dynamic-delete-button"
type="minus-circle-o"
disabled={envs.length === 1}
onClick={() => this.remove(k)}
onClick={() => this.remove(k._id)}
/>
) : null}
</Col>

View File

@ -3,7 +3,7 @@ import 'babel-polyfill'
import thunkMiddleware from 'redux-thunk'
import promiseMiddleware from 'redux-promise';
import ReactDOM from 'react-dom'
import App from './App'
import App from './Application'
import { createStore, combineReducers, applyMiddleware } from 'redux'
import { Provider } from 'react-redux'
import ReduxContainer from './ReduxContainer.js'

View File

@ -32,8 +32,8 @@ export default (state = initialState, action) => {
...state,
isLogin: true,
loginState: MEMBER_STATUS,
uid: action.payload.data.uid,
userName: action.payload.data.userName
uid: action.payload.data.data.uid,
userName: action.payload.data.data.username
};
}
case LOGIN_OUT: {

View File

@ -32,8 +32,8 @@ export default (state = initialState, action) => {
...state,
isLogin: true,
loginState: MEMBER_STATUS,
uid: action.payload.data.uid,
userName: action.payload.data.userName
uid: action.payload.data.data.uid,
userName: action.payload.data.data.username
};
}
case LOGIN_OUT: {