mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-06 12:45:22 +08:00
feat: 代码优化
This commit is contained in:
parent
abc947df2c
commit
505cceb98c
@ -85,8 +85,7 @@ export default class InterfaceTest extends Component {
|
|||||||
data: {
|
data: {
|
||||||
a:1
|
a:1
|
||||||
},
|
},
|
||||||
success: (res, header) => {
|
success: (res) => {
|
||||||
console.log(header)
|
|
||||||
this.setState({res})
|
this.setState({res})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -24,7 +24,7 @@ class MockUrl extends Component {
|
|||||||
clipboard () {
|
clipboard () {
|
||||||
const btn = document.querySelector('#mock-clipboard')
|
const btn = document.querySelector('#mock-clipboard')
|
||||||
const txt = document.querySelector('#mock-p').innerHTML
|
const txt = document.querySelector('#mock-p').innerHTML
|
||||||
console.log('txt', txt)
|
|
||||||
new Clipboard(btn, {
|
new Clipboard(btn, {
|
||||||
text: () => txt,
|
text: () => txt,
|
||||||
target () {
|
target () {
|
||||||
|
@ -6,7 +6,8 @@ import { autobind } from 'core-decorators'
|
|||||||
import {
|
import {
|
||||||
reqTagValue,
|
reqTagValue,
|
||||||
reqHeaderValue,
|
reqHeaderValue,
|
||||||
deleteReqHeader
|
deleteReqHeader,
|
||||||
|
addReqHeader
|
||||||
} from '../../../actions/addInterface.js'
|
} from '../../../actions/addInterface.js'
|
||||||
|
|
||||||
@connect(
|
@connect(
|
||||||
@ -20,7 +21,8 @@ import {
|
|||||||
{
|
{
|
||||||
reqTagValue,
|
reqTagValue,
|
||||||
reqHeaderValue,
|
reqHeaderValue,
|
||||||
deleteReqHeader
|
deleteReqHeader,
|
||||||
|
addReqHeader
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -30,6 +32,7 @@ class ReqList extends Component {
|
|||||||
reqTagValue: PropTypes.func,
|
reqTagValue: PropTypes.func,
|
||||||
reqHeaderValue: PropTypes.func,
|
reqHeaderValue: PropTypes.func,
|
||||||
deleteReqHeader: PropTypes.func,
|
deleteReqHeader: PropTypes.func,
|
||||||
|
addReqHeader: PropTypes.func,
|
||||||
_id: PropTypes.number,
|
_id: PropTypes.number,
|
||||||
dataNum: PropTypes.number,
|
dataNum: PropTypes.number,
|
||||||
value: PropTypes.object
|
value: PropTypes.object
|
||||||
@ -43,12 +46,20 @@ class ReqList extends Component {
|
|||||||
handleChange (value) {
|
handleChange (value) {
|
||||||
const dir = 'AddInterface/edit'
|
const dir = 'AddInterface/edit'
|
||||||
const url = location.href
|
const url = location.href
|
||||||
|
const newObject = []
|
||||||
|
|
||||||
if (url.includes(dir)) {
|
if (url.includes(dir)) {
|
||||||
const { seqGroup, value: { id } } = this.props
|
const { seqGroup, value: { id } } = this.props
|
||||||
seqGroup[id].name = value
|
seqGroup[id].name = value
|
||||||
|
seqGroup.forEach(v => {
|
||||||
|
const {id, name, value} = v
|
||||||
|
newObject.push({id, name, value})
|
||||||
|
})
|
||||||
|
this.props.addReqHeader( newObject )
|
||||||
} else {
|
} else {
|
||||||
const { seqGroup, dataNum } = this.props
|
const { seqGroup, dataNum } = this.props
|
||||||
seqGroup[dataNum].name = value
|
seqGroup[dataNum].name = value
|
||||||
|
this.props.addReqHeader(Object.create(seqGroup))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +67,13 @@ class ReqList extends Component {
|
|||||||
handleBlur (e) {
|
handleBlur (e) {
|
||||||
const value = e.target.value
|
const value = e.target.value
|
||||||
const { seqGroup, value: { id } } = this.props
|
const { seqGroup, value: { id } } = this.props
|
||||||
|
const newObject = []
|
||||||
seqGroup[id].value = value
|
seqGroup[id].value = value
|
||||||
|
seqGroup.forEach(v => {
|
||||||
|
const {id, name, value} = v
|
||||||
|
newObject.push({id, name, value})
|
||||||
|
})
|
||||||
|
this.props.addReqHeader(newObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
@ -82,7 +99,7 @@ class ReqList extends Component {
|
|||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<em className="title">头部标签</em>
|
<em className="title">头部标签</em>
|
||||||
<Select defaultValue={name} style={{ width: 220 }} onChange={this.handleChange} size="large">
|
<Select value={name} style={{ width: 220 }} onChange={this.handleChange} size="large">
|
||||||
<Option value="">选择请求头</Option>
|
<Option value="">选择请求头</Option>
|
||||||
<Option value="Accept">Accept</Option>
|
<Option value="Accept">Accept</Option>
|
||||||
<Option value="Accept-Charset">Accept-Charset</Option>
|
<Option value="Accept-Charset">Accept-Charset</Option>
|
||||||
|
@ -58,6 +58,7 @@ class ReqMethod extends Component {
|
|||||||
render () {
|
render () {
|
||||||
const { Option } = Select
|
const { Option } = Select
|
||||||
const { url, interfaceName, method } = this.props
|
const { url, interfaceName, method } = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<table>
|
<table>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -65,7 +66,7 @@ class ReqMethod extends Component {
|
|||||||
<th>协议 :</th>
|
<th>协议 :</th>
|
||||||
<td>
|
<td>
|
||||||
<span className="h3">请求方式</span>
|
<span className="h3">请求方式</span>
|
||||||
<Select defaultValue={method} style={{ width: 220 }} onChange={this.handleChange} size="large">
|
<Select value={method} style={{ width: 220 }} onChange={this.handleChange} size="large">
|
||||||
<Option value="POST">POST</Option>
|
<Option value="POST">POST</Option>
|
||||||
<Option value="GET">GET</Option>
|
<Option value="GET">GET</Option>
|
||||||
<Option value="PUT">PUT</Option>
|
<Option value="PUT">PUT</Option>
|
||||||
|
@ -27,7 +27,7 @@ class Result extends Component {
|
|||||||
render () {
|
render () {
|
||||||
const TabPane = Tabs.TabPane
|
const TabPane = Tabs.TabPane
|
||||||
const { mockJson } = this.props
|
const { mockJson } = this.props
|
||||||
console.log('mockJson', typeof mockJson, mockJson)
|
|
||||||
return (
|
return (
|
||||||
<div className="result">
|
<div className="result">
|
||||||
<Tabs defaultActiveKey="1">
|
<Tabs defaultActiveKey="1">
|
||||||
|
@ -58,7 +58,7 @@ class Interface extends Component {
|
|||||||
.then(result => {
|
.then(result => {
|
||||||
result = result.data.data
|
result = result.data.data
|
||||||
result.map(value => {
|
result.map(value => {
|
||||||
value.add_time = moment(value.add_time).format('YYYY-MM-DD HH:mm:ss')
|
value.add_time = moment(value.add_time*1000).format('YYYY-MM-DD HH:mm:ss')
|
||||||
return value
|
return value
|
||||||
})
|
})
|
||||||
this.props.fetchInterfaceData(result)
|
this.props.fetchInterfaceData(result)
|
||||||
|
@ -81,7 +81,6 @@ class InterfaceTable extends Component {
|
|||||||
title: '功能',
|
title: '功能',
|
||||||
'key': 'action',
|
'key': 'action',
|
||||||
render: (data) => {
|
render: (data) => {
|
||||||
// const deleteInterface = this.deleteInterface.bind(this, data._id)
|
|
||||||
const confirm = this.confirm.bind(this, data._id)
|
const confirm = this.confirm.bind(this, data._id)
|
||||||
return (
|
return (
|
||||||
<span>
|
<span>
|
||||||
|
Loading…
Reference in New Issue
Block a user