| | |
| | | import React, {Component} from 'react' |
| | | import { fromJS } from 'immutable' |
| | | import md5 from 'md5' |
| | | import { Input, Select, Button, Tabs, Radio, Modal } from 'antd' |
| | | import { Input, Select, Button, Tabs, Radio, Modal, Spin } from 'antd' |
| | | |
| | | import Api from '@/views/interface/api' |
| | | import Utils from '@/utils/utils.js' |
| | |
| | | active: 'raw', |
| | | body: null, |
| | | response: null, |
| | | status: '' |
| | | status: '', |
| | | loading: false |
| | | } |
| | | |
| | | UNSAFE_componentWillMount() { |
| | |
| | | if (config.raw) { |
| | | try { |
| | | raws = JSON.parse(config.raw) |
| | | } catch { |
| | | } catch (e) { |
| | | Modal.error({ |
| | | title: '参数格式错误,必须为JSON格式!' |
| | | }) |
| | |
| | | n = JSON.stringify(n) |
| | | } |
| | | |
| | | this.setState({loading: true}) |
| | | |
| | | if (/logon/ig.test(url)) { |
| | | Api.dologon(url, config.method, header, n).then(res => { |
| | | this.handleResponse(res) |
| | |
| | | |
| | | body = body.replace(/\n/ig, '<br/>') |
| | | body = body.replace(/\s/ig, ' ') |
| | | } catch { |
| | | } catch (e) { |
| | | body = null |
| | | } |
| | | } |
| | |
| | | body = `请求异常${status === 'Network Error' ? ',可能原因:1、网络异常;2、接口跨域。' : '!'}` |
| | | } |
| | | |
| | | this.setState({response: res, body, status}) |
| | | this.setState({response: res, body, status, loading: false}) |
| | | } |
| | | |
| | | encryptParam (param) { |
| | |
| | | let keys = Object.keys(param).sort() |
| | | let values = '' |
| | | keys.forEach(key => { |
| | | if (key.toLowerCase() === 'rduri' || key.toLowerCase() === 't') return |
| | | if (param[key] === undefined) { |
| | | if (key.toLowerCase() === 'rduri') return |
| | | if (key.toLowerCase() === 't' || key.toLowerCase() === 'sign' || param[key] === undefined) { |
| | | delete param[key] |
| | | } else if (typeof(param[key]) === 'object') { |
| | | return |
| | | } |
| | | |
| | | if (typeof(param[key]) === 'object') { |
| | | values += key + JSON.stringify(param[key]) |
| | | } else { |
| | | if (param[key] && /: =$/.test(param[key])) { |
| | | param[key] = param[key].replace(/: =$/, '==') |
| | | } |
| | | values += key + param[key] |
| | | } |
| | | }) |
| | |
| | | } |
| | | |
| | | render () { |
| | | const { active, config, response, body, status } = this.state |
| | | const { active, config, response, body, status, loading } = this.state |
| | | |
| | | let hasParam = config.params.filter(item => item.selected && item.key).length > 0 |
| | | let hasHeader = config.headers.filter(item => item.selected && item.key).length |
| | |
| | | <Button type="primary" onClick={this.send}>Send</Button> |
| | | <Button onClick={this.save}>Save</Button> |
| | | </div> |
| | | <Tabs animated={false}> |
| | | <Tabs animated={false} defaultActiveKey={hasBody ? 'Body' : 'Params'}> |
| | | <Tabs.TabPane forceRender={true} tab={<span className={hasParam ? 'active' : ''}>Params</span>} key="Params"> |
| | | <EditTable data={config.params} onChange={this.changeParams}/> |
| | | </Tabs.TabPane> |
| | |
| | | <div className="response"> |
| | | {response ? <div className="header"> |
| | | {body ? 'Body' : 'Response'} |
| | | {status ? <span className="status">Status: <span className={status === '200OK' ? 'green' : ''}>{status}</span></span> : null} |
| | | {status ? <span className="status">Status: <span className={status === '200OK' ? 'green' : 'yellow'}>{status}</span></span> : null} |
| | | </div> : <div className="header"> |
| | | Response |
| | | <span className="empty">Hit the Send button to get a response.</span> |
| | | </div>} |
| | | <div style={{paddingLeft: '3px', paddingTop: '3px'}} dangerouslySetInnerHTML={{__html: body}}></div> |
| | | {loading ? <div className="pending"><Spin size="large"/></div> : null} |
| | | </div> |
| | | </div> |
| | | ) |