diff --git a/client/App.js b/client/App.js
index 79321f06..903b0e8e 100644
--- a/client/App.js
+++ b/client/App.js
@@ -55,7 +55,6 @@ class App extends Component {
}
componentDidMount() {
- console.log('app.js init')
axios.get('/user/status').then((res) => {
if (res.data.errcode === 0 && res.data.data._id > 0) {
this.setState({
@@ -70,17 +69,13 @@ class App extends Component {
this.setState({
login: GUEST_STATUS
})
- console.log(err.message)
+ console.log(err)
})
}
render() {
- console.log(MEMBER_STATUS)
- console.log(this.route(this.state.login))
return this.route(this.state.login)
-
-
}
}
diff --git a/client/actions/addInterFace.js b/client/actions/addInterFace.js
index 29eeacec..4675fb63 100644
--- a/client/actions/addInterFace.js
+++ b/client/actions/addInterFace.js
@@ -6,7 +6,6 @@ import {
DELETE_INTERFACE_SEQ_HEADER,
GET_INTERFACE_REQ_PARAMS,
GET_INTERFACE_RES_PARAMS,
- // SAVE_INTERFACE_FORMS,
PUSH_INTERFACE_NAME,
PUSH_INTERFACE_METHOD
} from '../constants/action-types.js'
@@ -60,13 +59,6 @@ export function getResParams (value) {
};
}
-// export function saveForms (value) {
-// return {
-// type: SAVE_INTERFACE_FORMS,
-// payload: value
-// };
-// }
-
export function pushInterfaceName (value) {
return {
type: PUSH_INTERFACE_NAME,
@@ -80,5 +72,3 @@ export function pushInterfaceMethod (value) {
payload: value
}
}
-
-
diff --git a/client/actions/addInterface.js b/client/actions/addInterface.js
index 29eeacec..4675fb63 100644
--- a/client/actions/addInterface.js
+++ b/client/actions/addInterface.js
@@ -6,7 +6,6 @@ import {
DELETE_INTERFACE_SEQ_HEADER,
GET_INTERFACE_REQ_PARAMS,
GET_INTERFACE_RES_PARAMS,
- // SAVE_INTERFACE_FORMS,
PUSH_INTERFACE_NAME,
PUSH_INTERFACE_METHOD
} from '../constants/action-types.js'
@@ -60,13 +59,6 @@ export function getResParams (value) {
};
}
-// export function saveForms (value) {
-// return {
-// type: SAVE_INTERFACE_FORMS,
-// payload: value
-// };
-// }
-
export function pushInterfaceName (value) {
return {
type: PUSH_INTERFACE_NAME,
@@ -80,5 +72,3 @@ export function pushInterfaceMethod (value) {
payload: value
}
}
-
-
diff --git a/client/actions/interfaceAction.js b/client/actions/interfaceAction.js
index 7a8e4702..196feff1 100644
--- a/client/actions/interfaceAction.js
+++ b/client/actions/interfaceAction.js
@@ -1,33 +1,11 @@
import {
FETCH_INTERFACE_DATA,
LIST_INTERFACE_CLICK,
- PROJECT_MEMBER_INTERFACE
+ PROJECT_MEMBER_INTERFACE,
+ DELETE_INTERFACE_DATA
} from '../constants/action-types.js'
export function fetchInterfaceData (value) {
- // const data = [{
- // key: '1',
- // name: 'John Brown',
- // age: 32,
- // address: 'New York No. 1 Lake Park',
- // date: '2015-11-11 13:00:15',
- // features: '3'
- // }, {
- // key: '2',
- // name: 'Jim Green',
- // age: 42,
- // address: 'London No. 1 Lake Park',
- // date: '2015-11-11 13:00:15',
- // features: '3'
- // }, {
- // key: '3',
- // name: 'Joe Black',
- // age: 32,
- // address: 'Sidney No. 1 Lake Park',
- // date: '2015-11-11 13:00:15',
- // features: '3'
- // }]
-
return {
type: FETCH_INTERFACE_DATA,
payload: value
@@ -45,3 +23,10 @@ export function closeProjectMember () {
type: PROJECT_MEMBER_INTERFACE
}
}
+
+export function deleteInterfaceData (value) {
+ return {
+ type: DELETE_INTERFACE_DATA,
+ payload: value
+ }
+}
diff --git a/client/app.js b/client/app.js
index 79321f06..903b0e8e 100644
--- a/client/app.js
+++ b/client/app.js
@@ -55,7 +55,6 @@ class App extends Component {
}
componentDidMount() {
- console.log('app.js init')
axios.get('/user/status').then((res) => {
if (res.data.errcode === 0 && res.data.data._id > 0) {
this.setState({
@@ -70,17 +69,13 @@ class App extends Component {
this.setState({
login: GUEST_STATUS
})
- console.log(err.message)
+ console.log(err)
})
}
render() {
- console.log(MEMBER_STATUS)
- console.log(this.route(this.state.login))
return this.route(this.state.login)
-
-
}
}
diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js
index b4350708..d4a6f98f 100644
--- a/client/components/Header/Header.js
+++ b/client/components/Header/Header.js
@@ -43,8 +43,7 @@ class HeaderCom extends Component {
location: PropTypes.object
}
componentDidMount() {
- const { router } = this.props;
- console.log(router);
+ // const { router } = this.props;
}
linkTo = (e) =>{
this.setState({
diff --git a/client/constants/action-types.js b/client/constants/action-types.js
index 1ee684b2..37d4978a 100644
--- a/client/constants/action-types.js
+++ b/client/constants/action-types.js
@@ -3,6 +3,7 @@ export const FETCH_INTERFACE_DATA = 'FETCH_INTERFACE_DATA'
export const LIST_INTERFACE_CLICK = 'LIST_INTERFACE_CLICK'
export const PROJECT_MEMBER_INTERFACE = 'PROJECT_MEMBER_INTERFACE'
export const PUSH_INTERFACE_NAME = 'PUSH_INTERFACE_NAME'
+export const DELETE_INTERFACE_DATA = 'DELETE_INTERFACE_DATA'
// addInterFace
export const FETCH_ADD_INTERFACE_INPUT = 'FETCH_ADD_INTERFACE_INPUT'
@@ -12,7 +13,6 @@ export const ADD_INTERFACE_SEQ_HEADER = 'ADD_INTERFACE_SEQ_HEADER'
export const DELETE_INTERFACE_SEQ_HEADER = 'DELETE_INTERFACE_SEQ_HEADER'
export const GET_INTERFACE_REQ_PARAMS = 'GET_INTERFACE_REQ_PARAMS'
export const GET_INTERFACE_RES_PARAMS = 'GET_INTERFACE_RES_PARAMS'
-// export const SAVE_INTERFACE_FORMS = 'SAVE_INTERFACE_FORMS'
export const PUSH_INTERFACE_METHOD = 'PUSH_INTERFACE_METHOD'
// group
diff --git a/client/containers/AddInterface/AddInterface.js b/client/containers/AddInterface/AddInterface.js
index 604ec438..4e278f53 100644
--- a/client/containers/AddInterface/AddInterface.js
+++ b/client/containers/AddInterface/AddInterface.js
@@ -10,7 +10,14 @@ import ReqHeader from './ReqHeader/ReqHeader.js'
import ReqParams from './ReqParams/ReqParams.js'
import ResParams from './ResParams/ResParams.js'
import Result from './Result/Result.js'
-import { saveForms } from '../../actions/addInterface.js'
+import {
+ saveForms,
+ getResParams,
+ getReqParams,
+ addReqHeader,
+ pushInputValue,
+ pushInterfaceName
+} from '../../actions/addInterface.js'
@connect(
state => {
@@ -19,35 +26,128 @@ import { saveForms } from '../../actions/addInterface.js'
resParams: state.addInterface.resParams,
method: state.addInterface.method,
url: state.addInterface.url,
+ seqGroup: state.addInterface.seqGroup,
interfaceName: state.addInterface.interfaceName
}
},
{
- saveForms
+ saveForms,
+ getReqParams,
+ getResParams,
+ addReqHeader,
+ pushInputValue,
+ pushInterfaceName
}
)
class AddInterface extends Component {
static propTypes = {
+ url: PropTypes.string,
+ method: PropTypes.string,
reqParams: PropTypes.string,
resParams: PropTypes.string,
- method: PropTypes.string,
- url: PropTypes.string,
+ seqGroup: PropTypes.array,
interfaceName: PropTypes.string,
- saveForms: PropTypes.func
+ saveForms: PropTypes.func,
+ addReqHeader: PropTypes.func,
+ getReqParams: PropTypes.func,
+ getResParams: PropTypes.func,
+ pushInputValue: PropTypes.func,
+ pushInterfaceName: PropTypes.func
}
constructor (props) {
super(props)
+ this.state = {
+ isLoading: ''
+ }
+ }
+
+ componentDidMount () {
+ const ifTrue = this.verificationURL()
+ let interfaceId = undefined
+ if (ifTrue) {
+ interfaceId = this.getInterfaceId()
+ this.initInterfaceData(interfaceId)
+ } else {
+ const props = this.props
+ props.pushInputValue('')
+ props.pushInterfaceName('')
+ props.getReqParams('')
+ props.getResParams('')
+ props.addReqHeader([
+ {
+ id: 0,
+ name: '',
+ value: ''
+ }
+ ])
+ }
+ }
+
+ getInterfaceId () {
+ const value = location.hash.match(/\d+/g)
+ return value ? value[0] : ''
+ }
+
+ verificationURL () {
+ const dir = 'AddInterface/edit'
+ const url = location.href
+ if (url.includes(dir)) {
+ return true
+ }
+ }
+
+ editState (data) {
+ const props = this.props
+ const { path, title, req_params_other, res_body, req_headers} = data
+ props.pushInputValue(path)
+ props.pushInterfaceName(title)
+ props.getReqParams(req_params_other)
+ props.getResParams(res_body)
+ props.addReqHeader(req_headers)
+ }
+
+ initInterfaceData (interfaceId) {
+ const params = { id: interfaceId }
+
+ axios.get('/interface/get', {params: params})
+ .then(result => {
+ result = result.data.data
+ result.req_headers.map((value, key) => {
+ value.id = key
+ return value
+ })
+ this.editState(result)
+ })
+ .catch(e => {
+ console.log(e)
+ })
+ }
+
+ setLoading (boolean) {
+ this.setState({
+ isLoading: boolean ? 'is-loading' : ''
+ })
+ }
+
+ routerPage () {
+ const origin = location.origin
+ const pathname = location.pathname
+ location.href = `${origin}${pathname}#/interface`
}
@autobind
saveForms () {
- const { interfaceName, url, reqParams, resParams } = this.props
+ let postURL = undefined
+ const { interfaceName, url, seqGroup, reqParams, resParams } = this.props
+ const ifTrue = this.verificationURL()
+ const interfaceId = this.getInterfaceId()
const params = {
title: interfaceName,
path: url,
method: 'POST',
+ req_headers: seqGroup,
project_id: 558,
req_params_type: 'json',
req_params_other: reqParams,
@@ -55,9 +155,19 @@ class AddInterface extends Component {
res_body: resParams
}
- axios.post('/interface/add', params)
- .then(data => {
- console.log('data', data)
+ if (ifTrue) {
+ params.id = interfaceId
+ postURL = '/interface/up'
+ } else {
+ postURL = '/interface/add'
+ }
+
+ this.setLoading(true)
+
+ axios.post(postURL, params)
+ .then(() => {
+ this.setLoading()
+ this.routerPage()
})
.catch(e => {
console.log(e)
@@ -66,6 +176,7 @@ class AddInterface extends Component {
render () {
const TabPane = Tabs.TabPane
+ const isLoading = this.state.isLoading
return (
URL : | -+ | + + |
---|---|---|
名称 : | -+ | + + |
)|(<\/p>)| |(
)|\s+/g
- const E = wangEditor
- const editor = new E('#req-cover')
editor.customConfig.menus = []
editor.customConfig.onchange = html => {
html = html.replace(reg, '')
- console.log(html)
this.props.getReqParams(html)
}
+ setTimeout(() => {
+ this.initParams()
+ }, 200)
editor.create()
}
diff --git a/client/containers/AddInterface/ResParams/ResParams.js b/client/containers/AddInterface/ResParams/ResParams.js
index 80b69b4c..b27b935d 100644
--- a/client/containers/AddInterface/ResParams/ResParams.js
+++ b/client/containers/AddInterface/ResParams/ResParams.js
@@ -4,6 +4,8 @@ import { connect } from 'react-redux'
import wangEditor from 'wangeditor'
import { getResParams } from '../../../actions/addInterface.js'
+const editor = new wangEditor('#res-cover')
+
@connect(
state => {
return {
@@ -25,15 +27,23 @@ class ResParams extends Component {
super(props)
}
+ initResParams () {
+ const { resParams } = this.props
+ if (resParams) {
+ editor.txt.html(resParams)
+ }
+ }
+
componentDidMount () {
const reg = /(
)|(<\/p>)| |(
)|\s+/g
- const E = wangEditor
- const editor = new E('#res-cover')
editor.customConfig.menus = []
editor.customConfig.onchange = html => {
html = html.replace(reg, '')
this.props.getResParams(html)
}
+ setTimeout(() => {
+ this.initResParams()
+ }, 200)
editor.create()
}
diff --git a/client/containers/Interface/Interface.js b/client/containers/Interface/Interface.js
index 2a823af8..88852848 100644
--- a/client/containers/Interface/Interface.js
+++ b/client/containers/Interface/Interface.js
@@ -6,7 +6,7 @@ import axios from 'axios'
import InterfaceList from './InterfaceList/InterfaceList.js'
import InterfaceTable from './InterfaceTable/InterfaceTable.js'
import InterfaceMode from './InterfaceMode/InterfaceMode.js'
-
+import moment from 'moment'
import {
fetchInterfaceData,
projectMember,
@@ -43,7 +43,6 @@ class Interface extends Component {
componentWillMount () {
// 558 665 704 743
- this.props.fetchInterfaceData()
const params = {
params: {
project_id: 558
@@ -51,8 +50,13 @@ class Interface extends Component {
}
axios.get('/interface/list', params)
- .then(data => {
- console.log(data)
+ .then(result => {
+ result = result.data.data
+ result.map(value => {
+ value.add_time = moment(value.add_time).format('YYYY-MM-DD HH:mm:ss')
+ return value
+ })
+ this.props.fetchInterfaceData(result)
})
.catch(e => {
console.log(e)
@@ -61,7 +65,6 @@ class Interface extends Component {
render () {
const { interfaceData, projectMember, modalVisible } = this.props
-
return (